用xdebug的函数跟踪功能测试网站性能
2012-03-20 17:48
197 查看
相信做php开发的朋友很多都认识xdebug,它确实是php开发过程中检查错误与性能分析的好工具。本章将介绍它的一个蛮不错的功能:函数跟踪。它可以根据程序在实际运行时的执行顺序,跟踪记录所有函数的执行时间,以及函数调用时的上下文,包括实际参数和返回值。
要开启xdebug的函数跟踪功能,需要在php.ini中做一些设置。设置如下:
extension=php_xdebug.dll
[xdebug]
xdebug.auto_trace=on
xdebug.trace_options=1
xdebug.trace_output_dir="E:\web\server\tmp\xdebug\trace"
xdebug.trace_output_name=trace.%c
配置好了时候,重启Apache,然后执行页面就会在E:\web\server\tmp\xdebug\trace目录下生成报告文件。
打开报告文件,格式类似如下:
0.0348 379272 -> dirname() E:\web\host\mysite.com\framework\Controller.php:27
0.0395 655712 -> require(E:\web\host\mysite.com\framework\smarty\Smarty.class.php) E:\web\host\mysite.com\framework\Controller.php:27
0.0396 657784 -> defined() E:\web\host\mysite.com\framework\smarty\Smarty.class.php:37
0.0396 657824 -> define() E:\web\host\mysite.com\framework\smarty\Smarty.class.php:38
0.0397 657840 -> defined() E:\web\host\mysite.com\framework\smarty\Smarty.class.php:45
0.0398 657864 -> dirname() E:\web\host\mysite.com\framework\smarty\Smarty.class.php:46
0.0399 657864 -> define() …………………………………………………………………………………………………………………………..…………………………………………………………………………………………………………………………..
0.0206 300960 -> require_once(E:\web\host\mysite.com\app\protected\models\Test.php)
0.0209 300672 -> is_resource() E:\web\host\mysite.com\framework\Model.php:63
0.0209 300672 -> Model->_connect() E:\web\host\mysite.com\framework\Model.php:63
0.0210 301776 -> PDO->__construct() E:\web\host\mysite.com\framework\Model.php:71
0.0253 299736 -> Test->selectData() E:\web\host\mysite.com\app\protected\controllers\DefaultController.php:25
0.0254 299896 -> Model->select() E:\web\host\mysite.com\app\protected\models\Test.php:43
从报告中,可以看到require(E:\web\host\mysite.com\framework\smarty\Smarty.class.php)花了0.0047s,另外Test->selectData()函数花了0.0043秒,这两个函数花的时间远远高于其他函数所花的时间,好了,有了这些报告,我们就知道可以从哪些地方优化网站性能了。
要开启xdebug的函数跟踪功能,需要在php.ini中做一些设置。设置如下:
extension=php_xdebug.dll
[xdebug]
xdebug.auto_trace=on
xdebug.trace_options=1
xdebug.trace_output_dir="E:\web\server\tmp\xdebug\trace"
xdebug.trace_output_name=trace.%c
配置好了时候,重启Apache,然后执行页面就会在E:\web\server\tmp\xdebug\trace目录下生成报告文件。
打开报告文件,格式类似如下:
0.0348 379272 -> dirname() E:\web\host\mysite.com\framework\Controller.php:27
0.0395 655712 -> require(E:\web\host\mysite.com\framework\smarty\Smarty.class.php) E:\web\host\mysite.com\framework\Controller.php:27
0.0396 657784 -> defined() E:\web\host\mysite.com\framework\smarty\Smarty.class.php:37
0.0396 657824 -> define() E:\web\host\mysite.com\framework\smarty\Smarty.class.php:38
0.0397 657840 -> defined() E:\web\host\mysite.com\framework\smarty\Smarty.class.php:45
0.0398 657864 -> dirname() E:\web\host\mysite.com\framework\smarty\Smarty.class.php:46
0.0399 657864 -> define() …………………………………………………………………………………………………………………………..…………………………………………………………………………………………………………………………..
0.0206 300960 -> require_once(E:\web\host\mysite.com\app\protected\models\Test.php)
0.0209 300672 -> is_resource() E:\web\host\mysite.com\framework\Model.php:63
0.0209 300672 -> Model->_connect() E:\web\host\mysite.com\framework\Model.php:63
0.0210 301776 -> PDO->__construct() E:\web\host\mysite.com\framework\Model.php:71
0.0253 299736 -> Test->selectData() E:\web\host\mysite.com\app\protected\controllers\DefaultController.php:25
0.0254 299896 -> Model->select() E:\web\host\mysite.com\app\protected\models\Test.php:43
从报告中,可以看到require(E:\web\host\mysite.com\framework\smarty\Smarty.class.php)花了0.0047s,另外Test->selectData()函数花了0.0043秒,这两个函数花的时间远远高于其他函数所花的时间,好了,有了这些报告,我们就知道可以从哪些地方优化网站性能了。
相关文章推荐
- 用xdebug的函数跟踪功能测试网站性能
- 网站性能-xdebug工具的使用
- php性能优化分析工具XDebug 大型网站调试工具
- php性能优化分析工具XDebug 大型网站调试工具
- 大型网站调试工具之一(php性能优化分析工具XDebug)
- php性能优化分析工具XDebug 大型网站调试工具
- 大型网站调试工具之一(php性能优化分析工具XDebug)
- 网站性能跟踪及优化
- 大型网站调试工具之一(php性能优化分析工具XDebug)
- Linux下用内存管理器的钩子函数跟踪内存泄漏 本篇文章来源于 Linux公社网站(www.linuxidc.com) 原文链接:http://www.linuxidc.com/Linux/200
- 大型网站调试工具之一(php性能优化分析工具XDebug)
- 分享Web应用运行的细节问题:预编译提高网站性能、跟踪用户习惯和解决线程同步
- 大型网站调试工具之一(php性能优化分析工具XDebug)
- Xdebug文档(四)函数跟踪
- Web应用运行的细节问题:预编译提高网站性能、跟踪用户习惯和解决线程同步
- 大型网站调试工具之一(php性能优化分析工具XDebug)
- 大型网站调试工具之一(php性能优化分析工具XDebug)
- 大型网站调试工具之一(php性能优化分析工具XDebug)
- 大型网站调试工具之一(php性能优化分析工具XDebug)
- 分享Web应用运行的细节问题:预编译提高网站性能、跟踪用户习惯和解决线程同步