`
CJxixi
  • 浏览: 104171 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

php 性能分析工具xhprof使用手册

阅读更多

xhprof 是fb搞的一个用来分析php程序性能的工具,使用轻巧方便。官方地址:http://mirror.facebook.net/facebook/xhprof/doc.html#installation

 

1,安装使用:

wget http://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
<directory_for_htdocs>
cd extension
phpize

./configure --with-php-config=/usr/local/php/bin/php-confg

make
make install


编辑php.ini:

[xhprof]
extension=xhprof.so
;
; directory used by default implementation of the iXHProfRuns
; interface (namely, the XHProfRuns_Default class) for storing
; XHProf runs.
;
xhprof.output_dir=<directory_for_storing_xhprof_runs>

注意设置xhprof.output_dir的目录权限

 

重启服务让修改生效,现在就可以使用XHProf了,不过为了显示效果更炫,最好继续安装Graphviz。

 

使用phpinfo()确认是否正确安装

安装Graphviz:

wget http://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


安装完成后,会生成/usr/local/bin/dot文件,你应该确保路径在PATH环境变量里,以便XHProf能找到它。

使用phpinfo()确认是否正确安装

 


使用XHProf:

// start profiling ,开启xhprof功能
xhprof_enable();

// run program
....

// stop profiler
$xhprof_data = xhprof_disable();

//
// Saving the XHProf run
// using the default implementation of iXHProfRuns.
//
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();

// Save the run under a namespace "xhprof_foo".
//
// **NOTE**:
// By default save_run() will automatically generate a unique
// run id for you. [You can override that behavior by passing
// a run id (optional arg) to the save_run() method instead.]
//
$run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_foo");

echo "---------------\n".
"Assuming you have set up the http based UI for \n".
"XHProf at some address, you can view run at \n".
"
http://192.168.2.128/xhprof_html/index.php?run=$run_id&source=xhprof_foo\n".
"---------------\n";


如此一来,会在上面设定的xhprof.output_dir目录里生成名字类似49bafaa3a3f66.xhprof_foo的数据文件,可以很方便的通过Web方式浏览效果:

http://192.168.2.128/xhprof_html/index.php?run=49bafaa3a3f66&source=xhprof_foo

目前显示的是表格形式的显示,点击页面上的[View Full Callgraph],就能看到图片了。

 

2, 结果分析:

 

主要的

Inclusive Time (或子树时间):包括子函数所有执行时间。

Exclusive Time/Self Time:函数执行本身花费的时间,不包括子树执行时间。

Wall时间:花去了的时间或挂钟时间。

CPU时间:用户耗的时间+内核耗的时间

表单中的

Function Name 函数名

Calls 调用次数

Calls% 调用百分比

Incl. Wall Time (microsec) 调用的包括子函数所有花费时间 以微秒算(一百万分之一秒)

IWall% 调用的包括子函数所有花费时间的百分比

Excl. Wall Time (microsec) 函数执行本身花费的时间,不包括子树执行时间,以微秒算(一百万分之一秒)

EWall% 函数执行本身花费的时间的百分比,不包括子树执行时间

Incl. CPU(microsecs) 调用的包括子函数所有花费的cpu时间。减Incl. Wall Time即为等待cpu的时间

减Excl. Wall Time即为等待cpu的时间

ICpu% Incl. CPU(microsecs)的百分比

Excl. CPU(microsec) 函数执行本身花费的cpu时间,不包括子树执行时间,以微秒算(一百万分之一秒)。

ECPU% Excl. CPU(microsec)的百分比

Incl.MemUse(bytes) 包括子函数执行使用的内存。

IMemUse% Incl.MemUse(bytes)的百分比

Excl.MemUse(bytes) 函数执行本身内存,以字节算

EMemUse% Excl.MemUse(bytes)的百分比

Incl.PeakMemUse(bytes) Incl.MemUse的峰值

IPeakMemUse% Incl.PeakMemUse(bytes) 的峰值百分比

Excl.PeakMemUse(bytes) Excl.MemUse的峰值

EPeakMemUse% EMemUse% 峰值百分比

 

 

 

 

 

分享到:
评论
2 楼 marx 2012-12-09  
marx 写道
make: *** No targets specified and no makefile found

为什么我phpize后执行make  报上面这错, 没有生成makefile文件 ?

可以了 
1 楼 marx 2012-12-09  
make: *** No targets specified and no makefile found

为什么我phpize后执行make  报上面这错, 没有生成makefile文件 ?

相关推荐

Global site tag (gtag.js) - Google Analytics