EventPlace (Function<? super Throwable, ? extends StackTraceElement> function) { // Use async stack trace processing to reduce overhead. // Both plain Throwable#getStackTrace and StackWalker API are slower. Throwable throwable = new Throwable(); return new EventPlace() { @Override public StackTraceElement getStackFrame() { return function.apply(throwable); } @Override public StackTraceElement @Nullable [] getStackTrace() { return throwable.getStackTrace(); } }; }