Bug 1402267 - Add a scalar telemetry probe that tracks SessionFile worker restarts. data-r=liuche, r?ttaubert,chutten
MozReview-Commit-ID: F3kCfz18kcQ
--- a/browser/components/sessionstore/SessionFile.jsm
+++ b/browser/components/sessionstore/SessionFile.jsm
@@ -82,16 +82,20 @@ this.SessionFile = {
},
/**
* Return the paths to the files used to store, backup, etc.
* the state of the file.
*/
get Paths() {
return SessionFileInternal.Paths;
+ },
+
+ get MaxWriteFailures() {
+ return kMaxWriteFailures;
}
};
Object.freeze(SessionFile);
var Path = OS.Path;
var profileDir = OS.Constants.Path.profileDir;
@@ -347,16 +351,17 @@ var SessionFileInternal = {
* amount of failures to deal with. This will spawn a fresh worker upon the next
* write.
* This also resets the `_workerHealth` stats.
*/
_checkWorkerHealth() {
if (this._workerHealth.failures >= kMaxWriteFailures) {
SessionWorker.terminate();
this._workerHealth.failures = 0;
+ Telemetry.scalarAdd("browser.session.restore.worker_restart_count", 1);
}
},
write(aData) {
if (RunState.isClosed) {
return Promise.reject(new Error("SessionFile is closed"));
}
new file mode 100644
--- /dev/null
+++ b/browser/components/sessionstore/test/unit/test_scalar_worker_restarts.js
@@ -0,0 +1,39 @@
+/*
+ * The primary purpose of this test is to ensure that the sessionstore component
+ * records information about erroneous workers into a scalar.
+ */
+
+"use strict";
+const Telemetry = Services.telemetry;
+const ScalarId = "browser.session.restore.worker_restart_count";
+
+// Prepare the session file.
+var profd = do_get_profile();
+Cu.import("resource:///modules/sessionstore/SessionFile.jsm", this);
+
+/**
+ * In order to use browser.session.restore.worker_restart_count scalar, it has
+ * to be registered in "toolkit/components/telemetry/Scalars.yaml".
+ * This test ensures that the scalar is registered and empty.
+ */
+add_task(async function test_ensure_scalar_is_empty() {
+ const scalars = Telemetry.snapshotScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTOUT, false).parent || {};
+ Assert.ok(!(ScalarId in scalars), "Sanity check; no scalars should be there yet.");
+});
+
+/**
+ * Makes sure that the scalar is positively updated when amount of failures
+ * becomes higher than the threshold.
+ */
+add_task(async function test_worker_restart() {
+ let backstagePass = Cu.import("resource:///modules/sessionstore/SessionFile.jsm", {});
+ backstagePass.SessionFileInternal._workerHealth.failures = backstagePass.kMaxWriteFailures + 1;
+ backstagePass.SessionFileInternal._checkWorkerHealth();
+
+ Assert.equal(backstagePass.SessionFileInternal._workerHealth.failures, 0,
+ "Worker failure count should've been reset.");
+
+ // Checking if the scalar is positively updated.
+ const scalars = Telemetry.snapshotScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTOUT, false).parent;
+ Assert.equal(scalars[ScalarId], 1, "Should be increased with one hit.");
+});
--- a/browser/components/sessionstore/test/unit/xpcshell.ini
+++ b/browser/components/sessionstore/test/unit/xpcshell.ini
@@ -4,13 +4,14 @@ firefox-appdir = browser
skip-if = toolkit == 'android'
support-files =
data/sessionCheckpoints_all.json
data/sessionstore_invalid.js
data/sessionstore_valid.js
[test_backup_once.js]
[test_histogram_corrupt_files.js]
+[test_migration_lz4compression.js]
+[test_scalar_worker_restarts.js]
[test_shutdown_cleanup.js]
[test_startup_nosession_async.js]
[test_startup_session_async.js]
[test_startup_invalid_session.js]
-[test_migration_lz4compression.js]
--- a/toolkit/components/telemetry/Scalars.yaml
+++ b/toolkit/components/telemetry/Scalars.yaml
@@ -356,16 +356,32 @@ browser.session.restore:
expires: never
kind: uint
notification_emails:
- bwinton@mozilla.com
release_channel_collection: opt-out
record_in_processes:
- 'main'
+ worker_restart_count:
+ bug_numbers:
+ - 1402267
+ description: >
+ A counter incremented every time the SessionFile worker is restarted due
+ to too many failures, as defined in the browser.sessionstore.max_write_failures
+ pref.
+ expires: "64"
+ kind: uint
+ notification_emails:
+ - mdeboer@mozilla.com
+ - session-restore-telemetry-alerts@mozilla.com
+ release_channel_collection: opt-out
+ record_in_processes:
+ - 'main'
+
# This section is for probes used to measure use of the Webextensions storage.sync API.
storage.sync.api.usage:
extensions_using:
bug_numbers:
- 1328974
description: >
The count of webextensions that have data stored in the chrome.storage.sync API.
This includes extensions that have not used the storage.sync API this session.