Monday, January 28, 2008

DTraceing Apache Tomcat Server

Dtrace Support as been added to Java SE 6 Hotspot VM . The hotspot and hotspot_jni provider are used to probe the JVM internal states as well as java application. Since Apache Tomcat server is a java application, we can use hotspot provider to analysis the Tomcat server as well as the web application it is running.

To use DTrace with Tomcat server do the following step.

1 . Start the Apache Tomcat server.

bash-3.00$ startup.sh

Using CATALINA_BASE: /opt/apache-tomcat-6.0.14

Using CATALINA_HOME: /opt/apache-tomcat-6.0.14

Using CATALINA_TMPDIR: /opt/apache-tomcat-6.0.14/temp

Using JRE_HOME: /usr/jdk/instances/jdk1.6

2. Find the process id(PID) of the tomcat server and use the following the command

    bash-3.00$ jinfo -flag +ExtendedDTraceProbes XXXX

    

    in the place of XXXX use the PID of the tomcat server.

This command is used to enable the method-entry and method-return probe.

3. u are done. Run the dtrace script.

    Example

    #!/usr/sbin/dtrace -qs

dtrace:::BEGIN

{

        printf("Tracing... Hit Ctrl-C to end.\n");

}    


 

hotspot*:::method-entry

{

        self->indent++;

        printf("%*s %s %s.%s\n",self->indent,"","->", stringof(copyin(arg1, arg2)), stringof(copyin(arg3, arg4)));

        this->class = (char *) copyin(arg1, arg2 + 1);

        this->class[arg2] = '\0';

        this->method = (char *) copyin(arg3, arg4 + 1);

        this->class[arg4] = '\0';

        @calls[stringof(this->class), stringof(this->method)] = count();

}


 

hotspot*:::method-return

{

        printf("%*s %s %s.%s\n", self->indent, "", "<-", stringof(copyin(arg1, arg2)), stringof(copyin(arg3, arg4)));

        self->indent--;

}


 

dtrace:::END

{

        printa("%48s.%-24s %@4d\n",@calls);

}

    


 

No comments: