Skip to content
This repository
Newer
Older
100644 61 lines (35 sloc) 2.196 kb
8b171a62 »
2012-03-17 new stack folders
1 Flame Graphs visualize hot-CPU code-paths.
a64ac12d »
2011-12-15 README content
2
8b171a62 »
2012-03-17 new stack folders
3 See: http://dtrace.org/blogs/brendan/2011/12/16/flame-graphs/
4
5 These can be created in three steps:
a64ac12d »
2011-12-15 README content
6
7 1. Capture stacks
8 2. Fold stacks
9 3. flamegraph.pl
10
11
12 1. Capture stacks
13
8b171a62 »
2012-03-17 new stack folders
14 Stack samples can be captured using DTrace, perf_events or SystemTap.
15
a64ac12d »
2011-12-15 README content
16 Using DTrace to capture 60 seconds of kernel stacks at 997 Hertz:
17
18 # dtrace -x stackframes=100 -n 'profile-997 /arg0/ { @[stack()] = count(); } tick-60s { exit(0); }' -o out.kern_stacks
19
20 Using DTrace to capture 60 seconds of user-level stacks for PID 12345 at 997 Hertz:
21
22 # dtrace -x ustackframes=100 -n 'profile-997 /PID == 12345/ { @[ustack()] = count(); } tick-60s { exit(0); }' -o out.user_stacks
23
24 You can include "arg1" in the predicate if you just want to study user-level CPU time only; otherwise it includes kernel time in the user-level flame graph (eg, syscall time). (Make sure you understand what that means!)
25
26
27 2. Fold stacks
28
8b171a62 »
2012-03-17 new stack folders
29 Use the stackcollapse programs to fold stack samples into single lines. The programs provided are:
30
31 - stackcollapse.pl: for DTrace stacks
32 - stackcollapse-perf.pl: for perf_events "perf script" output
33 - stackcollapse-stap.pl: for SystemTap stacks
34
35 Usage example:
a64ac12d »
2011-12-15 README content
36
37 $ ./stackcollapse.pl out.kern_stacks > out.kern_folded
38
39 The output looks like this:
40
41 unix`_sys_sysenter_post_swapgs 1401
42 unix`_sys_sysenter_post_swapgs,genunix`close 5
43 unix`_sys_sysenter_post_swapgs,genunix`close,genunix`closeandsetf 85
44 unix`_sys_sysenter_post_swapgs,genunix`close,genunix`closeandsetf,c2audit`audit_closef 26
45 unix`_sys_sysenter_post_swapgs,genunix`close,genunix`closeandsetf,c2audit`audit_setf 5
46 unix`_sys_sysenter_post_swapgs,genunix`close,genunix`closeandsetf,genunix`audit_getstate 6
47 unix`_sys_sysenter_post_swapgs,genunix`close,genunix`closeandsetf,genunix`audit_unfalloc 2
48 unix`_sys_sysenter_post_swapgs,genunix`close,genunix`closeandsetf,genunix`closef 48
49 [...]
50
51
52 3. flamegraph.pl
53
54 Use flamegraph.pl to render a SVG.
55
56 $ ./flamegraph.pl out.kern_folded > kernel.svg
57
58 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:
59
60 $ grep cpuid out.kern_folded | ./flamegraph.pl > cpuid.svg
Something went wrong with that request. Please try again.