5

生成火焰图分析php代码

 2 years ago
source link: https://y2k38.github.io/posts/how-to-generate-php-flamegraphs/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

生成火焰图分析php代码

发表于

2020-01-23 更新于 2020-02-02

flamegraph是一款可视化工具,用户分析程序堆栈调用,x轴堆栈轨迹,y轴堆栈深度,x轴长度越长,占用更多cpu时间。下面简单介绍如何使用xdebug以及flamegraph生成火焰图

配置xdebug参数

xdebug.trace_output_name = xdebug.trace.%t.%s
xdebug.trace_enable_trigger = 1
xdebug.trace_output_dir = /tmp
xdebug.trace_enable_trigger_value = "<secret key>"
xdebug.trace_format=1

下载flamegraph,git clone https://github.com/brendangregg/FlameGraph.git,放置在任意位置

获取堆栈数据

请求页面/接口url,在url后面增加?XDEBUG_TRACE=<secret key>,获取php堆栈数据 curl http://youdomain.com?XDEBUG_TRACE=<secret key>

转换堆栈数据

./stackcollapse-xdebug.php /tmp/xdebug.trace.1579703170._data_www_yii2_web_index_php.xt > out.folded

生成火焰图

./flamegraph.pl out.folded > out.svg

yii2 flamegraph example

How to generate PHP Flamegraphs
Flame Graphs visualize profiled code


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK