现在的位置: 首页 > 综合 > 正文

xhprof安装与使用小记

2012年12月23日 ⁄ 综合 ⁄ 共 1363字 ⁄ 字号 评论关闭

编译安装

wget http://pecl.php.net/get/xhprof-0.9.2.tgz
tar zxf xhprof-0.9.2.tgz
cd xhprof-0.9.2/extension/
phpize ./configure --with-php-config=/usr/local/php/bin/php-config
make
make install

配置 php.ini

在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当中

<?php
 // 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                  包括子函数一起所占用的CPU
Exclusive CPU                  函数自身所占用的CPU

注: 需要使用ctype这个扩展

FROM:http://www.cnblogs.com/bluefrog/archive/2012/03/01/2374922.html

 

抱歉!评论已关闭.