当前位置:Gxlcms > PHP教程 > php7下xhprof性能分析工具的安装与使用的图文代码教程

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

时间:2021-07-01 10:21:17 帮助过:18人阅读


安装 xhprof

  1. cd xhprof/extension/
  2. phpize
  3. ./configure
  4. makemake install

然后在/etc/php.ini中根据情况加入

  1. extension=xhprof.so

执行

  1. php -m | grep xhprof

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

运行

可以直接运行从github上clone下来的文件里面example目录下的那个例子

输出如下

  1. Array
  2. ( [main()] => Array ( [ct] => 1 [wt] => 9 ))
  3. ---------------Assuming you have set up the http based UI for
  4. XHProf at some address, you can view run at
  5. http://<xhprof-ui-address>/index.php?run=592567308784c&source=xhprof_foo
  6. ---------------

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

访问

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

可看见输出

图示

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

报错

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

随机应变

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

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

xhprof_lib.php和xhprof_runs.php到入口文件同级目录,然后在入口文件起始位置添加

  1. // start profiling
  2. xhprof_enable();

结束位置添加

  1. // stop profiler
  2. $xhprof_data = xhprof_disable();
  3. // display raw xhprof data for the profiler run
  4. print_r($xhprof_data);
  5. include_once "xhprof_lib.php";
  6. include_once "xhprof_runs.php";
  7. // save raw data for this profiler run using default
  8. // implementation of iXHProfRuns.
  9. $xhprof_runs = new XHProfRuns_Default();
  10. // save the run under a namespace "xhprof_foo"
  11. $run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_foo");
  12. echo "---------------\n".
  13. "Assuming you have set up the http based UI for \n".
  14. "XHProf at some address, you can view run at \n".
  15. "http://<xhprof-ui-address>/index.php?run=$run_id&source=xhprof_foo\n".
  16. "---------------\n";

即可得到如上所示的那个url,然后再次去访问

  1. http://***/xhprof_html/index.php?run=*****&source=xhprof_foo

得到如下所示页面

图示

查看图片

图示

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

补充

  1. Function Name:方法名称。
  2. Calls:方法被调用的次数。
  3. Calls%:方法调用次数在同级方法总数调用次数中所占的百分比。
  4. Incl.Wall Time(microsec):方法执行花费的时间,包括子方法的执行时间。(单位:微秒)
  5. IWall%:方法执行花费的时间百分比。
  6. Excl. Wall Time(microsec):方法本身执行花费的时间,不包括子方法的执行时间。(单位:微秒)
  7. EWall%:方法本身执行花费的时间百分比。
  8. Incl. CPU(microsecs):方法执行花费的CPU时间,包括子方法的执行时间。(单位:微秒)
  9. ICpu%:方法执行花费的CPU时间百分比。
  10. Excl. CPU(microsec):方法本身执行花费的CPU时间,不包括子方法的执行时间。(单位:微秒)
  11. ECPU%:方法本身执行花费的CPU时间百分比。
  12. Incl.MemUse(bytes):方法执行占用的内存,包括子方法执行占用的内存。(单位:字节)
  13. IMemUse%:方法执行占用的内存百分比。
  14. Excl.MemUse(bytes):方法本身执行占用的内存,不包括子方法执行占用的内存。(单位:字节)
  15. EMemUse%:方法本身执行占用的内存百分比。
  16. Incl.PeakMemUse(bytes):Incl.MemUse峰值。(单位:字节)
  17. IPeakMemUse%:Incl.MemUse峰值百分比。
  18. Excl.PeakMemUse(bytes):Excl.MemUse峰值。单位:(字节)
  19. EPeakMemUse%:Excl.MemUse峰值百分比。

以上就是php7下xhprof性能分析工具的安装与使用的图文代码教程的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行