__init__.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:cprofile_graph 作者: campos-ddc 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号