-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1077455-link-detail-overview-perf.patch
464 lines (427 loc) · 15.9 KB
/
1077455-link-detail-overview-perf.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
From 087ea31f60e57d9e48d18c208a36c140f0e3d0c9 Mon Sep 17 00:00:00 2001
From: Jordan Santell <[email protected]>
Date: Fri, 21 Nov 2014 13:40:20 -0800
Subject: Bug 1077455 - Link the details and overview views together in
the new performance tool. r=vp
---
browser/devtools/performance/controller.js | 5 +++
browser/devtools/performance/test/browser.ini | 2 +
.../browser_perf-details-calltree-render-02.js | 37 ++++++++++++++++++
.../test/browser_perf-overview-selection.js | 45 ++++++++++++++++++++++
browser/devtools/performance/test/head.js | 33 +++++++++++++++-
browser/devtools/performance/views/call-tree.js | 37 +++++++++++++++---
browser/devtools/performance/views/overview.js | 40 +++++++++++++++++++
7 files changed, 192 insertions(+), 7 deletions(-)
create mode 100644 browser/devtools/performance/test/browser_perf-details-calltree-render-02.js
create mode 100644 browser/devtools/performance/test/browser_perf-overview-selection.js
diff --git a/browser/devtools/performance/controller.js b/browser/devtools/performance/controller.js
index 59cf85b..b18b6e2 100644
--- a/browser/devtools/performance/controller.js
+++ b/browser/devtools/performance/controller.js
@@ -3,16 +3,17 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
Cu.import("resource://gre/modules/Task.jsm");
Cu.import("resource://gre/modules/devtools/Loader.jsm");
Cu.import("resource:///modules/devtools/ViewHelpers.jsm");
+Cu.import("resource://gre/modules/devtools/Console.jsm");
let require = devtools.require;
devtools.lazyRequireGetter(this, "Services");
devtools.lazyRequireGetter(this, "promise");
devtools.lazyRequireGetter(this, "EventEmitter",
"devtools/toolkit/event-emitter");
devtools.lazyRequireGetter(this, "DevToolsUtils",
"devtools/toolkit/DevToolsUtils");
@@ -36,16 +37,20 @@ const EVENTS = {
TIMELINE_DATA: "Performance:TimelineData",
// Emitted by the PerformanceView on record button click
UI_START_RECORDING: "Performance:UI:StartRecording",
UI_STOP_RECORDING: "Performance:UI:StopRecording",
// Emitted by the OverviewView when more data has been rendered
OVERVIEW_RENDERED: "Performance:UI:OverviewRendered",
+ // Emitted by the OverviewView when a range has been selected in the graphs
+ OVERVIEW_RANGE_SELECTED: "Performance:UI:OverviewRangeSelected",
+ // Emitted by the OverviewView when a selection range has been removed
+ OVERVIEW_RANGE_CLEARED: "Performance:UI:OverviewRangeCleared",
// Emitted by the CallTreeView when a call tree has been rendered
CALL_TREE_RENDERED: "Performance:UI:CallTreeRendered"
};
/**
* The current target and the profiler connection, set by this tool's host.
*/
diff --git a/browser/devtools/performance/test/browser.ini b/browser/devtools/performance/test/browser.ini
index 9b7496e..dff4fc4 100644
--- a/browser/devtools/performance/test/browser.ini
+++ b/browser/devtools/performance/test/browser.ini
@@ -26,9 +26,11 @@ support-files =
[browser_perf-shared-connection-03.js]
# bug 1077464
#[browser_perf-shared-connection-04.js]
[browser_perf-data-samples.js]
[browser_perf-data-massaging-01.js]
[browser_perf-ui-recording.js]
[browser_perf-overview-render-01.js]
[browser_perf-overview-render-02.js]
+[browser_perf-overview-selection.js]
[browser_perf-details-calltree-render-01.js]
+[browser_perf-details-calltree-render-02.js]
diff --git a/browser/devtools/performance/test/browser_perf-details-calltree-render-02.js b/browser/devtools/performance/test/browser_perf-details-calltree-render-02.js
new file mode 100644
index 0000000..6d3d097
--- /dev/null
+++ b/browser/devtools/performance/test/browser_perf-details-calltree-render-02.js
@@ -0,0 +1,37 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/**
+ * Tests that the call tree view renders after recording.
+ */
+function spawnTest () {
+ let { panel } = yield initPerformance(SIMPLE_URL);
+ let { EVENTS, CallTreeView, OverviewView } = panel.panelWin;
+
+ let updated = 0;
+ CallTreeView.on(EVENTS.CALL_TREE_RENDERED, () => updated++);
+
+ let rendered = once(CallTreeView, EVENTS.CALL_TREE_RENDERED);
+
+ yield startRecording(panel);
+ yield busyWait(100);
+ yield stopRecording(panel);
+ yield rendered;
+
+ rendered = once(CallTreeView, EVENTS.CALL_TREE_RENDERED);
+ OverviewView.emit(EVENTS.OVERVIEW_RANGE_SELECTED, { beginAt: 0, endAt: 10 });
+ yield rendered;
+
+ ok(true, "Call tree rerenders when a range in the overview graph is selected.");
+
+ rendered = once(CallTreeView, EVENTS.CALL_TREE_RENDERED);
+ OverviewView.emit(EVENTS.OVERVIEW_RANGE_CLEARED);
+ yield rendered;
+
+ ok(true, "Call tree rerenders when a range in the overview graph is removed.");
+
+ is(updated, 3, "CallTreeView rerendered 3 times.");
+
+ yield teardown(panel);
+ finish();
+}
diff --git a/browser/devtools/performance/test/browser_perf-overview-selection.js b/browser/devtools/performance/test/browser_perf-overview-selection.js
new file mode 100644
index 0000000..4572a9a
--- /dev/null
+++ b/browser/devtools/performance/test/browser_perf-overview-selection.js
@@ -0,0 +1,45 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/**
+ * Tests that events are fired from OverviewView from selection manipulation.
+ */
+function spawnTest () {
+ let { panel } = yield initPerformance(SIMPLE_URL);
+ let { EVENTS, OverviewView } = panel.panelWin;
+ let beginAt, endAt, params, _;
+
+ yield startRecording(panel);
+
+ yield once(OverviewView, EVENTS.OVERVIEW_RENDERED);
+
+ yield stopRecording(panel);
+
+ let graph = OverviewView.framerateGraph;
+ let MAX = graph.width;
+
+ // Select the first half of the graph
+ let results = onceSpread(OverviewView, EVENTS.OVERVIEW_RANGE_SELECTED);
+ dragStart(graph, 0);
+ dragStop(graph, MAX / 2);
+
+ [_, { beginAt, endAt }] = yield results;
+
+ let actual = graph.getMappedSelection();
+ ise(beginAt, actual.min, "OVERVIEW_RANGE_SELECTED fired with beginAt value on click.");
+ ise(endAt, actual.max, "OVERVIEW_RANGE_SELECTED fired with endAt value on click.");
+
+ // Listen to deselection
+ results = onceSpread(OverviewView, EVENTS.OVERVIEW_RANGE_CLEARED);
+ dropSelection(graph);
+ [_, params] = yield results;
+
+ is(graph.hasSelection(), false, "selection no longer on graph.");
+ is(params, undefined, "OVERVIEW_RANGE_CLEARED fired with no additional arguments.");
+
+ results = beginAt = endAt = graph = OverviewView = null;
+
+ panel.panelWin.clearNamedTimeout("graph-scroll");
+ yield teardown(panel);
+ finish();
+}
diff --git a/browser/devtools/performance/test/head.js b/browser/devtools/performance/test/head.js
index 4654ad9..5f74789 100644
--- a/browser/devtools/performance/test/head.js
+++ b/browser/devtools/performance/test/head.js
@@ -96,38 +96,46 @@ function removeTab(aTab, aWindow) {
return deferred.promise;
}
function handleError(aError) {
ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
finish();
}
-function once(aTarget, aEventName, aUseCapture = false) {
+function once(aTarget, aEventName, aUseCapture = false, spread = false) {
info("Waiting for event: '" + aEventName + "' on " + aTarget + ".");
let deferred = Promise.defer();
for (let [add, remove] of [
["on", "off"], // Use event emitter before DOM events for consistency
["addEventListener", "removeEventListener"],
["addListener", "removeListener"]
]) {
if ((add in aTarget) && (remove in aTarget)) {
aTarget[add](aEventName, function onEvent(...aArgs) {
aTarget[remove](aEventName, onEvent, aUseCapture);
- deferred.resolve(...aArgs);
+ deferred.resolve(spread ? aArgs : aArgs[0]);
}, aUseCapture);
break;
}
}
return deferred.promise;
}
+/**
+ * Like `once`, except returns an array so we can
+ * access all arguments fired by the event.
+ */
+function onceSpread(aTarget, aEventName, aUseCapture) {
+ return once(aTarget, aEventName, aUseCapture, true);
+}
+
function test () {
Task.spawn(spawnTest).then(finish, handleError);
}
function initBackend(aUrl) {
info("Initializing a performance front.");
if (!DebuggerServer.initialized) {
@@ -277,8 +285,29 @@ function waitUntil(predicate, interval = 10) {
return Promise.resolve(true);
}
let deferred = Promise.defer();
setTimeout(function() {
waitUntil(predicate).then(() => deferred.resolve(true));
}, interval);
return deferred.promise;
}
+
+// EventUtils just doesn't work!
+
+function dragStart(graph, x, y = 1) {
+ x /= window.devicePixelRatio;
+ y /= window.devicePixelRatio;
+ graph._onMouseMove({ clientX: x, clientY: y });
+ graph._onMouseDown({ clientX: x, clientY: y });
+}
+
+function dragStop(graph, x, y = 1) {
+ x /= window.devicePixelRatio;
+ y /= window.devicePixelRatio;
+ graph._onMouseMove({ clientX: x, clientY: y });
+ graph._onMouseUp({ clientX: x, clientY: y });
+}
+
+function dropSelection(graph) {
+ graph.dropSelection();
+ graph.emit("mouseup");
+}
diff --git a/browser/devtools/performance/views/call-tree.js b/browser/devtools/performance/views/call-tree.js
index ea3943c..a97f206 100644
--- a/browser/devtools/performance/views/call-tree.js
+++ b/browser/devtools/performance/views/call-tree.js
@@ -8,46 +8,75 @@
*/
let CallTreeView = {
/**
* Sets up the view with event binding.
*/
initialize: function () {
this.el = $(".call-tree");
this._graphEl = $(".call-tree-cells-container");
+ this._onRangeChange = this._onRangeChange.bind(this);
this._stop = this._stop.bind(this);
+ OverviewView.on(EVENTS.OVERVIEW_RANGE_SELECTED, this._onRangeChange);
+ OverviewView.on(EVENTS.OVERVIEW_RANGE_CLEARED, this._onRangeChange);
PerformanceController.on(EVENTS.RECORDING_STOPPED, this._stop);
},
/**
* Unbinds events.
*/
destroy: function () {
+ OverviewView.off(EVENTS.OVERVIEW_RANGE_SELECTED, this._onRangeChange);
+ OverviewView.off(EVENTS.OVERVIEW_RANGE_CLEARED, this._onRangeChange);
PerformanceController.off(EVENTS.RECORDING_STOPPED, this._stop);
},
+ /**
+ * Method for handling all the set up for rendering a new
+ * call tree.
+ */
+ render: function (profilerData, beginAt, endAt, options={}) {
+ let threadNode = this._prepareCallTree(profilerData, beginAt, endAt, options);
+ this._populateCallTree(threadNode, options);
+ this.emit(EVENTS.CALL_TREE_RENDERED);
+ },
+
+ /**
+ * Called when recording is stopped.
+ */
_stop: function (_, { profilerData }) {
- this._prepareCallTree(profilerData);
+ this._profilerData = profilerData;
+ this.render(profilerData);
+ },
+
+ /**
+ * Fired when a range is selected or cleared in the OverviewView.
+ */
+ _onRangeChange: function (_, params) {
+ // When a range is cleared, we'll have no beginAt/endAt data,
+ // so the rebuild will just render all the data again.
+ let { beginAt, endAt } = params || {};
+ this.render(this._profilerData, beginAt, endAt);
},
/**
* Called when the recording is stopped and prepares data to
* populate the call tree.
*/
- _prepareCallTree: function (profilerData, beginAt, endAt, options={}) {
+ _prepareCallTree: function (profilerData, beginAt, endAt, options) {
let threadSamples = profilerData.profile.threads[0].samples;
let contentOnly = !Prefs.showPlatformData;
// TODO handle inverted tree bug 1102347
let invertTree = false;
let threadNode = new ThreadNode(threadSamples, contentOnly, beginAt, endAt, invertTree);
options.inverted = invertTree && threadNode.samples > 0;
- this._populateCallTree(threadNode, options);
+ return threadNode;
},
/**
* Renders the call tree.
*/
_populateCallTree: function (frameNode, options={}) {
let root = new CallView({
autoExpandDepth: options.inverted ? 0 : undefined,
@@ -57,17 +86,15 @@ let CallTreeView = {
});
// Clear out other graphs
this._graphEl.innerHTML = "";
root.attachTo(this._graphEl);
let contentOnly = !Prefs.showPlatformData;
root.toggleCategories(!contentOnly);
-
- this.emit(EVENTS.CALL_TREE_RENDERED);
}
};
/**
* Convenient way of emitting events from the view.
*/
EventEmitter.decorate(CallTreeView);
diff --git a/browser/devtools/performance/views/overview.js b/browser/devtools/performance/views/overview.js
index 292a0a4..1f28aa9 100644
--- a/browser/devtools/performance/views/overview.js
+++ b/browser/devtools/performance/views/overview.js
@@ -1,16 +1,17 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const OVERVIEW_UPDATE_INTERVAL = 100;
const FRAMERATE_CALC_INTERVAL = 16; // ms
const FRAMERATE_GRAPH_HEIGHT = 60; // px
+const GRAPH_SCROLL_EVENTS_DRAIN = 50; // ms
/**
* View handler for the overview panel's time view, displaying
* framerate over time.
*/
let OverviewView = {
/**
@@ -19,44 +20,83 @@ let OverviewView = {
initialize: function () {
this._framerateEl = $("#time-framerate");
this._ticksData = [];
this._start = this._start.bind(this);
this._stop = this._stop.bind(this);
this._onTimelineData = this._onTimelineData.bind(this);
this._onRecordingTick = this._onRecordingTick.bind(this);
+ this._onGraphMouseUp = this._onGraphMouseUp.bind(this);
+ this._onGraphScroll = this._onGraphScroll.bind(this);
this._initializeFramerateGraph();
+ this.framerateGraph.on("mouseup", this._onGraphMouseUp);
+ this.framerateGraph.on("scroll", this._onGraphScroll);
PerformanceController.on(EVENTS.RECORDING_STARTED, this._start);
PerformanceController.on(EVENTS.RECORDING_STOPPED, this._stop);
PerformanceController.on(EVENTS.TIMELINE_DATA, this._onTimelineData);
},
/**
* Unbinds events.
*/
destroy: function () {
+ this.framerateGraph.off("mouseup", this._onGraphMouseUp);
+ this.framerateGraph.off("scroll", this._onGraphScroll);
+ clearNamedTimeout("graph-scroll");
PerformanceController.off(EVENTS.RECORDING_STARTED, this._start);
PerformanceController.off(EVENTS.RECORDING_STOPPED, this._stop);
+ PerformanceController.off(EVENTS.TIMELINE_DATA, this._onTimelineData);
},
/**
* Called at most every OVERVIEW_UPDATE_INTERVAL milliseconds
* and uses data fetched from `_onTimelineData` to render
* data into all the corresponding overview graphs.
*/
_onRecordingTick: Task.async(function *() {
yield this.framerateGraph.setDataWhenReady(this._ticksData);
this.emit(EVENTS.OVERVIEW_RENDERED);
this._draw();
}),
/**
+ * Fired when the graph selection has changed. Called by
+ * mouseup and scroll events.
+ */
+ _onSelectionChange: function () {
+ if (this.framerateGraph.hasSelection()) {
+ let { min: beginAt, max: endAt } = this.framerateGraph.getMappedSelection();
+ this.emit(EVENTS.OVERVIEW_RANGE_SELECTED, { beginAt, endAt });
+ } else {
+ this.emit(EVENTS.OVERVIEW_RANGE_CLEARED);
+ }
+ },
+
+ /**
+ * Listener handling the "mouseup" event for the framerate graph.
+ * Fires an event to be handled elsewhere.
+ */
+ _onGraphMouseUp: function () {
+ this._onSelectionChange();
+ },
+
+ /**
+ * Listener handling the "scroll" event for the framerate graph.
+ * Fires an event to be handled elsewhere.
+ */
+ _onGraphScroll: function () {
+ setNamedTimeout("graph-scroll", GRAPH_SCROLL_EVENTS_DRAIN, () => {
+ this._onSelectionChange();
+ });
+ },
+
+ /**
* Sets up the framerate graph.
*/
_initializeFramerateGraph: function () {
let graph = new LineGraphWidget(this._framerateEl, L10N.getStr("graphs.fps"));
graph.minDistanceBetweenPoints = 1;
graph.fixedHeight = FRAMERATE_GRAPH_HEIGHT;
graph.selectionEnabled = false;
this.framerateGraph = graph;
--
1.8.4.2