1、安装
wget -c http://pecl.php.net/get/xhprof-0.9.2.tgztar -xzvf./xhprof-0.9.2.tgzcp ./xhprof-0.9.2.tgz ./www //xhprof自身带有一个web版的分析页面,放到我的web服务器下面cd ./xhprof-0.9.2/extension/usr/local/php/bin/phpize./configure --enable-xhprof--with-php-config=/usr/local/php/bin/php-configmake && make install
[xhprof]extension=xhprof.soxhprof.output_dir=/data/xhprof //如果不加存放目录的话,默认是放在/tmp下面 (注意:要有写的权限,直接 777 吧)!
service apache2 restart
// 启动xhprofxhprof_enable(xhprof_flags_cpu + xhprof_flags_memory); 各种牛逼的代码。。。。。。。// 停止xhprof$xhprof_data = xhprof_disable();$xhprof_root = realpath(dirname(__file__) . '/..');include_once$xhprof_root . /xhprof_lib/utils/xhprof_lib.php;include_once$xhprof_root . /xhprof_lib/utils/xhprof_runs.php; // 保存统计数据,生成统计id和source名称$xhprof_runs = new xhprofruns_default();$run_id = $xhprof_runs->save_run($xhprof_data, xhprof_foo); //source名称是xhprof_foo// 查看统计信息echoxhprof view
;
2、显示结果
有分表格形式和图片显示各个函数的调用情况
表格的这样些字段
列名 描述
function name 方法名称。
calls 方法被调用的次数。
calls% 方法调用次数在同级方法总数调用次数中所占的百分比。
incl.wall time (microsec) 方法执行花费的时间,包括子方法的执行时间。(单位:微秒)
iwall% 方法执行花费的时间百分比。
excl. wall time (microsec) 方法本身执行花费的时间,不包括子方法的执行时间。(单位:微秒)
ewall% 方法本身执行花费的时间百分比。
incl. cpu (microsecs) 方法执行花费的cpu时间,包括子方法的执行时间。(单位:微秒)
icpu% 方法执行花费的cpu时间百分比。
excl. cpu (microsec) 方法本身执行花费的cpu时间,不包括子方法的执行时间。(单位:微秒)
ecpu% 方法本身执行花费的cpu时间百分比。
incl.memuse (bytes) 方法执行占用的内存,包括子方法执行占用的内存。(单位:字节)
imemuse% 方法执行占用的内存百分比。
excl.memuse (bytes) 方法本身执行占用的内存,不包括子方法执行占用的内存。(单位:字节)
ememuse% 方法本身执行占用的内存百分比。
incl.peakmemuse (bytes) incl.memuse峰值。(单位:字节)
ipeakmemuse% incl.memuse峰值百分比。
excl.peakmemuse (bytes) excl.memuse峰值。单位:(字节)
epeakmemuse% excl.memuse峰值百分比。
图片的就需要去安装libpng和graphviz
安装libpng
wget -c http://sourceforge.net/projects/libpng/files/libpng15/1.5.23beta01/libpng-1.5.23beta01.tar.gz/downloadtar -xzvf ./libpng-1.5.23beta01.tar.gzcd ./libpng-1.5.23beta01./configuremake && make install
安装graphviz
wget -c http://www.graphviz.org/pub/graphviz/stable/sources/graphviz-2.24.0.tar.gztar -xzvf ./graphviz-2.24.0.tar.gzcd ./graphviz-2.24.0./configuremake && make install
安装完,重启一下apache
service apache2 restart
在表格页面点击[view full callgraph]
就可以以图片形式来展示各个代码段的调用以性能情况
以上就介绍了ubuntu安装xhprof,包括了方面的内容,希望对php教程有兴趣的朋友有所帮助。