gecko-dev/startupcache/test/browser_startupcache_telemetry.js
Doug Thayer 55db157391 Bug 1364235 - Collect telemetry stats on startup cache hits and misses r=kmag
In bug 1264235 we have some indication that observed bugs with the
startup cache might have been resolved, but we don't really know
until we collect data. Collecting these stats will give us the
ability to have more certainty that the startup cache is functioning
correctly in the wild.

Differential Revision: https://phabricator.services.mozilla.com/D19573

--HG--
extra : moz-landing-system : lando
2019-03-05 16:52:57 +00:00

41 lines
1.7 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const LABELS_STARTUP_CACHE_REQUESTS = {
HitMemory: 0,
HitDisk: 1,
Miss: 2,
};
add_task(async function() {
Services.obs.notifyObservers(null, "startupcache-invalidate");
Services.telemetry.getSnapshotForHistograms("main", true);
let newWin = await BrowserTestUtils.openNewBrowserWindow();
let snapshot = Services.telemetry.getSnapshotForHistograms("main", true);
function histValue(label) {
return snapshot.parent.STARTUP_CACHE_REQUESTS.values[label] || 0;
}
Assert.equal(histValue(LABELS_STARTUP_CACHE_REQUESTS.HitMemory), 0);
Assert.equal(histValue(LABELS_STARTUP_CACHE_REQUESTS.HitDisk), 0);
Assert.notEqual(histValue(LABELS_STARTUP_CACHE_REQUESTS.Miss), 0);
await BrowserTestUtils.closeWindow(newWin);
newWin = await BrowserTestUtils.openNewBrowserWindow();
snapshot = Services.telemetry.getSnapshotForHistograms("main", true);
Assert.notEqual(histValue(LABELS_STARTUP_CACHE_REQUESTS.HitMemory), 0);
Assert.equal(histValue(LABELS_STARTUP_CACHE_REQUESTS.HitDisk), 0);
Assert.notEqual(histValue(LABELS_STARTUP_CACHE_REQUESTS.Miss), 0);
await BrowserTestUtils.closeWindow(newWin);
Services.obs.notifyObservers(null, "startupcache-invalidate", "memoryOnly");
newWin = await BrowserTestUtils.openNewBrowserWindow();
snapshot = Services.telemetry.getSnapshotForHistograms("main", true);
Assert.notEqual(histValue(LABELS_STARTUP_CACHE_REQUESTS.HitMemory), 0);
Assert.notEqual(histValue(LABELS_STARTUP_CACHE_REQUESTS.HitDisk), 0);
// Some misses can come through - just ensure it's a small number
Assert.ok(histValue(LABELS_STARTUP_CACHE_REQUESTS.Miss) < 5);
await BrowserTestUtils.closeWindow(newWin);
});