php 程序性能分析,xhprof php性能分析工具

先安装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数据文件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值