-
Notifications
You must be signed in to change notification settings - Fork 9
/
memory.mozcmd
43 lines (34 loc) · 1.7 KB
/
memory.mozcmd
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
[{
name: "memory",
description: "Get a memory report for the current page",
exec: function(args, context) {
Components.utils.import("resource://gre/modules/DownloadUtils.jsm");
let output = '<h1>Memory report:</h1><br/><table>';
let total = 0;
let url = context.environment.contentDocument.location.href;
url = url.replace(/\//g, "\\");
let pathPrefix = "explicit/js/compartment(" + url + ")";
let memMgr = Components.classes["@mozilla.org/memory-reporter-manager;1"]
.getService(Components.interfaces.nsIMemoryReporterManager);
let reporters = memMgr.enumerateMultiReporters();
while (reporters.hasMoreElements()) {
let reporter = reporters.getNext().QueryInterface(Components.interfaces.nsIMemoryMultiReporter);
reporter.collectReports(function(process, path, kind, units, amount, description, closure) {
if (path.indexOf(pathPrefix) != 0)
return;
if (units != Components.interfaces.nsIMemoryReporter.UNITS_BYTES)
return;
total += amount;
let pathDetail = path.slice(pathPrefix.length + 1);
let [formattedSize, formattedUnit] = DownloadUtils.convertByteUnits(amount);
output += '<tr><td><abbr title="' + description + '">' + pathDetail + '</abbr></td><td>' + formattedSize + ' ' + formattedUnit + '</td></tr>';
}, reporter);
}
if (total == 0)
return "Page not found in memory?!";
let [formattedSize, formattedUnit] = DownloadUtils.convertByteUnits(total);
output += '<tr><td><b>Total</b></td><td><b>' + formattedSize + ' ' + formattedUnit + '</b></td></tr>';
output += "</table>"
return output;
}
}]