<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/features.dtrace.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'zh',
  ),
  'this' => 
  array (
    0 => 'features.dtrace.systemtap.php',
    1 => '使用 SystemTap 监控 PHP DTrace 静态探针',
    2 => '使用 SystemTap 监控 PHP DTrace 静态探针',
  ),
  'up' => 
  array (
    0 => 'features.dtrace.php',
    1 => 'DTrace 动态跟踪',
  ),
  'prev' => 
  array (
    0 => 'features.dtrace.dtrace.php',
    1 => '使用 PHP 和 DTrace',
  ),
  'next' => 
  array (
    0 => 'funcref.php',
    1 => '函数参考',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'zh',
    'path' => 'features/dtrace.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="features.dtrace.systemtap" class="sect1">
  <h2 class="title">使用 SystemTap 监控 PHP DTrace 静态探针</h2>
  <p class="para">
   在某些 Linux 发行版上，可以使用 SystemTap 跟踪工具来跟踪 PHP 的静态 DTrace 探针。
   此特性在 PHP 5.4.20 和 PHP 5.5 中具备。
  </p>

  <div class="sect2" id="features.dtrace.systemtap-install">
   <h3 class="title">安装支持 SystemTap 的 PHP </h3>

   <p class="para">
    安装 SystemTap SDT 开发包。
    <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">
    安装 PHP 并启用 DTrace 探针：
    <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">使用 SystemTap 列出 PHP 静态探针</h3>

   <p class="para">
    使用 <var class="filename">stap</var> 命令列出 PHP 静态探针：
    <div class="informalexample">
     <div class="example-contents">
<div class="cdata"><pre>
# stap -l &#039;process.provider(&quot;php&quot;).mark(&quot;*&quot;)&#039; -c &#039;sapi/cli/php -i&#039;
</pre></div>
     </div>

    </div>
   </p>

   <p class="para">
    输出如下：
    <div class="informalexample">
     <div class="example-contents">
<div class="cdata"><pre>
process(&quot;sapi/cli/php&quot;).provider(&quot;php&quot;).mark(&quot;compile__file__entry&quot;)
process(&quot;sapi/cli/php&quot;).provider(&quot;php&quot;).mark(&quot;compile__file__return&quot;)
process(&quot;sapi/cli/php&quot;).provider(&quot;php&quot;).mark(&quot;error&quot;)
process(&quot;sapi/cli/php&quot;).provider(&quot;php&quot;).mark(&quot;exception__caught&quot;)
process(&quot;sapi/cli/php&quot;).provider(&quot;php&quot;).mark(&quot;exception__thrown&quot;)
process(&quot;sapi/cli/php&quot;).provider(&quot;php&quot;).mark(&quot;execute__entry&quot;)
process(&quot;sapi/cli/php&quot;).provider(&quot;php&quot;).mark(&quot;execute__return&quot;)
process(&quot;sapi/cli/php&quot;).provider(&quot;php&quot;).mark(&quot;function__entry&quot;)
process(&quot;sapi/cli/php&quot;).provider(&quot;php&quot;).mark(&quot;function__return&quot;)
process(&quot;sapi/cli/php&quot;).provider(&quot;php&quot;).mark(&quot;request__shutdown&quot;)
process(&quot;sapi/cli/php&quot;).provider(&quot;php&quot;).mark(&quot;request__startup&quot;)
</pre></div>
     </div>

    </div>
   </p>
  </div>

  <div class="sect2" id="features.dtrace.systemtap-examples">
   <h3 class="title">SystemTap 示例</h3>

   <p class="para">
    <div class="example" id="example-1">
     <p><strong>示例 #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(&quot;sapi/cli/php&quot;).provider(&quot;php&quot;).mark(&quot;compile__file__entry&quot;) {
    printf(&quot;Probe compile__file__entry\n&quot;);
    printf(&quot;  compile_file %s\n&quot;, user_string($arg1));
    printf(&quot;  compile_file_translated %s\n&quot;, user_string($arg2));
}
probe process(&quot;sapi/cli/php&quot;).provider(&quot;php&quot;).mark(&quot;compile__file__return&quot;) {
    printf(&quot;Probe compile__file__return\n&quot;);
    printf(&quot;  compile_file %s\n&quot;, user_string($arg1));
    printf(&quot;  compile_file_translated %s\n&quot;, user_string($arg2));
}
probe process(&quot;sapi/cli/php&quot;).provider(&quot;php&quot;).mark(&quot;error&quot;) {
    printf(&quot;Probe error\n&quot;);
    printf(&quot;  errormsg %s\n&quot;, user_string($arg1));
    printf(&quot;  request_file %s\n&quot;, user_string($arg2));
    printf(&quot;  lineno %d\n&quot;, $arg3);
}
probe process(&quot;sapi/cli/php&quot;).provider(&quot;php&quot;).mark(&quot;exception__caught&quot;) {
    printf(&quot;Probe exception__caught\n&quot;);
    printf(&quot;  classname %s\n&quot;, user_string($arg1));
}
probe process(&quot;sapi/cli/php&quot;).provider(&quot;php&quot;).mark(&quot;exception__thrown&quot;) {
    printf(&quot;Probe exception__thrown\n&quot;);
    printf(&quot;  classname %s\n&quot;, user_string($arg1));
}
probe process(&quot;sapi/cli/php&quot;).provider(&quot;php&quot;).mark(&quot;execute__entry&quot;) {
    printf(&quot;Probe execute__entry\n&quot;);
    printf(&quot;  request_file %s\n&quot;, user_string($arg1));
    printf(&quot;  lineno %d\n&quot;, $arg2);
}
probe process(&quot;sapi/cli/php&quot;).provider(&quot;php&quot;).mark(&quot;execute__return&quot;) {
    printf(&quot;Probe execute__return\n&quot;);
    printf(&quot;  request_file %s\n&quot;, user_string($arg1));
    printf(&quot;  lineno %d\n&quot;, $arg2);
}
probe process(&quot;sapi/cli/php&quot;).provider(&quot;php&quot;).mark(&quot;function__entry&quot;) {
    printf(&quot;Probe function__entry\n&quot;);
    printf(&quot;  function_name %s\n&quot;, user_string($arg1));
    printf(&quot;  request_file %s\n&quot;, user_string($arg2));
    printf(&quot;  lineno %d\n&quot;, $arg3);
    printf(&quot;  classname %s\n&quot;, user_string($arg4));
    printf(&quot;  scope %s\n&quot;, user_string($arg5));
}
probe process(&quot;sapi/cli/php&quot;).provider(&quot;php&quot;).mark(&quot;function__return&quot;) {
    printf(&quot;Probe function__return: %s\n&quot;, user_string($arg1));
    printf(&quot; function_name %s\n&quot;, user_string($arg1));
    printf(&quot;  request_file %s\n&quot;, user_string($arg2));
    printf(&quot;  lineno %d\n&quot;, $arg3);
    printf(&quot;  classname %s\n&quot;, user_string($arg4));
    printf(&quot;  scope %s\n&quot;, user_string($arg5));
}
probe process(&quot;sapi/cli/php&quot;).provider(&quot;php&quot;).mark(&quot;request__shutdown&quot;) {
    printf(&quot;Probe request__shutdown\n&quot;);
    printf(&quot;  file %s\n&quot;, user_string($arg1));
    printf(&quot;  request_uri %s\n&quot;, user_string($arg2));
    printf(&quot;  request_method %s\n&quot;, user_string($arg3));
}
probe process(&quot;sapi/cli/php&quot;).provider(&quot;php&quot;).mark(&quot;request__startup&quot;) {
    printf(&quot;Probe request__startup\n&quot;);
    printf(&quot;  file %s\n&quot;, user_string($arg1));
    printf(&quot;  request_uri %s\n&quot;, user_string($arg2));
    printf(&quot;  request_method %s\n&quot;, user_string($arg3));
}</pre>
</div>
     </div>

    </div>
   </p>
   <p class="para">
    在 PHP 脚本的执行过程中，上述脚本会跟踪所有的 PHP 核心静态探针：
    <div class="informalexample">
     <div class="example-contents">
<div class="cdata"><pre>
# stap -c &#039;sapi/cli/php test.php&#039; all_probes.stp
</pre></div>
     </div>

    </div>
   </p>
  </div>
 </div><?php manual_footer($setup); ?>