DTrace: observing PHP

I’ve finally got some spare time to download a PEAR module for DTrace. What a great module! I’ve found a little problem with it, wrote a letter to Wez Furlong, and he immediately changed the source code to make it work even better. Thanks a lot, Wez! ūüôā

So, here it is – my first PHP Dtrace script: php-scripts-snoop.d


#!/usr/sbin/dtrace -s
#pragma D option quiet
:dtrace.so::function-entry
/ copyinstr(arg0) == "" /
{
printf("%d -> %-30sn", pid, copyinstr(arg1));}
:dtrace.so::function-return
/ copyinstr(arg0) == "" /
{
printf("%d <- %-30sn", pid, copyinstr(arg1));
}

So go ahead, download the script, do

solaris# chmod a+x ./php-scripts-snoop.d

for it, and after you start it in a terminal of your web-server, you can run PHP scripts from this server, and our DTrace script will be reporting us whenever each PHP script stars or finishes, specifying which Apache process is responsible for this:

solaris# ./php-scripts-snoop.d
204934 -> /export/www/pma/index.php
204934 <- /export/www/pma/index.php
204934 -> /export/www/pma/css/phpmyadmin.css.php
204934 <- /export/www/pma/css/phpmyadmin.css.php
204936 -> /export/www/pma/left.php
204934 -> /export/www/pma/queryframe.php
204936 <- /export/www/pma/left.php
204936 -> /export/www/pma/main.php
204934 <- /export/www/pma/queryframe.php
204934 -> /export/www/pma/css/phpmyadmin.css.php
204934 <- /export/www/pma/css/phpmyadmin.css.php
204934 -> /export/www/pma/css/phpmyadmin.css.php
204936 -> /export/www/pma/css/phpmyadmin.css.php
204934 <- /export/www/pma/css/phpmyadmin.css.php
204934 -> /export/www/1.php
204934 <- /export/www/1.php
204936 <- /export/www/pma/css/phpmyadmin.css.php

pS: yes, starting of today I’ve decided to provide download links for each of my scripts – should be more convenient for you now. This means that sooner or later I’ll update all the archive blog entries to have download links for respective scripts.

Comments

  1. hey Gleb, cool blog.
    I will try to install DTrace on debian to check this out. keep posting!

Speak Your Mind

*