From 89f2f8dc9aeb66d72584d58986e89231d3f93655 Mon Sep 17 00:00:00 2001 From: Oliver Henshaw Date: Thu, 4 Jun 2015 07:01:00 -0400 Subject: [PATCH] Bug 1164886 - Add optional logging for async shutdown barriers. r=Yoric --- modules/libpref/init/all.js | 2 ++ .../asyncshutdown/AsyncShutdown.jsm | 25 ++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index 4f2007334a0..e79aaa9afc3 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -792,6 +792,8 @@ pref("toolkit.identity.debug", false); // AsyncShutdown delay before crashing in case of shutdown freeze pref("toolkit.asyncshutdown.timeout.crash", 60000); +// Extra logging for AsyncShutdown barriers and phases +pref("toolkit.asyncshutdown.log", false); // Enable deprecation warnings. pref("devtools.errorconsole.deprecation_warnings", true); diff --git a/toolkit/components/asyncshutdown/AsyncShutdown.jsm b/toolkit/components/asyncshutdown/AsyncShutdown.jsm index 9e06795141f..91d250324ef 100644 --- a/toolkit/components/asyncshutdown/AsyncShutdown.jsm +++ b/toolkit/components/asyncshutdown/AsyncShutdown.jsm @@ -196,6 +196,22 @@ function log(msg, prefix = "", error = null) { } } } +const PREF_DEBUG_LOG = "toolkit.asyncshutdown.log"; +let DEBUG_LOG = false; +try { + DEBUG_LOG = Services.prefs.getBoolPref(PREF_DEBUG_LOG); +} catch (ex) { + // Ignore errors +} +Services.prefs.addObserver(PREF_DEBUG_LOG, function() { + DEBUG_LOG = Services.prefs.getBoolPref(PREF_DEBUG_LOG); +}, false); + +function debug(msg, error=null) { + if (DEBUG_LOG) { + return log(msg, "DEBUG: ", error); + } +} function warn(msg, error = null) { return log(msg, "WARNING: ", error); } @@ -511,6 +527,7 @@ Spinner.prototype = { Promise.reject(ex); } } + debug(`Finished phase ${ topic }`); } }; @@ -644,6 +661,7 @@ function Barrier(name) { if (!this._waitForMe) { throw new Error(`Phase "${ this._name } is finished, it is too late to register completion condition "${ name }"`); } + debug(`Adding blocker ${ name } for phase ${ this._name }`); // Normalize the details @@ -711,9 +729,10 @@ function Barrier(name) { // As conditions may hold lots of memory, we attempt to cleanup // as soon as we are done (which might be in the next tick, if // we have been passed a resolved promise). - promise = promise.then(() => - this._removeBlocker(condition) - ); + promise = promise.then(() => { + debug(`Completed blocker ${ name } for phase ${ this._name }`); + this._removeBlocker(condition); + }); if (this._isStarted) { // The wait has already started. The blocker should be