Performance Blog

Dtrace support for PHP

Posted on: May 1, 2007

Dtrace is one of the coolest things in Solaris 10, adding great observability to applications. A Dtrace provider for PHP that adds probes to function entry and exit points has long been available. I finally got around to integrating this with the php in Cool Stack. 

Bryan Cantrill has some excellent examples of how to use dtrace to trace through your php code, down to the system libraries and kernel (if you want to go that far !) .

Instructions for installing the php dtrace extension

1. Download the shared library for the extension :

    dtrace.so.x86.bz2

    dtrace.so.sparc.bz2

2. Install the extension :

    # bunzip2 dtrace.so.<arch>.bz2
  # cp dtrace.so.<arch> /opt/coolstack/php5/lib/php/extensions/no-debug*/dtrace.so

3. Enable the dtrace extension :

  Edit your php.ini (default is in /opt/coolstack/php5/lib/php.ini) and add the line :

  extension="dtrace.so"

4. Check if the extension has been correctly loaded by executing a sample php script that takes a long time to run (you can use Bryan’s blastoff.php to do this). 

#/opt/coolstack# dtrace -l |grep php
39131   php16088         dtrace.so                php_dtrace_execute function-entry
39132   php16088         dtrace.so       php_dtrace_execute_internal function-entry
39133   php16088         dtrace.so                php_dtrace_execute function-return
39134   php16088         dtrace.so       php_dtrace_execute_internal function-return
#

5. You should now be able to use the dtrace provider whenever you want using dtrace scripts. The dtrace provider will work with mod_php if you’re running Apache or if you’re running php stand-alone. Here is a sample command that will show which functions are called :

# dtrace -n function-entry'{printf("called %s() in %s at line %d\n", \
copyinstr(arg0), copyinstr(arg1), arg2)}' -q

Please feel free to contribute additional dtrace scripts.

 

Shanti

Advertisements

3 Responses to "Dtrace support for PHP"

hello,
i have problems with dtrace and php in os2008.11. Could you help me?
dtrace: error on enabled probe ID 57 (ID 5917: php26172:dtrace.so:php_dtrace_execute_internal:function-entry): invalid address (0xfceeb38b) in predicate at DIF offset 64
with:
php*:::function-entry
/arg0 != NULL && copyinstr(arg0) == ""/
{
printf("%d -> %-30s\n", pid, copyinstr(arg1));
}
php*:::function-return
/arg0 != NULL && copyinstr(arg0) == ""/
{
printf("%d <- %-30s\n", pid, copyinstr(arg1));
}
could you help me? A. Leventhal suggested me to contact you

Please use the Web Stack forum for support. It’s at http://forums.sun.com/forum.jspa?forumID=980
And when you do, please state which version you’re running on what platform.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Pages

Latest Tweets

Categories

Archives

%d bloggers like this: