Method Calls
The main focus of most profiling tools is to provide a profile of method calls. This gives you a good idea of where the bottlenecks in your code are and is probably the most important way to pinpoint where to target your efforts. By showing which methods and lines take the most time, a good profiling tool can save you time and effort in locating bottlenecks.
Most method profilers work by sampling the call stack at regular
intervals and recording the methods on the stack.[8] This
regular snapshot identifies the method currently being executed (the
method at the top of the stack) and all the methods below, to the
program’s entry point. By accumulating the number of hits on
each method, the resulting profile usually identifies where the
program is spending most of its time. This profiling technique
assumes that the sampled methods are representative, i.e., if 10% of
stacks sampled show method foo( )
at the top of
the stack, then the assumption is that method foo()
takes 10% of the running time. However, this is a
sampling
technique
, and so it is not
foolproof: methods can be missed altogether or have their weighting
misrecorded if some of their execution calls are missed. But usually
only the shortest tests are skewed. Any reasonably long test (i.e.,
over seconds, rather than milliseconds) will normally give correct
results.
Warning
This sampling technique can be difficult to get right. It is not enough to simply sample the stack. The profiler must also ensure that it ...
Get Java Performance Tuning now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.