Skip to content

Commit 50afebf

Browse files
added computeNodeTimes to slow-node-times.js, to do a preorder traversal of the node tree to compute overall times. Quicker than doing dfsIterator at each level
1 parent a94ee66 commit 50afebf

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

app/components/slow-node-times.js

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,31 @@ function selfTime(node) {
1313
return value;
1414
}
1515
}
16+
return 0;
1617
}
1718

18-
function nodeTime(node) {
19-
let nodeTotal = 0;
20-
for (let childNode of node.dfsIterator((n) => n.label.broccoliNode)) {
21-
nodeTotal += selfTime(childNode);
19+
// Given a node, compute the total time taken by the node
20+
// and its children (by summing the total time of the children
21+
// and adding the self time of the node). Return that value,
22+
// and assign it to the _stats.time.plugin attribute of the node.
23+
// Note: we skip the non-broccoliNodes except at the beginning
24+
// (the root of the tree is not a broccoliNode, but we want to
25+
// proceed to its children
26+
function computeNodeTimes(node) {
27+
var total = selfTime(node);
28+
29+
for (let childNode of node.adjacentIterator()) {
30+
if (childNode.label.broccoliNode) {
31+
total += computeNodeTimes(childNode);
32+
}
2233
}
2334

24-
return nodeTotal;
35+
Ember.set(node._stats.time, 'plugin', total);
36+
37+
return total;
2538
}
2639

40+
2741
export default Ember.Component.extend({
2842
graph: inject.service(),
2943

@@ -34,16 +48,18 @@ export default Ember.Component.extend({
3448

3549
nodes: computed('data', 'filter', 'pluginNameFilter', 'groupByPluginName', function() {
3650
let data = this.get('data');
51+
3752
let nodes = [];
3853

39-
if (!data) { return nodes; }
54+
if (!data) {
55+
return nodes;
56+
}
57+
58+
computeNodeTimes(data); // start at root node of tree (which is not a broccoliNode)
4059

4160
for (let node of data.dfsIterator()) {
4261
if (node.label.broccoliNode) {
4362
nodes.push(node);
44-
if (!node._stats.time.plugin) {
45-
node._stats.time.plugin = nodeTime(node);
46-
}
4763
}
4864
}
4965

@@ -86,6 +102,7 @@ export default Ember.Component.extend({
86102

87103
pluginNames: computed('nodes', function() {
88104
let nodes = this.get('nodes');
105+
89106
if (!nodes || nodes.length === 0) {
90107
return [];
91108
}

0 commit comments

Comments
 (0)