当前位置: 首页 > 后端技术 > PHP

结合phpxdebugwebGrind查看调用链接和性能(适用于老项目的整理和维护)

时间:2023-03-29 16:02:29 PHP

背景:由于最近维护老项目,各种工厂类,各种parent嵌入父类。各种抽象扩展,依赖于项目外的许多通用和中间件。不能在IDE中直接跳转,急需清除方法的调用链接。研究中出现了以下组件组合。本文不涉及具体安装步骤,核心是文末链接地址^_^涉及基础组件python3gprof2dot.pyscriptphp7.*xdebugphp的扩展,如果没有安装,访问本手册安装graphviz(dot)webgrind主要用于web图形操作,shell_exec为dot和python,注意clone后需要根据自己机器安装python的位置更改config.php】效果点击上图中的ShowCallGraph,并选择需要跟踪的接口(上图下拉框中的列表),可以有如下可选组件openssl(主要解决pip3installgprof2dot的'SSLError'问题,本文不涉及解决这个问题)安装时如何使用QCachegrind给请求的url添加参数?分析文件,如xx.com?XDEBUG_PROFILExdebug配置,主要涉及profiler相关选项[xdebug]zend_extension=/home/r/php7.13/lib/php/extensions/no-debug-non-zts-20151012/xdebug.soxdebug.idekey="PHPSTORM"xdebug.default_enable=On#xdebug.remote_connect_back=1xdebug.remote_port=9001xdebug.remote_enable=onxdebug.remote_host=10.2.23.200xdebug.remote_port=9001xdebug.remote_handler="db,autodemote.startdebugx"xdebugx在"xdebug.auto_trace=1xdebug.trace_output_dir="/tmp/xdebug"xdebug.profiler_output_dir="/tmp/xdebug"xdebug.profile_output_name="script.%t-%s"xdebug.profiler_output_dir="/home/r/php7/xdebug/profiler"#xdebug.trace_output_dir="/home/r/www/xdebug_trace"#xdebug.trace_output_dir="/home/r/www/xdebug_trace"#xdebug.trace_output_name="%R.html"#xdebug.collect_params=2#xdebug.collect_return=1#xdebug.show_mem_delta=1#xdebug.trace_format=2xdebug.profiler_enable_trigger=1xdebug.profiler_output_name=cachegrind.out.%t.%pxdebug.profiler_enable=1xdebug.profiler_append=0xdebug.profiler_aggregare=0webgrind项目的nginx配置服务器{listen80;服务器名称p.webgrind.com;根/home/r/www/webgrind/webgrind;index.php;access_log/home/r/nginx/logs/webgrind.access.log;error_log/home/r/nginx/logs/webgrind.error.log;位置/{索引index.php;try_files$uri$uri//index.php?$args;}location~.*\.(php|php7)?${fastcgi_pass127.0.0.1:9000;fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;fastcgi_indexindex.php;包括fastcgi_params;client_max_body_size30M;client_body_temp_path/数据;}}其他参考配置(主要是config.php和index.php)centos6*版本下载阿里云Centos-6.repo文件wget-OCentOS-Base.repohttp://mirrors.aliyun.com/repo/centos-6.reporeloadsyumyumcleanallyummakecacheyuminstallgraphvizwindowsversionwindows比较简单,可以先通过脚本测试xdebug收集的信息py脚本能不能生成图pythongprof2dot.py-n10-fcallgrind.\cacheGrind\cachegrind.out.1657783826.106186|dot-Tpng-omy.png核心文章:https://github.com/jrfonseca/。..https://github.com/jokkedk/we...https://pyspace.github.io/pys...相关下载链接:http://www.openssl.org/source...https://www.python.org/ftp/py...https://raw.githubusercontent...http://slproweb.com/download/...https://gitlab.com/api/v4/pro...https://www.seidengroup.com/p...其他性能和调用链生成工具oneAPMxhprof+xhGuiworkerman-statisticsBlackfirenewRelictidewaysgo-callvishttps://repo.seidengroup.com/...