Skip to content

Instantly share code, notes, and snippets.

@bsmithyman

bsmithyman/graph_stack.py

Last active May 4, 2016
Embed
What would you like to do?
Generate a call graph for the enclosed context
import contextlib
import os.path
from pycallgraph import PyCallGraph
from pycallgraph.output import GraphvizOutput
@contextlib.contextmanager
def graph_stack(filename):
'Generate a call graph for the enclosed context'
go = GraphvizOutput(output_file=filename)
go.output_type = os.path.splitext(filename)[-1][1:]
with PyCallGraph(output=go):
yield
# --------
if __name__ == '__main__':
def do_hello(times):
for i in xrange(times):
hello()
def hello():
print('Hello World!')
with graph_stack('test.pdf'):
do_hello(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment