Brendan Gregg's [CPU Flame Graphs](http://www.brendangregg.com/FlameGraphs/cpuflamegraphs.html) are a way of visualising CPU usage over a period of time based on call stacks.

His [FlameGraph github project](https://github.com/brendangregg/FlameGraph) provides a language-independent way to plot these graphs:

For each language, FlameGraph requires a way of providing stack input in the form of lines like this:

```
grandparent_func;parent_func;func 42

```

This means that the instrumented program was observed running function `func`, where that was called from `parent_func`, in turn called from top-level function `grandparent_func`. It says that call stack was observed 42 times.

How can I gather stack information from Python programs and provide it to FlameGraph?

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

[![enter image description here](https://i.stack.imgur.com/VQ0nW.png)](https://i.stack.imgur.com/VQ0nW.png)