Search code examples
javaprofilingprofiler

Why is JVM Monitor showing the wrong invocation count?


By logging a static variable I can see that I call my function belongsInResults() 14,000 times in my test run, but JVM Monitor's "invocation count" reads only 215. This function is only called in one place. Here's JVM's call tree report, with belongsInResults() at the bottom:

Image of call tree report:

I produced this by setting a breakpoint in my unit test just before the call to mergePrefixes and another one just after, and starting and stopping the profiling there.

I'm also curious why "self time" does not add up to 100%.


Solution

  • There are two ways profilers can work: - adding code do every method (instrumentation) - doing a thread dump in fixed intervals (sampling)

    Only first can provide accurate invocation counts, but has much higher overhead