您的位置:首页 > 编程语言 > PHP开发

php7 安装使用 xhprof 性能分析工具

2018-02-06 14:49 267 查看
1:  php7 版的xhprof 从 https://github.com/longxinH/xhprof 获取

git clone  https://github.com/longxinH/xhprof 

2:  安装xhprof

cd xhprof/extension/

/usr/local/php/bin/phpize

 ./configure  --with-php-config=/usr/local/php/bin/php-config

make && make install

在php.ini中添加

extension=xhprof.so;

重启php-fpm 然后查看

php -m|grep xhprof

3:xhprof  使用

3.1在 xhprof/xhprof_html中有个index.php  。我们配置一个虚拟主机(xhprof.test.net) 指向这里。

比如想测试自己的项目,例如一款框架的性能分析。

复制xhprof_lib/utils/下的两个文件

xhprof_lib.php和xhprof_runs.php到入口文件同级目录,然后在入口文件起始位置添加
// start profiling
xhprof_enable();


1

2

结束位置添加

// stop profiler

$xhprof_data = xhprof_disable();

// display raw xhprof data for the profiler run

print_r($xhprof_data);

include_once "xhprof_lib.php";

include_once "xhprof_runs.php";

// save raw data for this profiler run using default

// implementation of iXHProfRuns.

$xhprof_runs = new XHProfRuns_Default();

// save the run under a namespace "xhprof_foo"

$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.test.net/index.php?run=$run_id&source=xhprof_foo\n".

     "---------------\n"

可得到如上所示的那个url,然后再次去访问
http://xhprof.test.net/index.php?run=*****&source=xhprof_foo;
4: 补充

Function Name:方法名称。

    Calls:方法被调用的次数。

    Calls%:方法调用次数在同级方法总数调用次数中所占的百分比。

    Incl.Wall Time(microsec):方法执行花费的时间,包括子方法的执行时间。(单位:微秒)

    IWall%:方法执行花费的时间百分比。

    Excl. Wall Time(microsec):方法本身执行花费的时间,不包括子方法的执行时间。(单位:微秒)

    EWall%:方法本身执行花费的时间百分比。

    Incl. CPU(microsecs):方法执行花费的CPU时间,包括子方法的执行时间。(单位:微秒)

    ICpu%:方法执行花费的CPU时间百分比。

    Excl. CPU(microsec):方法本身执行花费的CPU时间,不包括子方法的执行时间。(单位:微秒)

    ECPU%:方法本身执行花费的CPU时间百分比。

    Incl.MemUse(bytes):方法执行占用的内存,包括子方法执行占用的内存。(单位:字节)

    IMemUse%:方法执行占用的内存百分比。

    Excl.MemUse(bytes):方法本身执行占用的内存,不包括子方法执行占用的内存。(单位:字节)

    EMemUse%:方法本身执行占用的内存百分比。

    Incl.PeakMemUse(bytes):Incl.MemUse峰值。(单位:字节)

    IPeakMemUse%:Incl.MemUse峰值百分比。

    Excl.PeakMemUse(bytes):Excl.MemUse峰值。单位:(字节)

    EPeakMemUse%:Excl.MemUse峰值百分比。
5 报错

failedto
execute cmd:" dot -Tpng".stderr:sh:
dot:commandnotfound

//解决方案

yum install graphviz -y

文章参考:http://blog.csdn.net/qq_28602957/article/details/72697901
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  php