def _profile_from_parser(
parser,
graph_filename=DEFAULT_GRAPH_FILENAME,
node_threshold=DEFAULT_NODE_THRESHOLD,
edge_threshold=DEFAULT_EDGE_THRESHOLD,
view=DEFAULT_VIEW,
colour_nodes_by_selftime=DEFAULT_COLOUR_NODES_BY_SELFTIME):
# Parse pstats and prune graph based on thresholds
profile = parser.parse()
profile.prune(
node_threshold,
edge_threshold,
colour_nodes_by_selftime=colour_nodes_by_selftime)
# Convert graph to dot format
dot_file = StringIO()
dot = gprof2dot.DotWriter(dot_file)
dot.graph(profile, theme=gprof2dot.themes['color'])
# Convert dot to image
graph = pygraphviz.AGraph(string=dot_file.getvalue())
graph.draw(graph_filename, prog='dot')
# Open image
if view:
_view_file(graph_filename)
评论列表
文章目录