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