8

编译xhprof时的一个小意外

 3 years ago
source link: https://www.cnxct.com/you-do-not-have-dot-image-generation-utility-installed/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
编译xhprof时的一个小意外 – CFC4N的博客

新项目基本开发完毕,剩余收尾工作。趁美工调整新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性能监控图优化结果

莿鸟栖草堂 由 CFC4N 创作,采用 知识共享 署名-非商业性使用-相同方式共享(3.0未本地化版本)许可协议进行许可。基于http://www.cnxct.com上的作品创作。转载请注明转自:编译xhprof时的一个小意外

No related posts.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK