# Flame Graphs visualize profiled code
Main Website: http://www.brendangregg.com/flamegraphs.html
Example (click to zoom):
[![Example](http://www.brendangregg.com/FlameGraphs/cpu-bash-flamegraph.svg)](http://www.brendangregg.com/FlameGraphs/cpu-bash-flamegraph.svg)
Click a box to zoom the Flame Graph to this stack frame only.
To search and highlight all stack frames matching a regular expression, click the _search_ button in the upper right corner or press Ctrl-F.
By default, search is case sensitive, but this can be toggled by pressing Ctrl-I or by clicking the _ic_ button in the upper right corner.
Other sites:
- The Flame Graph article in ACMQ and CACM: http://queue.acm.org/detail.cfm?id=2927301 http://cacm.acm.org/magazines/2016/6/202665-the-flame-graph/abstract
- CPU profiling using Linux perf\_events, DTrace, SystemTap, or ktap: http://www.brendangregg.com/FlameGraphs/cpuflamegraphs.html
- CPU profiling using XCode Instruments: http://schani.wordpress.com/2012/11/16/flame-graphs-for-instruments/
- CPU profiling using Xperf.exe: http://randomascii.wordpress.com/2013/03/26/summarizing-xperf-cpu-usage-with-flame-graphs/
- Memory profiling: http://www.brendangregg.com/FlameGraphs/memoryflamegraphs.html
- Other examples, updates, and news: http://www.brendangregg.com/flamegraphs.html#Updates
Flame graphs can be created in three steps:
1. Capture stacks
2. Fold stacks
3. flamegraph.pl
1\. Capture stacks
=================
Stack samples can be captured using Linux perf\_events, FreeBSD pmcstat (hwpmc), DTrace, SystemTap, and many other profilers. See the stackcollapse-\* converters.
### Linux perf\_events
Using Linux perf\_events (aka "perf") to capture 60 seconds of 99 Hertz stack samples, both user- and kernel-level stacks, all processes:
```
# perf record -F 99 -a -g -- sleep 60
# perf script > out.perf
```
Now only capturing PID 181:
```
# perf record -F 99 -p 181 -g -- sleep 60
# perf script > out.perf
```
### DTrace
Using DTrace to capture 60 seconds of kernel stacks at 997 Hertz:
```
# dtrace -x stackframes=100 -n 'profile-997 /arg0/ { @[stack()] = count(); } tick-60s { exit(0); }' -o out.kern_stacks
```
Using DTrace to capture 60 seconds of user-level stacks for PID 12345 at 97 Hertz:
```
# dtrace -x ustackframes=100 -n 'profile-97 /pid == 12345 && arg1/ { @[ustack()] = count(); } tick-60s { exit(0); }' -o out.user_stacks
```
60 seconds of user-level stacks, including time spent in-kernel, for PID 12345 at 97 Hertz:
```
# dtrace -x ustackframes=100 -n 'profile-97 /pid == 12345/ { @[ustack()] = count(); } tick-60s { exit(0); }' -o out.user_stacks
```
Switch `ustack()` for `jstack()` if the application has a ustack helper to include translated frames (eg, node.js frames; see: http://dtrace.org/blogs/dap/2012/01/05/where-does-your-node-program-spend-its-time/). The rate for user-level stack collection is deliberately slower than kernel, which is especially important when using `jstack()` as it performs additional work to translate frames.
2\. Fold stacks
==============
Use the stackcollapse programs to fold stack samples into single lines. The programs provided are:
- `stackcollapse.pl`: for DTrace stacks
- `stackcollapse-perf.pl`: for Linux perf_events "perf script" output
- `stackcollapse-pmc.pl`: for FreeBSD pmcstat -G stacks
- `stackcollapse-stap.pl`: for SystemTap stacks
- `stackcollapse-instruments.pl`: for XCode Instruments
- `stackcollapse-vtune.pl`: for Intel VTune profiles
- `stackcollapse-ljp.awk`: for Lightweight Java Profiler
- `stackcollapse-jstack.pl`: for Java jstack(1) output
- `stackcollapse-gdb.pl`: for gdb(1) stacks
- `stackcollapse-go.pl`: for Golang pprof stacks
- `stackcollapse-vsprof.pl`: for Microsoft Visual Studio profiles
- `stackcollapse-wcp.pl`: for wallClockProfiler output
Usage example:
```
For perf_events:
$ ./stackcollapse-perf.pl out.perf > out.folded
For DTrace:
$ ./stackcollapse.pl out.kern_stacks > out.kern_folded
```
The output looks like this:
```
unix`_sys_sysenter_post_swapgs 1401
unix`_sys_sysenter_post_swapgs;genunix`close 5
unix`_sys_sysenter_post_swapgs;genunix`close;genunix`closeandsetf 85
unix`_sys_sysenter_post_swapgs;genunix`close;genunix`closeandsetf;c2audit`audit_closef 26
unix`_sys_sysenter_post_swapgs;genunix`close;genunix`closeandsetf;c2audit`audit_setf 5
unix`_sys_sysenter_post_swapgs;genunix`close;genunix`closeandsetf;genunix`audit_getstate 6
unix`_sys_sysenter_post_swapgs;genunix`close;genunix`closeandsetf;genunix`audit_unfalloc 2
unix`_sys_sysenter_post_swapgs;genunix`close;genunix`closeandsetf;genunix`closef 48
[...]
```
3\. flamegraph.pl
================
Use flamegraph.pl to render a SVG.
```
$ ./flamegraph.pl out.kern_folded > kernel.svg
```
An advantage of having the folded input file (and why this is separate to flamegraph.pl) is that you can use grep for functions of interest. Eg:
```
$ grep cpuid out.kern_folded | ./flamegraph.pl > cpuid.svg
```
Provided Examples
=================
### Linux perf\_events
An example output from Linux "perf script" is included, gzip'd, as example-perf-stacks.txt.gz. The resulting flame graph is example-perf.svg:
[![Example](http://www.brendangregg.com/FlameGraphs/example-perf.svg)](http://www.brendangregg.com/FlameGraphs/example-perf.svg)
You can create this using:
```
$ gunzip -c example-perf-stacks.txt.gz | ./stackcollapse-perf.pl --all | ./flamegraph.pl --color=java --hash > example-perf.svg
```
This shows my typical workflow: I'll gzip profiles on the target, then copy them to my laptop for analysis. Since I have hundreds of profiles, I leave them gzip'd!
Since this profile included Java, I used the flamegraph.pl --color=java palette. I've also used stackcollapse-perf.pl --all, which includes all annotations that help flamegraph.pl use separate colors for kernel and user level code. The resulting flame graph uses: green == Java, yellow == C++, red == user-mode native, orange == kernel.
This profile was from an analysis of vert.x performance. The benchmark client, wrk, is also visible in the flame graph.
### DTrace
An example output from DTrace is also included, example-dtrace-stacks.txt, and the resulting flame graph, example-dtrace.svg:
[![Example](http://www.brendangregg.com/FlameGraphs/example-dtrace.svg)](http://www.brendangregg.com/FlameGraphs/example-dtrace.svg)
You can generate this using:
```
$ ./stackcollapse.pl example-stacks.txt | ./flamegraph.pl > example.svg
```
This was from a particular performance investigation: the Flame Graph identified that CPU time was spent in the lofs module, and quantified that time.
Options
=======
See the USAGE message (--help) for options:
USAGE: ./flamegraph.pl [options] infile > outfile.svg
--title TEXT # change title text
--subtitle TEXT # second level title (optional)
--width NUM # width of image (default 1200)
--height NUM # height of each frame (default 16)
--minwidth NUM # omit smaller functions (default 0.1 pixels)
--fonttype FONT # font type (default "Verdana")
--fontsize NUM # font size (default 12)
--countname TEXT # count type label (default "samples")
--nametype TEXT # name type label (default "Function:")
--colors PALETTE # set color palette. choices are: hot (default), mem,
# io, wakeup, chain, java, js, perl, red, green, blue,
# aqua, yellow, purple, orange
--bgcolors COLOR # set background colors. gradient choices are yellow
# (default), blue, green, grey; flat colors use "#rrggbb"
--hash # colors are keyed by function name hash
--cp # use consistent palette (palette.map)
--reverse # generate stack-reversed flame graph
--inverted # icicle graph
--flamechart # produce a flame chart (sort by time, do not merge stacks)
--negate # switch differential hues (blue<->red)
--notes TEXT # add notes comment in SVG (for debugging)
--help # this message
eg,
./flamegraph.pl --title="Flame Gr
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
收起资源包目录
性能验证工具,可以查看到每个子函数的时间消耗情况 (180个子文件)
stackcollapse-sample.awk 8KB
stackcollapse-perf-sched.awk 6KB
stackcollapse-ljp.awk 2KB
config 267B
gatherthc-kern.d 575B
gatherhc-kern.d 461B
description 73B
exclude 240B
example-perf-stacks.txt.gz 108KB
HEAD 179B
HEAD 179B
HEAD 32B
HEAD 23B
cpu-zoomable.html 450KB
pack-2709f57ff9b7813da36dda8b15e008fb0810eda3.idx 32KB
index 16KB
jmaps 3KB
master 179B
master 41B
README.md 9KB
pack-2709f57ff9b7813da36dda8b15e008fb0810eda3.pack 1.9MB
packed-refs 301B
stackcollapse-xdebug.php 6KB
flamegraph.pl 37KB
stackcollapse-perf.pl 13KB
hotcoldgraph.pl 8KB
stackcollapse-jstack.pl 5KB
range-perf.pl 4KB
difffolded.pl 4KB
stackcollapse-go.pl 4KB
stackcollapse-vtune.pl 3KB
stackcollapse-vsprof.pl 3KB
stackcollapse.pl 3KB
pkgsplit-perf.pl 3KB
thcstackcollapse.pl 3KB
stackcollapse-pmc.pl 3KB
hcstackcollapse.pl 2KB
stackcollapse-stap.pl 2KB
stackcollapse-elfutils.pl 2KB
stackcollapse-wcp.pl 2KB
stackcollapse-gdb.pl 2KB
stackcollapse-java-exceptions.pl 2KB
stackcollapse-bpftrace.pl 2KB
files.pl 2KB
stackcollapse-recursive.pl 2KB
stackcollapse-aix.pl 1KB
aix-perf.pl 638B
stackcollapse-instruments.pl 514B
stackcollapse-chrome-tracing.py 4KB
README 475B
README 252B
pre-rebase.sample 5KB
update.sample 4KB
pre-commit.sample 2KB
pre-push.sample 1KB
prepare-commit-msg.sample 1KB
commit-msg.sample 896B
applypatch-msg.sample 452B
pre-applypatch.sample 398B
post-update.sample 189B
test.sh 861B
record-test.sh 669B
cpu-mysql-filt.svg 791KB
cpu-mysql.svg 615KB
cpu-illumos-syscalls.svg 573KB
cpu-illumos-ipdce.svg 407KB
example-perf.svg 395KB
palette-example-broken.svg 297KB
cpu-mixedmode-flamegraph-java.svg 294KB
palette-example-working.svg 275KB
cpu-qemu-both.svg 206KB
cpu-iozone.svg 163KB
example-dtrace.svg 152KB
brkbytes-mysql.svg 117KB
cpu-illumos-tcpfuse.svg 113KB
cpu-linux-tar.svg 109KB
cpu-ipnet-diff.svg 94KB
hotcold-kernelthread.svg 81KB
off-mysql-busy.svg 77KB
cpu-linux-tcpsend.svg 69KB
mallocbytes-bash.svg 53KB
off-mysql-idle.svg 53KB
io-mysql.svg 51KB
io-gzip.svg 12KB
cpu-grep.svg 10KB
off-bash.svg 10KB
example-dtrace-stacks.txt 1.32MB
perf-vertx-stacks-01.txt 1022KB
perf-vertx-stacks-01-collapsed-all.txt 258KB
perf-vertx-stacks-01-collapsed-jit.txt 254KB
perf-iperf-stacks-pidtid-01.txt 253KB
perf-vertx-stacks-01-collapsed-tid.txt 245KB
perf-vertx-stacks-01-collapsed-kernel.txt 243KB
perf-vertx-stacks-01-collapsed-pid.txt 243KB
perf-vertx-stacks-01-collapsed-addrs.txt 239KB
perf-rust-Yamakaky-dcpu.txt 144KB
perf-numa-stacks-01.txt 138KB
perf-java-stacks-01.txt 113KB
perf-cycles-instructions-01.txt 56KB
perf-rust-Yamakaky-dcpu-collapsed-tid.txt 53KB
共 180 条
- 1
- 2
a10578268
- 粉丝: 1
- 资源: 9
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0