downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Our source is open

The syntax highlighted source is automatically generated by PHP from the plaintext script. If you're interested in what's behind the several functions we used, you can always take a look at the source of the following files:

Of course, if you want to see the source of this page, we have it available. You can also browse the SVN repository for this website on svn.php.net.

Source of: /manual/en/apd.examples.usage.php

<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once
dirname(__FILE__) ."/toc/apd.examples.inc";
$setup = array (
 
'home' =>
  array (
   
0 => 'index.php',
   
1 => 'PHP Manual',
  ),
 
'head' =>
  array (
   
0 => 'UTF-8',
   
1 => 'en',
  ),
 
'this' =>
  array (
   
0 => 'apd.examples.usage.php',
   
1 => 'How to use PHP-APD in your scripts',
  ),
 
'up' =>
  array (
   
0 => 'apd.examples.php',
   
1 => 'Examples',
  ),
 
'prev' =>
  array (
   
0 => 'apd.examples.php',
   
1 => 'Examples',
  ),
 
'next' =>
  array (
   
0 => 'ref.apd.php',
   
1 => 'APD Functions',
  ),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);

manual_header();
?>
<div id="apd.examples.usage" class="section">
  <h2 class="title">How to use PHP-APD in your scripts</h2>
  <div class="procedure">
   <ol type="1"><li>
    <p class="para">
     As the first line of your PHP script, call the apd_set_pprof_trace() function
     to start the trace:
    </p>
    <p class="para">
     </p><div class="example-contents programlisting">
 <div class="phpcode"><code><span style="color: #000000">
apd_set_pprof_trace();</span>
</code></div>
     </div>
<p>
    </p>
    <p class="para">
     You can insert the line anywhere in your script, but if you do not start
     tracing at the beginning of your script you discard profile data that might
     otherwise lead you to a performance bottleneck.
    </p>
   </li>
   <li>
    <p class="para">
     Now run your script. The dump output will be written to
     <var class="filename">apd.dumpdir/pprof_pid.ext</var>.
     <div class="tip"><b class="tip">Tip</b>
     <p class="para">
       If you&#039;re running the CGI version of PHP, you will need to add the &#039;-e&#039;
       flag to enable extended information for apd to work properly. For
       example:
       <strong class="userinput"><code>php -e -f script.php</code></strong>

     </p>
     </div>
    </p>
   </li>
   <li>
    <p class="para">
     To display formatted profile data, issue the <strong class="command">pprofp</strong>
     command with the sort and display options of your choice. The formatted
     output will look something like:
     <div class="example-contents screen">
<div class="cdata"><pre>
bash-2.05b$ pprofp -R /tmp/pprof.22141.0

Trace for /home/dan/testapd.php
Total Elapsed Time = 0.00
Total System Time  = 0.00
Total User Time    = 0.00


Real         User        System             secs/    cumm
%Time (excl/cumm)  (excl/cumm)  (excl/cumm) Calls    call    s/call  Memory Usage Name
--------------------------------------------------------------------------------------
100.0 0.00 0.00  0.00 0.00  0.00 0.00     1  0.0000   0.0009            0 main
56.9 0.00 0.00  0.00 0.00  0.00 0.00     1  0.0005   0.0005            0 apd_set_pprof_trace
28.0 0.00 0.00  0.00 0.00  0.00 0.00    10  0.0000   0.0000            0 preg_replace
14.3 0.00 0.00  0.00 0.00  0.00 0.00    10  0.0000   0.0000            0 str_replace
</pre></div>
     </div>
    </p>
    <p class="para">
     The -R option used in this example sorts the profile table by the amount
     of real time the script spent executing a given function. The &quot;cumm call&quot;
     column reveals how many times each function was called, and the &quot;s/call&quot;
     column reveals how many seconds each call to the function required, on
     average.
    </p>
   </li>
   <li>
    <p class="para">
    To generate a calltree file that you can import into the KCacheGrind
    profile analysis application, issue the <strong class="command">pprof2calltree</strong>
    comand.
    </p>
   </li>
  </ol></div>
 </div><?php manual_footer(); ?>
 
show source | credits | sitemap | contact | advertising | mirror sites