title: CPU Flame Graphs for Python
body: <p>Brendan Gregg's <a href="http://www.brendangregg.com/FlameGraphs/cpuflamegraphs.html" rel="noreferrer">CPU Flame Graphs</a> are a way of visualising CPU usage over a period of time based on call stacks.</p>
  
  <p>His <a href="https://github.com/brendangregg/FlameGraph" rel="noreferrer">FlameGraph github project</a> provides a language-independent way to plot these graphs:</p>
  
  <p>For each language, FlameGraph requires a way of providing stack input in the form of lines like this:</p>
  
  <pre><code>grandparent_func;parent_func;func 42
  </code></pre>
  
  <p>This means that the instrumented program was observed running function <code>func</code>, where that was called from <code>parent_func</code>, in turn called from top-level function <code>grandparent_func</code>.  It says that call stack was observed 42 times.</p>
  
  <p>How can I gather stack information from Python programs and provide it to FlameGraph?</p>
  
  <p>For bonus points: How can that be extended so that both the C and Python stack is shown, or even down to the kernel on Linux (in a similar way to some of the Java and node.js flame graphs on Brendan's website)?</p>
  
  <p><a href="https://i.stack.imgur.com/VQ0nW.png" rel="noreferrer"><img src="https://i.stack.imgur.com/VQ0nW.png" alt="enter image description here"></a></p>