Miha Rekar
May 26, 2016
370

# Flame Graphs

Talk I gave at Slovenia Ruby User Group meetup in May '16. What are flame graphs, how to read them, simple tutorial, practical example.

- The Flame Graph: http://queue.acm.org/detail.cfm?id=2927301
- flamegraph gem: https://github.com/SamSaffron/flamegraph
- rack-mini-profiler: https://github.com/MiniProfiler/rack-mini-profiler
- ruby-prof-flamegraph: https://github.com/oozou/ruby-prof-flamegraph

May 26, 2016

## Transcript

1. FLAME GRAPHS

2. WHY AND WHAT
• How SW is consuming CPU
• DTrace is verbose and unreadable
• Brendan Gregg
• combine stack traces with common paths

3. FLAME GRAPHS EXPLAINED
• each box represents a function (a merged stack frame)
• y-axis (vertical) shows stack depth
• top function led directly to the proﬁling event
• everything beneath it is ancestry (explains why)
• x-axis (horizontal) shows the sample sorted alphabetically
• box width shows the total time it was on-CPU

4. LOOKS

5. TUTORIAL
Q: Which function is on CPU the most?

6. TUTORIAL
A: f()
top edge shows who is on CPU directly

7. TUTORIAL
Q: Why is f() on CPU?

8. TUTORIAL
A: a() → b() → c() → e() → f()
f() was called by e(), e() was called by c(),…

9. TUTORIAL
Q: How does b() compare to g()?

10. TUTORIAL
A: b() looks like it is running (present) about 10
times more often than g()

11. TUTORIAL
Q: Why are we running f()?

12. TUTORIAL
A: code path branches can reveal key functions:
a() choose the b() path
c() choose the e() path
look for branches

13. REAL WORLD EXAMPLE
• Sam Saﬀron
• gem 'ﬂamegraph'
Flamegraph.generate(filename) do
end

14. 1.083 (± 0.0%) i/s - 33.000 in 30.861265s
ORIGINAL

15. 8.368 (±12.0%) i/s - 244.000 in 30.037836s | 7.5x improvement
CACHE KRAMDOWN

16. 10.140 (± 9.9%) i/s - 292.000 in 30.025553s | 9.4x improvement
MEMOIZATION & CO.