EMZETT.
Login

Profiling and flame graphs

In short: Profiling measures where a program spends its time or memory. A flame graph shows the result as stacked bars.

In more detail: A profiler looks at short intervals to see which function is currently running (sampling) and counts. Functions that appear often are the hotspots. Measure first, then optimize: gut feeling is often wrong.

In Depth

  • Reading a flame graph: Width = share of time, height = call stack. Wide bars at the top are candidates for optimization.
  • CPU vs. waiting: A program may be waiting on a database, network or locks. A pure CPU profiler does not see that.
  • Tools: perf (Linux), Chrome performance tab, py-spy, Java Flight Recorder, pprof (Go).
  • Memory profile: Shows which places use much memory or cause leaks.
  • Rule: Tackle only the biggest hotspot, then measure again.

See also: Debuggers and core dumps