资讯详情

php7下xhprof性能分析工具的安装与使用的图文代码教程

安装 xhprofcd xhprof/extension/

phpize

./configure

makemake install

然后在/etc/php.ini中根据情况加入extension=xhprof.so

执行php -m | grep xhprof

输出输出,说明php扩展安装成功,然后重启Apache或者php-fpm

运行

可直接运行github上clone在下面的文件中example目录中的例子

输出如下Array

( [main()] => Array ( [ct] => 1 [wt] => 9 ))

---------------Assuming you have set up the http based UI for

XHProf at some address, you can view run at

http:///index.php?run=592567308784c&source=xhprof_foo

---------------

然后复制index.php后面的?run=592567308784c&source=xhprof_foo

访问xhprof_html/index.php?run=592567308784c&source=xhprof_foo

可看见输出

48c0ec3579724b7af4c24c69425e7cc4.png

点击中间的 View Full Callgraph 即可看见性能分析图片

报错failed to execute cmd:" dot -Tpng". stderr:sh: dot:command not found。//解决方案yum install graphviz

随机应变

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

复制xhprof_lib/utils下面两个文件

xhprof_lib.php和xhprof_runs.php在入口文件的起始位置添加/// start profiling

xhprof_enable();

结束位置添加// 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:///index.php?run=$run_id&source=xhprof_foo\n".

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

你可以得到上面所示的那个url,然后再去访问http://***/xhprof_html/index.php?run=*****&source=xhprof_foo

获取以下所示页面

查看图片

图中的红色部分性能低,耗时长。我们可以根据哪些函数标记为红色来优化系统代码

补充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峰值百分比。

标签: ecpu电容

锐单商城拥有海量元器件数据手册IC替代型号,打造 电子元器件IC百科大全!

锐单商城 - 一站式电子元器件采购平台