用xdebug的函数跟踪功能测试网站性能

发表于:2015-9-30 10:20

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:小小平凡世界    来源:51Testing软件测试网采编

  相信做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秒,这两个函数花的时间远远高于其他函数所花的时间,好了,有了这些报告,我们就知道可以从哪些地方优化网站性能了。
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号