<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Using SystemTap with PHP DTrace Static Probes</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="features.dtrace.dtrace.html">Using PHP and DTrace</a></div> <div class="next" style="text-align: right; float: right;"><a href="funcref.html">Function Reference</a></div> <div class="up"><a href="features.dtrace.html">DTrace Dynamic Tracing</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="features.dtrace.systemtap" class="sect1"> <h2 class="title">Using SystemTap with PHP DTrace Static Probes</h2> <p class="para"> On some Linux distributions, the SystemTap tracing utility can be used to trace PHP's static DTrace probes. This is available with PHP 5.4.20 and PHP 5.5. </p> <div class="sect2" id="features.dtrace.systemtap-install"> <h3 class="title">Installing PHP with SystemTap</h3> <p class="para"> Install the SystemTap SDT development package: <div class="informalexample"> <div class="example-contents"> <div class="shellcode"><pre class="shellcode"># yum install systemtap-sdt-devel</pre> </div> </div> </div> </p> <p class="para"> Install PHP with the DTrace probes enabled: <div class="informalexample"> <div class="example-contents"> <div class="shellcode"><pre class="shellcode"># ./configure --enable-dtrace ... # make</pre> </div> </div> </div> </p> </div> <div class="sect2" id="features.dtrace.systemtap-list-probes"> <h3 class="title">Listing Static Probes with SystemTap</h3> <p class="para"> The static probes in PHP can be listed using <var class="filename">stap</var>: <div class="informalexample"> <div class="example-contents"> <div class="cdata"><pre> # stap -l 'process.provider("php").mark("*")' -c 'sapi/cli/php -i' </pre></div> </div> </div> </p> <p class="para"> This outputs: <div class="informalexample"> <div class="example-contents"> <div class="cdata"><pre> process("sapi/cli/php").provider("php").mark("compile__file__entry") process("sapi/cli/php").provider("php").mark("compile__file__return") process("sapi/cli/php").provider("php").mark("error") process("sapi/cli/php").provider("php").mark("exception__caught") process("sapi/cli/php").provider("php").mark("exception__thrown") process("sapi/cli/php").provider("php").mark("execute__entry") process("sapi/cli/php").provider("php").mark("execute__return") process("sapi/cli/php").provider("php").mark("function__entry") process("sapi/cli/php").provider("php").mark("function__return") process("sapi/cli/php").provider("php").mark("request__shutdown") process("sapi/cli/php").provider("php").mark("request__startup") </pre></div> </div> </div> </p> </div> <div class="sect2" id="features.dtrace.systemtap-examples"> <h3 class="title">SystemTap with PHP Example</h3> <p class="para"> <div class="example" id="example-402"> <p><strong>Example #1 <var class="filename">all_probes.stp</var> for tracing all PHP Static Probes with SystemTap</strong></p> <div class="example-contents"> <div class="shellcode"><pre class="shellcode">probe process("sapi/cli/php").provider("php").mark("compile__file__entry") { printf("Probe compile__file__entry\n"); printf(" compile_file %s\n", user_string($arg1)); printf(" compile_file_translated %s\n", user_string($arg2)); } probe process("sapi/cli/php").provider("php").mark("compile__file__return") { printf("Probe compile__file__return\n"); printf(" compile_file %s\n", user_string($arg1)); printf(" compile_file_translated %s\n", user_string($arg2)); } probe process("sapi/cli/php").provider("php").mark("error") { printf("Probe error\n"); printf(" errormsg %s\n", user_string($arg1)); printf(" request_file %s\n", user_string($arg2)); printf(" lineno %d\n", $arg3); } probe process("sapi/cli/php").provider("php").mark("exception__caught") { printf("Probe exception__caught\n"); printf(" classname %s\n", user_string($arg1)); } probe process("sapi/cli/php").provider("php").mark("exception__thrown") { printf("Probe exception__thrown\n"); printf(" classname %s\n", user_string($arg1)); } probe process("sapi/cli/php").provider("php").mark("execute__entry") { printf("Probe execute__entry\n"); printf(" request_file %s\n", user_string($arg1)); printf(" lineno %d\n", $arg2); } probe process("sapi/cli/php").provider("php").mark("execute__return") { printf("Probe execute__return\n"); printf(" request_file %s\n", user_string($arg1)); printf(" lineno %d\n", $arg2); } probe process("sapi/cli/php").provider("php").mark("function__entry") { printf("Probe function__entry\n"); printf(" function_name %s\n", user_string($arg1)); printf(" request_file %s\n", user_string($arg2)); printf(" lineno %d\n", $arg3); printf(" classname %s\n", user_string($arg4)); printf(" scope %s\n", user_string($arg5)); } probe process("sapi/cli/php").provider("php").mark("function__return") { printf("Probe function__return: %s\n", user_string($arg1)); printf(" function_name %s\n", user_string($arg1)); printf(" request_file %s\n", user_string($arg2)); printf(" lineno %d\n", $arg3); printf(" classname %s\n", user_string($arg4)); printf(" scope %s\n", user_string($arg5)); } probe process("sapi/cli/php").provider("php").mark("request__shutdown") { printf("Probe request__shutdown\n"); printf(" file %s\n", user_string($arg1)); printf(" request_uri %s\n", user_string($arg2)); printf(" request_method %s\n", user_string($arg3)); } probe process("sapi/cli/php").provider("php").mark("request__startup") { printf("Probe request__startup\n"); printf(" file %s\n", user_string($arg1)); printf(" request_uri %s\n", user_string($arg2)); printf(" request_method %s\n", user_string($arg3)); }</pre> </div> </div> </div> </p> <p class="para"> The above script will trace all core PHP static probe points throughout the duration of a running PHP script: <div class="informalexample"> <div class="example-contents"> <div class="cdata"><pre> # stap -c 'sapi/cli/php test.php' all_probes.stp </pre></div> </div> </div> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="features.dtrace.dtrace.html">Using PHP and DTrace</a></div> <div class="next" style="text-align: right; float: right;"><a href="funcref.html">Function Reference</a></div> <div class="up"><a href="features.dtrace.html">DTrace Dynamic Tracing</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>