It's been said in other questions that jvisualvm sampling works as a "lightweight" profiling tool by calculating metrics directly from Java stack frames.

Its almost unanimously agreed that such a technique is faster but not as accurate in terms of its "timings". My question: why is this method not as accurate? And, what is it not as accurate as (as opposed to what? Are there more precise profiling techniques?)?

  • 1
    When the goal is to find speedup opportunities (as opposed to just general measurements) it's a mistake to assume that accuracy of timing and metrics are important. More on that. Feb 6, 2012 at 22:51
  • It's like a doctor looking for a tumor in a CT scan. He doesn't find it by measuring. He finds it by looking. Then he can measure it if he wants to. Feb 10, 2012 at 18:13

1 Answer 1


There are a few factors I am aware of:

  1. Look at the javadoc of System.currentTimeMillis() and note what it says about the Operating System granularity. For even more fun, look at the source code of that method and see how it rounds to a millisecond. A similar rule applies for Java's nanosecond support, look at the source code to see how it is actually used and you might be surprised.

  2. There are still gaps where there are no Java APIs to measure certain things, e.g. Clock counters on a CPU (which we're working on with jpcm) and APIs into the running GC itself.

HTH a little.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.