Xhprof - PHP函数级分层性能分析工具安装

下载 Available Releases [Xhprof-PHP函数手册]
VersionStateRelease DateDownloads 
0.9.4beta2013-09-30xhprof-0.9.4.tgz (822.3kB)[Changelog]
0.9.3beta2013-05-20xhprof-0.9.3.tgz (822.1kB)[Changelog]
0.9.2beta2009-06-01xhprof-0.9.2.tgz (909.8kB)[Changelog]
0.9.1beta2009-03-21xhprof-0.9.1.tgz (903.6kB)[Changelog]
windows(1)demo2010-12-09xhprof_php_5.3.3-.zip (66kB)[Changelog]
windows(2)demo2010-12-09xhprof_php_5.3.3+.zip (11kB)[Changelog]
本地模式 [ LINUX ]
1. 编译安装
  wget http://pecl.php.net/get/xhprof-0.9.3.tgz
  tar zxvf xhprof-0.9.2.tgz
  cd xhprof-0.9.2/extension/
  sudo phpize
  ./configure --with-php-config=/usr/local/php/bin/php-config
  sudo make
  sudo make install
  或者 yum install php-xhprof
2. 配置 php.ini
[xhprof]
extension=xhprof.so;
xhprof.output_dir=/tmp/xhprof

重启PHP-fpm  or  Apache
3. 嵌入代码
<?php
// cpu:XHPROF_FLAGS_CPU 内存:XHPROF_FLAGS_MEMORY
// 如果两个一起:XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY 
xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);

//要测试的php代码

$data = xhprof_disable();   //返回运行数据
 
// xhprof_lib在下载的包里存在这个目录,记得将目录包含到运行的php代码中
include_once "xhprof_lib/utils/xhprof_lib.php";  
include_once "xhprof_lib/utils/xhprof_runs.php";  
 
$objXhprofRun = new XHProfRuns_Default(); 

// 第一个参数j是xhprof_disable()函数返回的运行信息
// 第二个参数是自定义的命名空间字符串(任意字符串),
// 返回运行ID,用这个ID查看相关的运行结果
$run_id = $objXhprofRun->save_run($data, "xhprof");
var_dump($run_id);
4. 页面展示
将xhprof_lib&&xhprof_html相关目录copy到可以访问到的地址
访问 xxx/xhprof_html/index.php?run=$run_id&source=xhprof 就可经看到你的php代码运行的相关情况

下面是一些参数说明
Inclusive Time                 包括子函数所有执行时间。
Exclusive Time/Self Time       函数执行本身花费的时间,不包括子树执行时间。
Wall Time                      花去了的时间或挂钟时间。
CPU Time                       用户耗的时间+内核耗的时间
Inclusive CPU                  包括子函数一起所占用的CPU
Exclusive CPU                  函数自身所占用的CPU

5、PHP5.4以上的bug解决

We use xhprof to profile our web application framework. The pecl installer was failing with `[xhprof.lo] Error 1` in the make phase with PHP 5.4. Here's how to fix that.

Currently, trying
sudo pecl install xhprof-beta
throws the following errors in the `make` phase for PHP >= 5.4:

In file included from /usr/include/php5/main/php.h:33:0,
from /tmp/pear/temp/xhprof/extension/xhprof.c:27:
/usr/include/php5/main/php_config.h:2396:0: warning: "_GNU_SOURCE" redefined [enabled by default]
/tmp/pear/temp/xhprof/extension/xhprof.c:24:0: note: this is the location of the previous definition
/tmp/pear/temp/xhprof/extension/xhprof.c:236:1: warning: 'visibility' attribute ignored [-Wattributes]
/tmp/pear/temp/xhprof/extension/xhprof.c:240:28: warning: 'visibility' attribute ignored [-Wattributes]
/tmp/pear/temp/xhprof/extension/xhprof.c: In function 'hp_get_function_name':
/tmp/pear/temp/xhprof/extension/xhprof.c:898:10: warning: assignment discards 'const' qualifier from pointer target type [enabled by default]
/tmp/pear/temp/xhprof/extension/xhprof.c:909:13: warning: assignment discards 'const' qualifier from pointer target type [enabled by default]
/tmp/pear/temp/xhprof/extension/xhprof.c:911:13: warning: assignment discards 'const' qualifier from pointer target type [enabled by default]
/tmp/pear/temp/xhprof/extension/xhprof.c:930:34: error: 'znode_op' has no member named 'u'
/tmp/pear/temp/xhprof/extension/xhprof.c:963:9: warning: passing argument 1 of 'hp_get_base_filename' discards 'const' qualifier from pointer target type [enabled by default]
/tmp/pear/temp/xhprof/extension/xhprof.c:856:14: note: expected 'char *' but argument is of type 'const char *'
/tmp/pear/temp/xhprof/extension/xhprof.c: In function 'hp_execute_internal':
/tmp/pear/temp/xhprof/extension/xhprof.c:1650:24: error: 'znode_op' has no member named 'u'
/tmp/pear/temp/xhprof/extension/xhprof.c:1651:59: error: 'struct <anonymous>' has no member named 'return_reference'
/tmp/pear/temp/xhprof/extension/xhprof.c:1652:25: error: 'znode_op' has no member named 'u'
/tmp/pear/temp/xhprof/extension/xhprof.c: In function 'hp_compile_file':
/tmp/pear/temp/xhprof/extension/xhprof.c:1683:3: warning: passing argument 1 of 'hp_get_base_filename' discards 'const' qualifier from pointer target type [enabled by default]
/tmp/pear/temp/xhprof/extension/xhprof.c:856:14: note: expected 'char *' but argument is of type 'const char *'make: *** [xhprof.lo] Error 1
ERROR: `make' failed

According to a PHP bug report, this issue was fixed by Facebook but not made available on pecl, so you will need to install from the xhprof github repo, like so:

wget https://github.com/facebook/xhprof/archive/master.zip
unzip master.zip
cd xhprof-master/extension/
phpize
./configure
make
sudo make install

And enable the module in your php.ini, where `xhprof.output_dir` is the directory into which profiles will be generated.

[xhprof]
extension=xhprof.so
xhprof.output_dir="/var/tmp/xhprof"

And restart apache, with either of the following two:
sudo service apache2 restart or sudo apachectl graceful

Existing users who have upgraded to PHP 5.4 may opt for this xhprof-0.9.2 patch.


版权及转载说明

本站原创、转载文章欢迎任何形式的转载,但请务必注明出处,尊重他人劳动共创开源社区

本站转载文章版权归原作者所有,如发现本站文章涉嫌侵权请点击「联系我们」反馈,本站将立即给予删除

转载请注明:文章转载自:全分享社区 「http://www.aweb.cc

本文标题:Xhprof - PHP函数级分层性能分析工具安装

本文地址:http://www.aweb.cc/article/detail/id/480.html

php统计字符串中中英文字符的个数 <<上一篇 下一篇>>PHP扩展函数库-文件系统、进程与网络