Java Reference
In-Depth Information
Sampling Profilers
Profiling happens in one of two modes: sampling mode or instrumented mode. Sampling
mode is the basic mode of profiling and carries the least amount of overhead. That's import-
ant, since one of the pitfalls of profiling is that by introducing measurement into the applica-
tion, you are altering its performance characteristics. (Still, you must profile: how else will
you know if the cat inside your program is still alive?) Limiting the impact of profiling will
lead to results that more closely model how the application behaves under usual circum-
stances.
Unfortunately, sampling profilers can be subject to all sorts of errors. Sampling profilers
work when a timer periodically fires; the profiler then looks at each thread and determines
which method the thread is executing. That method is then charged with having been ex-
ecuted since the timer previously fired.
The most common sampling error is illustrated by Figure 3-1 . The thread here is alternating
between executing methodA (shown in the shaded bars) and methodB (shown in the clear
bars). If the timer fires only when the thread happens to be in methodB , the profile will report
that the thread spent all its time executing methodB ; in reality, more time was actually spent
in methodA .
Figure 3-1. Alternate method execution
This is the most common sampling error, but it is by no means the only one. The way to min-
imize these errors is to profile over a longer period of time, and to reduce the time interval
between samples. Reducing the interval between samples is counter-productive to the goal of
minimizing the impact of profiling on the application; there is a balance here. Profiling tools
Search WWH ::




Custom Search