Bug 1192335 - Expose bytesize from memory module's getAllocations. r=fitzgen
authorJordan Santell <jsantell@mozilla.com>
Fri, 07 Aug 2015 12:27:32 -0700
changeset 256921 1c3965ae8dee604bdf4f6aa812bddf97e2981705
parent 256920 369e47f0839252d06eddf39f63269158c9756791
child 256922 26f98bdef1b6de29bc9dd2910d5db57581fcfadf
push id29195
push userphilringnalda@gmail.com
push dateSun, 09 Aug 2015 01:37:55 +0000
treeherdermozilla-central@fd63d8ed9d2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfitzgen
bugs1192335
milestone42.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1192335 - Expose bytesize from memory module's getAllocations. r=fitzgen
toolkit/devtools/server/tests/mochitest/chrome.ini
toolkit/devtools/server/tests/mochitest/test_memory_allocations_07.html
toolkit/devtools/shared/memory.js
--- a/toolkit/devtools/server/tests/mochitest/chrome.ini
+++ b/toolkit/devtools/server/tests/mochitest/chrome.ini
@@ -73,16 +73,17 @@ skip-if = buildapp == 'mulet'
 [test_makeGlobalObjectReference.html]
 [test_memory.html]
 [test_memory_allocations_01.html]
 [test_memory_allocations_02.html]
 [test_memory_allocations_03.html]
 [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]
 [test_memory_gc_01.html]
 [test_memory_gc_events.html]
 [test_preference.html]
 [test_registerActor.html]
 [test_SaveHeapSnapshot.html]
new file mode 100644
--- /dev/null
+++ b/toolkit/devtools/server/tests/mochitest/test_memory_allocations_07.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>
--- a/toolkit/devtools/shared/memory.js
+++ b/toolkit/devtools/shared/memory.js
@@ -221,16 +221,21 @@ let Memory = exports.Memory = Class({
    *
    *            {
    *              allocations: [<index into "frames" below>, ...],
    *              allocationsTimestamps: [
    *                <timestamp for allocations[0]>,
    *                <timestamp for allocations[1]>,
    *                ...
    *              ],
+   *              allocationSizes: [
+   *                <bytesize for allocations[0]>,
+   *                <bytesize for allocations[1]>,
+   *                ...
+   *              ],
    *              frames: [
    *                {
    *                  line: <line number for this frame>,
    *                  column: <column number for this frame>,
    *                  source: <filename string for this frame>,
    *                  functionDisplayName: <this frame's inferred function name function or null>,
    *                  parent: <index into "frames">
    *                },
@@ -270,33 +275,35 @@ let Memory = exports.Memory = Class({
       reportException("MemoryBridge.prototype.getAllocations",
                       "Warning: allocations log overflowed and lost some data.");
     }
 
     const allocations = this.dbg.memory.drainAllocationsLog()
     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;
       }
 
       // 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.
       let index = this._frameCache.addFrame(waived);
 
       packet.allocations.push(index);
       packet.allocationsTimestamps.push(timestamp);
+      packet.allocationSizes.push(size);
     }
 
     return this._frameCache.updateFramePacket(packet);
   }, `getting allocations`),
 
   /*
    * Force a browser-wide GC.
    */