|
1 | 1 | import Ember from 'ember';
|
| 2 | +import heimdallGraph from 'heimdalljs-graph'; |
2 | 3 |
|
3 | 4 | const {
|
4 | 5 | computed
|
5 | 6 | } = Ember;
|
6 | 7 |
|
| 8 | +function selfTime(node) { |
| 9 | + for (let [statName, value] of node.statsIterator()) { |
| 10 | + if (statName === 'time.self') { |
| 11 | + return value; |
| 12 | + } |
| 13 | + } |
| 14 | +} |
| 15 | + |
| 16 | +function nodeTime(node) { |
| 17 | + let nodeTotal = selfTime(node); |
| 18 | + |
| 19 | + for (let childNode of node.dfsIterator((n) => n.label.broccoliNode)) { |
| 20 | + nodeTotal += selfTime(childNode); |
| 21 | + } |
| 22 | + |
| 23 | + return nodeTotal; |
| 24 | +} |
| 25 | + |
7 | 26 | export default Ember.Component.extend({
|
8 | 27 | nodes: computed('data', 'filter', 'pluginNameFilter', 'groupByPluginName', function() {
|
9 | 28 | let data = this.get('data');
|
10 |
| - let groupByPluginName = this.get('groupByPluginName'); |
11 |
| - let pluginName = this.get('pluginNameFilter'); |
12 | 29 | if (!data) { return []; }
|
13 | 30 |
|
14 |
| - let nodes = data.nodes.filter((node) => { |
15 |
| - if (!node.label.broccoliNode) { return false; } |
16 |
| - if (pluginName && node.label.broccoliPluginName !== pluginName) { return false; } |
| 31 | + let nodes = []; |
| 32 | + let graph = heimdallGraph.loadFromJSON(data); |
17 | 33 |
|
18 |
| - return true; |
19 |
| - }) |
20 |
| - |
21 |
| - if (groupByPluginName) { |
22 |
| - let pluginNameMap = nodes.reduce((memo, node) => { |
23 |
| - let pluginName = node.label.broccoliPluginName; |
24 |
| - memo[pluginName] = memo[pluginName] || { count: 0, time: 0 }; |
25 |
| - memo[pluginName].time += node.stats.time.self; |
26 |
| - memo[pluginName].count++; |
27 |
| - return memo; |
28 |
| - }, {}) |
29 |
| - |
30 |
| - nodes = []; |
31 |
| - for (let pluginName in pluginNameMap) { |
| 34 | + for (let node of graph.dfsIterator()) { |
| 35 | + if (node.label.broccoliNode) { |
32 | 36 | nodes.push({
|
33 |
| - label: { name: pluginName, broccoliPluginName: pluginNameMap[pluginName].count }, |
34 |
| - stats: { |
35 |
| - time: { self: pluginNameMap[pluginName].time} |
36 |
| - } |
37 |
| - }); |
| 37 | + label: node.label, |
| 38 | + time: nodeTime(node) |
| 39 | + }) |
38 | 40 | }
|
39 | 41 | }
|
40 | 42 |
|
41 |
| - let addonNodes = nodes |
| 43 | + //let groupByPluginName = this.get('groupByPluginName'); |
| 44 | + //let pluginName = this.get('pluginNameFilter'); |
| 45 | + // nodes = data.nodes.filter((node) => { |
| 46 | + // if (!node.label.broccoliNode) { return false; } |
| 47 | + // if (pluginName && node.label.broccoliPluginName !== pluginName) { return false; } |
| 48 | + |
| 49 | + // return true; |
| 50 | + // }) |
| 51 | + |
| 52 | + // if (groupByPluginName) { |
| 53 | + // let pluginNameMap = nodes.reduce((memo, node) => { |
| 54 | + // let pluginName = node.label.broccoliPluginName; |
| 55 | + // memo[pluginName] = memo[pluginName] || { count: 0, time: 0 }; |
| 56 | + // memo[pluginName].time += node.stats.time.self; |
| 57 | + // memo[pluginName].count++; |
| 58 | + // return memo; |
| 59 | + // }, {}) |
| 60 | + |
| 61 | + // nodes = []; |
| 62 | + // for (let pluginName in pluginNameMap) { |
| 63 | + // nodes.push({ |
| 64 | + // label: { name: pluginName, broccoliPluginName: pluginNameMap[pluginName].count }, |
| 65 | + // stats: { |
| 66 | + // time: { self: pluginNameMap[pluginName].time} |
| 67 | + // } |
| 68 | + // }); |
| 69 | + // } |
| 70 | + // } |
| 71 | + |
| 72 | + let sortedNodes = nodes |
42 | 73 | .sort((a, b) => {
|
43 |
| - return b.stats.time.self - a.stats.time.self; |
| 74 | + return b.time - a.time; |
44 | 75 | });
|
45 | 76 |
|
46 |
| - return addonNodes; |
| 77 | + return sortedNodes; |
47 | 78 | }),
|
48 | 79 |
|
49 | 80 | totalTime: computed('nodes', function() {
|
50 | 81 | let nodes = this.get('nodes');
|
51 | 82 |
|
52 | 83 | return nodes.reduce(function(previousValue, node){
|
53 |
| - return previousValue + node.stats.time.self; |
| 84 | + return previousValue + node.time; |
54 | 85 | }, 0);
|
55 | 86 | }),
|
56 | 87 |
|
|
0 commit comments