What Are Flame Graphs and How to Read Them - DevConTLV X

5a5fcbae333f071dc7a28f4958509db5?s=47 Miha Rekar
November 15, 2016

What Are Flame Graphs and How to Read Them - DevConTLV X

A talk I gave at DevConTLV X in November 2016

https://www.youtube.com/watch?v=lIo0cEhT-Js

Further read:
- The Flame Graph: http://queue.acm.org/detail.cfm?id=2927301
- Blazing Performance with Flame Graphs (video): https://www.usenix.org/conference/lisa13/technical-sessions/plenary/gregg
- 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

5a5fcbae333f071dc7a28f4958509db5?s=128

Miha Rekar

November 15, 2016
Tweet

Transcript

  1. ! @mr_foto

  2. COMING HERE

  3. COMING HERE

  4. COMING HERE

  5. None
  6. WHOIS @mr_foto # Software Developer $ Ruby Slovenia organizer %

    Long Distance Runner & Event Photographer ☕ Coffee Connoisseur ⌨ Keyboard Enthusiast ) Special
  7. *FLAME GRAPHS*

  8. WHY AND WHAT • Interactive visualization of stack traces •

    From beginners to experts • Can be used for many things • How SW is consuming CPU • Brendan Gregg
  9. None
  10. None
  11. None
  12. 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
  13. None
  14. SAMPLING • Time interval • Observe what’s going on •

    Which action caused current action • Real-world example
  15. SAMPLING My Day Reading Emails

  16. My Day Reading Emails Replying to Emails SAMPLING

  17. My Day Writing Code SAMPLING

  18. My Day Writing Code Writing Tests SAMPLING

  19. My Day Writing Code Writing Tests Running Tests SAMPLING

  20. My Day Writing Code Writing Tests Running Tests Fixing Tests

    SAMPLING
  21. My Day Writing Code Running Tests SAMPLING

  22. My Day Making Espresso SAMPLING

  23. SAMPLING My Day Reading Emails

  24. My Day Writing Code SAMPLING

  25. My Day Writing Code Running Tests SAMPLING

  26. My Day Reading Emails Replying to Emails SAMPLING

  27. SAMPLING

  28. GROUPING

  29. GROUPING

  30. GROUPING My Day Reading Emails Replying Writing Code ☕ Writing

    Tests Running Running Fix
  31. MOAR EXPLAINING Function

  32. MOAR EXPLAINING Stack Depth

  33. MOAR EXPLAINING Stack Depth

  34. MOAR EXPLAINING Ordered by Alphabet

  35. MOAR EXPLAINING Total Time on CPU

  36. Q&A Q: Which function is on CPU the most?

  37. Q&A A: f() top edge shows what is on CPU

    directly
  38. Q&A Q: Why is f() on CPU?

  39. Q&A A: a() → b() → c() → e() →

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

  41. Q&A A: b() looks like it is running (present) about

    10 times more often than g()
  42. Q&A Q: Why are we running f()?

  43. Q&A A: code path branches can reveal key functions:
 a()

    choose the b() path
 c() choose the e() path look for branches
  44. FOR REAL

  45. REAL WORLD EXAMPLE • Sam Saffron • gem 'flamegraph' Flamegraph.generate(filename)

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

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

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

    improvement MEMOIZATION & CO.
  49. NOW WHAT? • You’re here • Ask me • Ask

    someone smarter than me • Ask anyone else • Read/watch blog posts/videos
  50. None
  51. http://mr.si/
 @mr_foto THANK YOU http://rug.si/
 @RubySlovenia