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

Blog::Navigation

GetJava Download Button
Get the Source
Personal Blog

Blog::Referers

Today's Page Hits: 50

Powered by Roller Weblogger.
« Observability highli... | Main | Sun Tech Days 2006 @... »
20060112 Thursday January 12, 2006

Running Java observability tools on "events"

Java serviceability, observability tools such as jstack, jmap, jstat are run asynchronously. i.e., these tools can be "attached" to running Java program at any time (without requiring any VM event). But sometimes, you may want to run these tools on specific "event(s)". For example, you can use -XX:OnError flag to run any of these tools at the time of fatal error exit. For example, you can create heapdump on exit using jmap -F -dump command. What about other events such as gc begin/end, class load/unload, thread start/stop etc?

Mustang (Java SE 6) supports many built-in probes for DTrace. These may be used to dynamically trace JVM and your Java programs. DTrace supports system action that can be used to run arbitrary program from D-script. If you use system action along with JVM built-in probes, then you can run any of the Java serviceability tools such as jstack, jmap based on specific "event(s)". For example, you can write a D-script that triggers java heapdump after 100'th GC event occurs.

Sample D-script: test.d

int cnt;

BEGIN {
    cnt = 0; /* initialize count */
}

hotspot1274:::gc_begin  
{
   cnt++;
}

hotspot1274:::gc-begin 
 / cnt == 100 / 
{
    /* create java heap dump */
    system("jmap -dump:format=b,file=heap.bin 1274"); 
}



where 1274 is pid of your java process. Heap dump is created in "heap.bin" file after 100'th GC event. More complex "events" are possible with different DTrace probe and predicate combinations. Note that the system action is a destructive DTrace action -- this means you have to run DTrace with -w option to enable it. I ran the above script with the following command line:

/usr/sbin/dtrace -s test.d -w 

More examples of running Java Serviceability tools on "events":



( Jan 12 2006, 05:35:11 PM IST ) Permalink Comments [1] del.icio.us | furl | simpy | slashdot | technorati | digg

Comments:

I don't know a whole lot about using dtrace, but I assume you can parameterise the script with 1274 both in the system call and the probe match line?

Posted by Ken Horn on January 12, 2006 at 08:08 PM IST #

Post a Comment:

Comments are closed for this entry.
Copyright (C) 2005, A. Sundararajan's Weblog