



Because the instrumentation introduced by the profiler, some small methods might not be eligible to be inlined anymore. Another problem which may arise as a result of the way an instrumented profiler modifies the bytecode is the following as you may know, JIT compiler inlines small methods. This approach involves a higher performance impact, but generates a more accurate measurement when compared to the result from the sampling profiler. This method usually involves injecting bytecode into the classes for the purpose of profiling. Instrumented profilers introduce a much larger performance overhead into the application. However, as we discussed earlier, this solution might impact the performance characteristics of the application, so a balance is the key. If the sampling happens only when the thread is in a save method (more probable as this method dominates), the profiler will report that the thread spent 100% of its time in save method, which is of course not accurate.Ī rather logical way to minimize this sampling error is to reduce the time interval between sampling and increase the profiling time. As there are gaps between consecutive measurements, sampling profiler achieves a trade-off between the level of accuracy obtained vs the overhead involved in actually taking the measurement, This is illustrated in the following figure:Īs you can see, the thread spent most of its time in save method and a little bit in read method. So the profiler looks at each thread and determines which method the thread is executing at that moment. Using a sampling technique, we get a snapshot of the next stack trace when the timer fires. This is important because introducing heavy measurement into the application can change the performance characteristics significantly. This type of profiler carries the least amount of overhead. Sampling ProfilersĪ sampling profiler involves periodically asking the JVM for the current point of execution of all currently alive threads. There are two basic techniques used by profilers – sampling and instrumentation. But do you know which profiler you should use? If you ever had some serious issues with a performance of your Java application, most probably you know how valuable thread profiling can be.
