|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 "use strict"; |
|
6 |
|
7 const {Cc, Ci, Cu} = require("chrome"); |
|
8 let protocol = require("devtools/server/protocol"); |
|
9 let {method, RetVal} = protocol; |
|
10 |
|
11 /** |
|
12 * An actor that returns memory usage data for its parent actor's window. |
|
13 * A tab-scoped instance of this actor will measure the memory footprint of its |
|
14 * parent tab. A global-scoped instance however, will measure the memory |
|
15 * footprint of the chrome window referenced by the root actor. |
|
16 */ |
|
17 let MemoryActor = protocol.ActorClass({ |
|
18 typeName: "memory", |
|
19 |
|
20 initialize: function(conn, tabActor) { |
|
21 protocol.Actor.prototype.initialize.call(this, conn); |
|
22 this.tabActor = tabActor; |
|
23 this._mgr = Cc["@mozilla.org/memory-reporter-manager;1"] |
|
24 .getService(Ci.nsIMemoryReporterManager); |
|
25 }, |
|
26 |
|
27 destroy: function() { |
|
28 this._mgr = null; |
|
29 protocol.Actor.prototype.destroy.call(this); |
|
30 }, |
|
31 |
|
32 /** |
|
33 * A method that returns a detailed breakdown of the memory consumption of the |
|
34 * associated window. |
|
35 * |
|
36 * @returns object |
|
37 */ |
|
38 measure: method(function() { |
|
39 let result = {}; |
|
40 |
|
41 let jsObjectsSize = {}; |
|
42 let jsStringsSize = {}; |
|
43 let jsOtherSize = {}; |
|
44 let domSize = {}; |
|
45 let styleSize = {}; |
|
46 let otherSize = {}; |
|
47 let totalSize = {}; |
|
48 let jsMilliseconds = {}; |
|
49 let nonJSMilliseconds = {}; |
|
50 |
|
51 try { |
|
52 this._mgr.sizeOfTab(this.tabActor.window, jsObjectsSize, jsStringsSize, jsOtherSize, |
|
53 domSize, styleSize, otherSize, totalSize, jsMilliseconds, nonJSMilliseconds); |
|
54 result.total = totalSize.value; |
|
55 result.domSize = domSize.value; |
|
56 result.styleSize = styleSize.value; |
|
57 result.jsObjectsSize = jsObjectsSize.value; |
|
58 result.jsStringsSize = jsStringsSize.value; |
|
59 result.jsOtherSize = jsOtherSize.value; |
|
60 result.otherSize = otherSize.value; |
|
61 result.jsMilliseconds = jsMilliseconds.value.toFixed(1); |
|
62 result.nonJSMilliseconds = nonJSMilliseconds.value.toFixed(1); |
|
63 } catch (e) { |
|
64 console.error(e); |
|
65 let url = this.tabActor.url; |
|
66 console.error("Error getting size of "+url); |
|
67 } |
|
68 |
|
69 return result; |
|
70 }, { |
|
71 request: {}, |
|
72 response: RetVal("json"), |
|
73 }) |
|
74 }); |
|
75 |
|
76 exports.MemoryActor = MemoryActor; |
|
77 |
|
78 exports.MemoryFront = protocol.FrontClass(MemoryActor, { |
|
79 initialize: function(client, form) { |
|
80 protocol.Front.prototype.initialize.call(this, client, form); |
|
81 this.actorID = form.memoryActor; |
|
82 client.addActorPool(this); |
|
83 this.manage(this); |
|
84 } |
|
85 }); |
|
86 |
|
87 exports.register = function(handle) { |
|
88 handle.addGlobalActor(MemoryActor, "memoryActor"); |
|
89 handle.addTabActor(MemoryActor, "memoryActor"); |
|
90 }; |
|
91 |
|
92 exports.unregister = function(handle) { |
|
93 handle.removeGlobalActor(MemoryActor, "memoryActor"); |
|
94 handle.removeTabActor(MemoryActor, "memoryActor"); |
|
95 }; |