зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1540694 - Fix DEBUG_DEVTOOLS_ALLOCATIONS now that DevTools share the unique system compartment. r=jdescottes
In bug 1517210, DevTools started sharing the same compartment than JSMs. So we can no longer use a Debugger instance bound to jsdebugger.jsm as it would run in the same compartment than DevTools code we want to inspect from the allocation tracker. Instead, we instantiate the Debugger from a custom Sandbox loaded in a unique and distinct compartment. Depends on D26077 Differential Revision: https://phabricator.services.mozilla.com/D26078 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
9a96c419f3
Коммит
953f28d1a8
|
@ -12,6 +12,30 @@
|
|||
|
||||
const { Constructor: CC } = Components;
|
||||
|
||||
// Print allocation count if DEBUG_DEVTOOLS_ALLOCATIONS is set to "normal",
|
||||
// and allocation sites if DEBUG_DEVTOOLS_ALLOCATIONS is set to "verbose".
|
||||
const env = Cc["@mozilla.org/process/environment;1"].getService(Ci.nsIEnvironment);
|
||||
const DEBUG_ALLOCATIONS = env.get("DEBUG_DEVTOOLS_ALLOCATIONS");
|
||||
if (DEBUG_ALLOCATIONS) {
|
||||
// Use a custom loader with `invisibleToDebugger` flag for the allocation tracker
|
||||
// as it instantiates custom Debugger API instances and has to be running in a distinct
|
||||
// compartments from DevTools and system scopes (JSMs, XPCOM,...)
|
||||
const { DevToolsLoader } = ChromeUtils.import("resource://devtools/shared/Loader.jsm");
|
||||
const loader = new DevToolsLoader();
|
||||
loader.invisibleToDebugger = true;
|
||||
|
||||
const { allocationTracker } = loader.require("devtools/shared/test-helpers/allocation-tracker");
|
||||
const tracker = allocationTracker();
|
||||
registerCleanupFunction(() => {
|
||||
if (DEBUG_ALLOCATIONS == "normal") {
|
||||
tracker.logCount();
|
||||
} else if (DEBUG_ALLOCATIONS == "verbose") {
|
||||
tracker.logAllocationSites();
|
||||
}
|
||||
tracker.stop();
|
||||
});
|
||||
}
|
||||
|
||||
function scopedCuImport(path) {
|
||||
const scope = {};
|
||||
ChromeUtils.import(path, scope);
|
||||
|
@ -91,23 +115,6 @@ registerCleanupFunction(() => {
|
|||
Services.obs.removeObserver(ConsoleObserver, "console-api-log-event");
|
||||
});
|
||||
|
||||
// Print allocation count if DEBUG_DEVTOOLS_ALLOCATIONS is set to "normal",
|
||||
// and allocation sites if DEBUG_DEVTOOLS_ALLOCATIONS is set to "verbose".
|
||||
const env = Cc["@mozilla.org/process/environment;1"].getService(Ci.nsIEnvironment);
|
||||
const DEBUG_ALLOCATIONS = env.get("DEBUG_DEVTOOLS_ALLOCATIONS");
|
||||
if (DEBUG_ALLOCATIONS) {
|
||||
const { allocationTracker } = require("devtools/shared/test-helpers/allocation-tracker");
|
||||
const tracker = allocationTracker();
|
||||
registerCleanupFunction(() => {
|
||||
if (DEBUG_ALLOCATIONS == "normal") {
|
||||
tracker.logCount();
|
||||
} else if (DEBUG_ALLOCATIONS == "verbose") {
|
||||
tracker.logAllocationSites();
|
||||
}
|
||||
tracker.stop();
|
||||
});
|
||||
}
|
||||
|
||||
var waitForTime = DevToolsUtils.waitForTime;
|
||||
|
||||
function loadFrameScriptUtils(browser = gBrowser.selectedBrowser) {
|
||||
|
|
|
@ -36,17 +36,15 @@
|
|||
"use strict";
|
||||
|
||||
const { Cu } = require("chrome");
|
||||
const ChromeUtils = require("ChromeUtils");
|
||||
|
||||
// Get a "Debugger" constructor. Can't call `addDebuggerToGlobal`
|
||||
// on the frame script global, so call it on jsdebugger one...
|
||||
const global = require("resource://gre/modules/jsdebugger.jsm");
|
||||
const {addDebuggerToGlobal} = global;
|
||||
const global = Cu.getGlobalForObject(this);
|
||||
const {addDebuggerToGlobal} = ChromeUtils.import("resource://gre/modules/jsdebugger.jsm");
|
||||
addDebuggerToGlobal(global);
|
||||
const { Debugger } = global;
|
||||
|
||||
exports.allocationTracker = function() {
|
||||
dump("DEVTOOLS ALLOCATION: Start logging allocations\n");
|
||||
let dbg = new Debugger();
|
||||
let dbg = new global.Debugger();
|
||||
|
||||
// Enable allocation site tracking, to have the stack for each allocation
|
||||
dbg.memory.trackingAllocationSites = true;
|
||||
|
@ -59,7 +57,7 @@ exports.allocationTracker = function() {
|
|||
dbg.addAllGlobalsAsDebuggees();
|
||||
|
||||
// Remove this global to ignore all its object/JS
|
||||
dbg.removeDebuggee(Cu.getGlobalForObject({}));
|
||||
dbg.removeDebuggee(global);
|
||||
|
||||
// addAllGlobalsAsDebuggees won't automatically track new ones,
|
||||
// so ensure tracking all new globals
|
||||
|
|
Загрузка…
Ссылка в новой задаче