-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1102347-link-debugger-to-perf.patch
278 lines (257 loc) · 9.81 KB
/
1102347-link-debugger-to-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
From 6dfd6aa71f34dddb9695888f96860e53933764d0 Mon Sep 17 00:00:00 2001
From: Jordan Santell <[email protected]>
Date: Wed, 10 Dec 2014 16:11:39 -0800
Subject: Bug 1102347 - Add jump to lines in the debugger from new
performance call tree. r=vp
diff --git a/browser/devtools/performance/performance-controller.js b/browser/devtools/performance/performance-controller.js
index 245f60b..4a4bc4d 100644
--- a/browser/devtools/performance/performance-controller.js
+++ b/browser/devtools/performance/performance-controller.js
@@ -50,16 +50,20 @@ const EVENTS = {
OVERVIEW_RANGE_CLEARED: "Performance:UI:OverviewRangeCleared",
// Emitted by the DetailsView when a subview is selected
DETAILS_VIEW_SELECTED: "Performance:UI:DetailsViewSelected",
// Emitted by the CallTreeView when a call tree has been rendered
CALL_TREE_RENDERED: "Performance:UI:CallTreeRendered",
+ // When a source is shown in the JavaScript Debugger at a specific location.
+ SOURCE_SHOWN_IN_JS_DEBUGGER: "Performance:UI:SourceShownInJsDebugger",
+ SOURCE_NOT_FOUND_IN_JS_DEBUGGER: "Performance:UI:SourceNotFoundInJsDebugger",
+
// Emitted by the WaterfallView when it has been rendered
WATERFALL_RENDERED: "Performance:UI:WaterfallRendered"
};
/**
* The current target and the profiler connection, set by this tool's host.
*/
let gToolbox, gTarget, gFront;
diff --git a/browser/devtools/performance/test/browser.ini b/browser/devtools/performance/test/browser.ini
index 6e56842..bca94be 100644
--- a/browser/devtools/performance/test/browser.ini
+++ b/browser/devtools/performance/test/browser.ini
@@ -30,11 +30,13 @@ support-files =
[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.js]
+[browser_perf-jump-to-debugger-01.js]
+[browser_perf-jump-to-debugger-02.js]
[browser_perf-details-calltree-render-01.js]
[browser_perf-details-calltree-render-02.js]
[browser_perf-details-waterfall-render-01.js]
diff --git a/browser/devtools/performance/test/browser_perf-jump-to-debugger-01.js b/browser/devtools/performance/test/browser_perf-jump-to-debugger-01.js
new file mode 100644
index 0000000..8e967fe
--- /dev/null
+++ b/browser/devtools/performance/test/browser_perf-jump-to-debugger-01.js
@@ -0,0 +1,27 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/**
+ * Tests if the performance tool can jump to the debugger.
+ */
+
+function spawnTest () {
+ let { target, panel, toolbox } = yield initPerformance(SIMPLE_URL);
+ let { viewSourceInDebugger } = panel.panelWin;
+
+ yield viewSourceInDebugger(SIMPLE_URL, 14);
+
+ let debuggerPanel = toolbox.getPanel("jsdebugger");
+ ok(debuggerPanel, "The debugger panel was opened.");
+
+ let { DebuggerView } = debuggerPanel.panelWin;
+ let Sources = DebuggerView.Sources;
+
+ is(Sources.selectedValue, getSourceActor(Sources, SIMPLE_URL),
+ "The correct source is shown in the debugger.");
+ is(DebuggerView.editor.getCursor().line + 1, 14,
+ "The correct line is highlighted in the debugger's source editor.");
+
+ yield teardown(panel);
+ finish();
+}
diff --git a/browser/devtools/performance/test/browser_perf-jump-to-debugger-02.js b/browser/devtools/performance/test/browser_perf-jump-to-debugger-02.js
new file mode 100644
index 0000000..d72a291
--- /dev/null
+++ b/browser/devtools/performance/test/browser_perf-jump-to-debugger-02.js
@@ -0,0 +1,41 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/**
+ * Tests if the performance tool can jump to the debugger, when the source was already
+ * loaded in that tool.
+ */
+
+function spawnTest() {
+ let { target, panel, toolbox } = yield initPerformance(SIMPLE_URL, "jsdebugger");
+ let debuggerWin = panel.panelWin;
+ let debuggerEvents = debuggerWin.EVENTS;
+ let { DebuggerView } = debuggerWin;
+ let Sources = DebuggerView.Sources;
+
+ yield debuggerWin.once(debuggerEvents.SOURCE_SHOWN);
+ ok("A source was shown in the debugger.");
+
+ is(Sources.selectedValue, getSourceActor(Sources, SIMPLE_URL),
+ "The correct source is initially shown in the debugger.");
+ is(DebuggerView.editor.getCursor().line, 0,
+ "The correct line is initially highlighted in the debugger's source editor.");
+
+ yield toolbox.selectTool("performance");
+ let perfPanel = toolbox.getCurrentPanel();
+ let perfWin = perfPanel.panelWin;
+ let { viewSourceInDebugger } = perfWin;
+
+ yield viewSourceInDebugger(SIMPLE_URL, 14);
+
+ panel = toolbox.getPanel("jsdebugger");
+ ok(panel, "The debugger panel was reselected.");
+
+ is(DebuggerView.Sources.selectedValue, getSourceActor(Sources, SIMPLE_URL),
+ "The correct source is still shown in the debugger.");
+ is(DebuggerView.editor.getCursor().line + 1, 14,
+ "The correct line is now highlighted in the debugger's source editor.");
+
+ yield teardown(perfPanel);
+ finish();
+}
diff --git a/browser/devtools/performance/test/head.js b/browser/devtools/performance/test/head.js
index 25ae10f..1cf7ef5 100644
--- a/browser/devtools/performance/test/head.js
+++ b/browser/devtools/performance/test/head.js
@@ -153,27 +153,27 @@ function initBackend(aUrl) {
let connection = getPerformanceActorsConnection(target);
yield connection.open();
let front = new PerformanceFront(connection);
return { target, front };
});
}
-function initPerformance(aUrl) {
+function initPerformance(aUrl, selectedTool="performance") {
info("Initializing a performance pane.");
return Task.spawn(function*() {
let tab = yield addTab(aUrl);
let target = TargetFactory.forTab(tab);
yield target.makeRemote();
Services.prefs.setBoolPref("devtools.performance_dev.enabled", true);
- let toolbox = yield gDevTools.showToolbox(target, "performance");
+ let toolbox = yield gDevTools.showToolbox(target, selectedTool);
let panel = toolbox.getCurrentPanel();
return { target, panel, toolbox };
});
}
function* teardown(panel) {
info("Destroying the performance tool.");
@@ -312,8 +312,13 @@ function dragStop(graph, x, y = 1) {
graph._onMouseMove({ clientX: x, clientY: y });
graph._onMouseUp({ clientX: x, clientY: y });
}
function dropSelection(graph) {
graph.dropSelection();
graph.emit("mouseup");
}
+
+function getSourceActor(aSources, aURL) {
+ let item = aSources.getItemForAttachment(a => a.source.url === aURL);
+ return item && item.value;
+}
diff --git a/browser/devtools/performance/views/details-call-tree.js b/browser/devtools/performance/views/details-call-tree.js
index a97f206..9149738 100644
--- a/browser/devtools/performance/views/details-call-tree.js
+++ b/browser/devtools/performance/views/details-call-tree.js
@@ -9,16 +9,17 @@
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._onLink = this._onLink.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);
},
/**
@@ -53,16 +54,23 @@ let CallTreeView = {
*/
_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);
},
+ _onLink: function (_, treeItem) {
+ let { url, line } = treeItem.frame.getInfo();
+ viewSourceInDebugger(url, line).then(
+ () => this.emit(EVENTS.SOURCE_SHOWN_IN_JS_DEBUGGER),
+ () => this.emit(EVENTS.SOURCE_NOT_FOUND_IN_JS_DEBUGGER));
+ },
+
/**
* Called when the recording is stopped and prepares data to
* populate the call tree.
*/
_prepareCallTree: function (profilerData, beginAt, endAt, options) {
let threadSamples = profilerData.profile.threads[0].samples;
let contentOnly = !Prefs.showPlatformData;
// TODO handle inverted tree bug 1102347
@@ -80,21 +88,51 @@ let CallTreeView = {
_populateCallTree: function (frameNode, options={}) {
let root = new CallView({
autoExpandDepth: options.inverted ? 0 : undefined,
frame: frameNode,
hidden: options.inverted,
inverted: options.inverted
});
+ // Bind events
+ root.on("link", this._onLink);
+
// Clear out other graphs
this._graphEl.innerHTML = "";
root.attachTo(this._graphEl);
let contentOnly = !Prefs.showPlatformData;
root.toggleCategories(!contentOnly);
}
};
/**
* Convenient way of emitting events from the view.
*/
EventEmitter.decorate(CallTreeView);
+
+/**
+ * Opens/selects the debugger in this toolbox and jumps to the specified
+ * file name and line number.
+ * @param string url
+ * @param number line
+ */
+let viewSourceInDebugger = Task.async(function *(url, line) {
+ // If the Debugger was already open, switch to it and try to show the
+ // source immediately. Otherwise, initialize it and wait for the sources
+ // to be added first.
+ let debuggerAlreadyOpen = gToolbox.getPanel("jsdebugger");
+
+ let { panelWin: dbg } = yield gToolbox.selectTool("jsdebugger");
+
+ if (!debuggerAlreadyOpen) {
+ yield new Promise((resolve) => dbg.once(dbg.EVENTS.SOURCES_ADDED, () => resolve(dbg)));
+ }
+
+ let { DebuggerView } = dbg;
+ let item = DebuggerView.Sources.getItemForAttachment(a => a.source.url === url);
+
+ if (item) {
+ return DebuggerView.setEditorLocation(item.attachment.source.actor, line, { noDebug: true });
+ }
+ return Promise.reject();
+});
--
1.8.4.2