Karp 的技术博客

最近项目面临测试基本服务ok, 开始检查性能及流程问题. 使用xhprof可视化观察接口问题. 出现一些问题

1. 下载xhprof

这里下载吧 :https://github.com/longxinH/xhprof.git

2. 安装 xhprof 扩展

cd xhprof/extension/

/usr/local/php/bin/phpize 
./configure --with-php-config=/opt/php-7.0.14/bin/php-config --enable-xhprof
make&&make install

3. 修改 php.ini 文件

php -i | grep php.ini 

[xhprof]
extension=xhprof.so
xhprof.output_dir=/data/www/xhprof/save_output_dir //该目录自由定义即可,用来保存xhprof生成的源文件

4.安装dot (绘图工具)

sudo yum install -y graphviz 
  • 如果遇到错误 failed to execute cmd: " dot -Tpng". stderr: (process:24220): Pango-WARNING **: Invalid UTF-8 string passed to pango_layout_set_text() 。暂时不清楚怎么解决,可以选择避开它。将 xhprof_lib/utils/callgraph_utils.php 的 121,122 行的打印和 exit 注释掉。
  • 如果遇到错误 Error: either we can not find profile data for run_id xxx or the threshold 0.01 is too small or you do not have 'dot' image generation utility installed,无法生成 png 图片,可能是因为生成的文件中有不能识别的字符,修复如下:

      $cmd="dot-T".$type;
      //在cmd之后添加一个转码工作就可以了
      $dot_script=iconv("UTF-8","ASCII//IGNORE",$dot_script);

xhprof 性能参数说明:

性能点 描述 :

  • Inclusive Time 包括子函数所有执行时间
  • Exclusive Time/Self Time 函数执行本身花费的时间,不包括子树执行时间
  • Wall Time 花去了的时间或挂钟时间
  • CPU Time 用户耗的时间 + 内核耗的时间
  • Inclusive CPU 包括子函数一起所占用的 CPU
  • Exclusive CPU 函数自身所占用的 CPU

php xhprof

版权属于:karp
作品采用:本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。
更新于: 2018年03月01日 15:27
7

目录

来自 《php7.2 使用xhprof 问题》