xhprof安装和使用

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值