fast way to infer caller
Ceki Gülcü
ceki at qos.ch
Wed Apr 6 15:30:51 UTC 2022
Hello,
As you are probably aware, one of the important primitives used in
logging libraries is inferring the caller of a given logging statement.
The current common practice is to create a throwable and process its
stack trace. This is rather wasteful and rather slow. As an alternative,
I have tried using the StackWalker API to infer the caller but was
unsatisfied with the performance.
MethodHandles.lookup().lookupClass() looks very promising except that
there is no way to specify the depth.
I am looking for a method to obtain the Nth caller at a cost of around
100 to 200 nanoseconds of CPU time. Do you think the JDK could cater
for this use case?
--
Ceki Gülcü
Sponsoring SLF4J/logback/reload4j at https://github.com/sponsors/qos-ch
More information about the core-libs-dev
mailing list