bug 1366294 - Part 13 - Fix telemetry-using tests. r=Dexter
☠☠ backed out by 2c1ee57abd49 ☠ ☠
authorChris H-C <chutten@mozilla.com>
Mon, 17 Jul 2017 11:28:55 -0400
changeset 418922 e7a3ac603f7c6389c60eb70e6a595b2e24858b7f
parent 418921 fb40775d14517a387f3520e59515e119c70f2830
child 418923 94944363e7402c42e1be4ba0092b3de56df45f1c
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersDexter
bugs1366294
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
bug 1366294 - Part 13 - Fix telemetry-using tests. r=Dexter Some tests were using "secret" APIs to get at telemetry knowledge from various processes in various ways. Adjust them so that they work with the new ways of doing things. MozReview-Commit-ID: 2iBL00HVGyg
browser/components/sessionstore/test/browser_sessionStorage_size.js
dom/base/test/browser_use_counters.js
dom/ipc/tests/browser_remote_navigation_delay_telemetry.js
toolkit/components/osfile/tests/xpcshell/test_telemetry.js
toolkit/components/terminator/tests/xpcshell/test_terminator_reload.js
--- a/browser/components/sessionstore/test/browser_sessionStorage_size.js
+++ b/browser/components/sessionstore/test/browser_sessionStorage_size.js
@@ -5,34 +5,46 @@
 
 const RAND = Math.random();
 const URL = "http://mochi.test:8888/browser/" +
             "browser/components/sessionstore/test/browser_sessionStorage.html" +
             "?" + RAND;
 
 const OUTER_VALUE = "outer-value-" + RAND;
 
+function getEstimateChars() {
+  let snap;
+  if (gMultiProcessBrowser) {
+    snap = Services.telemetry.histogramSnapshots.content["FX_SESSION_RESTORE_DOM_STORAGE_SIZE_ESTIMATE_CHARS"];
+  } else {
+    snap = Services.telemetry.histogramSnapshots.parent["FX_SESSION_RESTORE_DOM_STORAGE_SIZE_ESTIMATE_CHARS"];
+  }
+  if (!snap) {
+    return 0;
+  }
+  return snap.counts[4];
+}
+
 // Test that we record the size of messages.
 add_task(async function test_telemetry() {
   Services.telemetry.canRecordExtended = true;
-  let suffix = gMultiProcessBrowser ? "#content" : "";
-  let histogram = Services.telemetry.getHistogramById("FX_SESSION_RESTORE_DOM_STORAGE_SIZE_ESTIMATE_CHARS" + suffix);
-  let snap1 = histogram.snapshot();
+
+  let prev = getEstimateChars()
 
   let tab = BrowserTestUtils.addTab(gBrowser, URL);
   let browser = tab.linkedBrowser;
   await promiseBrowserLoaded(browser);
 
   // Flush to make sure we submitted telemetry data.
   await TabStateFlusher.flush(browser);
 
   // There is no good way to make sure that the parent received the histogram entries from the child processes.
   // Let's stick to the ugly, spinning the event loop until we have a good approach (Bug 1357509).
   await BrowserTestUtils.waitForCondition(() => {
-    return histogram.snapshot().counts[4] > snap1.counts[4];
+    return getEstimateChars() > prev;
   });
 
   Assert.ok(true);
   await promiseRemoveTab(tab);
   Services.telemetry.canRecordExtended = false;
 });
 
 // Lower the size limit for DOM Storage content. Check that DOM Storage
--- a/dom/base/test/browser_use_counters.js
+++ b/dom/base/test/browser_use_counters.js
@@ -103,25 +103,35 @@ function waitForPageLoad(browser) {
       }
       addEventListener("load", listener, true);
     });
   });
 }
 
 function grabHistogramsFromContent(use_counter_middlefix, page_before = null) {
   let telemetry = Cc["@mozilla.org/base/telemetry;1"].getService(Ci.nsITelemetry);
-  let suffix = Services.appinfo.browserTabsRemoteAutostart ? "#content" : "";
-  let gather = () => [
-    telemetry.getHistogramById("USE_COUNTER2_" + use_counter_middlefix + "_PAGE" + suffix).snapshot().sum,
-    telemetry.getHistogramById("USE_COUNTER2_" + use_counter_middlefix + "_DOCUMENT" + suffix).snapshot().sum,
-    telemetry.getHistogramById("CONTENT_DOCUMENTS_DESTROYED" + suffix).snapshot().sum,
-    telemetry.getHistogramById("TOP_LEVEL_CONTENT_DOCUMENTS_DESTROYED" + suffix).snapshot().sum,
-  ];
+  let gather = () => {
+    let snapshots;
+    if (Services.appinfo.browserTabsRemoteAutostart) {
+      snapshots = telemetry.histogramSnapshots.content;
+    } else {
+      snapshots = telemetry.histogramSnapshots.parent;
+    }
+    let checkGet = (probe) => {
+      return snapshots[probe] ? snapshots[probe].sum : 0;
+    };
+    return [
+      checkGet("USE_COUNTER2_" + use_counter_middlefix + "_PAGE"),
+      checkGet("USE_COUNTER2_" + use_counter_middlefix + "_DOCUMENT"),
+      checkGet("CONTENT_DOCUMENTS_DESTROYED"),
+      checkGet("TOP_LEVEL_CONTENT_DOCUMENTS_DESTROYED"),
+    ];
+  };
   return BrowserTestUtils.waitForCondition(() => {
-    return page_before != telemetry.getHistogramById("USE_COUNTER2_" + use_counter_middlefix + "_PAGE" + suffix).snapshot().sum;
+    return page_before != gather()[0];
   }).then(gather, gather);
 }
 
 var check_use_counter_iframe = async function(file, use_counter_middlefix, check_documents=true) {
   info("checking " + file + " with histogram " + use_counter_middlefix);
 
   let newTab = BrowserTestUtils.addTab(gBrowser,  "about:blank");
   gBrowser.selectedTab = newTab;
--- a/dom/ipc/tests/browser_remote_navigation_delay_telemetry.js
+++ b/dom/ipc/tests/browser_remote_navigation_delay_telemetry.js
@@ -8,45 +8,42 @@ add_task(async function test_memory_dist
     return;
   }
 
   await SpecialPowers.pushPrefEnv({set: [["toolkit.telemetry.enabled", true]]});
   let canRecordExtended = Services.telemetry.canRecordExtended;
   Services.telemetry.canRecordExtended = true;
   registerCleanupFunction(() => Services.telemetry.canRecordExtended = canRecordExtended);
 
-  // Note the #content suffix after the id. This is the only way this API lets us fetch the
-  // histogram entries reported by a content process.
-  let histogram = Services.telemetry.getKeyedHistogramById("FX_TAB_REMOTE_NAVIGATION_DELAY_MS#content");
-  histogram.clear();
+  Services.telemetry.snapshotSubsessionKeyedHistograms(true /*clear*/);
 
   // Open a remote page in a new tab to trigger the WebNavigation:LoadURI.
   let tab1 = await BrowserTestUtils.openNewForegroundTab(gBrowser, "http://example.com");
   ok(tab1.linkedBrowser.isRemoteBrowser, "|tab1| should have a remote browser.");
 
   // Open a new tab with about:robots, so it ends up in the parent process with a non-remote browser.
   let tab2 = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:robots");
   ok(!tab2.linkedBrowser.isRemoteBrowser, "|tab2| should have a non-remote browser.");
   // Navigate the tab, so it will change remotness and it triggers the SessionStore:restoreTabContent case.
   await BrowserTestUtils.loadURI(tab2.linkedBrowser, "http://example.com");
   ok(tab2.linkedBrowser.isRemoteBrowser, "|tab2| should have a remote browser by now.");
 
   // There is no good way to make sure that the parent received the histogram entries from the child processes.
   // Let's stick to the ugly, spinning the event loop until we have a good approach (Bug 1357509).
   await BrowserTestUtils.waitForCondition(() => {
-    let s = histogram.snapshot();
-    return "WebNavigation:LoadURI" in s && "SessionStore:restoreTabContent" in s;
+    let s = Services.telemetry.snapshotSubsessionKeyedHistograms().content["FX_TAB_REMOTE_NAVIGATION_DELAY_MS"];
+    return s && "WebNavigation:LoadURI" in s && "SessionStore:restoreTabContent" in s;
   });
 
-  let s = histogram.snapshot();
+  let s = Services.telemetry.snapshotSubsessionKeyedHistograms().content["FX_TAB_REMOTE_NAVIGATION_DELAY_MS"];
   let restoreTabSnapshot = s["SessionStore:restoreTabContent"];
   ok(restoreTabSnapshot.sum > 0, "Zero delay for the restoreTabContent case is unlikely.");
   ok(restoreTabSnapshot.sum < 10000, "More than 10 seconds delay for the restoreTabContent case is unlikely.");
 
   let loadURISnapshot = s["WebNavigation:LoadURI"];
   ok(loadURISnapshot.sum > 0, "Zero delay for the LoadURI case is unlikely.");
   ok(loadURISnapshot.sum < 10000, "More than 10 seconds delay for the LoadURI case is unlikely.");
 
-  histogram.clear();
+  Services.telemetry.snapshotSubsessionKeyedHistograms(true /*clear*/);
 
   await BrowserTestUtils.removeTab(tab2);
   await BrowserTestUtils.removeTab(tab1);
 });
--- a/toolkit/components/osfile/tests/xpcshell/test_telemetry.js
+++ b/toolkit/components/osfile/tests/xpcshell/test_telemetry.js
@@ -22,42 +22,42 @@ function getCount(histogram) {
 }
 
 // Ensure that launching the OS.File worker adds data to the relevant
 // histograms
 add_task(async function test_startup() {
   let LAUNCH = "OSFILE_WORKER_LAUNCH_MS";
   let READY = "OSFILE_WORKER_READY_MS";
 
-  let before = Services.telemetry.histogramSnapshots;
+  let before = Services.telemetry.histogramSnapshots.parent;
 
   // Launch the OS.File worker
   await File.getCurrentDirectory();
 
-  let after = Services.telemetry.histogramSnapshots;
+  let after = Services.telemetry.histogramSnapshots.parent;
 
 
   do_print("Ensuring that we have recorded measures for histograms");
   do_check_eq(getCount(after[LAUNCH]), getCount(before[LAUNCH]) + 1);
   do_check_eq(getCount(after[READY]), getCount(before[READY]) + 1);
 
   do_print("Ensuring that launh <= ready");
   do_check_true(after[LAUNCH].sum <= after[READY].sum);
 });
 
 // Ensure that calling writeAtomic adds data to the relevant histograms
 add_task(async function test_writeAtomic() {
   let LABEL = "OSFILE_WRITEATOMIC_JANK_MS";
 
-  let before = Services.telemetry.histogramSnapshots;
+  let before = Services.telemetry.histogramSnapshots.parent;
 
   // Perform a write.
   let path = Path.join(Constants.Path.profileDir, "test_osfile_telemetry.tmp");
   await File.writeAtomic(path, LABEL, { tmpPath: path + ".tmp" } );
 
-  let after = Services.telemetry.histogramSnapshots;
+  let after = Services.telemetry.histogramSnapshots.parent;
 
   do_check_eq(getCount(after[LABEL]), getCount(before[LABEL]) + 1);
 });
 
 function run_test() {
   run_next_test();
 }
--- a/toolkit/components/terminator/tests/xpcshell/test_terminator_reload.js
+++ b/toolkit/components/terminator/tests/xpcshell/test_terminator_reload.js
@@ -28,17 +28,17 @@ var HISTOGRAMS = {
 add_task(async function init() {
   do_get_profile();
   PATH = Path.join(Constants.Path.localProfileDir, "ShutdownDuration.json");
 });
 
 add_task(async function test_reload() {
   do_print("Forging data");
   let data = {};
-  let telemetrySnapshots = Services.telemetry.histogramSnapshots;
+  let telemetrySnapshots = Services.telemetry.histogramSnapshots.parent;
   let i = 0;
   for (let k of Object.keys(HISTOGRAMS)) {
     let id = HISTOGRAMS[k];
     data[k] = i++;
     Assert.equal(telemetrySnapshots[id] || undefined, undefined, "Histogram " + id + " is empty");
   }
 
 
@@ -59,17 +59,17 @@ add_task(async function test_reload() {
   let tt = Cc["@mozilla.org/toolkit/shutdown-terminator-telemetry;1"].
     createInstance(Ci.nsIObserver);
   tt.observe(null, "profile-after-change", "");
 
   do_print("Waiting until telemetry is updated");
   // Now wait until Telemetry is updated
   await wait;
 
-  telemetrySnapshots = Services.telemetry.histogramSnapshots;
+  telemetrySnapshots = Services.telemetry.histogramSnapshots.parent;
   for (let k of Object.keys(HISTOGRAMS)) {
     let id = HISTOGRAMS[k];
     do_print("Testing histogram " + id);
     let snapshot = telemetrySnapshots[id];
     let count = 0;
     for (let x of snapshot.counts) {
       count += x;
     }