Bug 1488375 - Use target.getFront to instantiate MemoryFront; r=ochameau
authoryulia <ystartsev@mozilla.com>
Wed, 17 Oct 2018 10:36:33 +0000
changeset 497409 a53e0884fcb170c2cde943ba20aa7fc5ef083e42
parent 497408 5df04b130a16afcaa917204055b8227f1ef0f411
child 497410 23ee4dcfdbaf0d4508d76ac9f8cb9bbcf3e61db7
push id9996
push userarchaeopteryx@coole-files.de
push dateThu, 18 Oct 2018 18:37:15 +0000
treeherdermozilla-beta@8efe26839243 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersochameau
bugs1488375
milestone64.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 1488375 - Use target.getFront to instantiate MemoryFront; r=ochameau Differential Revision: https://phabricator.services.mozilla.com/D7097
devtools/client/memory/panel.js
devtools/server/tests/mochitest/memory-helpers.js
devtools/server/tests/mochitest/test_memory.html
devtools/server/tests/mochitest/test_memory_allocations_01.html
devtools/server/tests/mochitest/test_memory_allocations_02.html
devtools/server/tests/mochitest/test_memory_allocations_03.html
devtools/server/tests/mochitest/test_memory_allocations_04.html
devtools/server/tests/mochitest/test_memory_allocations_05.html
devtools/server/tests/mochitest/test_memory_allocations_06.html
devtools/server/tests/mochitest/test_memory_allocations_07.html
devtools/server/tests/mochitest/test_memory_attach_01.html
devtools/server/tests/mochitest/test_memory_attach_02.html
devtools/server/tests/mochitest/test_memory_census.html
devtools/server/tests/mochitest/test_memory_gc_01.html
devtools/server/tests/mochitest/test_memory_gc_events.html
devtools/shared/fronts/memory.js
--- a/devtools/client/memory/panel.js
+++ b/devtools/client/memory/panel.js
@@ -1,16 +1,15 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
 const EventEmitter = require("devtools/shared/event-emitter");
-const { MemoryFront } = require("devtools/shared/fronts/memory");
 const { Cu } = require("chrome");
 const HeapAnalysesClient = require("devtools/shared/heapsnapshot/HeapAnalysesClient");
 
 function MemoryPanel(iframeWindow, toolbox) {
   this.panelWin = iframeWindow;
   this._toolbox = toolbox;
 
   const { BrowserLoader } = Cu.import("resource://devtools/client/shared/browser-loader.js", {});
@@ -26,21 +25,17 @@ function MemoryPanel(iframeWindow, toolb
 MemoryPanel.prototype = {
   async open() {
     if (this._opening) {
       return this._opening;
     }
 
     this.panelWin.gToolbox = this._toolbox;
     this.panelWin.gTarget = this.target;
-
-    const rootForm = await this.target.root;
-    this.panelWin.gFront = new MemoryFront(this.target.client,
-                                           this.target.form,
-                                           rootForm);
+    this.panelWin.gFront = this.target.getFront("memory");
     this.panelWin.gHeapAnalysesClient = new HeapAnalysesClient();
 
     await this.panelWin.gFront.attach();
 
     this._opening = this.initializer.initialize().then(() => {
       this.isReady = true;
       this.emit("ready");
       return this;
--- a/devtools/server/tests/mochitest/memory-helpers.js
+++ b/devtools/server/tests/mochitest/memory-helpers.js
@@ -1,48 +1,40 @@
 /* exported Task, startServerAndGetSelectedTabMemory, destroyServerAndFinish,
    waitForTime, waitUntil */
 "use strict";
 
 const { require } = ChromeUtils.import("resource://devtools/shared/Loader.jsm", {});
 const Services = require("Services");
-const { DebuggerClient } = require("devtools/shared/client/debugger-client");
-const { DebuggerServer } = require("devtools/server/main");
-
-const { MemoryFront } = require("devtools/shared/fronts/memory");
+const { TargetFactory } = require("devtools/client/framework/target");
 
 // Always log packets when running tests.
 Services.prefs.setBoolPref("devtools.debugger.log", true);
 var gReduceTimePrecision = Services.prefs.getBoolPref("privacy.reduceTimerPrecision");
 Services.prefs.setBoolPref("privacy.reduceTimerPrecision", false);
 SimpleTest.registerCleanupFunction(function() {
   Services.prefs.clearUserPref("devtools.debugger.log");
   Services.prefs.setBoolPref("privacy.reduceTimerPrecision", gReduceTimePrecision);
 });
 
-function startServerAndGetSelectedTabMemory() {
-  DebuggerServer.init();
-  DebuggerServer.registerAllActors();
-  const client = new DebuggerClient(DebuggerServer.connectPipe());
-
-  return client.connect()
-    .then(() => client.listTabs())
-    .then(response => {
-      const form = response.tabs[response.selected];
-      const memory = MemoryFront(client, form, response);
-
-      return { memory, client };
-    });
+async function getTargetForSelectedTab() {
+  const browserWindow = Services.wm.getMostRecentWindow("navigator:browser");
+  const target = await TargetFactory.forTab(browserWindow.gBrowser.selectedTab);
+  return target;
 }
 
-function destroyServerAndFinish(client) {
-  client.close().then(() => {
-    DebuggerServer.destroy();
-    SimpleTest.finish();
-  });
+async function startServerAndGetSelectedTabMemory() {
+  const target = await getTargetForSelectedTab();
+  const memory = target.getFront("memory");
+  return {memory, target};
+}
+
+async function destroyServerAndFinish(target) {
+  await target.destroy();
+  SimpleTest.finish();
 }
 
 function waitForTime(ms) {
   return new Promise((resolve, reject) => {
     setTimeout(resolve, ms);
   });
 }
 
--- a/devtools/server/tests/mochitest/test_memory.html
+++ b/devtools/server/tests/mochitest/test_memory.html
@@ -14,26 +14,26 @@ Bug 923275 - Add a memory monitor widget
 <script src="memory-helpers.js" type="application/javascript"></script>
 <script>
 "use strict";
 
 window.onload = function() {
   SimpleTest.waitForExplicitFinish();
 
   (async function() {
-    const { memory, client } = await startServerAndGetSelectedTabMemory();
+    const { memory, target } = await startServerAndGetSelectedTabMemory();
     const measurement = await memory.measure();
     ok(measurement.total > 0, "total memory is valid");
     ok(measurement.domSize > 0, "domSize is valid");
     ok(measurement.styleSize > 0, "styleSize is valid");
     ok(measurement.jsObjectsSize > 0, "jsObjectsSize is valid");
     ok(measurement.jsStringsSize > 0, "jsStringsSize is valid");
     ok(measurement.jsOtherSize > 0, "jsOtherSize is valid");
     ok(measurement.otherSize > 0, "otherSize is valid");
     ok(measurement.jsMilliseconds, "jsMilliseconds is valid");
     ok(measurement.nonJSMilliseconds, "nonJSMilliseconds is valid");
-    destroyServerAndFinish(client);
+    await destroyServerAndFinish(target);
   })();
 };
 </script>
 </pre>
 </body>
 </html>
--- a/devtools/server/tests/mochitest/test_memory_allocations_01.html
+++ b/devtools/server/tests/mochitest/test_memory_allocations_01.html
@@ -14,17 +14,17 @@ Bug 1067491 - Test recording allocations
 <script src="memory-helpers.js" type="application/javascript"></script>
 <script>
 "use strict";
 
 window.onload = function() {
   SimpleTest.waitForExplicitFinish();
 
   (async function() {
-    const { memory, client } = await startServerAndGetSelectedTabMemory();
+    const { memory, target } = await startServerAndGetSelectedTabMemory();
     await memory.attach();
 
     await memory.startRecordingAllocations();
     ok(true, "Can start recording allocations");
 
     // Allocate some objects.
 
     let alloc1, alloc2, alloc3;
@@ -90,15 +90,15 @@ window.onload = function() {
       // to start failing if they changed their implementations in a way that
       // added or removed stack frames here.
     }
 
     is(expectedLines.size, 0,
        "Should have found all the expected lines");
 
     await memory.detach();
-    destroyServerAndFinish(client);
+    destroyServerAndFinish(target);
   })();
 };
 </script>
 </pre>
 </body>
 </html>
--- a/devtools/server/tests/mochitest/test_memory_allocations_02.html
+++ b/devtools/server/tests/mochitest/test_memory_allocations_02.html
@@ -14,17 +14,17 @@ Bug 1132764 - Test controlling the maxim
 <script src="memory-helpers.js" type="application/javascript"></script>
 <script>
 "use strict";
 
 window.onload = function() {
   SimpleTest.waitForExplicitFinish();
 
   (async function() {
-    const { memory, client } = await startServerAndGetSelectedTabMemory();
+    const { memory, target } = await startServerAndGetSelectedTabMemory();
     await memory.attach();
 
     const allocs = [];
     let eventsFired = 0;
     let intervalId = null;
     function onAlloc() {
       eventsFired++;
     }
@@ -66,15 +66,15 @@ window.onload = function() {
     });
     stopAllocating();
     ok(performance.now() - drainTimer < startTime,
        "Allocation events fired on GC before timer");
     await memory.stopRecordingAllocations();
 
     memory.off("allocations", onAlloc);
     await memory.detach();
-    destroyServerAndFinish(client);
+    destroyServerAndFinish(target);
   })();
 };
 </script>
 </pre>
 </body>
 </html>
--- a/devtools/server/tests/mochitest/test_memory_allocations_03.html
+++ b/devtools/server/tests/mochitest/test_memory_allocations_03.html
@@ -14,17 +14,17 @@ Bug 1067491 - Test that frames keep the 
 <script src="memory-helpers.js" type="application/javascript"></script>
 <script>
 "use strict";
 
 window.onload = function() {
   SimpleTest.waitForExplicitFinish();
 
   (async function() {
-    const { memory, client } = await startServerAndGetSelectedTabMemory();
+    const { memory, target } = await startServerAndGetSelectedTabMemory();
     await memory.attach();
 
     await memory.startRecordingAllocations();
 
     // Allocate twice with the exact same stack (hence setTimeout rather than
     // allocating directly in the generator), but with getAllocations() calls in
     // between.
 
@@ -66,15 +66,15 @@ window.onload = function() {
     }
 
     for (let i = 0; i < first.frames.length; i++) {
       info("Checking frames at index " + i + ":");
       assertSameFrame(first.frames[i], second.frames[i]);
     }
 
     await memory.detach();
-    destroyServerAndFinish(client);
+    destroyServerAndFinish(target);
   })();
 };
 </script>
 </pre>
 </body>
 </html>
--- a/devtools/server/tests/mochitest/test_memory_allocations_04.html
+++ b/devtools/server/tests/mochitest/test_memory_allocations_04.html
@@ -14,17 +14,17 @@ Bug 1068171 - Test controlling the memor
 <script src="memory-helpers.js" type="application/javascript"></script>
 <script>
 "use strict";
 
 window.onload = function() {
   SimpleTest.waitForExplicitFinish();
 
   (async function() {
-    const { memory, client } = await startServerAndGetSelectedTabMemory();
+    const { memory, target } = await startServerAndGetSelectedTabMemory();
     await memory.attach();
 
     const allocs = [];
     function allocator() {
       for (let i = 0; i < 100; i++) {
         allocs.push({});
       }
     }
@@ -48,15 +48,15 @@ window.onload = function() {
        + "whatever allocations the actor and SpiderMonkey make).");
 
     // We don't test any other probabilities because the test would be
     // non-deterministic. We don't have a way to control the PRNG like we do in
     // jit-tests
     // (js/src/jit-test/tests/debug/Memory-allocationsSamplingProbability-*.js).
 
     await memory.detach();
-    destroyServerAndFinish(client);
+    destroyServerAndFinish(target);
   })();
 };
 </script>
 </pre>
 </body>
 </html>
--- a/devtools/server/tests/mochitest/test_memory_allocations_05.html
+++ b/devtools/server/tests/mochitest/test_memory_allocations_05.html
@@ -14,17 +14,17 @@ Bug 1068144 - Test getting the timestamp
 <script src="memory-helpers.js" type="application/javascript"></script>
 <script>
 "use strict";
 
 window.onload = function() {
   SimpleTest.waitForExplicitFinish();
 
   (async function() {
-    const { memory, client } = await startServerAndGetSelectedTabMemory();
+    const { memory, target } = await startServerAndGetSelectedTabMemory();
     await memory.attach();
 
     const allocs = [];
     function allocator() {
       allocs.push(new Object());
     }
 
     // Using setTimeout results in wildly varying delays that make it hard to
@@ -79,15 +79,15 @@ window.onload = function() {
         ok(delta >= 1,
            "The timestamp should be about 1 ms after the last timestamp.");
       }
 
       lastTimestamp = timestamp;
     }
 
     await memory.detach();
-    destroyServerAndFinish(client);
+    destroyServerAndFinish(target);
   })();
 };
 </script>
 </pre>
 </body>
 </html>
--- a/devtools/server/tests/mochitest/test_memory_allocations_06.html
+++ b/devtools/server/tests/mochitest/test_memory_allocations_06.html
@@ -14,17 +14,17 @@ Bug 1132764 - Test controlling the maxim
 <script src="memory-helpers.js" type="application/javascript"></script>
 <script>
 "use strict";
 
 window.onload = function() {
   SimpleTest.waitForExplicitFinish();
 
   (async function() {
-    const { memory, client } = await startServerAndGetSelectedTabMemory();
+    const { memory, target } = await startServerAndGetSelectedTabMemory();
     await memory.attach();
 
     const allocs = [];
     function allocator() {
       allocs.push(new Object());
     }
 
     await memory.startRecordingAllocations({
@@ -37,15 +37,15 @@ window.onload = function() {
 
     const response = await memory.getAllocations();
     await memory.stopRecordingAllocations();
 
     is(response.allocations.length, 1,
        "There should only be one entry in the allocations log.");
 
     await memory.detach();
-    destroyServerAndFinish(client);
+    destroyServerAndFinish(target);
   })();
 };
 </script>
 </pre>
 </body>
 </html>
--- a/devtools/server/tests/mochitest/test_memory_allocations_07.html
+++ b/devtools/server/tests/mochitest/test_memory_allocations_07.html
@@ -14,17 +14,17 @@ Bug 1192335 - Test getting the byte size
 <script src="memory-helpers.js" type="application/javascript"></script>
 <script>
 "use strict";
 
 window.onload = function() {
   SimpleTest.waitForExplicitFinish();
 
   (async function() {
-    const { memory, client } = await startServerAndGetSelectedTabMemory();
+    const { memory, target } = await startServerAndGetSelectedTabMemory();
     await memory.attach();
 
     const allocs = [];
     function allocator() {
       allocs.push(new Object());
     }
 
     await memory.startRecordingAllocations();
@@ -40,17 +40,17 @@ window.onload = function() {
     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");
 
     await memory.detach();
-    destroyServerAndFinish(client);
+    destroyServerAndFinish(target);
   })();
 };
 
 function isPositiveNumber(n) {
   return typeof n === "number" && n > 0;
 }
 </script>
 </pre>
--- a/devtools/server/tests/mochitest/test_memory_attach_01.html
+++ b/devtools/server/tests/mochitest/test_memory_attach_01.html
@@ -14,20 +14,20 @@ Bug 960671 - Test attaching and detachin
 <script src="memory-helpers.js" type="application/javascript"></script>
 <script>
 "use strict";
 
 window.onload = function() {
   SimpleTest.waitForExplicitFinish();
 
   (async function() {
-    const { memory, client } = await startServerAndGetSelectedTabMemory();
+    const { memory, target } = await startServerAndGetSelectedTabMemory();
     await memory.attach();
     ok(true, "Shouldn't have gotten an error attaching.");
     await memory.detach();
     ok(true, "Shouldn't have gotten an error detaching.");
-    destroyServerAndFinish(client);
+    destroyServerAndFinish(target);
   })();
 };
 </script>
 </pre>
 </body>
 </html>
--- a/devtools/server/tests/mochitest/test_memory_attach_02.html
+++ b/devtools/server/tests/mochitest/test_memory_attach_02.html
@@ -14,17 +14,17 @@ Bug 960671 - Test attaching and detachin
 <script src="memory-helpers.js" type="application/javascript"></script>
 <script>
 "use strict";
 
 window.onload = function() {
   SimpleTest.waitForExplicitFinish();
 
   (async function() {
-    const { memory, client } = await startServerAndGetSelectedTabMemory();
+    const { memory, target } = await startServerAndGetSelectedTabMemory();
 
     let e = null;
     try {
       await memory.detach();
     } catch (ee) {
       e = ee;
     }
     ok(e, "Should have hit the wrongState error");
@@ -35,15 +35,15 @@ window.onload = function() {
     try {
       await memory.attach();
     } catch (ee) {
       e = ee;
     }
     ok(e, "Should have hit the wrongState error");
 
     await memory.detach();
-    destroyServerAndFinish(client);
+    destroyServerAndFinish(target);
   })();
 };
 </script>
 </pre>
 </body>
 </html>
--- a/devtools/server/tests/mochitest/test_memory_census.html
+++ b/devtools/server/tests/mochitest/test_memory_census.html
@@ -14,22 +14,22 @@ Bug 1067491 - Test taking a census over 
 <script src="memory-helpers.js" type="application/javascript"></script>
 <script>
 "use strict";
 
 window.onload = function() {
   SimpleTest.waitForExplicitFinish();
 
   (async function() {
-    const { memory, client } = await startServerAndGetSelectedTabMemory();
+    const { memory, target } = await startServerAndGetSelectedTabMemory();
     await memory.attach();
 
     const census = await memory.takeCensus();
     is(typeof census, "object");
 
     await memory.detach();
-    destroyServerAndFinish(client);
+    destroyServerAndFinish(target);
   })();
 };
 </script>
 </pre>
 </body>
 </html>
--- a/devtools/server/tests/mochitest/test_memory_gc_01.html
+++ b/devtools/server/tests/mochitest/test_memory_gc_01.html
@@ -14,17 +14,17 @@ Bug 1067491 - Test forcing a gc.
 <script src="memory-helpers.js" type="application/javascript"></script>
 <script>
 "use strict";
 
 window.onload = function() {
   SimpleTest.waitForExplicitFinish();
 
   (async function() {
-    const { memory, client } = await startServerAndGetSelectedTabMemory();
+    const { memory, target } = await startServerAndGetSelectedTabMemory();
 
     let beforeGC, afterGC;
 
     do {
       let objects = [];
       for (let i = 0; i < 1000; i++) {
         const o = {};
         o[Math.random()] = 1;
@@ -36,15 +36,15 @@ window.onload = function() {
 
       await memory.forceGarbageCollection();
 
       afterGC = (await memory.measure()).total;
     } while (beforeGC < afterGC);
 
     ok(true, "The amount of memory after GC should eventually decrease");
 
-    destroyServerAndFinish(client);
+    destroyServerAndFinish(target);
   })();
 };
 </script>
 </pre>
 </body>
 </html>
--- a/devtools/server/tests/mochitest/test_memory_gc_events.html
+++ b/devtools/server/tests/mochitest/test_memory_gc_events.html
@@ -16,29 +16,29 @@ Bug 1137527 - Test receiving GC events f
 "use strict";
 
 window.onload = function() {
   SimpleTest.waitForExplicitFinish();
 
   const EventEmitter = require("devtools/shared/event-emitter");
 
   (async function() {
-    const { memory, client } = await startServerAndGetSelectedTabMemory();
+    const { memory, target } = await startServerAndGetSelectedTabMemory();
     await memory.attach();
 
     const gotGcEvent = new Promise(resolve => {
       EventEmitter.on(memory, "garbage-collection", gcData => {
         ok(gcData, "Got GC data");
         resolve();
       });
     });
 
     memory.forceGarbageCollection();
     await gotGcEvent;
 
     await memory.detach();
-    destroyServerAndFinish(client);
+    destroyServerAndFinish(target);
   })();
 };
 </script>
 </pre>
 </body>
 </html>
--- a/devtools/shared/fronts/memory.js
+++ b/devtools/shared/fronts/memory.js
@@ -7,23 +7,21 @@ const { memorySpec } = require("devtools
 const protocol = require("devtools/shared/protocol");
 
 loader.lazyRequireGetter(this, "FileUtils",
                          "resource://gre/modules/FileUtils.jsm", true);
 loader.lazyRequireGetter(this, "HeapSnapshotFileUtils",
                          "devtools/shared/heapsnapshot/HeapSnapshotFileUtils");
 
 const MemoryFront = protocol.FrontClassWithSpec(memorySpec, {
-  initialize: function(client, form, rootForm = null) {
+  initialize: function(client, form) {
     protocol.Front.prototype.initialize.call(this, client, form);
     this._client = client;
     this.actorID = form.memoryActor;
-    this.heapSnapshotFileActorID = rootForm
-      ? rootForm.heapSnapshotFileActor
-      : null;
+    this.heapSnapshotFileActorID = null;
     this.manage(this);
   },
 
   /**
    * Save a heap snapshot, transfer it from the server to the client if the
    * server and client do not share a file system, and return the local file
    * path to the heap snapshot.
    *
@@ -59,17 +57,18 @@ const MemoryFront = protocol.FrontClassW
    * returned.
    *
    * @param {String} snapshotId
    *
    * @returns Promise<String>
    */
   transferHeapSnapshot: protocol.custom(async function(snapshotId) {
     if (!this.heapSnapshotFileActorID) {
-      throw new Error("MemoryFront initialized without a rootForm");
+      const form = await this._client.mainRoot.rootForm;
+      this.heapSnapshotFileActorID = form.heapSnapshotFileActor;
     }
 
     try {
       const request = this._client.request({
         to: this.heapSnapshotFileActorID,
         type: "transferHeapSnapshot",
         snapshotId
       });