From 96f3e16d1ad57e35cbb957472b51b82bcc1b2864 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Thu, 25 Oct 2018 19:04:01 -0700 Subject: [PATCH] Bug 1482091: Part 2 - Remove TelemetryStopwatch.jsm in favor of native implementation. r=chutten Differential Revision: https://phabricator.services.mozilla.com/D9888 --HG-- extra : rebase_source : a9daea3a9efea37acdbcaecda8bf0b7f69631de4 extra : histedit_source : bb8b416b1387da9de3bd95c7a171f10426a22602 --- browser/base/content/browser.js | 1 - .../performance/browser_startup_content.js | 1 - .../components/migration/MigrationUtils.jsm | 2 - .../places/content/historySidebar.js | 2 - browser/components/places/content/places.js | 1 - .../sessionstore/ContentSessionStore.jsm | 3 - .../components/sessionstore/SessionSaver.jsm | 1 - .../components/sessionstore/SessionStore.jsm | 1 - browser/modules/AsyncTabSwitcher.jsm | 1 - browser/modules/Sanitizer.jsm | 1 - browser/modules/SchedulePressure.jsm | 2 - devtools/client/shared/telemetry.js | 2 +- dom/html/test/browser_fullscreen-newtab.js | 6 + mobile/android/chrome/content/aboutLogins.js | 1 - mobile/android/chrome/content/browser.js | 2 - mobile/android/components/SessionStore.js | 1 - mobile/android/modules/Sanitizer.jsm | 1 - .../extensions/ExtensionTelemetry.jsm | 2 - .../components/narrate/NarrateControls.jsm | 1 - .../osfile/modules/osfile_async_front.jsm | 1 - toolkit/components/places/UnifiedComplete.js | 1 - toolkit/components/search/nsSearchService.js | 1 - .../telemetry/app/TelemetryStopwatch.jsm | 434 ------------------ .../telemetry/docs/collection/histograms.rst | 2 +- .../docs/collection/measuring-time.rst | 2 +- toolkit/components/telemetry/moz.build | 1 - .../tests/unit/test_TelemetrySend.js | 2 - toolkit/content/widgets/tabbox.xml | 17 +- 28 files changed, 11 insertions(+), 482 deletions(-) delete mode 100644 toolkit/components/telemetry/app/TelemetryStopwatch.jsm diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index 3600c8f0b089..7fade8d62542 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -64,7 +64,6 @@ XPCOMUtils.defineLazyModuleGetters(this, { SitePermissions: "resource:///modules/SitePermissions.jsm", TabCrashHandler: "resource:///modules/ContentCrashHandlers.jsm", TelemetryEnvironment: "resource://gre/modules/TelemetryEnvironment.jsm", - TelemetryStopwatch: "resource://gre/modules/TelemetryStopwatch.jsm", Translation: "resource:///modules/translation/Translation.jsm", UITour: "resource:///modules/UITour.jsm", UpdateUtils: "resource://gre/modules/UpdateUtils.jsm", diff --git a/browser/base/content/test/performance/browser_startup_content.js b/browser/base/content/test/performance/browser_startup_content.js index abcb4850f5ad..5ca0e0b25355 100644 --- a/browser/base/content/test/performance/browser_startup_content.js +++ b/browser/base/content/test/performance/browser_startup_content.js @@ -82,7 +82,6 @@ const intermittently_loaded_whitelist = { ]), modules: new Set([ "resource://gre/modules/sessionstore/Utils.jsm", - "resource://gre/modules/TelemetryStopwatch.jsm", ]), }; diff --git a/browser/components/migration/MigrationUtils.jsm b/browser/components/migration/MigrationUtils.jsm index 7da9db4acb72..e273b88d46a2 100644 --- a/browser/components/migration/MigrationUtils.jsm +++ b/browser/components/migration/MigrationUtils.jsm @@ -28,8 +28,6 @@ ChromeUtils.defineModuleGetter(this, "ResponsivenessMonitor", "resource://gre/modules/ResponsivenessMonitor.jsm"); ChromeUtils.defineModuleGetter(this, "Sqlite", "resource://gre/modules/Sqlite.jsm"); -ChromeUtils.defineModuleGetter(this, "TelemetryStopwatch", - "resource://gre/modules/TelemetryStopwatch.jsm"); ChromeUtils.defineModuleGetter(this, "WindowsRegistry", "resource://gre/modules/WindowsRegistry.jsm"); ChromeUtils.defineModuleGetter(this, "setTimeout", diff --git a/browser/components/places/content/historySidebar.js b/browser/components/places/content/historySidebar.js index d1761470f5fc..54e6306e9eab 100644 --- a/browser/components/places/content/historySidebar.js +++ b/browser/components/places/content/historySidebar.js @@ -20,8 +20,6 @@ XPCOMUtils.defineLazyScriptGetter(this, ["PlacesInsertionPoint", "PlacesControll "chrome://browser/content/places/controller.js"); /* End Shared Places Import */ -ChromeUtils.import("resource://gre/modules/TelemetryStopwatch.jsm"); - var gHistoryTree; var gSearchBox; var gHistoryGrouping = ""; diff --git a/browser/components/places/content/places.js b/browser/components/places/content/places.js index 488e437c1cad..749d8c11abe4 100644 --- a/browser/components/places/content/places.js +++ b/browser/components/places/content/places.js @@ -24,7 +24,6 @@ XPCOMUtils.defineLazyScriptGetter(this, ["PlacesInsertionPoint", "PlacesControll /* End Shared Places Import */ ChromeUtils.import("resource://gre/modules/AppConstants.jsm"); -ChromeUtils.import("resource://gre/modules/TelemetryStopwatch.jsm"); ChromeUtils.defineModuleGetter(this, "MigrationUtils", "resource:///modules/MigrationUtils.jsm"); ChromeUtils.defineModuleGetter(this, "BookmarkJSONUtils", diff --git a/browser/components/sessionstore/ContentSessionStore.jsm b/browser/components/sessionstore/ContentSessionStore.jsm index f28dda86f4ad..e619ea1dc1f9 100644 --- a/browser/components/sessionstore/ContentSessionStore.jsm +++ b/browser/components/sessionstore/ContentSessionStore.jsm @@ -10,9 +10,6 @@ ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm", this); ChromeUtils.import("resource://gre/modules/Timer.jsm", this); ChromeUtils.import("resource://gre/modules/Services.jsm", this); -ChromeUtils.defineModuleGetter(this, "TelemetryStopwatch", - "resource://gre/modules/TelemetryStopwatch.jsm"); - function debug(msg) { Services.console.logStringMessage("SessionStoreContent: " + msg); } diff --git a/browser/components/sessionstore/SessionSaver.jsm b/browser/components/sessionstore/SessionSaver.jsm index c6dbf261e4ea..7710bb69ed9e 100644 --- a/browser/components/sessionstore/SessionSaver.jsm +++ b/browser/components/sessionstore/SessionSaver.jsm @@ -9,7 +9,6 @@ var EXPORTED_SYMBOLS = ["SessionSaver"]; ChromeUtils.import("resource://gre/modules/Timer.jsm", this); ChromeUtils.import("resource://gre/modules/Services.jsm", this); ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm", this); -ChromeUtils.import("resource://gre/modules/TelemetryStopwatch.jsm", this); XPCOMUtils.defineLazyModuleGetters(this, { AppConstants: "resource://gre/modules/AppConstants.jsm", diff --git a/browser/components/sessionstore/SessionStore.jsm b/browser/components/sessionstore/SessionStore.jsm index ceca64ac4e88..2e5bb8913cae 100644 --- a/browser/components/sessionstore/SessionStore.jsm +++ b/browser/components/sessionstore/SessionStore.jsm @@ -156,7 +156,6 @@ const RESTORE_TAB_CONTENT_REASON = { ChromeUtils.import("resource://gre/modules/PrivateBrowsingUtils.jsm", this); ChromeUtils.import("resource://gre/modules/Services.jsm", this); -ChromeUtils.import("resource://gre/modules/TelemetryStopwatch.jsm", this); ChromeUtils.import("resource://gre/modules/TelemetryTimestamps.jsm", this); ChromeUtils.import("resource://gre/modules/Timer.jsm", this); ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm", this); diff --git a/browser/modules/AsyncTabSwitcher.jsm b/browser/modules/AsyncTabSwitcher.jsm index ea8ab31f4d10..6c24165bfa1a 100644 --- a/browser/modules/AsyncTabSwitcher.jsm +++ b/browser/modules/AsyncTabSwitcher.jsm @@ -11,7 +11,6 @@ ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm"); XPCOMUtils.defineLazyModuleGetters(this, { AppConstants: "resource://gre/modules/AppConstants.jsm", Services: "resource://gre/modules/Services.jsm", - TelemetryStopwatch: "resource://gre/modules/TelemetryStopwatch.jsm", }); XPCOMUtils.defineLazyPreferenceGetter(this, "gTabWarmingEnabled", diff --git a/browser/modules/Sanitizer.jsm b/browser/modules/Sanitizer.jsm index aff9934c8071..bad4a1f0284f 100644 --- a/browser/modules/Sanitizer.jsm +++ b/browser/modules/Sanitizer.jsm @@ -12,7 +12,6 @@ XPCOMUtils.defineLazyModuleGetters(this, { AppConstants: "resource://gre/modules/AppConstants.jsm", PlacesUtils: "resource://gre/modules/PlacesUtils.jsm", FormHistory: "resource://gre/modules/FormHistory.jsm", - TelemetryStopwatch: "resource://gre/modules/TelemetryStopwatch.jsm", ContextualIdentityService: "resource://gre/modules/ContextualIdentityService.jsm", }); diff --git a/browser/modules/SchedulePressure.jsm b/browser/modules/SchedulePressure.jsm index 7218204d82f2..d22c4fd454aa 100644 --- a/browser/modules/SchedulePressure.jsm +++ b/browser/modules/SchedulePressure.jsm @@ -7,8 +7,6 @@ var EXPORTED_SYMBOLS = ["SchedulePressure"]; ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm"); -ChromeUtils.defineModuleGetter(this, "TelemetryStopwatch", - "resource://gre/modules/TelemetryStopwatch.jsm"); XPCOMUtils.defineLazyPreferenceGetter(this, "SCHEDULE_PRESSURE_ENABLED", "browser.schedulePressure.enabled", true); XPCOMUtils.defineLazyPreferenceGetter(this, "TIMEOUT_AMOUNT", diff --git a/devtools/client/shared/telemetry.js b/devtools/client/shared/telemetry.js index 45f844f7e0f3..0e0fa863f1b9 100644 --- a/devtools/client/shared/telemetry.js +++ b/devtools/client/shared/telemetry.js @@ -11,7 +11,7 @@ "use strict"; const Services = require("Services"); -const { TelemetryStopwatch } = require("resource://gre/modules/TelemetryStopwatch.jsm"); +const TelemetryStopwatch = require("TelemetryStopwatch"); const { getNthPathExcluding } = require("devtools/shared/platform/stack"); const { TelemetryEnvironment } = require("resource://gre/modules/TelemetryEnvironment.jsm"); const WeakMapMap = require("devtools/client/shared/WeakMapMap"); diff --git a/dom/html/test/browser_fullscreen-newtab.js b/dom/html/test/browser_fullscreen-newtab.js index 41dee1b1348e..1b9aae9dc872 100644 --- a/dom/html/test/browser_fullscreen-newtab.js +++ b/dom/html/test/browser_fullscreen-newtab.js @@ -1,5 +1,11 @@ "use strict"; +// This test tends to trigger a race in the fullscreen time telemetry, +// where the fullscreen enter and fullscreen exit events (which use the +// same histogram ID) overlap. That causes TelemetryStopwatch to log an +// error. +SimpleTest.ignoreAllUncaughtExceptions(true); + const kPage = "http://example.org/browser/" + "dom/html/test/file_fullscreen-newtab.html"; diff --git a/mobile/android/chrome/content/aboutLogins.js b/mobile/android/chrome/content/aboutLogins.js index f5fe5c609031..9fd199e83ca4 100644 --- a/mobile/android/chrome/content/aboutLogins.js +++ b/mobile/android/chrome/content/aboutLogins.js @@ -5,7 +5,6 @@ ChromeUtils.import("resource://services-common/utils.js"); /* global: CommonUtils */ ChromeUtils.import("resource://gre/modules/Services.jsm"); ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm"); -ChromeUtils.import("resource://gre/modules/TelemetryStopwatch.jsm"); XPCOMUtils.defineLazyGetter(window, "gChromeWin", () => window.docShell.rootTreeItem.domWindow diff --git a/mobile/android/chrome/content/browser.js b/mobile/android/chrome/content/browser.js index 1716ae608b6e..1fb3165d20ad 100644 --- a/mobile/android/chrome/content/browser.js +++ b/mobile/android/chrome/content/browser.js @@ -105,8 +105,6 @@ ChromeUtils.defineModuleGetter(this, "RuntimePermissions", "resource://gre/modul ChromeUtils.defineModuleGetter(this, "WebsiteMetadata", "resource://gre/modules/WebsiteMetadata.jsm"); -ChromeUtils.defineModuleGetter(this, "TelemetryStopwatch", "resource://gre/modules/TelemetryStopwatch.jsm"); - XPCOMUtils.defineLazyServiceGetter(this, "FontEnumerator", "@mozilla.org/gfx/fontenumerator;1", "nsIFontEnumerator"); diff --git a/mobile/android/components/SessionStore.js b/mobile/android/components/SessionStore.js index 9c38e33f2192..5e126e46558e 100644 --- a/mobile/android/components/SessionStore.js +++ b/mobile/android/components/SessionStore.js @@ -16,7 +16,6 @@ XPCOMUtils.defineLazyModuleGetters(this, { SessionHistory: "resource://gre/modules/sessionstore/SessionHistory.jsm", SharedPreferences: "resource://gre/modules/SharedPreferences.jsm", Task: "resource://gre/modules/Task.jsm", - TelemetryStopwatch: "resource://gre/modules/TelemetryStopwatch.jsm", Utils: "resource://gre/modules/sessionstore/Utils.jsm", }); diff --git a/mobile/android/modules/Sanitizer.jsm b/mobile/android/modules/Sanitizer.jsm index a8f793cc97e1..5b3ea9051ae2 100644 --- a/mobile/android/modules/Sanitizer.jsm +++ b/mobile/android/modules/Sanitizer.jsm @@ -17,7 +17,6 @@ XPCOMUtils.defineLazyModuleGetters(this, { OS: "resource://gre/modules/osfile.jsm", ServiceWorkerCleanUp: "resource://gre/modules/ServiceWorkerCleanUp.jsm", Task: "resource://gre/modules/Task.jsm", - TelemetryStopwatch: "resource://gre/modules/TelemetryStopwatch.jsm", }); XPCOMUtils.defineLazyServiceGetters(this, { diff --git a/toolkit/components/extensions/ExtensionTelemetry.jsm b/toolkit/components/extensions/ExtensionTelemetry.jsm index cfc576ea73a1..9f0688794af5 100644 --- a/toolkit/components/extensions/ExtensionTelemetry.jsm +++ b/toolkit/components/extensions/ExtensionTelemetry.jsm @@ -9,8 +9,6 @@ var EXPORTED_SYMBOLS = ["ExtensionTelemetry", "getTrimmedString"]; ChromeUtils.defineModuleGetter(this, "Services", "resource://gre/modules/Services.jsm"); -ChromeUtils.defineModuleGetter(this, "TelemetryStopwatch", - "resource://gre/modules/TelemetryStopwatch.jsm"); // Map of the base histogram ids for the metrics recorded for the extensions. const histograms = { diff --git a/toolkit/components/narrate/NarrateControls.jsm b/toolkit/components/narrate/NarrateControls.jsm index 55edc9288943..ddc244eee01d 100644 --- a/toolkit/components/narrate/NarrateControls.jsm +++ b/toolkit/components/narrate/NarrateControls.jsm @@ -8,7 +8,6 @@ ChromeUtils.import("resource://gre/modules/narrate/VoiceSelect.jsm"); ChromeUtils.import("resource://gre/modules/narrate/Narrator.jsm"); ChromeUtils.import("resource://gre/modules/Services.jsm"); ChromeUtils.import("resource://gre/modules/AsyncPrefs.jsm"); -ChromeUtils.import("resource://gre/modules/TelemetryStopwatch.jsm"); var EXPORTED_SYMBOLS = ["NarrateControls"]; diff --git a/toolkit/components/osfile/modules/osfile_async_front.jsm b/toolkit/components/osfile/modules/osfile_async_front.jsm index f5051fe321bd..fc525aedc0d0 100644 --- a/toolkit/components/osfile/modules/osfile_async_front.jsm +++ b/toolkit/components/osfile/modules/osfile_async_front.jsm @@ -54,7 +54,6 @@ ChromeUtils.defineModuleGetter(this, "Task", // The implementation of communications ChromeUtils.import("resource://gre/modules/PromiseWorker.jsm", this); ChromeUtils.import("resource://gre/modules/Services.jsm", this); -ChromeUtils.import("resource://gre/modules/TelemetryStopwatch.jsm", this); ChromeUtils.import("resource://gre/modules/AsyncShutdown.jsm", this); var Native = ChromeUtils.import("resource://gre/modules/osfile/osfile_native.jsm", {}); diff --git a/toolkit/components/places/UnifiedComplete.js b/toolkit/components/places/UnifiedComplete.js index b196a387518d..71037101c34f 100644 --- a/toolkit/components/places/UnifiedComplete.js +++ b/toolkit/components/places/UnifiedComplete.js @@ -327,7 +327,6 @@ XPCOMUtils.defineLazyModuleGetters(this, { PlacesUtils: "resource://gre/modules/PlacesUtils.jsm", ProfileAge: "resource://gre/modules/ProfileAge.jsm", Sqlite: "resource://gre/modules/Sqlite.jsm", - TelemetryStopwatch: "resource://gre/modules/TelemetryStopwatch.jsm", UrlbarPrefs: "resource:///modules/UrlbarPrefs.jsm", UrlbarProviderOpenTabs: "resource:///modules/UrlbarProviderOpenTabs.jsm", UrlbarProvidersManager: "resource:///modules/UrlbarProvidersManager.jsm", diff --git a/toolkit/components/search/nsSearchService.js b/toolkit/components/search/nsSearchService.js index e8b21876ad8d..56176776e955 100644 --- a/toolkit/components/search/nsSearchService.js +++ b/toolkit/components/search/nsSearchService.js @@ -11,7 +11,6 @@ XPCOMUtils.defineLazyModuleGetters(this, { AsyncShutdown: "resource://gre/modules/AsyncShutdown.jsm", DeferredTask: "resource://gre/modules/DeferredTask.jsm", OS: "resource://gre/modules/osfile.jsm", - TelemetryStopwatch: "resource://gre/modules/TelemetryStopwatch.jsm", Deprecated: "resource://gre/modules/Deprecated.jsm", SearchStaticData: "resource://gre/modules/SearchStaticData.jsm", setTimeout: "resource://gre/modules/Timer.jsm", diff --git a/toolkit/components/telemetry/app/TelemetryStopwatch.jsm b/toolkit/components/telemetry/app/TelemetryStopwatch.jsm deleted file mode 100644 index b167997fac99..000000000000 --- a/toolkit/components/telemetry/app/TelemetryStopwatch.jsm +++ /dev/null @@ -1,434 +0,0 @@ -/* 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"; - -var EXPORTED_SYMBOLS = ["TelemetryStopwatch"]; - -ChromeUtils.import("resource://gre/modules/Services.jsm"); -ChromeUtils.defineModuleGetter(this, "Log", - "resource://gre/modules/Log.jsm"); - -// Weak map does not allow using null objects as keys. These objects are used -// as 'null' placeholders. -const NULL_OBJECT = {}; -const NULL_KEY = {}; - -/** - * Timers is a variation of a Map used for storing information about running - * Stopwatches. Timers has the following data structure: - * - * { - * "HISTOGRAM_NAME": WeakMap { - * Object || NULL_OBJECT: Map { - * "KEY" || NULL_KEY: startTime - * ... - * } - * ... - * } - * ... - * } - * - * - * @example - * // Stores current time for a keyed histogram "PLAYING_WITH_CUTE_ANIMALS". - * Timers.put("PLAYING_WITH_CUTE_ANIMALS", null, "CATS", Date.now()); - * - * @example - * // Returns information about a simple Stopwatch. - * let startTime = Timers.get("PLAYING_WITH_CUTE_ANIMALS", null, "CATS"); - */ -const Timers = { - _timers: new Map(), - - _inSeconds: new Set(), - - _validTypes(histogram, obj, key) { - const nonEmptyString = value => { - return typeof value === "string" && value !== "" && value.length > 0; - }; - return nonEmptyString(histogram) && - typeof obj == "object" && - (key === NULL_KEY || nonEmptyString(key)); - }, - - get(histogram, obj, key) { - key = key === null ? NULL_KEY : key; - obj = obj || NULL_OBJECT; - - if (!this.has(histogram, obj, key)) { - return null; - } - - return this._timers.get(histogram).get(obj).get(key); - }, - - put(histogram, obj, key, startTime, {inSeconds} = {}) { - key = key === null ? NULL_KEY : key; - obj = obj || NULL_OBJECT; - - if (!this._validTypes(histogram, obj, key)) { - return false; - } - - if (inSeconds) { - this._inSeconds.add(histogram); - } - - const objectMap = this._timers.get(histogram) || new WeakMap(); - const keyedInfo = objectMap.get(obj) || new Map(); - keyedInfo.set(key, startTime); - objectMap.set(obj, keyedInfo); - this._timers.set(histogram, objectMap); - return true; - }, - - has(histogram, obj, key) { - key = key === null ? NULL_KEY : key; - obj = obj || NULL_OBJECT; - - return this._timers.has(histogram) && - this._timers.get(histogram).has(obj) && - this._timers.get(histogram).get(obj).has(key); - }, - - delete(histogram, obj, key) { - key = key === null ? NULL_KEY : key; - obj = obj || NULL_OBJECT; - - if (!this.has(histogram, obj, key)) { - return false; - } - - this._inSeconds.delete(histogram); - - const objectMap = this._timers.get(histogram); - const keyedInfo = objectMap.get(obj); - if (keyedInfo.size > 1) { - keyedInfo.delete(key); - return true; - } - objectMap.delete(obj); - // NOTE: - // We never delete empty objecMaps from this._timers because there is no - // nice solution for tracking the number of objects in a WeakMap. - // WeakMap is not enumerable, so we can't deterministically say when it's - // empty. We accept that trade-off here, given that entries for short-lived - // objects will go away when they are no longer referenced - return true; - }, -}; - -var TelemetryStopwatch = { - /** - * Starts a timer associated with a telemetry histogram. The timer can be - * directly associated with a histogram, or with a pair of a histogram and - * an object. - * - * @param {String} aHistogram - a string which must be a valid histogram name. - * - * @param {Object} aObj - Optional parameter. If specified, the timer is - * associated with this object, meaning that multiple - * timers for the same histogram may be run - * concurrently, as long as they are associated with - * different objects. - * @param {Object} [options.inSeconds=false] - Record elapsed time for this - * histogram in seconds instead of milliseconds. Defaults to - * false. - * - * @returns {Boolean} True if the timer was successfully started, false - * otherwise. If a timer already exists, it can't be - * started again, and the existing one will be cleared in - * order to avoid measurements errors. - */ - start(aHistogram, aObj, {inSeconds} = {}) { - return TelemetryStopwatchImpl.start(aHistogram, aObj, null, {inSeconds}); - }, - - /** - * Returns whether a timer associated with a telemetry histogram is currently - * running. The timer can be directly associated with a histogram, or with a - * pair of a histogram and an object. - * - * @param {String} aHistogram - a string which must be a valid histogram name. - * - * @param {Object} aObj - Optional parameter. If specified, the timer is - * associated with this object, meaning that multiple - * timers for the same histogram may be run - * concurrently, as long as they are associated with - * different objects. - * - * @returns {Boolean} True if the timer exists and is currently running. - */ - running(aHistogram, aObj) { - return TelemetryStopwatchImpl.running(aHistogram, aObj, null); - }, - - /** - * Deletes the timer associated with a telemetry histogram. The timer can be - * directly associated with a histogram, or with a pair of a histogram and - * an object. Important: Only use this method when a legitimate cancellation - * should be done. - * - * @param {String} aHistogram - a string which must be a valid histogram name. - * - * @param {Object} aObj - Optional parameter. If specified, the timer is - * associated with this object, meaning that multiple - * timers or a same histogram may be run concurrently, - * as long as they are associated with different - * objects. - * - * @returns {Boolean} True if the timer exist and it was cleared, False - * otherwise. - */ - cancel(aHistogram, aObj) { - return TelemetryStopwatchImpl.cancel(aHistogram, aObj, null); - }, - - /** - * Returns the elapsed time for a particular stopwatch. Primarily for - * debugging purposes. Must be called prior to finish. - * - * @param {String} aHistogram - a string which must be a valid histogram name. - * If an invalid name is given, the function will - * throw. - * - * @param (Object) aObj - Optional parameter which associates the histogram - * timer with the given object. - * - * @param {Boolean} aCanceledOkay - Optional parameter which will suppress any - * warnings that normally fire when a stopwatch - * is finished after being cancelled. Defaults - * to false. - * - * @returns {Integer} time in milliseconds or -1 if the stopwatch was not - * found. - */ - timeElapsed(aHistogram, aObj, aCanceledOkay) { - return TelemetryStopwatchImpl.timeElapsed(aHistogram, aObj, null, - aCanceledOkay); - }, - - /** - * Stops the timer associated with the given histogram (and object), - * calculates the time delta between start and finish, and adds the value - * to the histogram. - * - * @param {String} aHistogram - a string which must be a valid histogram name. - * - * @param {Object} aObj - Optional parameter which associates the histogram - * timer with the given object. - * - * @param {Boolean} aCanceledOkay - Optional parameter which will suppress any - * warnings that normally fire when a stopwatch - * is finished after being cancelled. Defaults - * to false. - * - * @returns {Boolean} True if the timer was succesfully stopped and the data - * was added to the histogram, False otherwise. - */ - finish(aHistogram, aObj, aCanceledOkay) { - return TelemetryStopwatchImpl.finish(aHistogram, aObj, null, aCanceledOkay); - }, - - /** - * Starts a timer associated with a keyed telemetry histogram. The timer can - * be directly associated with a histogram and its key. Similarly to - * @see{TelemetryStopwatch.stat} the histogram and its key can be associated - * with an object. Each key may have multiple associated objects and each - * object can be associated with multiple keys. - * - * @param {String} aHistogram - a string which must be a valid histogram name. - * - * @param {String} aKey - a string which must be a valid histgram key. - * - * @param {Object} aObj - Optional parameter. If specified, the timer is - * associated with this object, meaning that multiple - * timers for the same histogram may be run - * concurrently,as long as they are associated with - * different objects. - * @param {Object} [options.inSeconds=false] - Record elapsed time for this - * histogram in seconds instead of milliseconds. Defaults to - * false. - * - * @returns {Boolean} True if the timer was successfully started, false - * otherwise. If a timer already exists, it can't be - * started again, and the existing one will be cleared in - * order to avoid measurements errors. - */ - startKeyed(aHistogram, aKey, aObj, {inSeconds} = {}) { - return TelemetryStopwatchImpl.start(aHistogram, aObj, aKey, {inSeconds}); - }, - - /** - * Returns whether a timer associated with a telemetry histogram is currently - * running. Similarly to @see{TelemetryStopwatch.running} the timer and its - * key can be associated with an object. Each key may have multiple associated - * objects and each object can be associated with multiple keys. - * - * @param {String} aHistogram - a string which must be a valid histogram name. - * - * @param {String} aKey - a string which must be a valid histgram key. - * - * @param {Object} aObj - Optional parameter. If specified, the timer is - * associated with this object, meaning that multiple - * timers for the same histogram may be run - * concurrently, as long as they are associated with - * different objects. - * - * @returns {Boolean} True if the timer exists and is currently running. - */ - runningKeyed(aHistogram, aKey, aObj) { - return TelemetryStopwatchImpl.running(aHistogram, aObj, aKey); - }, - - /** - * Deletes the timer associated with a keyed histogram. Important: Only use - * this method when a legitimate cancellation should be done. - * - * @param {String} aHistogram - a string which must be a valid histogram name. - * - * @param {String} aKey - a string which must be a valid histgram key. - * - * @param {Object} aObj - Optional parameter. If specified, the timer - * associated with this object is deleted. - * - * @return {Boolean} True if the timer exist and it was cleared, False - * otherwise. - */ - cancelKeyed(aHistogram, aKey, aObj) { - return TelemetryStopwatchImpl.cancel(aHistogram, aObj, aKey); - }, - - /** - * Returns the elapsed time for a particular stopwatch. Primarily for - * debugging purposes. Must be called prior to finish. - * - * @param {String} aHistogram - a string which must be a valid histogram name. - * - * @param {String} aKey - a string which must be a valid histgram key. - * - * @param {Object} aObj - Optional parameter. If specified, the timer - * associated with this object is used to calculate - * the elapsed time. - * - * @return {Integer} time in milliseconds or -1 if the stopwatch was not - * found. - */ - timeElapsedKeyed(aHistogram, aKey, aObj, aCanceledOkay) { - return TelemetryStopwatchImpl.timeElapsed(aHistogram, aObj, aKey, - aCanceledOkay); - }, - - /** - * Stops the timer associated with the given keyed histogram (and object), - * calculates the time delta between start and finish, and adds the value - * to the keyed histogram. - * - * @param {String} aHistogram - a string which must be a valid histogram name. - * - * @param {String} aKey - a string which must be a valid histgram key. - * - * @param {Object} aObj - optional parameter which associates the histogram - * timer with the given object. - * - * @param {Boolean} aCanceledOkay - Optional parameter which will suppress any - * warnings that normally fire when a stopwatch - * is finished after being cancelled. Defaults - * to false. - * - * @returns {Boolean} True if the timer was succesfully stopped and the data - * was added to the histogram, False otherwise. - */ - finishKeyed(aHistogram, aKey, aObj, aCanceledOkay) { - return TelemetryStopwatchImpl.finish(aHistogram, aObj, aKey, aCanceledOkay); - }, - - /** - * Set the testing mode. Used by tests. - */ - setTestModeEnabled(testing = true) { - TelemetryStopwatchImpl.suppressErrors(testing); - }, -}; - -var TelemetryStopwatchImpl = { - // Suppress errors. Used when testing. - _suppressErrors: false, - - suppressErrors(suppress) { - this._suppressErrors = suppress; - }, - - start(histogram, object, key, {inSeconds} = {}) { - if (Timers.has(histogram, object, key)) { - Timers.delete(histogram, object, key); - if (!this._suppressErrors) { - Cu.reportError(`TelemetryStopwatch: key "${histogram}" was already ` + - "initialized"); - } - return false; - } - - return Timers.put(histogram, object, key, Cu.now(), {inSeconds}); - }, - - running(histogram, object, key) { - return Timers.has(histogram, object, key); - }, - - cancel(histogram, object, key) { - return Timers.delete(histogram, object, key); - }, - - timeElapsed(histogram, object, key, aCanceledOkay) { - const startTime = Timers.get(histogram, object, key); - if (startTime === null) { - if (!aCanceledOkay && !this._suppressErrors) { - Cu.reportError("TelemetryStopwatch: requesting elapsed time for " + - `nonexisting stopwatch. Histogram: "${histogram}", ` + - `key: "${key}"`); - } - return -1; - } - - try { - const delta = Cu.now() - startTime; - if (Timers._inSeconds.has(histogram)) { - return Math.round(delta / 1000); - } - return Math.round(delta); - } catch (e) { - if (!this._suppressErrors) { - Cu.reportError("TelemetryStopwatch: failed to calculate elapsed time " + - `for Histogram: "${histogram}", key: "${key}", ` + - `exception: ${Log.exceptionStr(e)}`); - } - return -1; - } - }, - - finish(histogram, object, key, aCanceledOkay) { - const delta = this.timeElapsed(histogram, object, key, aCanceledOkay); - if (delta == -1) { - return false; - } - - try { - if (key) { - Services.telemetry.getKeyedHistogramById(histogram).add(key, delta); - } else { - Services.telemetry.getHistogramById(histogram).add(delta); - } - } catch (e) { - if (!this._suppressErrors) { - Cu.reportError("TelemetryStopwatch: failed to update the Histogram " + - `"${histogram}", using key: "${key}", ` + - `exception: ${Log.exceptionStr(e)}`); - } - return false; - } - - return Timers.delete(histogram, object, key); - }, -}; diff --git a/toolkit/components/telemetry/docs/collection/histograms.rst b/toolkit/components/telemetry/docs/collection/histograms.rst index ba04558c6fe9..44bc23d6f60b 100644 --- a/toolkit/components/telemetry/docs/collection/histograms.rst +++ b/toolkit/components/telemetry/docs/collection/histograms.rst @@ -272,7 +272,7 @@ Note that ``nsITelemetry.getHistogramById()`` will throw an ``NS_ERROR_FAILURE`` Adding a new Telemetry probe is not possible with Artifact builds. A full build is needed. -For histograms measuring time, `TelemetryStopwatch `_ can be used to avoid working with Dates manually: +For histograms measuring time, TelemetryStopwatch can be used to avoid working with Dates manually: .. code-block:: js diff --git a/toolkit/components/telemetry/docs/collection/measuring-time.rst b/toolkit/components/telemetry/docs/collection/measuring-time.rst index 0babfe23dc99..c2d972b3788b 100644 --- a/toolkit/components/telemetry/docs/collection/measuring-time.rst +++ b/toolkit/components/telemetry/docs/collection/measuring-time.rst @@ -7,7 +7,7 @@ These helpers record the elapsed time into histograms, so you have to create sui From JavaScript =============== -JavaScript can measure elapsed time using `TelemetryStopwatch.jsm `_. +JavaScript can measure elapsed time using TelemetryStopwatch. ``TelemetryStopwatch`` is a helper that simplifies recording elapsed time (in milliseconds) into histograms (plain or keyed). diff --git a/toolkit/components/telemetry/moz.build b/toolkit/components/telemetry/moz.build index 427c742298d7..13277c4a6a39 100644 --- a/toolkit/components/telemetry/moz.build +++ b/toolkit/components/telemetry/moz.build @@ -103,7 +103,6 @@ EXTRA_JS_MODULES += [ 'app/TelemetryEnvironment.jsm', 'app/TelemetryReportingPolicy.jsm', 'app/TelemetrySend.jsm', - 'app/TelemetryStopwatch.jsm', 'app/TelemetryStorage.jsm', 'app/TelemetryTimestamps.jsm', 'app/TelemetryUtils.jsm', diff --git a/toolkit/components/telemetry/tests/unit/test_TelemetrySend.js b/toolkit/components/telemetry/tests/unit/test_TelemetrySend.js index e31103d5a7f1..265e6d6266aa 100644 --- a/toolkit/components/telemetry/tests/unit/test_TelemetrySend.js +++ b/toolkit/components/telemetry/tests/unit/test_TelemetrySend.js @@ -17,8 +17,6 @@ ChromeUtils.import("resource://gre/modules/Services.jsm", this); ChromeUtils.import("resource://gre/modules/osfile.jsm", this); ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm", this); -ChromeUtils.import("resource://gre/modules/TelemetryStopwatch.jsm", this); - ChromeUtils.defineModuleGetter(this, "TelemetryHealthPing", "resource://gre/modules/HealthPing.jsm"); diff --git a/toolkit/content/widgets/tabbox.xml b/toolkit/content/widgets/tabbox.xml index 8648a8c26c75..eb26159f1fb5 100644 --- a/toolkit/content/widgets/tabbox.xml +++ b/toolkit/content/widgets/tabbox.xml @@ -421,19 +421,6 @@ /Mac/.test(navigator.platform) - - - @@ -447,7 +434,7 @@ if (this != this.parentNode.selectedItem) { // Not selected yet let stopwatchid = this.parentNode.getAttribute("stopwatchid"); if (stopwatchid) { - this.TelemetryStopwatch.start(stopwatchid); + TelemetryStopwatch.start(stopwatchid); } // Call this before setting the 'ignorefocus' attribute because this @@ -469,7 +456,7 @@ } if (stopwatchid) { - this.TelemetryStopwatch.finish(stopwatchid); + TelemetryStopwatch.finish(stopwatchid); } } // Otherwise this tab is already selected and we will fall