Last active
May 4, 2016 19:42
-
-
Save bsmithyman/8c6d5decb4f359ef28742c6f4e1d4389 to your computer and use it in GitHub Desktop.
Generate a call graph for the enclosed context
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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