Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Flame Graphs

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.

Further read:
- 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

Miha Rekar

May 26, 2016

More Decks by Miha Rekar

Other Decks in Technology



  2. WHY AND WHAT • How SW is consuming CPU •

    DTrace is verbose and unreadable • Brendan Gregg • combine stack traces with common paths
  3. None
  4. None
  5. FLAME GRAPHS EXPLAINED • each box represents a function (a

    merged stack frame) • y-axis (vertical) shows stack depth • top function led directly to the profiling 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
  6. LOOKS

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

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

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

  10. TUTORIAL A: a() → b() → c() → e() →

    f() f() was called by e(), e() was called by c(),…
  11. TUTORIAL Q: How does b() compare to g()?

  12. TUTORIAL A: b() looks like it is running (present) about

    10 times more often than g()
  13. TUTORIAL Q: Why are we running f()?

  14. TUTORIAL A: code path branches can reveal key functions:

    choose the b() path
 c() choose the e() path look for branches
  15. REAL WORLD EXAMPLE • Sam Saffron • gem 'flamegraph' Flamegraph.generate(filename)

    do # your work here end
  16. 1.083 (± 0.0%) i/s - 33.000 in 30.861265s ORIGINAL

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

  18. 10.140 (± 9.9%) i/s - 292.000 in 30.025553s | 9.4x

    improvement MEMOIZATION & CO.
  19. FURTHER READ • 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