编译xhprof时的一个小意外

新项目基本开发完毕,剩余收尾工作。趁美工调整新UI的时间,赶紧在测试机上安装PHP的性能检测利器xhprof。
下载地址http://pecl.php.net/package/xhprof,这里有tar包,我下了http://pecl.php.net/get/xhprof-0.9.2.tgz

tar zxvf xhprof-0.9.2.tgz
cd xhprof-0.9.2
cp -r xhprof_html xhprof_lib <directory_for_htdocs> # 应用程序所在目录,其中xhprof_lib是生成统计数据用到的类库。xhprof_html是查看统计数据的时候,用到的类库。
cd extension
/usr/local/php/bin/phpize
./configure
make
make install

之后,遍完成了。一路很“顺利”。
php.ini如下设置

extension=xhprof.so
; 存放目录,这个目录用来存放统计程序性能生成的数据。要有读写权限。
xhprof.output_dir=/var/xhprof_data

代码中,程序头部如下设置:

xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);

程序最下面:

$xhprof_data = xhprof_disable();
include_once "./xhprof_lib/utils/xhprof_lib.php";
include_once "./xhprof_lib/utils/xhprof_runs.php";
$xhprof_runs = new XHProfRuns_Default();
$run_id = $xhprof_runs->save_run($xhprof_data, 'xhprof');
echo 'http://<xhprof-ui-address >/index.php?run='.$run_id.'&source=xhprof';//source的值就是save_run的第二个参数的值。其中,网址就是上面保存xhprof_html的路径。

之后遍看到统计数据结果了。

可是,当我查看[View Full Callgraph]的时候,却提示如下:Error: either we can not find profile data for run_id 4d7f0bd99a12f or the threshold 0.01 is too small or you do not have ‘dot’ image generation utility installed.,这TMD神马玩意?是什么错呢?
关于dot的介绍,xhprof在这里写出来了:
http://mirror.facebook.net/facebook/xhprof/doc.html

dot (image generation utility): The callgraph image visualization ([View Callgraph]) feature relies on the presence of Graphviz “dot” utility in your path. “dot” is a utility to draw/generate an image for a directed graph.

GOOGLE了半天,也没找到可用的信息。问了下群里的同学,大牛老王告诉俺,xhprof绘制的是png图,系统(graphviz-2.24.0)不支持。才知道绘图的dot拓展没装成功。我的操作系统是UBUNTU 10.10 SERVER版的,也就是dot 不支持PNG。赶紧再次编译下graphviz,看看提示信息有什么缺少的。果然:

options:
  cgraph:        No (disabled by default - experimental)
  codegens:      No (disabled by default - deprecated)
  digcola:       Yes
  expat:         No (missing library)
  fontconfig:    No (missing fontconfig-config)
  freetype:      No (missing freetype-config)
  glut:          No (missing GL/glut.h)
  gts:           No (gts library not available)
  ipsepcola:     No (disabled by default - C++ portability issues)
  ltdl:          Yes
  ortho:         No (disabled by default - experimental)
  png:           No (missing png.h)

png: No (missing png.h)果然。。。。
赶紧到libpng官网down分源码,再次编译一下。
SF.NET上地址是 http://sourceforge.net/projects/libpng/files/libpng15/1.5.1/,我下的是http://sourceforge.net/projects/libpng/files/libpng15/1.5.1/libpng-1.5.1.tar.gz/download ,一气呵成,很顺利。
再次编译graphviz的时候,提示如下:

 ortho:         No (disabled by default - experimental)
  png:           Yes

好了,内牛满面。之后就是 make&make install了。
当打开[View Full Callgraph]的时候,果然是性感的资源占用统计图了。
展示下效果图:
优化前:

xhprof性能监控图优化前

xhprof性能监控图优化前

找到问题所在,稍微调试:

xhprof性能监控图找到问题,调试中

xhprof性能监控图找到问题,调试中

最终代码优化结果:

xhprof性能监控图优化结果

xhprof性能监控图优化结果

您可能喜欢下面几篇博文

发表评论

3 Comments.

  1. 自己写些小东西,还真没有搞过性能测试,等手头的东西做完我也来试试。

    验证码cangjingKong飘过。

  2. 这篇文章的名字,应该改为“使用xhprof时,graphviz为什么没生效”

Leave a Reply



[ Ctrl + Enter ]

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Trackbacks and Pingbacks:

CNXCT小组的博客 is Stephen Fry proof thanks to caching by WP Super Cache