Bug 1465120 - Use a different telemetry histogram key for the storage.local IndexedDB backend.
MozReview-Commit-ID: ApaNLXehExf
--- a/toolkit/components/extensions/child/ext-storage.js
+++ b/toolkit/components/extensions/child/ext-storage.js
@@ -2,18 +2,23 @@
ChromeUtils.defineModuleGetter(this, "ExtensionStorage",
"resource://gre/modules/ExtensionStorage.jsm");
ChromeUtils.defineModuleGetter(this, "ExtensionStorageIDB",
"resource://gre/modules/ExtensionStorageIDB.jsm");
ChromeUtils.defineModuleGetter(this, "TelemetryStopwatch",
"resource://gre/modules/TelemetryStopwatch.jsm");
+// Telemetry histogram keys for the JSONFile backend.
const storageGetHistogram = "WEBEXT_STORAGE_LOCAL_GET_MS";
const storageSetHistogram = "WEBEXT_STORAGE_LOCAL_SET_MS";
+// Telemetry histogram keys for the IndexedDB backend.
+const storageGetIDBHistogram = "WEBEXT_STORAGE_LOCAL_IDB_GET_MS";
+const storageSetIDBHistogram = "WEBEXT_STORAGE_LOCAL_IDB_SET_MS";
+
// Wrap a storage operation in a TelemetryStopWatch.
async function measureOp(histogram, fn) {
const stopwatchKey = {};
TelemetryStopwatch.start(histogram, stopwatchKey);
try {
let result = await fn();
TelemetryStopwatch.finish(histogram, stopwatchKey);
@@ -51,23 +56,23 @@ this.storage = class extends ExtensionAP
};
}
getLocalIDBBackend(context, {hasParentListeners, serialize, storagePrincipal}) {
const dbPromise = ExtensionStorageIDB.open(storagePrincipal);
return {
get(keys) {
- return measureOp(storageGetHistogram, async () => {
+ return measureOp(storageGetIDBHistogram, async () => {
const db = await dbPromise;
return db.get(keys);
});
},
set(items) {
- return measureOp(storageSetHistogram, async () => {
+ return measureOp(storageSetIDBHistogram, async () => {
const db = await dbPromise;
const changes = await db.set(items, {
serialize: ExtensionStorage.serialize,
});
if (!changes) {
return;
}
--- a/toolkit/components/extensions/test/xpcshell/test_ext_storage_telemetry.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_storage_telemetry.js
@@ -1,19 +1,31 @@
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";
ChromeUtils.import("resource://gre/modules/ExtensionStorageIDB.jsm");
-const HISTOGRAM_IDS = [
+const HISTOGRAM_JSON_IDS = [
"WEBEXT_STORAGE_LOCAL_SET_MS", "WEBEXT_STORAGE_LOCAL_GET_MS",
];
+const HISTOGRAM_IDB_IDS = [
+ "WEBEXT_STORAGE_LOCAL_IDB_SET_MS", "WEBEXT_STORAGE_LOCAL_IDB_GET_MS",
+];
+
+const HISTOGRAM_IDS = [].concat(HISTOGRAM_JSON_IDS, HISTOGRAM_IDB_IDS);
+
async function test_telemetry_background() {
+ const expectedEmptyHistograms = ExtensionStorageIDB.isBackendEnabled ?
+ HISTOGRAM_JSON_IDS : HISTOGRAM_IDB_IDS;
+
+ const expectedNonEmptyHistograms = ExtensionStorageIDB.isBackendEnabled ?
+ HISTOGRAM_IDB_IDS : HISTOGRAM_JSON_IDS;
+
const server = createHttpServer();
server.registerDirectory("/data/", do_get_file("data"));
const BASE_URL = `http://localhost:${server.identity.primaryPort}/data`;
async function contentScript() {
await browser.storage.local.set({a: "b"});
await browser.storage.local.get("a");
@@ -46,68 +58,74 @@ async function test_telemetry_background
let extension1 = ExtensionTestUtils.loadExtension(extInfo);
let extension2 = ExtensionTestUtils.loadExtension(extInfo);
clearHistograms();
let process = IS_OOP ? "extension" : "parent";
let snapshots = getSnapshots(process);
+
for (let id of HISTOGRAM_IDS) {
ok(!(id in snapshots), `No data recorded for histogram: ${id}.`);
}
await extension1.startup();
await extension1.awaitMessage("backgroundDone");
- for (let id of HISTOGRAM_IDS) {
+ for (let id of expectedNonEmptyHistograms) {
await promiseTelemetryRecorded(id, process, 1);
}
// Telemetry from extension1's background page should be recorded.
snapshots = getSnapshots(process);
- for (let id of HISTOGRAM_IDS) {
+ for (let id of expectedNonEmptyHistograms) {
equal(arraySum(snapshots[id].counts), 1,
`Data recorded for histogram: ${id}.`);
}
await extension2.startup();
await extension2.awaitMessage("backgroundDone");
- for (let id of HISTOGRAM_IDS) {
+ for (let id of expectedNonEmptyHistograms) {
await promiseTelemetryRecorded(id, process, 2);
}
// Telemetry from extension2's background page should be recorded.
snapshots = getSnapshots(process);
- for (let id of HISTOGRAM_IDS) {
+ for (let id of expectedNonEmptyHistograms) {
equal(arraySum(snapshots[id].counts), 2,
`Additional data recorded for histogram: ${id}.`);
}
await extension2.unload();
// Run a content script.
process = IS_OOP ? "content" : "parent";
let expectedCount = IS_OOP ? 1 : 3;
let contentScriptPromise = extension1.awaitMessage("contentDone");
let contentPage = await ExtensionTestUtils.loadContentPage(`${BASE_URL}/file_sample.html`);
await contentScriptPromise;
await contentPage.close();
- for (let id of HISTOGRAM_IDS) {
+ for (let id of expectedNonEmptyHistograms) {
await promiseTelemetryRecorded(id, process, expectedCount);
}
// Telemetry from extension1's content script should be recorded.
snapshots = getSnapshots(process);
- for (let id of HISTOGRAM_IDS) {
+ for (let id of expectedNonEmptyHistograms) {
equal(arraySum(snapshots[id].counts), expectedCount,
`Data recorded in content script for histogram: ${id}.`);
}
await extension1.unload();
+
+ // Telemetry for histograms that we expect to be empty.
+ for (let id of expectedEmptyHistograms) {
+ ok(!(id in snapshots), `No data recorded for histogram: ${id}.`);
+ }
}
add_task(function test_telemetry_background_file_backend() {
return runWithPrefs([[ExtensionStorageIDB.BACKEND_ENABLED_PREF, false]],
test_telemetry_background);
});
add_task(function test_telemetry_background_idb_backend() {
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -13441,28 +13441,50 @@
"record_in_processes": ["main", "content"],
"alert_emails": ["addons-dev-internal@mozilla.com"],
"bug_numbers": [1371398],
"expires_in_version": "67",
"kind": "exponential",
"releaseChannelCollection": "opt-out",
"high": 50000,
"n_buckets": 100,
- "description": "The amount of time it takes to perform a get via storage.local."
+ "description": "The amount of time it takes to perform a get via storage.local using the JSONFile backend."
},
"WEBEXT_STORAGE_LOCAL_SET_MS": {
"record_in_processes": ["main", "content"],
"alert_emails": ["addons-dev-internal@mozilla.com"],
"bug_numbers": [1371398],
"expires_in_version": "67",
"kind": "exponential",
"releaseChannelCollection": "opt-out",
"high": 50000,
"n_buckets": 100,
- "description": "The amount of time it takes to perform a set via storage.local."
+ "description": "The amount of time it takes to perform a set via storage.local using the JSONFile backend."
+ },
+ "WEBEXT_STORAGE_LOCAL_IDB_GET_MS": {
+ "record_in_processes": ["main", "content"],
+ "alert_emails": ["addons-dev-internal@mozilla.com"],
+ "bug_numbers": [1465120],
+ "expires_in_version": "67",
+ "kind": "exponential",
+ "releaseChannelCollection": "opt-out",
+ "high": 50000,
+ "n_buckets": 100,
+ "description": "The amount of time it takes to perform a get via storage.local using the IndexedDB backend."
+ },
+ "WEBEXT_STORAGE_LOCAL_IDB_SET_MS": {
+ "record_in_processes": ["main", "content"],
+ "alert_emails": ["addons-dev-internal@mozilla.com"],
+ "bug_numbers": [1465120],
+ "expires_in_version": "67",
+ "kind": "exponential",
+ "releaseChannelCollection": "opt-out",
+ "high": 50000,
+ "n_buckets": 100,
+ "description": "The amount of time it takes to perform a set via storage.local using the IndexedDB backend."
},
"EXTENSION_UPDATE_TYPE": {
"record_in_processes": ["main"],
"alert_emails": ["addons-dev-internal@mozilla.com"],
"bug_numbers": [1460336],
"expires_in_version": "66",
"kind": "categorical",
"labels": ["JSON", "RDF"],