xdebug+WinCacheGrind+qcachegrind来分析脚本执行时间

xdebug简介

Xdebug是php的一款调试工具,是基于zend的一个扩展,可以用来跟踪,调试和分析PHP程序的运行状况。如变量,函数调试,性能监测,代码覆盖率等


xdebug安装

1.下载xdebug源程序

git clone git://github.com/xdebug/xdebug.git
https://xdebug.org/download.php#releases

2.解压xdebug包
tar -xzvf xdebug.tgz

3.进入解压目录
cd xdebug

4.运行phpize
/usr/local/php/bin/phpize

5.编译
./configure --enable-xdebug --with-php-config=/usr/local/php/bin/php-config

6.安装
make && make install

7.安装成功后会在php扩展目录生成类似xdebug.so的扩展

8.安装xdebug客户端xdebugclient (需要libedit扩展)

cd debugclient
./configure --with-libedit
make
make install

xdebug配置

1.在php.ini配置文件中添加如下内容
zend_extension="/wherever/you/put/it/xdebug.so"
2.如果是php5.3之前版本线程安全,添加如下内容代替上面1的内容
zend_extension_ts="/wherever/you/put/it/xdebug.so"
3.自从php5.3之后zend_extension_ts, zend_extension_debug不再使用

4.xdebug的一些其他配置

;显示错误信息
xdebug.default_enable = 1

;函数调试
xdebug.auto_trace=on
xdebug.trace_output_dir
xdebug.trace_output_name
;Type: string, Default value: trace.%c
xdebug.collect_params = 1|3|4 (参数长度,参数值,参数=值)
xdebug.show_mem_delta=1 显示内存
xdebug.collect_return=1 显示返回值
xdebug.trace_options =1 追加日志
xdebug.collect_params=1
xdebug.collect_vars = 1

;开启性能分析
xdebug.profiler_enable=1
;性能分析日志保存目录
xdebug.profiler_output_dir = /data/logs/xdebug/
;性能分析日志文件名称
xdebug.profiler_output_name = cachegrind.out.log
;默认是如下格式,t时间,p进程id
;xdebug.profiler_output_name = cachegrind.out.%t.%p

;代码覆盖率
xdebug.coverage_enable = 1

;以下是远程调试配置
xdebug.remote_host= 127.0.0.1
xdebug.remote_connect_back = 1
xdebug.remote_port = 9000
xdebug.remote_log="/data/logs/xdebug/xdebug.log"

4.重启php使配置生效


性能分析日志工具

1.linux平台

工具KCacheGrind (Linux, KDE) https://kcachegrind.github.io/

2.win平台查看工具WinCacheGrind

相关网址

http://ceefour.github.io/wincachegrind/
https://sourceforge.net/projects/wincachegrind/
https://github.com/ceefour/wincachegrind/releases/tag/1.1

列名称含义

Self - Shows the execution time of the code in the current block

Cum. - Shows the total exuction time of functions that the current function (Self) calls

Avg vs. Total: Average is average time per call, Total is the total time spend in all calls.

3.Web方式查看webgrind

https://github.com/jokkedk/webgrind

 

 

现在开始安装qcachegrind工具吧(因为我用的是mac所以这里介绍用mac安装方式):

(1)brew install graphviz
    执行此命令安装graphviz,用来Call Graph功能
(2)brew install qcachegrind
    安装qcachegrind
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值