We use interceptors to measure the execution time of a bean’s public method invocation. nonetheless, when a bean’s method invoke other private methods, it seems to ignore the audit interceptor.
How can we measure the execution time of private methods as well?
Using AOP
You could implement a benchmarker using an Aspect-Oriented Programming library like AspectJ.
For instance, see:
Using a Profiler
Using JVMTI
Which is what some profilers do, actually.
You could resort to using the JVMTI API (not entirely sure this would fly, to be honest) to implement your own code inspector and directly hook yourself into the JVM.
The Sneaky and Evil Inlining Issue
Regarding jb’s (valid) concern in his answer that private methods might be inlined at either compilation time or runtime, some JVMs may not do it or allow to disable this feature.
-XnoOptoption that would disable optimizations (including this particular one).-XX:-Inline(not sure it still exists or does anything).However, it means you don’t measure exactly what you’d have in production when the inlining is activated. Still, probably handy for inspecting your code.