Java Profiling with MonkeyWrench
The MonkeyWrench Thread profiling screen displays, for each active thread, the following data:
- Thread ID
- Thread Name
- Thread state
- % of total CPU time (of all active threads)
- Total CPU time consumed by the thread
- CPU time consumed by the thread in the display interval
- Total times thread has blocked
- Number of times thread has blocked during the display interval
- Total time thread has spent blocked
- Time thread has spent blocked during the display interval
As with the other screens in the MonkeyWrench, all columns in the table are sortable, descending or ascending. In practice, you will usually sort on either the “% of Total CPU Time” or the “CPU Time In Window” columns, descending, showing you the most active threads either in general or for the current sampling interval (which you set in the Configuration screen when you started Thread profiling).
The bottom half of this screen displays a table of blocked and deadlocked threads. Because the MonkeyWrench has a significant impact on the application being profiled, many times a thread will block on a lock held by a MonkeyWrench thread (for example, the ThreadStatisticsUpdater), and vice‐versa. These blocks would not occur if the MonkeyWrench were not profiling your application, of course. For this reason, a checkbox (labeled “Ignore Profiler‐Caused Blocks”) is available; check this box and the MonkeyWrench will not display any blocks where a MonkeyWrench‐specific thread is either blocking or being blocked. In the example, we have left the box unchecked because there are no jEdit‐caused blocks, and we want to show examples of the data displayed in this table.
Figure 7 -- Threads Screen
The Blocked and Deadlocked Threads table displays the following data for each block:
- ID of blocked thread
- Name of blocked thread
- Boolean, true if the thread is deadlocked
- The lock name
- ID of the thread holding the lock
- Name of the thread holding the lock
In cases where a particular block occurs frequently, it is helpful to know the path taken by one of the threads. Selecting a entry in this table produces a window with the stack trace for that particular occurrence. Figure 8 is an example of one of the block events found when the threads were inspected.
Figure 8 -- Blocked Thread Stack Trace View
Note from Figure 7 that all of the MonkeyWrench‐caused blocks have the same lock – an instance of a com.gorillalogic.profiler.GorillaProfiler. This is the MonkeyWrench main profiler class. Since this is the class that every instrumented method in the target application calls to notify of method entries and exits, it’s a frequent object of contention. Of course this is only true during profiling, which is why the Threads screen provides the checkbox to suppress display of these contention events.
As with the other MonkeyWrench screens, the Threads screen provides buttons to clear Thread profiling data, as well as all profiling data. Additionally, it provides a button to clear the history of blocked and deadlocked threads.
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)