友善交流技术...
性能测试- xhprof深层次分析性能问题
上一篇 /
下一篇 2013-12-25 15:39:44
/ 个人分类:性能测试专题
这几天刚换了一个新的
工作,刚到一个公司就要表现一下.所以想通过xhprof来分析PHP页面中函数调用存在的问题.
费话不多说,下面讲一下xhprof使用过程及发现的问题
1安装xhprof:
wgethttp://pecl.php.net/get/xhprof-0.9.2.tgz
tar zxf xhprof-0.9.2.tgz
cd xhprof-0.9.2
cp -r xhprof_html xhprof_lib /www/www.hx.com/xhprof/
cd extension/
/usr/local/webserver/php/bin/phpize
./configure –with-php-config=/usr/local/webserver/php/bin/php-config
make && make install
2安装完提示:
Installing shared
extensions:
/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/
3 php.ini中添加
extension_dir =
"/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/"
这句我原来就有了,就这用添加下面两句
extension=xhprof.so
xhprof.output_dir=/www/logs/xhprof
分析日志输出在/www/logs/xhprof目录。
4 重新加载php配置文件和重启web
/ect/init.d/php-fpm1
reload
/ect/init.d//nginx -s reload
刷新phpinfo页面,看到输出中有了xhprof信息。
5 安装graphviz,一个画图工具
wgethttp://www.graphviz.org/pub/graphviz/stable/SOURCES/graphviz-2.24.0.tar.gz
tar zxf graphviz-2.24.0.tar.gz
cd graphviz-2.24.0
./configure
make && make install
6程序试例
头部:
xhprof_enable();
//xhprof_enable(XHPROF_FLAGS_NO_BUILTINS);不记录内置的函数
//xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY); 同时分析CPU和Mem的开销
$xhprof_on = true;
代码:
放置你要测试的代码.
尾部:
if($xhprof_on){
$xhprof_data = xhprof_disable();
$xhprof_root = '/share/web/xhprof/';
include_once $xhprof_root."xhprof_lib/utils/xhprof_lib.php";
include_once $xhprof_root."xhprof_lib/utils/xhprof_runs.php";
$xhprof_runs = new XHProfRuns_Default();
$run_id = $xhprof_runs->save_run($xhprof_data, "hx");
echo '<a href="http://10.168.1.1:80/xhprof/xhprof_html/index.php?run='.$run_id.'&source=hx"target="_blank">函数调用情况统计</a>';
}
7. 上图片查看效果
收藏
举报
TAG: