Skip to content

Commit 3932bf8

Browse files
authored
Merge pull request #12 from rwjblue/fixes
Fixes
2 parents f0dd8fd + 48d6bd2 commit 3932bf8

File tree

8 files changed

+88
-86
lines changed

8 files changed

+88
-86
lines changed

app/components/basic-tree.js

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ export default Ember.Component.extend({
4242
svgContainer.innerHTML = '';
4343

4444
let svg = select(svgContainer)
45-
.append("svg")
46-
.attr("preserveAspectRatio", "xMinYMin meet")
47-
.attr("viewBox", "0 0 300 300")
48-
.classed("svg-content", true);
45+
.append("svg")
46+
.attr("preserveAspectRatio", "xMinYMin meet")
47+
.attr("viewBox", "0 0 300 300")
48+
.classed("svg-content", true);
4949

5050
let g = svg.append("g");
5151

52-
let root = hierarchy(graphNode, (node) => {
52+
let root = hierarchy(graphNode, node => {
5353
let children = [];
5454
for (let child of node.adjacentIterator()) {
5555
if (this.nodeFilter && !this.nodeFilter(child)) {
@@ -61,41 +61,39 @@ export default Ember.Component.extend({
6161

6262
return children;
6363
})
64-
.sum(d => d._stats.time.self);
64+
.sum(d => d._stats.time.self);
6565

66-
// make debugging easier, this is dumb though
66+
// for debugging
6767
self.root = root;
6868

6969
let graph = cluster()
70-
.separation((a,b) => {
71-
return a.parent == b.parent ? 4 : 8;
72-
})
73-
.nodeSize([8, 180]);
70+
.separation((a,b) => a.parent == b.parent ? 4 : 8)
71+
.nodeSize([8, 180]);
7472

7573
function update(source) {
7674
graph(root);
7775
let nodes = root.descendants();
7876
let links = root.links();
7977
let node = g
80-
.selectAll(".node")
81-
.data(nodes, d => d.data.id);
78+
.selectAll(".node")
79+
.data(nodes, d => d.data.id);
8280

8381
let nodeEnter = node
84-
.enter()
85-
.append("g")
86-
.attr("class", 'node')
87-
.attr("transform", d => `translate(${d.y},${d.x})`)
88-
.on('click', (d) => {
89-
// Toggle children on click.
90-
if (d.children) {
91-
d._children = d.children;
92-
d.children = null;
93-
} else {
94-
d.children = d._children;
95-
d._children = null;
96-
}
97-
update(d);
98-
});
82+
.enter()
83+
.append("g")
84+
.attr("class", 'node')
85+
.attr("transform", d => `translate(${d.y},${d.x})`)
86+
.on('click', (d) => {
87+
// Toggle children on click.
88+
if (d.children) {
89+
d._children = d.children;
90+
d.children = null;
91+
} else {
92+
d.children = d._children;
93+
d._children = null;
94+
}
95+
update(d);
96+
});
9997

10098
// we want to wrap the next few text lines in a rect
10199
// but alignment is annoying, punting for now...
@@ -150,8 +148,8 @@ export default Ember.Component.extend({
150148
.remove();
151149

152150
let link = g
153-
.selectAll(".link")
154-
.data(links, d => d.target.data.id);
151+
.selectAll(".link")
152+
.data(links, d => d.target.data.id);
155153

156154
link
157155
.enter()

app/components/flame-graph.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,23 @@ export default Ember.Component.extend({
4040
},
4141

4242
convert(rawData) {
43-
let child, node, subTree, _i, _len, _ref;
44-
45-
node = {
43+
let node = {
4644
value: rawData._stats.time.self,
4745
treeValue: rawData._stats.time.self,
4846
name: rawData._label.name + (rawData._label.broccoliPluginName ? ' (' + rawData._label.broccoliPluginName + ')' : ''),
4947
stats: rawData._stats,
5048
children: []
5149
};
50+
5251
if (!rawData._children) {
5352
return node;
5453
}
5554

5655
let treeValue = node.treeValue;
57-
_ref = rawData._children;
58-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
59-
child = _ref[_i];
60-
subTree = this.convert(child);
56+
let _ref = rawData._children;
57+
for (let _i = 0, _len = _ref.length; _i < _len; _i++) {
58+
let child = _ref[_i];
59+
let subTree = this.convert(child);
6160
if (subTree) {
6261
node.children.push(subTree);
6362
treeValue += subTree.treeValue;
@@ -70,11 +69,10 @@ export default Ember.Component.extend({
7069
},
7170

7271
drawFlame(data) {
73-
let _this = this;
7472
let profile = this.convert(data);
75-
7673
let indent = -1;
77-
let objToString = function(obj) {
74+
75+
let objToString = obj => {
7876
indent++;
7977
let str = '';
8078
let pad = "&nbsp;";
@@ -90,7 +88,7 @@ export default Ember.Component.extend({
9088
let padded = pad.repeat(5).substring(0, pad.length * 5 - obj[p].toString().length * 6) + obj[p];
9189
str += padded;
9290
} else if (p === 'time') {
93-
let time = _this.formatTime(obj[p]);
91+
let time = this.formatTime(obj[p]);
9492
let padded = ' ' + pad.repeat(8).substring(0, pad.length * 8 - time.length * 6) + time + '<br/>';
9593
str += padded;
9694
}
@@ -101,10 +99,10 @@ export default Ember.Component.extend({
10199
return str;
102100
};
103101

104-
let tooltip = function(d) {
105-
let time = _this.formatTime(d.data.treeValue);
106-
let percent = " [" + (((d.data.treeValue / _this.get('totalTime')) * 100).toFixed(1)) + "%]";
107-
let self = " (self: " + _this.formatTime(d.data.stats.time.self) + ")";
102+
let tooltip = d => {
103+
let time = this.formatTime(d.data.treeValue);
104+
let percent = " [" + (((d.data.treeValue / this.get('totalTime')) * 100).toFixed(1)) + "%]";
105+
let self = " (self: " + this.formatTime(d.data.stats.time.self) + ")";
108106
return d.data.name + "<br/>" + time + percent + self + "<br/>" + objToString(d.data.stats);
109107
};
110108

app/components/slow-node-times.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,17 @@ function nodeTime(node) {
2727
export default Ember.Component.extend({
2828
graph: inject.service(),
2929

30-
sortDescending: true,
30+
init() {
31+
this._super(...arguments);
32+
this.sortDescending = true;
33+
},
3134

3235
nodes: computed('data', 'filter', 'pluginNameFilter', 'groupByPluginName', function() {
3336
let data = this.get('data');
34-
if (!data) { return []; }
35-
3637
let nodes = [];
3738

39+
if (!data) { return nodes; }
40+
3841
for (let node of data.dfsIterator()) {
3942
if (node.label.broccoliNode) {
4043
nodes.push(node);
@@ -77,25 +80,26 @@ export default Ember.Component.extend({
7780
}
7881

7982
return nodes;
80-
}),
83+
}).readOnly(),
8184

8285
sortedNodes: computed('nodes', 'sortDescending', function() {
86+
let sortDescending = this.get('sortDescending');
8387
return this.get('nodes').sort((a, b) => {
84-
if (this.get('sortDescending')) {
88+
if (sortDescending) {
8589
return b._stats.time.plugin - a._stats.time.plugin;
8690
} else {
8791
return a._stats.time.plugin - b._stats.time.plugin;
8892
}
8993
});
90-
}),
94+
}).readOnly(),
9195

9296
totalTime: computed('nodes', function() {
9397
let nodes = this.get('nodes');
9498

9599
return nodes.reduce(function(previousValue, node){
96100
return previousValue + node._stats.time.plugin;
97101
}, 0);
98-
}),
102+
}).readOnly(),
99103

100104
actions: {
101105
'focus-node'(node) {

app/controllers/graph.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export default Controller.extend({
1313
route: computed.alias('router.currentPath'),
1414

1515
init() {
16+
this._super(...arguments);
1617
this.set('router', getOwner(this).lookup('router:main'));
1718
}
1819
});

app/controllers/slow-nodes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default Ember.Controller.extend({
1010
actions: {
1111
parseFile(event) {
1212
let reader = new FileReader();
13-
reader.onload = (e) => {
13+
reader.onload = e => {
1414
var contents = e.target.result;
1515
this.get('graph').setGraph(JSON.parse(contents));
1616
};

app/styles/app.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,6 @@ body > [class="ember-view"],
7979
cursor: pointer;
8080
}
8181

82+
.td-time {
83+
text-align: right;
84+
}

app/templates/components/slow-node-times.hbs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<div class="level-item">
1212
<p class="control">
1313
<label class="checkbox">
14-
{{input type="checkbox" checked=groupByPluginName}}
14+
<input type="checkbox" checked={{groupByPluginName}} onchange={{action (mut groupByPluginName) value="target.checked"}}>
1515
Group by Plugin Name
1616
</label>
1717
</p>
@@ -24,7 +24,7 @@
2424
<tr>
2525
<td style="width: 65%">Description</td>
2626
<td>{{if groupByPluginName "Count" "Plugin Name"}}</td>
27-
<td>
27+
<td class="td-time">
2828
<a href="#" class="nodes-table_toggle" {{action "toggleTime"}}>Time (ms) <i class="fa fa-caret-{{if sortDescending 'down' 'up'}}"></i></a>
2929
</td>
3030
</tr>
@@ -34,8 +34,8 @@
3434
{{#each sortedNodes as |node|}}
3535
<tr class="table-row" {{action 'toggleDetailsForNode' node}}>
3636
<td>{{node.label.name}}</td>
37-
<td>{{node.label.broccoliPluginName}}</td>
38-
<td>{{ns-to-ms node._stats.time.plugin}}</td>
37+
<td class="table-row-plugin-name">{{node.label.broccoliPluginName}}</td>
38+
<td class="td-time">{{ns-to-ms node._stats.time.plugin}}</td>
3939
</tr>
4040
{{#if node.showDetails}}
4141
<tr>

app/utils/d3-flame-graphs-v4/d3-flame-graph.js

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,28 @@ import d3Tip from 'd3-tip';
55
import { partition, hierarchy } from 'd3-hierarchy';
66
import 'd3-transition';
77

8-
let indexOf = [].indexOf || function(item) {
9-
for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; }
10-
return -1;
11-
};
12-
13-
let getClassAndMethodName = function(fqdn) {
14-
let tokens;
8+
function getClassAndMethodName(fqdn) {
159
if (!fqdn) {
1610
return "";
1711
}
18-
tokens = fqdn.split(".");
12+
let tokens = fqdn.split(".");
1913
return tokens.slice(tokens.length - 2).join(".");
20-
};
14+
}
2115

2216
// Return a vector (0.0 -> 1.0) that is a hash of the input string.
2317
// The hash is computed to favor early characters over later ones, so
2418
// that strings with similar starts have similar vectors. Only the first
2519
// 6 characters are considered.
26-
let hash = function(name) {
27-
let i, j, maxHash, mod, ref, ref1, result, weight;
28-
ref = [0, 0, 1, 10], result = ref[0], maxHash = ref[1], weight = ref[2], mod = ref[3];
20+
function hash(name) {
21+
let ref = [0, 0, 1, 10];
22+
let result = ref[0];
23+
let maxHash = ref[1];
24+
let weight = ref[2];
25+
let mod = ref[3];
26+
2927
name = getClassAndMethodName(name).slice(0, 6);
30-
for (i = j = 0, ref1 = name.length - 1; 0 <= ref1 ? j <= ref1 : j >= ref1; i = 0 <= ref1 ? ++j : --j) {
28+
29+
for (let i = 0, j = 0, ref1 = name.length - 1; 0 <= ref1 ? j <= ref1 : j >= ref1; i = 0 <= ref1 ? ++j : --j) {
3130
result += weight * (name.charCodeAt(i) % mod);
3231
maxHash += weight * (mod - 1);
3332
weight *= 0.7;
@@ -37,7 +36,7 @@ let hash = function(name) {
3736
} else {
3837
return result;
3938
}
40-
};
39+
}
4140

4241
const FlameGraphUtils = {
4342
// augments each node in the tree with the maximum distance
@@ -58,9 +57,7 @@ const FlameGraphUtils = {
5857
node.augmented = true;
5958
return node;
6059
}
61-
let childSum = children.reduce((function(sum, child) {
62-
return sum + child.value;
63-
}), 0);
60+
let childSum = children.reduce((sum, child) => sum + child.value, 0);
6461
if (childSum < node.value) {
6562
children.push({
6663
value: node.value - childSum,
@@ -72,6 +69,7 @@ const FlameGraphUtils = {
7269
node.augmented = true;
7370
return node;
7471
},
72+
7573
partition(data) {
7674
let d3partition = partition();
7775

@@ -89,6 +87,7 @@ const FlameGraphUtils = {
8987
});
9088
return d3partition(root).descendants();
9189
},
90+
9291
hide(nodes, unhide) {
9392
if (unhide === null) {
9493
unhide = false;
@@ -134,7 +133,8 @@ const FlameGraphUtils = {
134133
});
135134
}
136135
};
137-
class FlameGraph {
136+
137+
export default class FlameGraph {
138138
constructor(selector, root, debug) {
139139
this._selector = selector;
140140
this._generateAccessors(['margin', 'cellHeight', 'zoomEnabled', 'zoomAction', 'tooltip', 'tooltipPlugin', 'color', 'labelFunction']);
@@ -226,7 +226,7 @@ class FlameGraph {
226226
if (this.tip) {
227227
this.tip.hide();
228228
}
229-
if (indexOf.call(this._ancestors, node) >= 0) {
229+
if (this._ancestors.indexOf(node) >= 0) {
230230
this._ancestors = this._ancestors.slice(0, this._ancestors.indexOf(node));
231231
} else {
232232
this._ancestors.push(this._root);
@@ -399,14 +399,14 @@ class FlameGraph {
399399
.attr('class', 'label')
400400
.style('font-size', this.fontSize + "em")
401401
.transition().attr('dy', (this.fontSize / 2) + "em").attr('x', (function() {
402-
return function(d) {
403-
return attrs.x(d) + 2;
404-
};
405-
})(this)).attr('y', (function(_this) {
406-
return function(d, idx) {
407-
return attrs.y(d, idx) + _this.cellHeight() / 2;
408-
};
409-
})(this)).text(attrs.text);
402+
return function(d) {
403+
return attrs.x(d) + 2;
404+
};
405+
})(this)).attr('y', (function(_this) {
406+
return function(d, idx) {
407+
return attrs.y(d, idx) + _this.cellHeight() / 2;
408+
};
409+
})(this)).text(attrs.text);
410410
return this;
411411
}
412412

@@ -546,5 +546,3 @@ class FlameGraph {
546546
return results;
547547
}
548548
}
549-
550-
export default FlameGraph;

0 commit comments

Comments
 (0)