@@ -13,17 +13,31 @@ function selfTime(node) {
13
13
return value ;
14
14
}
15
15
}
16
+ return 0 ;
16
17
}
17
18
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
+ }
22
33
}
23
34
24
- return nodeTotal ;
35
+ Ember . set ( node . _stats . time , 'plugin' , total ) ;
36
+
37
+ return total ;
25
38
}
26
39
40
+
27
41
export default Ember . Component . extend ( {
28
42
graph : inject . service ( ) ,
29
43
@@ -34,16 +48,18 @@ export default Ember.Component.extend({
34
48
35
49
nodes : computed ( 'data' , 'filter' , 'pluginNameFilter' , 'groupByPluginName' , function ( ) {
36
50
let data = this . get ( 'data' ) ;
51
+
37
52
let nodes = [ ] ;
38
53
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)
40
59
41
60
for ( let node of data . dfsIterator ( ) ) {
42
61
if ( node . label . broccoliNode ) {
43
62
nodes . push ( node ) ;
44
- if ( ! node . _stats . time . plugin ) {
45
- node . _stats . time . plugin = nodeTime ( node ) ;
46
- }
47
63
}
48
64
}
49
65
@@ -86,6 +102,7 @@ export default Ember.Component.extend({
86
102
87
103
pluginNames : computed ( 'nodes' , function ( ) {
88
104
let nodes = this . get ( 'nodes' ) ;
105
+
89
106
if ( ! nodes || nodes . length === 0 ) {
90
107
return [ ] ;
91
108
}
0 commit comments