先安装libpng*
 
下载安装xhprof
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
cd extension
phpize
./configure
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=/usr/local/nginx/www/pma/xhprof_data   (需要给777权限)
同时xhprof显示,也需要proc_open和ini_set
安装graphviz
Cd /etc/yum.repos.d/ && Wget http://www.graphviz.org/graphviz-rhel.repo
yum install ‘graphviz*’
配置程序
编辑需要profile的程序,在顶部加入:
xhprof_enable();
//xhprof_enable(XHPROF_FLAGS_NO_BUILTINS); 不记录内置的函数
//xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY); 同时分析CPU和Mem的开销
$xhprof_on = true;
然后在底部加入:
// stop profiler
$xhprof_data = xhprof_disable();
//
// Saving the XHProf run
// using the default implementation of iXHProfRuns.
//
include_once “./xhprof_lib/utils/xhprof_lib.php”;
include_once “./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”);
?>

php -f index.php  生成4e7bdb6bd8e6b.xhprof_foo数据文件