Angelo's Soapbox

Tuesday May 22, 2007

DTrace meets the AMP (Apache MySQL PHP) stack

During JavaOne this year Rags and I did a hands on lab on DTrace. The topic was "Using DTrace on Java and other Web 2.0 Languages in Solaris". Due to some unforeseen reason the lab was scheduled from 8:45 PM to 10:45 PM (Yes PM) and that to on the day of the big party at JavaOne. So I was expecting to be speaking to an empty room but lo and behold we had close to 100 engineers ( a few pretty drunk) and most stayed until the finished the lab.It was pretty heartening and was worth all the efforts that went into it.

One of the highlights of the lab was a script that we developed. It lists the JavaScript & PHP function entry and MySQL SQLs that happen live system. You need the following prerequisite for the script to be fully functional.

Here is the script. It takes one argument - the pid of the mysqld process in your system.

#!/usr/sbin/dtrace -ZqFs
/* We use terminal escape sequence to change color
 * Javascript - Red
 * PHP - Blue
 * MYSQL - Green
 */
 
trace_mozilla*:::js_function-entry
{
        printf("\033[01;31m%s\033[0m\n",copyinstr(arg2));
}

trace_mozilla*:::js_function-return
{
        printf("\033[01;31m%s\033[0m\n",copyinstr(arg2));
}

php*:::function-entry
/arg0/
{
        printf("\033[01;34m%s\033[0m\n",copyinstr(arg0));
}

php*:::function-return
/arg0/
{
        printf("\033[01;34m%s\033[0m\n",copyinstr(arg0));
}

pid$1::_Z16dispatch_command19enum_server_commandP3THDPcj:*
{
        self->sql = copyinstr(arg2);
        printf("\033[01;32m%s\033[0m\n",self->sql);
}

 You will see a nice color coded output. Javascript calls in Red, PHP in Blue and MySQL in green.

In subsequent blogs I try and go through the process of developing this code. Meanwhile enjoy Solaris DTrace

Comments:

Even better would be to use PostgreSQL, since it has DTrace probes. See http://www.postgresql.org/docs/8.2/interactive/dynamic-trace.html for docs.

Posted by Derek Morr on May 22, 2007 at 02:55 PM EST #

Post a Comment:
Comments are closed for this entry.

Archives
Links
Referrers