Bug 1192335 - Expose bytesize from memory module's getAllocations. r=fitzgen

This commit is contained in:
Jordan Santell 2015-08-07 12:27:32 -07:00
Родитель 2c0844778e
Коммит 824ddd71e6
3 изменённых файлов: 65 добавлений и 2 удалений

Просмотреть файл

@ -78,6 +78,7 @@ skip-if = buildapp == 'mulet'
[test_memory_allocations_04.html]
[test_memory_allocations_05.html]
[test_memory_allocations_06.html]
[test_memory_allocations_07.html]
[test_memory_attach_01.html]
[test_memory_attach_02.html]
[test_memory_census.html]

Просмотреть файл

@ -0,0 +1,55 @@
<!DOCTYPE HTML>
<html>
<!--
Bug 1192335 - Test getting the byte sizes for allocations.
-->
<head>
<meta charset="utf-8">
<title>Memory monitoring actor test</title>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
</head>
<body>
<pre id="test">
<script src="memory-helpers.js" type="application/javascript;version=1.8"></script>
<script>
window.onload = function() {
SimpleTest.waitForExplicitFinish();
Task.spawn(function* () {
var { memory, client } = yield startServerAndGetSelectedTabMemory();
yield memory.attach();
var allocs = [];
function allocator() {
allocs.push(new Object);
}
yield memory.startRecordingAllocations();
allocator();
allocator();
allocator();
var response = yield memory.getAllocations();
yield memory.stopRecordingAllocations();
ok(response.allocationSizes, "The response should have bytesizes.");
is(response.allocationSizes.length, response.allocations.length,
"There should be a bytesize for every allocation.");
ok(response.allocationSizes.length >= 3,
"There are atleast 3 allocations.");
ok(response.allocationSizes.every(isPositiveNumber), "every bytesize is a positive number");
yield memory.detach();
destroyServerAndFinish(client);
});
};
function isPositiveNumber (n) {
return typeof n === "number" && n > 0;
}
</script>
</pre>
</body>
</html>

Просмотреть файл

@ -226,6 +226,11 @@ let Memory = exports.Memory = Class({
* <timestamp for allocations[1]>,
* ...
* ],
* allocationSizes: [
* <bytesize for allocations[0]>,
* <bytesize for allocations[1]>,
* ...
* ],
* frames: [
* {
* line: <line number for this frame>,
@ -275,8 +280,9 @@ let Memory = exports.Memory = Class({
const packet = {
allocations: [],
allocationsTimestamps: [],
allocationSizes: [],
};
for (let { frame: stack, timestamp } of allocations) {
for (let { frame: stack, timestamp, size } of allocations) {
if (stack && Cu.isDeadWrapper(stack)) {
continue;
}
@ -284,7 +290,7 @@ let Memory = exports.Memory = Class({
// Safe because SavedFrames are frozen/immutable.
let waived = Cu.waiveXrays(stack);
// Ensure that we have a form, count, and index for new allocations
// Ensure that we have a form, size, and index for new allocations
// because we potentially haven't seen some or all of them yet. After this
// loop, we can rely on the fact that every frame we deal with already has
// its metadata stored.
@ -292,6 +298,7 @@ let Memory = exports.Memory = Class({
packet.allocations.push(index);
packet.allocationsTimestamps.push(timestamp);
packet.allocationSizes.push(size);
}
return this._frameCache.updateFramePacket(packet);