Tom Erickson's Weblog

Tom Erickson's Weblog

All | General

20071016 Tuesday October 16, 2007

 Chime In Your App

Several people have asked me if there is a way to drop a Chime display into their own application. For example, a Chime plugin for Netbeans might be nice (code, anyone?). It's not hard to drop a Chime display into any Java app. For those who want to try, here's an example:

TestChime.java [ view]

To compile and run the example (on Solaris Nevada build 35 or later), first install Chime, then enter the following commands (syscall.xml comes installed with Chime, although you can specify any valid display description):

; javac -cp /opt/OSOL0chime/lib/java/chime.jar:/usr/share/lib/java/dtrace.jar  \
TestChime.java
; java -cp .:/opt/OSOL0chime/lib/java/chime.jar:/usr/share/lib/java/dtrace.jar \
TestChime /opt/OSOL0chime/displays/syscall.xml

TestChime app

Voila! This test app creates its own frame and drops a Chime display into it. Here is the significant code that generates the display and adds it to panel p:

    DisplayDescription d = AggregationDisplay.getDescriptionFromFile(file);
    try {
        AggregationDisplay.prepareDescription(d);
    } catch (Exception e) {
        e.printStackTrace();
    }

    Command c = AggregationDisplay.createCommand(d);
    final AggregationDisplay display = new AggregationDisplay(c, d);
    p.add(display.getDisplay(), BorderLayout.CENTER);
    AbstractDisplay.startDisplay(display);

As in the example, you can provide your own controls that are more suitable for your app than the "Pause" button and "Interval in seconds" spinner that appear at the bottom of a Chime display. Here are the AggregationDisplay instance methods to do that:

    setPaused(boolean paused)
    boolean isPaused()
    setIntervalMillis(long millis)
    long getIntervalMillis()
    java.util.List <JMenuItem> menuItems()

The last method supplies the items for Chime's right-click popup menu. Chime interprets a null list element as a menu item separator, so your code needs to handle null list elements. From each JMenuItem, you can call getAction() to supply the action for the control you want to provide and getName() to label that control. Anything beyond that you can figure out from the Chime source code, starting with StatLauncher.java (which implements all of Chime's command-line options).

Many of Chime's menu items invoke actions that run in a new window. For example, drilldown displays, plots over time, and Chime's DTrace program viewer all run in a new window. Chime also prompts for DTrace macro arguments in a dialog box:

Chime macro arguments prompt

Currently (as of Chime version 1.4.29), if you need these features to run within your application frame, there is no easy way to do it: you will need to work with the Chime source code. If you do, please share your work to help the Chime project!

( Oct 16 2007, 09:33:02 PM PDT / Oct 16 2007, 09:33:02 PM PDT ) Permalink
Trackback: http://blogs.sun.com/tomee/entry/chime_in_your_app

20071009 Tuesday October 09, 2007

 Chime Sparklines

Continuing in the same vein as my previous blog entry, Chime Non-Repeating Keys, I've added another option for generating Chime displays on the command line.

    [-k add a sparkline to the first plottable data column]

Chime has had the ability to display sparklines since its initial OpenSolaris release, as demonstrated by the System Calls display that comes installed with Chime:

System Calls sparklines

The History column provides a view of the System Calls Per Second data over time. It scales from zero to max for each executable. Because the series uses a different vertical scale for each plot it cannot be compared visually as one might expect. If the same vertical scale was used for all executables, the plots would flatten out such that individual variation would no longer be visible. Instead, relative vertical scale is indicated by the cyan line, which is positioned farther to the right the higher the maximum value of the aggregation key. If you click on the History column header, it will sort the column in descending order by maximum value (cyan indicators farthest to the right will move to the top of the table).

The tooltip displays
  1. how much time has elapsed since the first non-zero data was plotted
  2. the maximum value defining the vertical scale of the plot
The tooltip 21 seconds: min 0 .. max 11,814 appeared when resting the mouse pointer (not shown) over the Xorg sparkline; a similar tooltip will appear as the mouse pointer moves across other sparklines.

To generate such a display directly from the command line:

% /opt/OSOL0chime/bin/chime -kTn 'syscall:::entry { @[execname] = count(); }'

Chime sparklines generated with -k option

The -k option adds the History column displaying the values from the @ aggregation over time. The -T option adds a total row. To change the labels in the title bar and column headers to match the System Calls display, enter the following command instead:

% /opt/OSOL0chime/bin/chime -kTn 'syscall:::entry \
{ @[execname] = count(); }' -t "System Calls" \
-h "Executable, History, System Calls Per Second"

To add thousands separators and change total units from "keys" to "executables", you will need to set properties in the wizard. Add -w to the previous command to save the display, then reopen it in the wizard with -W:

% /opt/OSOL0chime/bin/chime -kTn 'syscall:::entry \
{ @[execname] = count(); }' -t "System Calls" \
-h "Executable, History, System Calls Per Second" -w
Wrote /opt/OSOL0chime/displays/new/system_calls.xml
To run, enter "/opt/OSOL0chime/bin/chime -C /opt/OSOL0chime/displays/new/system_calls.xml".
% /opt/OSOL0chime/bin/chime -C \ 
/opt/OSOL0chime/displays/new/system_calls.xml -W

Chime wizard

Click Next until you reach step 4. Specify Columns.

Chime wizard, step 4. Specify Columns

Select the "Executable" column and click the Specify >> button to replace "keys" with "executables". Next, select the "System Calls Per Second" column and click the Specify >> button. Check the Value Per Second check box and select #,##0 from the Format list to request thousands separators. Click Next until you reach step 5. Test Run the Display, then click the Run Display button:

New System Calls Test Run

Close the display and click the Finish button. The next time you run Chime without any options, the finished "System Calls" display will be selectable from the "New Displays" Trace Group in the main window.

Sparklines in Chime rely on a custom renderer that you can get from the Chime source code (see src/org/opensolaris/chime/swingx/SparkLineRenderer.java). Chime uses JFreeChart to provide larger plots of selected values. For example, in the display just created, select Xorg, Java, and mixer_applet2 by holding down the Ctrl key while left-clicking the desired values in the table.

Multiple row selection

If values are moving targets because the current sort keeps changing the row under the mouse pointer, click the Pause button first (the button label will change to Resume; click the button again when you're ready). Right click anywhere on the selection to bring up the popup menu and select Plot Over Time:

Multiple row selection

Values already accumulated in the selected sparklines are displayed in the line graph that appears. The plot accumulates new data (scrolling to the left) after the initial capture as long as the original table remains open.

( Oct 09 2007, 10:35:10 PM PDT / Oct 09 2007, 10:35:10 PM PDT ) Permalink
Trackback: http://blogs.sun.com/tomee/entry/chime_sparklines


« October 2007 »
SunMonTueWedThuFriSat
 
1
2
3
4
5
6
7
8
10
11
12
13
14
15
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
   
       
Today


XML






Today's Page Hits: 18