As promised in the blog entry before this one, I’m going to show how to easily add a new tab for visualizing lock instances. This can be done more elegantly in 4.1, so I will post an update to this once 4.1 is out the door.
This is roughly what we need to do:
- Start JRMC in design mode.
- Add a new tab.
- Edit the new tab to add a histogram of all the locking events grouped by lock instance, and a trace tree slaved to that histogram, showing the traces for all the events of a selected lock instance.
- Optionally export the tab to a plug-in that can be shared with colleagues.
Starting with #1, we need to start JRMC in design mode. This can be done by providing the parameter –designer to the jrmc launcher.
On windows you can simply provide a shortcut to JRMC and add –designer to the target:
The designer parameter will make available an additional view in JRMC which controls switching between design and run mode in Mission Control.
Next start up Mission Control, and open up a recording you know contains some Java Blocking events. Next open up the designer view, by clicking Window | Show View | Designer View, as shown below. This view will only be available if you started Mission Control with –designer.
I like to have the Designer View to the left, but feel free to drag-and-drop it to dock the view wherever you find is most convenient.
Now, to change the structure of the tabs, such as adding a new tab, you actually need to close the recording. This will show the structure of the tabs in the Designer View. Click on the CPU/Threads tab group, and select New | New Tab.
Fill out the information about the new tab:
Feel free to add a nice icon. Once the information is filled out, press OK and load the recording again. You should now have an empty Lock Instances tab available.
Press the stop button in the Designer View to enter design mode. First thing we need to do is to choose how to layout the component. Right click the surface and select Vertical Split:
Add a histogram to the top half, by right clicking the top half and selecting Assign Component | Histogram | Event Histogram. In the dialog that appears, do the following changes:
- Change the Name to “Lock Instances”
- Change General | Role to Master
- Change General | Pie chart position to East
- In Columns, click the Browse button, then Browse again. Select the Java Blocked event type.
- Next click Add to add the columns to show.
- Add the Monitor Address attribute.
- Add the Duration field, and change the name to Count, the description to “The event count”. Change the Aggregate Function to Count. Also change the Content Type to Count. Click Pie Chart, and Sorted.
- In Group By, click Browse and select the Monitor Address attribute.
Click the play button to see your new histogram in action:
To add the trace tree, press stop to enter design view. Right click the bottom space and select Assign Component | Tree | Trace Tree. In the dialog that opens, modify:
- Change General | Role to Slave
- Set Expanded Tree Depth to 0
- In Columns click Browse and then Browse again in the next dialog. Select the Java Blocked event type.
- Click add to add the Duration attribute. Select Count as Aggregate Function and Count as Content Type. Click the sorted checkbox.
- In Group By, click Browse and select the Stacktrace attribute.
Press play to show the ready made tab ( don’t forget to select a Lock instance in the master histogram):
Last but not least, export the tab to a plug-in that you can share. First close the recording to see the tab structure again. Next right click on the Flight Recording root node. Select Export UI to Plug-in. In the dialog that follows, select only the Lock Instances tab. Press OK. You will now be presented with a dialog where the plug-in name and version can be changed. Once you are happy with the settings, click OK. Next select a place to save the plug-in. Once you’ve chosen a memorable spot, press OK.
The resulting .jar file can be used by anyone simply by placing it in the missioncontrol/plugins folder.
Tip: To add a Range Selector at the top, look at how the other tabs are configured in design mode.