xhprof安装和使用

来源:互联网 发布:单片机isp是什么意思 编辑:程序博客网 时间:2024/06/07 00:40

XHProf的一些特性:

1、效果图. 提供函数级的汇总信息,比如调用次数、执行时间、内存使用、CPU占用等。


2. 安装

下载对应的dll,拷贝到ext下。

http://www.xhprof.com/

</pre><p>修改php.ini</p><p><pre name="code" class="php">extension=php_xhprof.dll

xhprof.output_dir = "D:/Apache2/htdocs/xhprof_log" 


3.使用

下载对应的包(地址同上http://www.xhprof.com/)

以项目的形式安装在htdocs下。

另外建立一个log目录,xhprof_log,放在htdocs下。


4.测试

在htdocs下xhprof下建立test.php,代码如下

<?php    function bar($x) {      if ($x > 0) {        bar($x - 1);      }    }    function foo() {      for ($idx = 0; $idx < 2; $idx++) {        bar($idx);        $x = strlen("abc");      }    }    xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);    foo();    $xhprof_data = xhprof_disable();    //    // Saving the XHProf run    // using the default implementation of iXHProfRuns.    //    include_once "xhprof_lib/utils/xhprof_lib.php";    include_once "xhprof_lib/utils/xhprof_runs.php";    $xhprof_runs = new XHProfRuns_Default();    // Save the run under a namespace "xhprof_foo".    //    // **NOTE**:    // By default save_run() will automatically generate a unique    // run id for you. [You can override that behavior by passing    // a run id (optional arg) to the save_run() method instead.]    //    $run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_foo");    echo "---------------\n".         "Assuming you have set up the http based UI for \n".         "XHProf at some address, you can view run at \n".         "http://<xhprof-ui-address>/index.php?run=$run_id&source=xhprof_foo\n".         "---------------\n";    ?>

5.ending......




0 0