注册 登录  
 加关注
查看详情
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

阿飘的博客

十里平湖霜满天 寸寸青丝愁华年

 
 
 

日志

 
 

安装php的调试工具xhprof  

2011-11-07 21:51:29|  分类: php |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
facebook出的一个php的调试工具:
相关文档在:http://mirror.facebook.net/facebook/xhprof/doc.html
http://pecl.php.net/package/xhprof
首先就是需要到http://pecl.php.net/package/xhprof下载,或者直接
wget http://pecl.php.net/package/xhprof
然后:
tar xzvf xhprof-0.9.2.tgz
cd xhprof-0.9.2
注意在安装前需要安装phpize如果没有安装
在ubuntu下可以apt-get install php5-dev
如果安装不上,则可以

ubuntu 安装:
apt-get install autoconf
apt-get install php5-dev

centos 安装:
yum install php-devel
yum install autoconf

安装完成后
root@liufabin-laptop:/opt/xhprof-0.9.2# cd extension/
root@liufabin-laptop:/opt/xhprof-0.9.2/extension# phpize
Configuring for:
PHP Api Version:         20041225
Zend Module Api No:      20060613
Zend Extension Api No:   220060519
下一步非常重要:
  ./configure --with-php-config=/usr/bin/php-config
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc and cc understand -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking target system type... i686-pc-linux-gnu
checking for PHP prefix... /usr
checking for PHP includes... -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
checking for PHP extension directory... /usr/lib/php5/20060613+lfs
checking for PHP installed headers prefix... /usr/include/php5
checking for re2c... no
configure: WARNING: You will need re2c 0.12.0 or later if you want to regenerate PHP parsers.
checking for gawk... no
checking for nawk... nawk
checking if nawk is broken... no
checking whether to enable xhprof support... yes, shared
checking for a sed that does not truncate output... (cached) /bin/sed
checking for fgrep... /bin/grep -F
checking for ld used by gcc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864
checking whether the shell understands some XSI constructs... yes
checking whether the shell understands "+="... yes
checking for /usr/bin/ld option to reload object files... -r
checking how to recognize dependent libraries... pass_all
checking for ar... ar
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking how to run the C preprocessor... gcc -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... no
checking for gcc option to produce PIC... -fPIC -DPIC
checking if gcc PIC flag -fPIC -DPIC works... yes
checking if gcc static flag -static works... yes
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/usr/bin/ld) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
configure: creating ./config.status
config.status: creating config.h
config.status: config.h is unchanged
config.status: executing libtool commands
nfig
这个是默认的目录,你可以按照自己安装的目录更改
然后make&&make install 然后make test
即可,然后找到php.ini
添加:

1241 [xhprof]
1242 extension=xhprof.so
1243 ;#
1244 ;# directory used by default implementation of the iXHProfRuns
1245 ;# interface (namely, the XHProfRuns_Default class) for storing
1246 ;# XHProf runs.
1247 ;#
1248 xhprof.output_dir=/opt/xhprof/
 kilall -9 php
然后重启即可
你如果看到这个就算成功了
安装php的调试工具xhprof -  小和尚 - 小和尚真情无限
然后添加测试脚本:
<?php
 
function bar($x) {
if ($x > 0) {
bar($x - 1);
}
}
 
function foo() {
for ($idx = 0; $idx < 2; $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);

结果为:
Array
(
[foo==>bar] => Array
(
[ct] => 2
[wt] => 15
)

[foo==>strlen] => Array
(
[ct] => 2
[wt] => 0
)

[bar==>bar@1] => Array
(
[ct] => 1
[wt] => 2
)

[main()==>foo] => Array
(
[ct] => 1
[wt] => 38
)

[main()==>xhprof_disable] => Array
(
[ct] => 1
[wt] => 0
)

[main()] => Array
(
[ct] => 1
[wt] => 45
)

)



具体可以看文档
http://www.ec-os.net/misc/xhprof.html
  评论这张
 
阅读(1485)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018