Skip to content

Instantly share code, notes, and snippets.

@sanfx
Created June 9, 2017 17:53
Show Gist options
  • Save sanfx/90f93e42c04333e656f8fc21e7bd81fc to your computer and use it in GitHub Desktop.
Save sanfx/90f93e42c04333e656f8fc21e7bd81fc to your computer and use it in GitHub Desktop.
profile to graph on pdf with text on vector graphics
@contextlib.contextmanager
def profileYo(toolName, showGraph=False):
profiler = cProfile.Profile()
profiler.enable()
profilePath = "/tmp/%s_Profile" % toolName
dotPath = "/tmp/gprof.dot"
pdfPath = "/tmp/%s_Profile.pdf" % toolName
yield
profiler.disable()
profiler.dump_stats(profilePath)
# Show Graph
if showGraph:
os.system("/software/tools/scripts/gprof2dot %s" % (profilePath))
os.system("dot -Tpdf -o %s %s" % (pdfPath, dotPath))
os.system("acroread %s &" % pdfPath)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment