IT软件
当前位置 :首页工程软件IT软件

ubuntu下xhprof安装过程全纪录

来源: 作者: 时间:2011-09-23 点击:

下载安装XHProf

sudo apt-get install php5-dev(如果已安装,跳过此步)
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
sudo phpize(若提示sudo: phpize: command not found,则说明php5-dev未安装)
sudo ./configure
sudo make
sudo make install

创建xhprof.ini

touch /etc/php5/fpm/conf.d/xhprof.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=/tmp/xhprof
创建output_dir<输出路径>:
mkdir /tmp/xhprof && chmod 777 /tmp/xhprof

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

 

安装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能找到它。

 

在PHP中使用XHProf

// start profiling
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://<xhprof-ui-address>/index.php?run=$run_id&source=xhprof_foon".
"---------------n";
上一篇:
下一篇: 已经是最后一篇
最新评论共有 位网友发表了评论
发表评论
用户名: 密码: 游客发言不需要密码