Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?)?

share|improve this question
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. –  Mike Dunlavey Feb 6 '12 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. –  Mike Dunlavey Feb 10 '12 at 18:13

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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