Check out the new USENIX Web site. next up previous
Next: Thread-Aware CPU Time Sampling Up: Design Choices Previous: Granularity

Statistical Sampling vs. Code Instrumentation

There are two ways to obtain profiling information: either statistical sampling or code instrumentation. Statistical sampling is less disruptive to program execution, but cannot provide completely accurate information. Code instrumentation, on the other hand, may be more disruptive, but allows the profiler to record all the events it is interested in. Specifically in CPU time profiling, statistical sampling may reveal, for example, the relative percentage of time spent in frequently-called methods, whereas code instrumentation can report the exact number of time each method is invoked.

Our framework supports both statistical sampling and code instrumentation. Through the JVMPI, the profiler agent can periodically sample the stack of all running threads, thus discovering the most frequently active stack traces. Alternatively, the profiler agent may ask the virtual machine to send events on entering and exiting methods. Naturally the latter approach introduces additional C function call overhead to each profiled method.

A less disruptive way to implement code instrumentation is to inject profiling code directly into the profiled program. This type of code instrumentation is easier on the Java platform than on traditional CPUs, because there is a standard class file format. The JVMPI allows the profiler agent to instrument every class file before it is loaded by the virtual machine. The profiler agent may, for example, insert custom byte code sequence that records method invocations, control flow among the basic blocks, or other operations (such as object creation or monitor operations) performed inside the method body. When the profiler agent changes the content of a class file, it must ensure that the resulting class file is still valid according to the Java virtual machine specification.

next up previous
Next: Thread-Aware CPU Time Sampling Up: Design Choices Previous: Granularity
Sheng Liang