forked from jsantell/firefox-patches
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1089773-wae-getmemory.patch
296 lines (266 loc) · 10.8 KB
/
1089773-wae-getmemory.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
From 5ada10f5173c607f938443e0d79209949a5e8725 Mon Sep 17 00:00:00 2001
From: Jordan Santell <[email protected]>
Date: Tue, 20 Jan 2015 17:18:12 -0800
Subject: Bug 1089773 - Expose memory allocations for audio nodes via
WebAudioActor.getMemory(). r=vp
diff --git a/browser/devtools/webaudioeditor/test/browser.ini b/browser/devtools/webaudioeditor/test/browser.ini
index 3012b7e..c0152fc 100644
--- a/browser/devtools/webaudioeditor/test/browser.ini
+++ b/browser/devtools/webaudioeditor/test/browser.ini
@@ -25,16 +25,17 @@ support-files =
[browser_audionode-actor-connectparam.js]
[browser_audionode-actor-add-automation-event.js]
[browser_audionode-actor-get-automation-data-01.js]
[browser_audionode-actor-get-automation-data-02.js]
[browser_webaudio-actor-simple.js]
[browser_webaudio-actor-destroy-node.js]
[browser_webaudio-actor-connect-param.js]
[browser_webaudio-actor-automation-event.js]
+[browser_webaudio-actor-get-memory.js]
[browser_wa_destroy-node-01.js]
[browser_wa_first-run.js]
[browser_wa_reset-01.js]
[browser_wa_reset-02.js]
[browser_wa_reset-03.js]
[browser_wa_reset-04.js]
diff --git a/browser/devtools/webaudioeditor/test/browser_webaudio-actor-get-memory.js b/browser/devtools/webaudioeditor/test/browser_webaudio-actor-get-memory.js
new file mode 100644
index 0000000..d51dbaf
--- /dev/null
+++ b/browser/devtools/webaudioeditor/test/browser_webaudio-actor-get-memory.js
@@ -0,0 +1,26 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/**
+ * Test that the WebAudioActor.getMemory() returns a hash of memory in bytes.
+ */
+
+add_task(function*() {
+ let { target, front } = yield initBackend(SIMPLE_CONTEXT_URL);
+
+ let [_, [destNode, oscNode, gainNode], [connect1, connect2]] = yield Promise.all([
+ front.setup({ reload: true }),
+ get3(front, "create-node"),
+ get2(front, "connect-node")
+ ]);
+
+ let mem = null;
+ while (!(mem = yield front.getMemory())) {}
+
+ is(Object.keys(mem).length, 3, "getMemory() only returns memory information for current nodes");
+ is(typeof mem[destNode.actorID], "number", "getMemory() returns memory for DestinationNode");
+ is(typeof mem[gainNode.actorID], "number", "getMemory() returns memory for GainNode");
+ is(typeof mem[oscNode.actorID], "number", "getMemory() returns memory for OscillatorNode");
+
+ yield removeTab(target.tab);
+});
diff --git a/toolkit/devtools/server/actors/webaudio.js b/toolkit/devtools/server/actors/webaudio.js
index c610176..d7bac69 100644
--- a/toolkit/devtools/server/actors/webaudio.js
+++ b/toolkit/devtools/server/actors/webaudio.js
@@ -2,26 +2,27 @@
* 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 {Cc, Ci, Cu, Cr} = require("chrome");
const Services = require("Services");
-const { Promise: promise } = Cu.import("resource://gre/modules/Promise.jsm", {});
-const events = require("sdk/event/core");
+const { Task } = require("resource://gre/modules/Task.jsm");
+const { Promise: promise } = require("resource://gre/modules/Promise.jsm");
+const { on, once, off, emit } = require("sdk/event/core");
const { on: systemOn, off: systemOff } = require("sdk/system/events");
-const protocol = require("devtools/server/protocol");
const { CallWatcherActor, CallWatcherFront } = require("devtools/server/actors/call-watcher");
const { ThreadActor } = require("devtools/server/actors/script");
const AutomationTimeline = require("./utils/automation-timeline");
+const {
+ types, method, Arg, Option, RetVal, Actor, ActorClass, Front, FrontClass
+} = require("devtools/server/protocol");
-const { on, once, off, emit } = events;
-const { types, method, Arg, Option, RetVal } = protocol;
const AUTOMATION_GRANULARITY = 2000;
const AUTOMATION_GRANULARITY_MAX = 6000;
const AUDIO_GLOBALS = [
"AudioContext", "AudioNode", "AudioParam"
];
@@ -149,29 +150,29 @@ const NODE_PROPERTIES = {
}
};
/**
* An Audio Node actor allowing communication to a specific audio node in the
* Audio Context graph.
*/
types.addActorType("audionode");
-let AudioNodeActor = exports.AudioNodeActor = protocol.ActorClass({
+let AudioNodeActor = exports.AudioNodeActor = ActorClass({
typeName: "audionode",
/**
* Create the Audio Node actor.
*
* @param DebuggerServerConnection conn
* The server connection.
* @param AudioNode node
* The AudioNode that was created.
*/
initialize: function (conn, node) {
- protocol.Actor.prototype.initialize.call(this, conn);
+ Actor.prototype.initialize.call(this, conn);
// Store ChromeOnly property `id` to identify AudioNode,
// rather than storing a strong reference, and store a weak
// ref to underlying node for controlling.
this.nativeID = node.id;
this.node = Cu.getWeakReference(node);
// Stores the AutomationTimelines for this node's AudioParams.
@@ -556,52 +557,52 @@ let AudioNodeActor = exports.AudioNodeActor = protocol.ActorClass({
let timeline = this.automation[paramName];
timeline[eventName].apply(timeline, args);
}
});
/**
* The corresponding Front object for the AudioNodeActor.
*/
-let AudioNodeFront = protocol.FrontClass(AudioNodeActor, {
+let AudioNodeFront = FrontClass(AudioNodeActor, {
initialize: function (client, form) {
- protocol.Front.prototype.initialize.call(this, client, form);
+ Front.prototype.initialize.call(this, client, form);
// if we were manually passed a form, this was created manually and
// needs to own itself for now.
if (form) {
this.manage(this);
}
}
});
/**
* The Web Audio Actor handles simple interaction with an AudioContext
* high-level methods. After instantiating this actor, you'll need to set it
* up by calling setup().
*/
-let WebAudioActor = exports.WebAudioActor = protocol.ActorClass({
+let WebAudioActor = exports.WebAudioActor = ActorClass({
typeName: "webaudio",
initialize: function(conn, tabActor) {
- protocol.Actor.prototype.initialize.call(this, conn);
+ Actor.prototype.initialize.call(this, conn);
this.tabActor = tabActor;
this._onContentFunctionCall = this._onContentFunctionCall.bind(this);
// Store ChromeOnly ID (`nativeID` property on AudioNodeActor) mapped
// to the associated actorID, so we don't have to expose `nativeID`
// to the client in any way.
this._nativeToActorID = new Map();
this._onDestroyNode = this._onDestroyNode.bind(this);
this._onGlobalDestroyed = this._onGlobalDestroyed.bind(this);
this._onGlobalCreated = this._onGlobalCreated.bind(this);
},
destroy: function(conn) {
- protocol.Actor.prototype.destroy.call(this, conn);
+ Actor.prototype.destroy.call(this, conn);
this.finalize();
},
/**
* Starts waiting for the current tab actor's document global to be
* created, in order to instrument the Canvas context and become
* aware of everything the content does with Web Audio.
*
@@ -638,16 +639,39 @@ let WebAudioActor = exports.WebAudioActor = protocol.ActorClass({
// the global destruction and the `finalize` cleanup method on the actor.
on(this.tabActor, "window-destroyed", this._onGlobalDestroyed);
}, {
request: { reload: Option(0, "boolean") },
oneway: true
}),
/**
+ * Returns a hash of AudioNodeActor IDs with their memory consumption in bytes.
+ */
+ getMemory: method(Task.async(function *() {
+ let mem = yield this.context.getMemoryReport();
+
+ // Reduce memory down to a hash of only nodes that
+ // are currently on this document and context, and
+ // use actorIDs as the key instead of nativeIDs (as the front
+ // end does not currently have access to nativeIDs)
+ return Object.keys(mem).reduce((ret, nativeID) => {
+ let actor = this._getActorByNativeID(nativeID);
+ // If no actor found, probably a remenant from previous page that has
+ // not yet been collected
+ if (actor) {
+ ret[actor.actorID] = mem[nativeID];
+ }
+ return ret;
+ }, {});
+ }), {
+ response: { memory: RetVal("nullable:json") }
+ }),
+
+ /**
* Invoked whenever an instrumented function is called, like an AudioContext
* method or an AudioNode method.
*/
_onContentFunctionCall: function(functionCall) {
let { name } = functionCall.details;
// All Web Audio nodes inherit from AudioNode's prototype, so
// hook into the `connect` and `disconnect` methods
@@ -684,16 +708,17 @@ let WebAudioActor = exports.WebAudioActor = protocol.ActorClass({
_handleCreationCall: function (functionCall) {
let { caller, result } = functionCall.details;
// Keep track of the first node created, so we can alert
// the front end that an audio context is being used since
// we're not hooking into the constructor itself, just its
// instance's methods.
if (!this._firstNodeCreated) {
+ this.context = caller;
// Fire the start-up event if this is the first node created
// and trigger a `create-node` event for the context destination
this._onStartContext();
this._onCreateNode(caller.destination);
this._firstNodeCreated = true;
}
this._onCreateNode(result);
},
@@ -727,16 +752,17 @@ let WebAudioActor = exports.WebAudioActor = protocol.ActorClass({
if (!this._initialized) {
return;
}
this._initialized = false;
systemOff("webaudio-node-demise", this._onDestroyNode);
off(this.tabActor, "window-destroyed", this._onGlobalDestroyed);
off(this.tabActor, "window-ready", this._onGlobalCreated);
+ this.context = null;
this.tabActor = null;
this._nativeToActorID = null;
this._callWatcher.eraseRecording();
this._callWatcher.finalize();
this._callWatcher = null;
}, {
oneway: true
}),
@@ -943,26 +969,27 @@ let WebAudioActor = exports.WebAudioActor = protocol.ActorClass({
_onGlobalDestroyed: function ({id}) {
if (this._callWatcher._tracedWindowId !== id) {
return;
}
if (this._nativeToActorID) {
this._nativeToActorID.clear();
}
+ this.context = null;
systemOff("webaudio-node-demise", this._onDestroyNode);
}
});
/**
* The corresponding Front object for the WebAudioActor.
*/
-let WebAudioFront = exports.WebAudioFront = protocol.FrontClass(WebAudioActor, {
+let WebAudioFront = exports.WebAudioFront = FrontClass(WebAudioActor, {
initialize: function(client, { webaudioActor }) {
- protocol.Front.prototype.initialize.call(this, client, { actor: webaudioActor });
+ Front.prototype.initialize.call(this, client, { actor: webaudioActor });
this.manage(this);
}
});
WebAudioFront.AUTOMATION_METHODS = new Set(AUTOMATION_METHODS);
WebAudioFront.NODE_CREATION_METHODS = new Set(NODE_CREATION_METHODS);
WebAudioFront.NODE_ROUTING_METHODS = new Set(NODE_ROUTING_METHODS);
--
2.2.1