Guest User

Untitled

a guest
Jun 24th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. import sys
  2. from gprof2dot import gprof2dot
  3. import pygraphviz as pgv
  4. import os.path
  5.  
  6. PRUNE = True
  7. DEFAULT_NODE_TRESHOLD = 0.5
  8. DEFAULT_EDGE_TRESHOLD = 0.1
  9.  
  10. if __name__ == '__main__':
  11. # pstats -> dot
  12. if len(sys.argv) == 1:
  13. print >> sys.stderr, 'Invalid arguments!'
  14. sys.exit(1)
  15. pstatsfile = sys.argv[1]
  16. dotfilebasename, _ = os.path.splitext(pstatsfile)
  17. dotfile = dotfilebasename + '.dot'
  18.  
  19. parser = gprof2dot.PstatsParser(pstatsfile)
  20. profile = parser.parse()
  21.  
  22. with open(dotfile, 'wt') as f:
  23. dot = gprof2dot.DotWriter(f)
  24.  
  25. if PRUNE:
  26. node_treshold = DEFAULT_NODE_TRESHOLD
  27. edge_treshold = DEFAULT_EDGE_TRESHOLD
  28. else:
  29. node_treshold = 0
  30. edge_treshold = 0
  31.  
  32. profile.prune(node_treshold / 100, edge_treshold / 100)
  33. dot.graph(profile, gprof2dot.TEMPERATURE_COLORMAP)
  34.  
  35. # dot -> png
  36. graph = pgv.AGraph(dotfile)
  37. graph.layout('dot')
  38. pngfilebasename, _ = os.path.splitext(dotfile)
  39. pngfilename = pngfilebasename + '.png'
  40. graph.draw(pngfilename)
Add Comment
Please, Sign In to add comment