欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

Drupal/PHP性能分析工具之xDebug

Drupal/PHP性能分析工具之xDebug

PDF版本    

Profiling/Profiler,可以译为性能分析、程序分析或者程序剖析,是分析代码、查找问题以及解决程序性能问题中最常用的方法,大多程序语言都有相应的Profile工具或API方法,PHP中最常用的分析工具有,xdebug、xhprof,以及APD (Advanced PHP Debugger)。本文就xdebug的profiling功能做一下简要介绍,关于xhprof和APD会在后续博文中介绍。

xdebug的功能很多,比如断点调试,trace错误等等,还有就是profiling功能,它可以记录一个PHP请求的所有执行过程,然后通过相应的工具就可以查看其执行的具体细节,比如函数的执行顺序,消耗时间等等。

开启xdebug的profiling功能    

第一步,安装xdebug,一般用pecl安装即可,或者用apt/yum工具,windows下找对于的dll文件。
第二步,配置文件。

zend_extension=/usr/lib64/php/modules/xdebug.so
#注意修改路径 lib64 lib32等
 
xdebug.profiler_enable_trigger = 1
#通过在URL中传递参数XDEBUG_PROFILE来激活profiling,比如index.php?XDEBUG_PROFILE
xdebug.profiler_output_dir=/tmp/xdebug/
#确保文件夹存在,该位置是profiler输出文件的位置。
#xdebug会生成名为cachegrind.out.xxx类型的文件,该文件可以用相应的工具打开来查看程序的profiling。
                   

完成之后,重启服务器,然后在参数中添加XDEBUG_PROFILE来打开profiling,比如drupal的首页

http://www.example.com/index.php?XDEBUG_PROFILE

接下来,我们到/tmp/xdebug文件夹下面查看是否生成了profiling文件,windows下可以用wincachegrind,linux下可以使用kcachegrind,还有web版的webgrind,wincachegrind和kcachegrind都很简单,打开对应的out文件即可,本文就跨平台的webgrind做一下简要介绍。

WebGrind    

项目首页http://code.google.com/p/webgrind/    

下载webgrind,放置到web服务器目录下面,然后打开config.php文件,找到如下两行,修改为正确的值:

static $storageDir = '/tmp/storage';
static $profilerDir = '/tmp/xdebug';
                   

然后通过浏览器访问webgrind,比如 http://www.example.com/webgrind/index.php

Drupal PHP WebGrind Profiler    

最后可以给webgrind加个访问限制,如

AuthName "Only user access:"
AuthType Basic
AuthUserFile /var/www/html/www.example.com/html/profiler/.htpasswd
require valid-user
                   

WinCacheGrind地址
http://sourceforge.net/projects/wincachegrind/    

KCacheGrind地址    

   

http://kcachegrind.sourceforge.net/html/Home.html    


声明: 本站所有文章欢迎转载,所有文章未说明,均属于原创,转载均请注明出处。 
本文有效链接: http://www.drupal001.com/2012/02/drupal-php-profiling-xdebug-xhprof/ 
版权所有: Drupal与高性能网站架构 http://www.drupal001.com    

来自  http://www.drupal001.com/2012/02/drupal-php-profiling-xdebug-xhprof/

普通分类: