Dtrace support for PHP

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



Comments:

Looks very cool!

Posted by Vitório Sassi on May 23, 2008 at 03:55 AM PDT #

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

Posted by gerard on January 09, 2009 at 02:15 PM PST #

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.

Posted by Shanti on January 10, 2009 at 01:34 PM PST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

I'm a Senior Staff Engineer in the Performance & Applications Engineering Group (PAE). This blog focuses on tips to build, configure, tune and measure performance of popular open source web applications on Solaris.

Search

Archives
« April 2014
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
   
       
Today