2025年性能调优不能光靠拍脑门子

性能调优不能光靠拍脑门子qcachegrind 背景 可量化是问题解决的前提条件 性能优化不能仅仅局限于理论分析 要通过性能分析工具辅助来得出量化指标 从而更加准确的去衡量优化方案 每种成熟的语言都有自己的性能监测工具 例如 golang pprof php xdebug xhprof 这些性能监测工具通过钩子埋点等方式对程序的耗时 内存使用量

大家好,我是讯享网,很高兴认识大家。

qcachegrind

背景

  • golang : pprof
  • php : xdebug , xhprof

这些性能监测工具通过钩子埋点等方式对程序的耗时,内存使用量,调用顺序等关键数据进行记录.从而生成响应的监测报告.
这些文件生成时都是按照统一的报告协议进行记录,这样便于使用成熟的分析工具(或自研工具)来解析分析报告.同时也便于
开发通用的性能分析工具来解析不同语言产生的分析报告.

市面上比较流行的单机的性能监测工具有:

  • qcachegrind -> platform:Win / MacOS
  • kcachegrind -> platform:Linux
  • webgrind -> platform: Linux / Win / MacOS 这个非常棒

kcachegrind 与 qcachegrind实质上是同一个东西,只不过两者使用的图形引擎不同.kcachegrind基于KDE. 而qcachegrind基于Qt.


讯享网

xdebug 生成性能分析文件,qcachegrind格式化该文件,提供良好的可读性.

brew install graphviz brew install qcachegrind 

讯享网

MacOS: qcachegrind 安装

  1. brew install graphviz 执行此命令安装graphviz,用来Call Graph功能
  2. brew install qcachegrind 安装qcachegrind. (如果 call graph 功能不能使用.请sudo ln -s /usr/local/bin/dot /usr/bin/dot)

运行qcachegrind

讯享网#> nohup qcachegrind & 

dashboard 指标解读

  • invocation count
  • total inclusive cost => incl shows the time consumed by the function including callees
  • total self count shows the time consumed by the function not including callees cost

单词释义

  • caller 调用者
  • callees 被调用者
  • invocation 调用
  • invoke 调用,援引

xdebug 配置实例

[xdebug] zend_extension=/usr/lib/php/extensions/no-debug-non-zts-/xdebug.so xdebug.remote_enable=on xdebug.idekey='PHPSTORM' xdebug.remote_host=127.0.0.1 xdebug.remote_port=9001 ; 性能分析部分 xdebug.profiler_enable=Off ; 开启性能分析触发模式 而不是对于每一个请求都触发性能分析 与 xdebug.profiler_enable=0 时配合使用:w xdebug.profiler_enable_trigger=On ; url中包含XDEBUG_PROFILE参数对时才会触发性能分析 eg. http://local.web.vhall.com/index.php?XDEBUG_PROFILE=aaa xdebug.profiler_enable_trigger_value='aaa' xdebug.profiler_output_dir="/Users/sujianhui/PhpstormProjects/profiler_output" xdebug.profiler_output_name=callgrind.out.%u 

参考资料

qcachegrind安装指南 https://blog.csdn.net/weixin_/article/details/
QCacheGrind工具使用简介 https://blog.csdn.net/raoxiaoya/article/details/
xdebug速查表 https://blog.csdn.net//article/details/
phpstorm中xdebug的配置 https://www.cnblogs.com/yjken/p/8435018.html
仪表盘参数解读 https://stackoverflow.com/questions//how-do-i-read-the-ui-of-qcachegrind

小讯
上一篇 2025-03-09 10:37
下一篇 2025-04-01 21:48

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/80789.html