コード例 #1
0
 def setUp(self):
     graph = CallGraph()
     graph.add_stack([Node(1), Node(2)], dict(time=1))
     graph.add_stack([Node(1), Node(3)], dict(time=3))
     graph.add_stack([Node(1), Node(2), Node(3)], dict(time=7))
     graph.add_stack([Node(1), Node(4), Node(2), Node(3)], dict(time=2))
     self.graph = graph
コード例 #2
0
def profile_to_json(filename):
    root = os.path.abspath(options.datadir) + os.path.sep
    abspath = os.path.abspath(os.path.join(root, filename))
    assert (abspath + os.path.sep).startswith(root)
    graph = CallGraph.load(abspath)

    total = sum(stack.weights['calls'] for stack in graph.stacks)
    top_stacks = graph.stacks
    #top_stacks = [stack for stack in graph.stacks if stack.weights['calls'] > total*.005]
    filtered_nodes = set()
    for stack in top_stacks:
        filtered_nodes.update(stack.nodes)
    nodes = [
        dict(attrs=node.attrs, weights=node.weights, id=node.id)
        for node in filtered_nodes
    ]
    nodes = sorted(nodes, key=lambda n: -n['weights']['calls'])
    #index = {node['id']: i for i, node in enumerate(nodes)}
    index = dict([(node['id'], i) for i, node in enumerate(nodes)])

    # High-degree nodes are generally common utility functions, and
    # creating edges from all over the graph tends to obscure more than
    # it helps.
    degrees = Counter()
    dropped = set()
    for edge in six.itervalues(graph.edges):
        degrees[edge.child.id] += 1
        degrees[edge.parent.id] += 1
    for node, degree in six.iteritems(degrees):
        if degree > 6:
            dropped.add(node)

    edges = [
        dict(source=index[edge.parent.id],
             target=index[edge.child.id],
             weights=edge.weights) for edge in six.itervalues(graph.edges)
        if (edge.parent.id in index and edge.child.id in index
            and edge.parent.id not in dropped and edge.child.id not in dropped)
    ]
    stacks = [
        dict(nodes=[index[n.id] for n in stack.nodes], weights=stack.weights)
        for stack in top_stacks
    ]
    return dict(nodes=nodes, edges=edges, stacks=stacks)
コード例 #3
0
ファイル: viewer.py プロジェクト: Why-Not-Sky/plop
def profile_to_json(filename):
    root = os.path.abspath(options.datadir) + os.path.sep
    abspath = os.path.abspath(os.path.join(root, filename))
    assert (abspath + os.path.sep).startswith(root)
    graph = CallGraph.load(abspath)

    total = sum(stack.weights['calls'] for stack in graph.stacks)
    top_stacks = graph.stacks
    #top_stacks = [stack for stack in graph.stacks if stack.weights['calls'] > total*.005]
    filtered_nodes = set()
    for stack in top_stacks:
        filtered_nodes.update(stack.nodes)
    nodes=[dict(attrs=node.attrs, weights=node.weights, id=node.id)
           for node in filtered_nodes]
    nodes = sorted(nodes, key=lambda n: -n['weights']['calls'])
    #index = {node['id']: i for i, node in enumerate(nodes)}
    index = dict([(node['id'], i) for i, node in enumerate(nodes)])


    # High-degree nodes are generally common utility functions, and
    # creating edges from all over the graph tends to obscure more than
    # it helps.
    degrees = Counter()
    dropped = set()
    for edge in graph.edges.itervalues():
        degrees[edge.child.id] += 1
        degrees[edge.parent.id] += 1
    for node, degree in degrees.iteritems():
        if degree > 6:
            dropped.add(node)

    edges = [dict(source=index[edge.parent.id],
                  target=index[edge.child.id],
                  weights=edge.weights)
             for edge in graph.edges.itervalues()
             if (edge.parent.id in index and
                 edge.child.id in index and
                 edge.parent.id not in dropped and
                 edge.child.id not in dropped)]
    stacks = [dict(nodes=[index[n.id] for n in stack.nodes],
                   weights=stack.weights)
              for stack in top_stacks]
    return dict(nodes=nodes, edges=edges, stacks=stacks)