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
Tweet

More Decks by Miha Rekar

Other Decks in Technology

Transcript

  1. FLAME GRAPHS

    View full-size slide

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

    View full-size slide

  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 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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    a() choose the b() path

    c() choose the e() path
    look for branches

    View full-size slide

  12. REAL WORLD EXAMPLE
    • Sam Saffron
    • gem 'flamegraph'
    Flamegraph.generate(filename) do
    # your work here
    end

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  16. 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

    View full-size slide