5.20. XHProf

简介:

XHProf是facebook开源出来的一个php轻量级的性能分析工具,跟Xdebug类似,但性能开销更低,还可以用在生产环境中,也可以由程序开 关来控制是否进行profile。

https://github.com/facebook/xhprof

安装依赖工具

		
$ sudo apt-get install graphviz

or

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
		
		

编译安装xhprof

		
wget http://pecl.php.net/get/xhprof

tar zxf xhprof-0.9.2.tgz
cd xhprof-0.9.2
cp -r xhprof_html xhprof_lib /www/www.example.com/xhprof/
cd extension/
/usr/local/webserver/php/bin/phpize
./configure  –with-php-config=/srv/php/bin/php-config
make && make install
		
		

pecl 安装

# pecl install xhprof
		

指定版本

# pecl install xhprof-0.9.4
		

安装完提示:

Installing shared extensions:     /srv/php/lib/php/extensions/no-debug-non-zts-20060613/

cp /srv/php/lib/php/extensions/no-debug-non-zts-20060613/* /srv/php/lib/php/extensions/
		

增加xhprof.ini

		
cat >> /srv/php/etc/conf.d/xhprof.ini <<EOF
extension=xhprof.so
xhprof.output_dir=/www/logs/xhprof
EOF
		
		

分析日志输出在/www/logs/xhprof目录

检查安装是否成功

# /srv/php/bin/php -m | grep xhprof
xhprof
		

例 5.8. xhprof/sample.php

			
<?php

function bar($x) {
  if ($x > 0) {
    bar($x - 1);
  }
}

function foo() {
  for ($idx = 0; $idx < 5; $idx++) {
    bar($idx);
    $x = strlen("abc");
  }
}

// start profiling
xhprof_enable();

// run program
foo();

// stop profiler
$xhprof_data = xhprof_disable();

// display raw xhprof data for the profiler run
print_r($xhprof_data);


$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";

// save raw data for this profiler run using default
// implementation of iXHProfRuns.
$xhprof_runs = new XHProfRuns_Default();

// save the run under a namespace "xhprof_foo"
$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_foo\n".
     "---------------\n";
			
			


5.20.1. XHGui

https://github.com/preinheimer/xhgui




原文出处:Netkiller 系列 手札
本文作者:陈景峯
转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。

目录
相关文章
|
9月前
|
SQL 缓存 Linux
XHProf - PHP性能分析工具
XHProf - PHP性能分析工具的安装使用
116 1
|
10月前
|
设计模式 IDE 程序员
PHP中安装和使用xdebug
作为一个程序员,千万不要说你没有用过debug工具,不然有点说不过去。xdebug是PHP语言一个强大的利器,用他可以做很多事情。
124 0
|
10月前
|
机器学习/深度学习 Linux 测试技术
Linux环境下面安装PHP性能分析工具XHProf(PHP5.6)
Linux环境下面安装PHP性能分析工具XHProf(PHP5.6)
170 0
|
12月前
|
Shell PHP Windows
php的SAPI,CLI SAPI,CGI SAPI
php的SAPI,CLI SAPI,CGI SAPI
|
监控 应用服务中间件 PHP
php性能分析工具:xhprof
php性能分析工具:xhprof
182 0
php性能分析工具:xhprof
php.ini Xdebug配置
php.ini Xdebug配置
113 0
|
PHP 应用服务中间件 nginx