2011-05-03 17:12:58 -07:00
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<window title="about:memory"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml"></body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
const Cc = Components.classes;
const Ci = Components.interfaces;
var mgr = Cc["@mozilla.org/memory-reporter-manager;1"].
getService(Ci.nsIMemoryReporterManager);
2012-01-07 02:45:35 -08:00
// Access mgr.explicit and mgr.resident just to make sure they don't crash.
// We can't check their actual values because they're non-deterministic.
var dummy = mgr.explicit;
dummy = mgr.resident;
2011-06-29 16:39:32 -07:00
// Remove all the real reporters and multi-reporters; save them to
// restore at the end.
2011-07-24 20:56:50 -07:00
var e = mgr.enumerateReporters();
2011-05-03 17:12:58 -07:00
var realReporters = [];
2012-01-07 02:45:35 -08:00
dummy = 0;
2011-05-03 17:12:58 -07:00
while (e.hasMoreElements()) {
2011-06-29 16:39:32 -07:00
var r = e.getNext().QueryInterface(Ci.nsIMemoryReporter);
// Get the |amount| field, even though we don't use it, just to test
2011-06-15 20:01:04 -07:00
// that the reporter doesn't crash or anything.
2011-06-29 16:39:32 -07:00
dummy += r.amount;
mgr.unregisterReporter(r);
realReporters.push(r);
}
2011-07-24 20:56:50 -07:00
e = mgr.enumerateMultiReporters();
2011-06-29 16:39:32 -07:00
var realMultiReporters = [];
var dummy = 0;
while (e.hasMoreElements()) {
var r = e.getNext().QueryInterface(Ci.nsIMemoryMultiReporter);
// Call collectReports, even though we don't use its results, just to
2011-12-12 19:04:12 -08:00
// test that the multi-reporter doesn't crash or anything. And likewise
// for the |explicitNonHeap| field.
2011-06-29 16:39:32 -07:00
r.collectReports(function(){}, null);
2011-12-12 19:04:12 -08:00
dummy += r.explicitNonHeap;
2011-06-29 16:39:32 -07:00
mgr.unregisterMultiReporter(r);
realMultiReporters.push(r);
2011-05-03 17:12:58 -07:00
}
// Setup various fake-but-deterministic reporters.
const KB = 1024;
const MB = KB * KB;
2011-05-22 19:49:56 -07:00
const kUnknown = -1;
2011-07-19 07:33:49 -07:00
const NONHEAP = Ci.nsIMemoryReporter.KIND_NONHEAP;
const HEAP = Ci.nsIMemoryReporter.KIND_HEAP;
const OTHER = Ci.nsIMemoryReporter.KIND_OTHER;
2011-05-22 19:49:56 -07:00
2011-07-24 20:56:50 -07:00
const BYTES = Ci.nsIMemoryReporter.UNITS_BYTES;
const COUNT = Ci.nsIMemoryReporter.UNITS_COUNT;
const COUNT_CUMULATIVE = Ci.nsIMemoryReporter.UNITS_COUNT_CUMULATIVE;
const PERCENTAGE = Ci.nsIMemoryReporter.UNITS_PERCENTAGE;
2011-06-30 16:15:08 -07:00
function f2(aProcess, aPath, aKind, aUnits, aAmount) {
2011-06-05 18:22:45 -07:00
return {
process: aProcess,
path: aPath,
kind: aKind,
2011-06-30 16:15:08 -07:00
units: aUnits,
2011-06-05 18:22:45 -07:00
description: "(description)",
2011-06-16 11:34:09 -07:00
amount: aAmount
2011-06-05 18:22:45 -07:00
};
}
2011-06-30 16:15:08 -07:00
function f(aProcess, aPath, aKind, aAmount) {
return f2(aProcess, aPath, aKind, BYTES, aAmount);
}
2011-06-30 16:15:25 -07:00
var fakeReporters = [
2011-07-19 07:33:49 -07:00
f("", "heap-allocated", OTHER, 500 * MB),
f("", "heap-unallocated", OTHER, 100 * MB),
f("", "explicit/a", HEAP, 222 * MB),
f("", "explicit/b/a", HEAP, 85 * MB),
f("", "explicit/b/b", HEAP, 75 * MB),
f("", "explicit/b/c/a", HEAP, 70 * MB),
f("", "explicit/b/c/b", HEAP, 2 * MB), // omitted
f("", "explicit/g/a", HEAP, 6 * MB),
f("", "explicit/g/b", HEAP, 5 * MB),
2012-01-07 02:45:35 -08:00
f("", "explicit/g/other", HEAP, 4 * MB),
2011-07-19 07:33:49 -07:00
f("", "other1", OTHER, 111 * MB),
2011-08-11 00:04:44 -07:00
f2("", "other4", OTHER, COUNT_CUMULATIVE, 888)
2011-06-30 16:15:25 -07:00
];
var fakeMultiReporters = [
{ collectReports: function(cbObj, closure) {
function f(p, k, u, a) { cbObj.callback("", p, k, u, a, "(desc)", closure); }
2012-01-07 02:45:35 -08:00
f("explicit/c/d", NONHEAP, BYTES, 13 * MB),
f("explicit/c/d", NONHEAP, BYTES, 10 * MB), // dup
f("explicit/c/other", NONHEAP, BYTES, 77 * MB),
2011-07-19 07:33:49 -07:00
f("explicit/cc", NONHEAP, BYTES, 13 * MB);
f("explicit/cc", NONHEAP, BYTES, 10 * MB); // dup
f("explicit/d", NONHEAP, BYTES, 499 * KB); // omitted
f("explicit/e", NONHEAP, BYTES, 100 * KB); // omitted
f("explicit/f/g/h/i", HEAP, BYTES, 20 * MB);
2011-12-12 19:04:12 -08:00
},
explicitNonHeap: (100 + 13 + 10)*MB + (499 + 100)*KB
2011-06-30 16:15:25 -07:00
},
{ collectReports: function(cbObj, closure) {
function f(p, k, u, a) { cbObj.callback("", p, k, u, a, "(desc)", closure); }
2011-07-19 07:33:49 -07:00
f("other3", OTHER, COUNT, 777);
2011-07-20 21:08:24 -07:00
f("other2", OTHER, BYTES, 222 * MB);
f("perc2", OTHER, PERCENTAGE, 10000);
f("perc1", OTHER, PERCENTAGE, 4567);
2011-12-12 19:04:12 -08:00
},
explicitNonHeap: 0
2011-08-05 15:22:11 -07:00
},
{ collectReports: function(cbObj, closure) {
// The amounts are given in pages, so multiply here by 4kb.
function f(p, a) { cbObj.callback("", p, NONHEAP, BYTES, a * 4 * KB, "(desc)", closure); }
f("map/vsize/a", 24);
f("map/swap/a", 1);
f("map/swap/a", 2);
f("map/vsize/a", 19);
f("map/swap/b/c", 10);
f("map/resident/a", 42);
2011-12-12 19:04:12 -08:00
},
explicitNonHeap: 0
2011-06-30 16:15:25 -07:00
}
];
for (var i = 0; i < fakeReporters.length; i++) {
mgr.registerReporter(fakeReporters[i]);
}
for (var i = 0; i < fakeMultiReporters.length; i++) {
mgr.registerMultiReporter(fakeMultiReporters[i]);
}
2011-05-03 17:12:58 -07:00
2011-07-19 07:33:49 -07:00
// mgr.explicit sums "heap-allocated" and all the appropriate NONHEAP ones:
2011-07-06 22:54:34 -07:00
// - "explicit/c", "explicit/cc" x 2, "explicit/d", "explicit/e"
// - but *not* "explicit/c/d" x 2
// Check explicit now before we add the fake reporters for the fake 2nd
// and subsequent processes.
is(mgr.explicit, 500*MB + (100 + 13 + 10)*MB + 599*KB, "mgr.explicit");
2011-06-30 16:15:25 -07:00
var fakeReporters2 = [
2011-07-19 07:33:49 -07:00
f("2nd", "heap-allocated", OTHER, 1000 * MB),
f("2nd", "heap-unallocated",OTHER, 100 * MB),
2011-07-19 16:59:17 -07:00
f("2nd", "explicit/a/b/c", HEAP, 497 * MB),
f("2nd", "explicit/a/b/c", HEAP, 1 * MB), // dup: merge
2011-07-19 07:33:49 -07:00
f("2nd", "explicit/a/b/c", HEAP, 1 * MB), // dup: merge
2011-06-29 22:44:17 -07:00
f("2nd", "explicit/flip\\the\\backslashes",
2011-07-19 07:33:49 -07:00
HEAP, 200 * MB),
2011-09-07 17:14:47 -07:00
f("2nd", "explicit/compartment(compartment-url)",
2011-07-19 07:33:49 -07:00
HEAP, 200 * MB),
2011-06-29 22:44:17 -07:00
// The escaping of compartment names must prevent this script from running.
f("2nd", "danger<script>window.alert(1)</script>",
2011-07-19 07:33:49 -07:00
OTHER, 666 * MB),
f("2nd", "other1", OTHER, 111 * MB),
2011-05-03 17:12:58 -07:00
2011-07-07 06:14:53 -07:00
// kUnknown should be handled gracefully for "heap-allocated", non-leaf
2011-07-19 16:59:17 -07:00
// reporters, leaf-reporters, "other" reporters, and duplicated reporters.
2011-07-19 07:33:49 -07:00
f("3rd", "heap-allocated", OTHER, kUnknown),
f("3rd", "explicit/a/b", HEAP, 333 * MB),
f("3rd", "explicit/a/c", HEAP, 444 * MB),
2011-07-19 16:59:17 -07:00
f("3rd", "explicit/a/c", HEAP, kUnknown), // dup: merge
2011-07-19 07:33:49 -07:00
f("3rd", "explicit/a/d", HEAP, kUnknown),
2011-07-19 16:59:17 -07:00
f("3rd", "explicit/a/d", HEAP, kUnknown), // dup: merge
2011-07-19 07:33:49 -07:00
f("3rd", "explicit/b", NONHEAP, kUnknown),
f("3rd", "other1", OTHER, kUnknown)
2011-05-03 17:12:58 -07:00
];
2011-06-30 16:15:25 -07:00
for (var i = 0; i < fakeReporters2.length; i++) {
mgr.registerReporter(fakeReporters2[i]);
2011-05-03 17:12:58 -07:00
}
2011-06-30 16:15:25 -07:00
fakeReporters = fakeReporters.concat(fakeReporters2);
2011-05-03 17:12:58 -07:00
]]>
</script>
2011-05-11 16:09:50 -07:00
<iframe id="amFrame" height="300" src="about:memory"></iframe>
<iframe id="amvFrame" height="300" src="about:memory?verbose"></iframe>
2011-05-03 17:12:58 -07:00
<script type="application/javascript">
<![CDATA[
var amExpectedText =
"\
Main Process\n\
\n\
2011-05-22 19:49:56 -07:00
Explicit Allocations\n\
623.58 MB (100.0%) -- explicit\n\
├──232.00 MB (37.20%) -- b\n\
│ ├───85.00 MB (13.63%) -- a\n\
│ ├───75.00 MB (12.03%) -- b\n\
│ └───72.00 MB (11.55%) -- c\n\
│ ├──70.00 MB (11.23%) -- a\n\
│ └───2.00 MB (00.32%) -- (1 omitted)\n\
├──222.00 MB (35.60%) -- a\n\
2011-07-06 22:54:34 -07:00
├──100.00 MB (16.04%) -- c\n\
│ ├───77.00 MB (12.35%) -- other\n\
2011-07-19 16:59:17 -07:00
│ └───23.00 MB (03.69%) -- d [2]\n\
├───23.00 MB (03.69%) -- cc [2]\n\
2011-05-22 19:49:56 -07:00
├───20.00 MB (03.21%) -- f\n\
│ └──20.00 MB (03.21%) -- g\n\
│ └──20.00 MB (03.21%) -- h\n\
│ └──20.00 MB (03.21%) -- i\n\
2012-01-07 02:45:35 -08:00
├───15.00 MB (02.41%) -- g\n\
2011-05-22 19:49:56 -07:00
│ ├───6.00 MB (00.96%) -- a\n\
│ ├───5.00 MB (00.80%) -- b\n\
│ └───4.00 MB (00.64%) -- other\n\
├───11.00 MB (01.76%) -- heap-unclassified\n\
└────0.58 MB (00.09%) -- (2 omitted)\n\
2011-05-03 17:12:58 -07:00
\n\
2011-08-05 15:22:11 -07:00
Resident Set Size (RSS) Breakdown\n\
0.16 MB (100.0%) -- resident\n\
└──0.16 MB (100.0%) -- a\n\
\n\
Virtual Size Breakdown\n\
0.17 MB (100.0%) -- vsize\n\
└──0.17 MB (100.0%) -- a [2]\n\
\n\
Swap Usage Breakdown\n\
0.05 MB (100.0%) -- swap\n\
├──0.04 MB (76.92%) -- b\n\
│ └──0.04 MB (76.92%) -- c\n\
└──0.01 MB (23.08%) -- a [2]\n\
\n\
2011-05-03 17:12:58 -07:00
Other Measurements\n\
2011-07-07 06:14:53 -07:00
500.00 MB -- heap-allocated\n\
100.00 MB -- heap-unallocated\n\
2011-07-20 21:08:24 -07:00
111.00 MB -- other1\n\
222.00 MB -- other2\n\
2011-06-30 16:15:08 -07:00
777 -- other3\n\
2011-07-06 23:37:26 -07:00
888 -- other4\n\
2011-07-20 21:08:24 -07:00
45.67% -- perc1\n\
100.00% -- perc2\n\
2011-05-03 17:12:58 -07:00
\n\
2nd Process\n\
\n\
2011-05-22 19:49:56 -07:00
Explicit Allocations\n\
1,000.00 MB (100.0%) -- explicit\n\
2011-05-03 17:12:58 -07:00
├────499.00 MB (49.90%) -- a\n\
│ └──499.00 MB (49.90%) -- b\n\
2011-07-19 16:59:17 -07:00
│ └──499.00 MB (49.90%) -- c [3]\n\
2011-06-29 22:44:17 -07:00
├────200.00 MB (20.00%) -- flip/the/backslashes\n\
2011-09-07 17:14:47 -07:00
├────200.00 MB (20.00%) -- compartment(compartment-url)\n\
2011-05-22 19:49:56 -07:00
└────101.00 MB (10.10%) -- heap-unclassified\n\
2011-05-03 17:12:58 -07:00
\n\
Other Measurements\n\
2011-06-29 22:44:17 -07:00
666.00 MB -- danger<script>window.alert(1)</script>\n\
2011-07-20 21:08:24 -07:00
1,000.00 MB -- heap-allocated\n\
2011-07-07 06:14:53 -07:00
100.00 MB -- heap-unallocated\n\
2011-07-20 21:08:24 -07:00
111.00 MB -- other1\n\
2011-05-03 17:12:58 -07:00
\n\
3rd Process\n\
\n\
2012-01-17 20:23:55 -08:00
WARNING: the 'heap-allocated' memory reporter does not work for this platform and/or configuration. This means that 'heap-unclassified' is zero and the 'explicit' tree shows less memory than it should.\n\
\n\
2011-05-22 19:49:56 -07:00
Explicit Allocations\n\
777.00 MB (100.0%) -- explicit\n\
2012-01-07 02:45:35 -08:00
├──777.00 MB (100.0%) -- a\n\
2011-07-19 16:59:17 -07:00
│ ├──444.00 MB (57.14%) -- c [2]\n\
2011-05-22 19:49:56 -07:00
│ ├──333.00 MB (42.86%) -- b\n\
│ └────0.00 MB (00.00%) -- (1 omitted)\n\
└────0.00 MB (00.00%) -- (2 omitted)\n\
2011-05-03 17:12:58 -07:00
\n\
Other Measurements\n\
2011-07-07 06:14:53 -07:00
0.00 MB -- heap-allocated [*]\n\
2011-05-22 19:49:56 -07:00
0.00 MB -- other1 [*]\n\
2011-05-03 17:12:58 -07:00
\n\
";
var amvExpectedText =
"\
Main Process\n\
\n\
2011-05-22 19:49:56 -07:00
Explicit Allocations\n\
653,876,224 B (100.0%) -- explicit\n\
├──243,269,632 B (37.20%) -- b\n\
│ ├───89,128,960 B (13.63%) -- a\n\
│ ├───78,643,200 B (12.03%) -- b\n\
│ └───75,497,472 B (11.55%) -- c\n\
│ ├──73,400,320 B (11.23%) -- a\n\
│ └───2,097,152 B (00.32%) -- b\n\
├──232,783,872 B (35.60%) -- a\n\
2011-07-06 22:54:34 -07:00
├──104,857,600 B (16.04%) -- c\n\
│ ├───80,740,352 B (12.35%) -- other\n\
2011-07-19 16:59:17 -07:00
│ └───24,117,248 B (03.69%) -- d [2]\n\
├───24,117,248 B (03.69%) -- cc [2]\n\
2011-05-22 19:49:56 -07:00
├───20,971,520 B (03.21%) -- f\n\
│ └──20,971,520 B (03.21%) -- g\n\
│ └──20,971,520 B (03.21%) -- h\n\
│ └──20,971,520 B (03.21%) -- i\n\
2012-01-07 02:45:35 -08:00
├───15,728,640 B (02.41%) -- g\n\
2011-05-22 19:49:56 -07:00
│ ├───6,291,456 B (00.96%) -- a\n\
│ ├───5,242,880 B (00.80%) -- b\n\
│ └───4,194,304 B (00.64%) -- other\n\
├───11,534,336 B (01.76%) -- heap-unclassified\n\
├──────510,976 B (00.08%) -- d\n\
2011-05-03 17:12:58 -07:00
└──────102,400 B (00.02%) -- e\n\
\n\
2011-08-05 15:22:11 -07:00
Resident Set Size (RSS) Breakdown\n\
172,032 B (100.0%) -- resident\n\
└──172,032 B (100.0%) -- a\n\
\n\
Virtual Size Breakdown\n\
176,128 B (100.0%) -- vsize\n\
└──176,128 B (100.0%) -- a [2]\n\
\n\
Swap Usage Breakdown\n\
53,248 B (100.0%) -- swap\n\
├──40,960 B (76.92%) -- b\n\
│ └──40,960 B (76.92%) -- c\n\
└──12,288 B (23.08%) -- a [2]\n\
\n\
2011-05-03 17:12:58 -07:00
Other Measurements\n\
2011-07-07 06:14:53 -07:00
524,288,000 B -- heap-allocated\n\
104,857,600 B -- heap-unallocated\n\
2011-07-20 21:08:24 -07:00
116,391,936 B -- other1\n\
232,783,872 B -- other2\n\
2011-06-30 16:15:08 -07:00
777 -- other3\n\
2011-07-06 23:37:26 -07:00
888 -- other4\n\
2011-07-20 21:08:24 -07:00
45.67% -- perc1\n\
100.00% -- perc2\n\
2011-05-03 17:12:58 -07:00
\n\
2nd Process\n\
\n\
2011-05-22 19:49:56 -07:00
Explicit Allocations\n\
1,048,576,000 B (100.0%) -- explicit\n\
2011-05-03 17:12:58 -07:00
├────523,239,424 B (49.90%) -- a\n\
│ └──523,239,424 B (49.90%) -- b\n\
2011-07-19 16:59:17 -07:00
│ └──523,239,424 B (49.90%) -- c [3]\n\
2011-06-29 22:44:17 -07:00
├────209,715,200 B (20.00%) -- flip/the/backslashes\n\
2011-09-07 17:14:47 -07:00
├────209,715,200 B (20.00%) -- compartment(compartment-url)\n\
2011-05-22 19:49:56 -07:00
└────105,906,176 B (10.10%) -- heap-unclassified\n\
2011-05-03 17:12:58 -07:00
\n\
Other Measurements\n\
2011-06-29 22:44:17 -07:00
698,351,616 B -- danger<script>window.alert(1)</script>\n\
2011-07-20 21:08:24 -07:00
1,048,576,000 B -- heap-allocated\n\
2011-07-07 06:14:53 -07:00
104,857,600 B -- heap-unallocated\n\
2011-07-20 21:08:24 -07:00
116,391,936 B -- other1\n\
2011-05-03 17:12:58 -07:00
\n\
3rd Process\n\
\n\
2012-01-17 20:23:55 -08:00
WARNING: the 'heap-allocated' memory reporter does not work for this platform and/or configuration. This means that 'heap-unclassified' is zero and the 'explicit' tree shows less memory than it should.\n\
\n\
2011-05-22 19:49:56 -07:00
Explicit Allocations\n\
814,743,552 B (100.0%) -- explicit\n\
2012-01-07 02:45:35 -08:00
├──814,743,552 B (100.0%) -- a\n\
2011-07-19 16:59:17 -07:00
│ ├──465,567,744 B (57.14%) -- c [2]\n\
2011-05-22 19:49:56 -07:00
│ ├──349,175,808 B (42.86%) -- b\n\
2011-07-19 16:59:17 -07:00
│ └────────────0 B (00.00%) -- d [*] [2]\n\
2011-05-22 19:49:56 -07:00
├────────────0 B (00.00%) -- b [*]\n\
└────────────0 B (00.00%) -- heap-unclassified [*]\n\
2011-05-03 17:12:58 -07:00
\n\
Other Measurements\n\
2011-07-07 06:14:53 -07:00
0 B -- heap-allocated [*]\n\
2011-05-22 19:49:56 -07:00
0 B -- other1 [*]\n\
2011-05-03 17:12:58 -07:00
\n\
"
function finish()
{
2011-06-30 16:15:25 -07:00
// Unregister fake reporters and multi-reporters, re-register the real
// reporters and multi-reporters, just in case subsequent tests rely on
// them.
2011-05-03 17:12:58 -07:00
for (var i = 0; i < fakeReporters.length; i++) {
mgr.unregisterReporter(fakeReporters[i]);
}
2011-06-30 16:15:25 -07:00
for (var i = 0; i < fakeMultiReporters.length; i++) {
mgr.unregisterMultiReporter(fakeMultiReporters[i]);
}
2011-05-03 17:12:58 -07:00
for (var i = 0; i < realReporters.length; i++) {
mgr.registerReporter(realReporters[i]);
}
2011-06-29 16:39:32 -07:00
for (var i = 0; i < realMultiReporters.length; i++) {
mgr.registerMultiReporter(realMultiReporters[i]);
}
2011-05-03 17:12:58 -07:00
SimpleTest.finish();
}
2011-11-08 21:34:33 -08:00
function checkClipboard(actual, expected) {
if (actual != expected) {
2011-08-05 15:22:11 -07:00
dump("*******ACTUAL*******\n");
2011-11-08 21:34:33 -08:00
dump(actual);
2011-08-05 15:22:11 -07:00
dump("******EXPECTED******\n");
dump(expected);
dump("********************\n");
return false;
}
return true;
}
2011-05-03 17:12:58 -07:00
// Cut+paste the entire page and check that the cut text matches what we
// expect. This tests the output in general and also that the cutting and
// pasting works as expected.
function test(aFrame, aExpectedText, aNext) {
2011-08-05 15:22:11 -07:00
// Click all h2.collapsed elements so they expand.
var win = document.querySelector("#" + aFrame).contentWindow;
var nodes = win.document.querySelectorAll("pre.collapsed");
for (var i = 0; i < nodes.length; i++) {
nodes[i].classList.toggle('collapsed');
}
SimpleTest.executeSoon(function() {
document.querySelector("#" + aFrame).focus();
2011-11-08 21:34:33 -08:00
SimpleTest.waitForClipboard(
function(actual) { return checkClipboard(actual, aExpectedText) },
2011-08-05 15:22:11 -07:00
function() {
synthesizeKey("A", {accelKey: true});
synthesizeKey("C", {accelKey: true});
},
aNext,
function() {
ok(false, "pasted text doesn't match for " + aFrame);
finish();
}
);
});
2011-05-03 17:12:58 -07:00
}
addLoadEvent(function() {
test(
"amFrame",
amExpectedText,
function() {
test(
"amvFrame",
amvExpectedText,
function() {
finish()
}
)
}
);
});
SimpleTest.waitForExplicitFinish();
]]>
</script>
</window>