亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

使用 Xdebug + Webgrind 分析 PHP 程序

標簽:
PHP

安装 xdeubg zend 扩展

# yum install php-pecl-xdebug

配置 php.d/xdebug.ini

# vi /etc/php.d/xdebug.ini;加入以下内容; profilerxdebug.profiler_enable=1xdebug.profiler_enable_trigger=1xdebug.profiler_output_dir=/tmp/xdebugxdebug.profiler_output_name=cachegrind.out.%p; tracexdebug.auto_trace=1xdebug.show_exception_trace=1xdebug.trace_output_dir=/tmp/xdebugxdebug.trace_output_name=trace.%c

注:需手工创建 /tmp/xdebug 目录且所属用户应为 php-fpm 配置文件中的 user 用户。 配置完毕,重启 service php-fpm restart

下载 webgrind

$ cd /var/www/html/$ git clone git://github.com/jokkedk/webgrind.git

安装 graphviz

# yum install graphviz

graphviz 附带 dot 命令用于下文的配置。

使用 webgrind

webgrind v1.1 的版本增加了 Show Call Graph 按钮,依赖 pythondot 命令, 类似 xhprof 的View Full Callgraph 绘制程序调用流程图功能,相对于 xhprof 较简洁。 更多 xhprof 信息请查看 使用 XHProf 分析你的 PHP 程序。

配置 webgrind 的绘制流程图功能,查看 pythondot 命令位置 which pythonwhich dot,编辑 webgrind/config.php,将 $pythonExecutable = '/usr/bin/python'$dotExecutable = '/usr/bin/dot' 替换为刚查到相应路径。

在浏览器访问任意一个项目路径,/tmp/xdebug 目录下会生成一个 cachegrind.out.xxxxx 文件作为 webgrind 的数据来源,打开 webgrind 页面,如:http://localhost/webgrind/, 点击右上角update 按钮即会分析最后一次访问的项目地址的 PHP 程序,可以通过选择第二个 下拉框中的地址来分析相应的程序,点击 Show Call Graph 按钮就会显示当前分析的程序的 简明调用流程图。

表格中后三列的含义:

InvocationCount:函数调用次数TotalSelfCost:函数本身花费的时间TotalInclusiveCost:包含内部函数花费的时间

简析 webgrind 生成流程图

webgrind 生成流程图使用源码下的 library/gprof2dot.pypython 脚本, 先将cachegrind.out.xxxxx 转换成 DOT,再使用 dot 命令转换成图片输出。

PHP 使用 shell_exec 函数执行:

/usr/bin/python library/gprof2dot.py -n 10-f callgrind /tmp/xdebug/cachegrind.out.xxxxx |/usr/bin/dot -Tpng-o /tmp/xdebug/cachegrind.out.xxxxx-10.webgrind.png
转载请注明出处。
本文地址:http://blog.aboutc.net/profiling/18/php-profiler-xdebug-webgrind


點擊查看更多內容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消