xhprof安装&&使用

来源:互联网 发布:问卷统计软件 编辑:程序博客网 时间:2024/05/17 03:30

本日志记录下相关的过程,以便以后再次使用到

编译安装

wget http://pecl.php.net/get/xhprof-0.9.2.tgztar zxf xhprof-0.9.2.tgzcd xhprof-0.9.2/extension/sudo phpize./configure --with-php-config=/usr/local/php/bin/php-configsudo makesudo make install
配置 php.ini

[xhprof]extension=xhprof.so;; directory used by default implementation of the iXHProfRuns; interface (namely, the XHProfRuns_Default class) for storing; XHProf runs.;;xhprof.output_dir=<directory_for_storing_xhprof_runs>xhprof.output_dir=/tmp/xhprof

注:如果是64位系统需要将xhprof.so文件拷贝到相关的lib64的目录下

将代码加入到要测试的php当中

<?pho // cpu:XHPROF_FLAGS_CPU 内存:XHPROF_FLAGS_MEMORY // 如果两个一起:XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);  // 要测试的php代码   $data = xhprof_disable();   //返回运行数据  // xhprof_lib在下载的包里存在这个目录,记得将目录包含到运行的php代码中 include_once "xhprof_lib/utils/xhprof_lib.php";   include_once "xhprof_lib/utils/xhprof_runs.php";    $objXhprofRun = new XHProfRuns_Default();  // 第一个参数j是xhprof_disable()函数返回的运行信息 // 第二个参数是自定义的命名空间字符串(任意字符串), // 返回运行ID,用这个ID查看相关的运行结果 $run_id = $objXhprofRun->save_run($data, "xhprof"); var_dump($run_id);
查看运行结果
将xhprof_lib&&xhprof_html相关目录copy到可以访问到的地址访问 xxx/xhprof_html/index.php?run=$run_id&source=bluefrog 就可经看到你的php代码运行的相关情况下面是一些参数说明Inclusive Time                 包括子函数所有执行时间。Exclusive Time/Self Time  函数执行本身花费的时间,不包括子树执行时间。Wall Time                        花去了的时间或挂钟时间。CPU Time                        用户耗的时间+内核耗的时间Inclusive CPU                  包括子函数一起所占用的CPUExclusive CPU                  函数自身所占用的CPU

注: 需要使用ctype这个扩展







原创粉丝点击