summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@gmail.com>2018-12-24 05:06:54 +0100
committerwolfbeast <mcwerewolf@gmail.com>2018-12-24 05:06:54 +0100
commit202e78b731776c3a102ca2f465ed3864b27effd3 (patch)
treea122aa277f3a35df7b06216c1f82054c215339b4
parent3cf7e874fecf940ffeec00bafd3cf96d5c1b2a46 (diff)
downloadUXP-202e78b731776c3a102ca2f465ed3864b27effd3.tar
UXP-202e78b731776c3a102ca2f465ed3864b27effd3.tar.gz
UXP-202e78b731776c3a102ca2f465ed3864b27effd3.tar.lz
UXP-202e78b731776c3a102ca2f465ed3864b27effd3.tar.xz
UXP-202e78b731776c3a102ca2f465ed3864b27effd3.zip
Add performance warnings to Deprecated module.
Adds a dedicated handler for performance warnings to be logged to consoles if known performance-impacting methods are called. Search service init is changed from a deprecation warning to a performance warning for synchronous init. This also re-enables the warning for the Basilisk & Co. search service initialization which was previously removed in [a930a79] See also the discussion on #916.
-rw-r--r--modules/libpref/init/all.js3
-rw-r--r--toolkit/components/search/current/nsSearchService.js9
-rw-r--r--toolkit/components/search/orginal/nsSearchService.js6
-rw-r--r--toolkit/modules/Deprecated.jsm49
4 files changed, 60 insertions, 7 deletions
diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js
index 43d4b093c..f6a993962 100644
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -956,6 +956,9 @@ pref("toolkit.asyncshutdown.log", false);
// Enable deprecation warnings.
pref("devtools.errorconsole.deprecation_warnings", true);
+// Enable performance warnings.
+pref("devtools.errorconsole.performance_warnings", true);
+
// Disable debugging chrome
pref("devtools.chrome.enabled", false);
diff --git a/toolkit/components/search/current/nsSearchService.js b/toolkit/components/search/current/nsSearchService.js
index 99e73b50b..6e8f6da43 100644
--- a/toolkit/components/search/current/nsSearchService.js
+++ b/toolkit/components/search/current/nsSearchService.js
@@ -21,6 +21,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "OS",
"resource://gre/modules/osfile.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "Task",
"resource://gre/modules/Task.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "Deprecated",
+ "resource://gre/modules/Deprecated.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "SearchStaticData",
"resource://gre/modules/SearchStaticData.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "setTimeout",
@@ -2691,6 +2693,13 @@ SearchService.prototype = {
return;
}
+ let performanceWarning =
+ "Search service falling back to synchronous initialization. " +
+ "This is generally the consequence of an add-on using a deprecated " +
+ "search service API.";
+ Deprecated.perfWarning(performanceWarning, "https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIBrowserSearchService#async_warning");
+ LOG(performanceWarning);
+
this._syncInit();
if (!Components.isSuccessCode(this._initRV)) {
throw this._initRV;
diff --git a/toolkit/components/search/orginal/nsSearchService.js b/toolkit/components/search/orginal/nsSearchService.js
index 8d81e1a27..6b23724a7 100644
--- a/toolkit/components/search/orginal/nsSearchService.js
+++ b/toolkit/components/search/orginal/nsSearchService.js
@@ -2917,12 +2917,12 @@ SearchService.prototype = {
return;
}
- let warning =
+ let performanceWarning =
"Search service falling back to synchronous initialization. " +
"This is generally the consequence of an add-on using a deprecated " +
"search service API.";
- Deprecated.warning(warning, "https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIBrowserSearchService#async_warning");
- LOG(warning);
+ Deprecated.perfWarning(performanceWarning, "https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIBrowserSearchService#async_warning");
+ LOG(performanceWarning);
engineMetadataService.syncInit();
this._syncInit();
diff --git a/toolkit/modules/Deprecated.jsm b/toolkit/modules/Deprecated.jsm
index 7491a4938..981cd13ab 100644
--- a/toolkit/modules/Deprecated.jsm
+++ b/toolkit/modules/Deprecated.jsm
@@ -9,15 +9,21 @@ this.EXPORTED_SYMBOLS = [ "Deprecated" ];
const Cu = Components.utils;
const Ci = Components.interfaces;
const PREF_DEPRECATION_WARNINGS = "devtools.errorconsole.deprecation_warnings";
+const PREF_PERFORMANCE_WARNINGS = "devtools.errorconsole.performance_warnings";
Cu.import("resource://gre/modules/Services.jsm");
// A flag that indicates whether deprecation warnings should be logged.
-var logWarnings = Services.prefs.getBoolPref(PREF_DEPRECATION_WARNINGS);
+var logDepWarnings = Services.prefs.getBoolPref(PREF_DEPRECATION_WARNINGS);
+var logPerfWarnings = Services.prefs.getBoolPref(PREF_PERFORMANCE_WARNINGS);
Services.prefs.addObserver(PREF_DEPRECATION_WARNINGS,
function (aSubject, aTopic, aData) {
- logWarnings = Services.prefs.getBoolPref(PREF_DEPRECATION_WARNINGS);
+ logDepWarnings = Services.prefs.getBoolPref(PREF_DEPRECATION_WARNINGS);
+ }, false);
+Services.prefs.addObserver(PREF_PERFORMANCE_WARNINGS,
+ function (aSubject, aTopic, aData) {
+ logPerfWarnings = Services.prefs.getBoolPref(PREF_PERFORMANCE_WARNINGS);
}, false);
/**
@@ -58,7 +64,7 @@ this.Deprecated = {
* logged.
*/
warning: function (aText, aUrl, aStack) {
- if (!logWarnings) {
+ if (!logDepWarnings) {
return;
}
@@ -71,7 +77,42 @@ this.Deprecated = {
let textMessage = "DEPRECATION WARNING: " + aText +
"\nYou may find more details about this deprecation at: " +
- aUrl + "\n" +
+ aUrl + "\nCallstack:\n" +
+ // Append a callstack part to the deprecation message.
+ stringifyCallstack(aStack);
+
+ // Report deprecation warning.
+ Cu.reportError(textMessage);
+ },
+
+ /**
+ * Log a performance warning.
+ *
+ * @param string aText
+ * Performance issue warning text.
+ * @param string aUrl
+ * A URL pointing to documentation describing performance
+ * issue and the way to address it.
+ * @param nsIStackFrame aStack
+ * An optional callstack. If it is not provided a
+ * snapshot of the current JavaScript callstack will be
+ * logged.
+ */
+ perfWarning: function (aText, aUrl, aStack) {
+ if (!logPerfWarnings) {
+ return;
+ }
+
+ // If URL is not provided, report an error.
+ if (!aUrl) {
+ Cu.reportError("Error in Deprecated.perfWarning: warnings must " +
+ "provide a URL documenting this performance issue.");
+ return;
+ }
+
+ let textMessage = "PERFORMANCE WARNING: " + aText +
+ "\nYou may find more details about this problem at: " +
+ aUrl + "\nCallstack:\n" +
// Append a callstack part to the deprecation message.
stringifyCallstack(aStack);