зеркало из https://github.com/mozilla/gecko-dev.git
Backed out 3 changesets (bug 1468761) for telemetry related xpcshell failures. CLOSED TREE
Backed out changeset 8c08dcec61d8 (bug 1468761) Backed out changeset 9ee8406cf1d3 (bug 1468761) Backed out changeset 65bfae07e0f4 (bug 1468761)
This commit is contained in:
Родитель
ce2d30dc03
Коммит
6ddd7d4134
|
@ -206,11 +206,11 @@ const PROBE_TESTS = [
|
|||
*/
|
||||
function assertOnlyOneTypeSet(snapshot, category) {
|
||||
let categoryIndex = CATEGORIES.indexOf(category);
|
||||
Assert.equal(snapshot.values[categoryIndex], 1,
|
||||
Assert.equal(snapshot.counts[categoryIndex], 1,
|
||||
`Should have seen the ${category} count increment.`);
|
||||
// Use Array.prototype.reduce to sum up all of the
|
||||
// snapshot.count entries
|
||||
Assert.equal(Object.values(snapshot.values).reduce((a, b) => a + b, 0), 1,
|
||||
Assert.equal(snapshot.counts.reduce((a, b) => a + b), 1,
|
||||
"Should only be 1 collected value.");
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ var gNoAnimHistogram = Services.telemetry
|
|||
function snapshotCount(snapshot) {
|
||||
// Use Array.prototype.reduce to sum up all of the
|
||||
// snapshot.count entries
|
||||
return Object.values(snapshot.values).reduce((a, b) => a + b, 0);
|
||||
return snapshot.counts.reduce((a, b) => a + b);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -50,7 +50,10 @@ function hangContentProcess(browser, aMs) {
|
|||
async function testProbe(aProbe) {
|
||||
info(`Testing probe: ${aProbe}`);
|
||||
let histogram = Services.telemetry.getHistogramById(aProbe);
|
||||
let delayTime = MIN_HANG_TIME + 1; // Pick a bucket arbitrarily
|
||||
let buckets = histogram.snapshot().ranges.filter(function(value) {
|
||||
return (value > MIN_HANG_TIME && value < MAX_HANG_TIME);
|
||||
});
|
||||
let delayTime = buckets[0]; // Pick a bucket arbitrarily
|
||||
|
||||
// The tab spinner does not show up instantly. We need to hang for a little
|
||||
// bit of extra time to account for the tab spinner delay.
|
||||
|
@ -75,7 +78,7 @@ async function testProbe(aProbe) {
|
|||
// Now we should have a hang in our histogram.
|
||||
let snapshot = histogram.snapshot();
|
||||
BrowserTestUtils.removeTab(hangTab);
|
||||
ok(sum(Object.values(snapshot.values)) > 0,
|
||||
ok(sum(snapshot.counts) > 0,
|
||||
`Spinner probe should now have a value in some bucket`);
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ function getShieldHistogram() {
|
|||
}
|
||||
|
||||
function getShieldCounts() {
|
||||
return getShieldHistogram().snapshot().values;
|
||||
return getShieldHistogram().snapshot().counts;
|
||||
}
|
||||
|
||||
add_task(async function setup() {
|
||||
|
@ -33,7 +33,7 @@ add_task(async function setup() {
|
|||
ok(!TrackingProtection.enabled, "TP is not enabled");
|
||||
|
||||
let enabledCounts =
|
||||
Services.telemetry.getHistogramById("TRACKING_PROTECTION_ENABLED").snapshot().values;
|
||||
Services.telemetry.getHistogramById("TRACKING_PROTECTION_ENABLED").snapshot().counts;
|
||||
is(enabledCounts[0], 1, "TP was not enabled on start up");
|
||||
|
||||
let scalars = Services.telemetry.snapshotScalars(
|
||||
|
|
|
@ -32,11 +32,11 @@ const CATEGORIES = [
|
|||
*/
|
||||
function assertOnlyOneTypeSet(snapshot, category) {
|
||||
let categoryIndex = CATEGORIES.indexOf(category);
|
||||
Assert.equal(snapshot.values[categoryIndex], 1,
|
||||
Assert.equal(snapshot.counts[categoryIndex], 1,
|
||||
`Should have seen the ${category} count increment.`);
|
||||
// Use Array.prototype.reduce to sum up all of the
|
||||
// snapshot.count entries
|
||||
Assert.equal(Object.values(snapshot.values).reduce((a, b) => a + b, 0), 1,
|
||||
Assert.equal(snapshot.counts.reduce((a, b) => a + b), 1,
|
||||
"Should only be 1 collected value.");
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ const EXTENSION_ID1 = "@test-extension1";
|
|||
const EXTENSION_ID2 = "@test-extension2";
|
||||
|
||||
function snapshotCountsSum(snapshot) {
|
||||
return Object.values(snapshot.values).reduce((a, b) => a + b, 0);
|
||||
return snapshot.counts.reduce((a, b) => a + b, 0);
|
||||
}
|
||||
|
||||
function histogramCountsSum(histogram) {
|
||||
|
|
|
@ -20,13 +20,13 @@ const kStatusPref = "browser.search.reset.status";
|
|||
function checkTelemetryRecords(expectedValue) {
|
||||
let histogram = Services.telemetry.getHistogramById("SEARCH_RESET_RESULT");
|
||||
let snapshot = histogram.snapshot();
|
||||
// The probe is declared with 5 values, but we get 6 back from .counts
|
||||
let expectedCounts = [0, 0, 0, 0, 0, 0];
|
||||
if (expectedValue != null) {
|
||||
Assert.deepEqual(snapshot.values[expectedValue], 1,
|
||||
"histogram has expected content");
|
||||
} else {
|
||||
Assert.deepEqual(!!snapshot.values[expectedValue], false,
|
||||
"histogram has expected content");
|
||||
expectedCounts[expectedValue] = 1;
|
||||
}
|
||||
Assert.deepEqual(snapshot.counts, expectedCounts,
|
||||
"histogram has expected content");
|
||||
histogram.clear();
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ function test() {
|
|||
var snapshot = Services.telemetry.getHistogramById("STARTUP_MEASUREMENT_ERRORS")
|
||||
.snapshot();
|
||||
|
||||
if (snapshot.values[0] == 0)
|
||||
if (snapshot.counts[0] == 0)
|
||||
ok(startup_info.process <= startup_info.main, "process created before main is run " + uneval(startup_info));
|
||||
else
|
||||
todo(false, "An error occurred while recording the process creation timestamp, skipping this test");
|
||||
|
|
|
@ -62,8 +62,8 @@ add_task(async function test_no_files_exist() {
|
|||
// Checking if the histogram is updated negatively
|
||||
let h = Telemetry.getHistogramById(HistogramId);
|
||||
let s = h.snapshot();
|
||||
Assert.equal(s.values[0], 1, "One probe for the 'false' bucket.");
|
||||
Assert.equal(s.values[1], 0, "No probes in the 'true' bucket.");
|
||||
Assert.equal(s.counts[0], 1, "One probe for the 'false' bucket.");
|
||||
Assert.equal(s.counts[1], 0, "No probes in the 'true' bucket.");
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -85,8 +85,8 @@ add_task(async function test_one_file_valid() {
|
|||
// Checking if the histogram is updated negatively.
|
||||
let h = Telemetry.getHistogramById(HistogramId);
|
||||
let s = h.snapshot();
|
||||
Assert.equal(s.values[0], 1, "One probe for the 'false' bucket.");
|
||||
Assert.equal(s.values[1], 0, "No probes in the 'true' bucket.");
|
||||
Assert.equal(s.counts[0], 1, "One probe for the 'false' bucket.");
|
||||
Assert.equal(s.counts[1], 0, "No probes in the 'true' bucket.");
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -107,6 +107,6 @@ add_task(async function test_all_files_corrupt() {
|
|||
// Checking if the histogram is positively updated.
|
||||
let h = Telemetry.getHistogramById(HistogramId);
|
||||
let s = h.snapshot();
|
||||
Assert.equal(s.values[1], 1, "One probe for the 'true' bucket.");
|
||||
Assert.equal(s.values[0], 0, "No probes in the 'false' bucket.");
|
||||
Assert.equal(s.counts[1], 1, "One probe for the 'true' bucket.");
|
||||
Assert.equal(s.counts[0], 0, "No probes in the 'false' bucket.");
|
||||
});
|
||||
|
|
|
@ -39,8 +39,8 @@ var MetricsChecker = {
|
|||
deniedOffers: this.HISTOGRAMS.DENIED.snapshot().sum || 0,
|
||||
autoRejectedOffers: this.HISTOGRAMS.AUTO_REJECTED.snapshot().sum || 0,
|
||||
showOriginal: this.HISTOGRAMS.SHOW_ORIGINAL.snapshot().sum || 0,
|
||||
detectedLanguageChangedBefore: this.HISTOGRAMS.DETECTION_CHANGES.snapshot().values[1] || 0,
|
||||
detectedLanguageChangeAfter: this.HISTOGRAMS.DETECTION_CHANGES.snapshot().values[0] || 0,
|
||||
detectedLanguageChangedBefore: this.HISTOGRAMS.DETECTION_CHANGES.snapshot().counts[1] || 0,
|
||||
detectedLanguageChangeAfter: this.HISTOGRAMS.DETECTION_CHANGES.snapshot().counts[0] || 0,
|
||||
targetLanguageChanged: this.HISTOGRAMS.TARGET_CHANGES.snapshot().sum || 0,
|
||||
showUI: this.HISTOGRAMS.SHOW_UI.snapshot().sum || 0,
|
||||
detectLang: this.HISTOGRAMS.DETECT_LANG.snapshot().sum || 0,
|
||||
|
|
|
@ -137,19 +137,20 @@ add_task(async function test_subsessionSplit() {
|
|||
});
|
||||
|
||||
function checkTabCountHistogram(result, expected, message) {
|
||||
Assert.deepEqual(result.values, expected, message);
|
||||
let expectedPadded = result.counts.map((val, idx) => idx < expected.length ? expected[idx] : 0);
|
||||
Assert.deepEqual(result.counts, expectedPadded, message);
|
||||
}
|
||||
|
||||
add_task(async function test_tabsHistogram() {
|
||||
let openedTabs = [];
|
||||
let tabCountHist = getAndClearHistogram("TAB_COUNT");
|
||||
|
||||
checkTabCountHistogram(tabCountHist.snapshot(), {}, "TAB_COUNT telemetry - initial tab counts");
|
||||
checkTabCountHistogram(tabCountHist.snapshot(), [0, 0], "TAB_COUNT telemetry - initial tab counts");
|
||||
|
||||
// Add a new tab and check that the count is right.
|
||||
BrowserUsageTelemetry._lastRecordTabCount = 0;
|
||||
openedTabs.push(await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:blank"));
|
||||
checkTabCountHistogram(tabCountHist.snapshot(), {1: 0, 2: 1, 3: 0}, "TAB_COUNT telemetry - opening tabs");
|
||||
checkTabCountHistogram(tabCountHist.snapshot(), [0, 0, 1], "TAB_COUNT telemetry - opening tabs");
|
||||
|
||||
// Open a different page and check the counts.
|
||||
BrowserUsageTelemetry._lastRecordTabCount = 0;
|
||||
|
@ -158,24 +159,24 @@ add_task(async function test_tabsHistogram() {
|
|||
BrowserUsageTelemetry._lastRecordTabCount = 0;
|
||||
await BrowserTestUtils.loadURI(tab.linkedBrowser, "http://example.com/");
|
||||
await BrowserTestUtils.browserLoaded(tab.linkedBrowser);
|
||||
checkTabCountHistogram(tabCountHist.snapshot(), {1: 0, 2: 1, 3: 2, 4: 0}, "TAB_COUNT telemetry - loading page");
|
||||
checkTabCountHistogram(tabCountHist.snapshot(), [0, 0, 1, 2], "TAB_COUNT telemetry - loading page");
|
||||
|
||||
// Open another tab
|
||||
BrowserUsageTelemetry._lastRecordTabCount = 0;
|
||||
openedTabs.push(await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:blank"));
|
||||
checkTabCountHistogram(tabCountHist.snapshot(), {1: 0, 2: 1, 3: 2, 4: 1, 5: 0}, "TAB_COUNT telemetry - opening more tabs");
|
||||
checkTabCountHistogram(tabCountHist.snapshot(), [0, 0, 1, 2, 1], "TAB_COUNT telemetry - opening more tabs");
|
||||
|
||||
// Add a new window and then some tabs in it. A new window starts with one tab.
|
||||
BrowserUsageTelemetry._lastRecordTabCount = 0;
|
||||
let win = await BrowserTestUtils.openNewBrowserWindow();
|
||||
checkTabCountHistogram(tabCountHist.snapshot(), {1: 0, 2: 1, 3: 2, 4: 1, 5: 1, 6: 0}, "TAB_COUNT telemetry - opening window");
|
||||
checkTabCountHistogram(tabCountHist.snapshot(), [0, 0, 1, 2, 1, 1], "TAB_COUNT telemetry - opening window");
|
||||
|
||||
// Do not trigger a recount if _lastRecordTabCount is recent on new tab
|
||||
BrowserUsageTelemetry._lastRecordTabCount = Date.now() - (MINIMUM_TAB_COUNT_INTERVAL_MS / 2);
|
||||
{
|
||||
let oldLastRecordTabCount = BrowserUsageTelemetry._lastRecordTabCount;
|
||||
openedTabs.push(await BrowserTestUtils.openNewForegroundTab(win.gBrowser, "about:blank"));
|
||||
checkTabCountHistogram(tabCountHist.snapshot(), {1: 0, 2: 1, 3: 2, 4: 1, 5: 1, 6: 0}, "TAB_COUNT telemetry - new tab, recount event ignored");
|
||||
checkTabCountHistogram(tabCountHist.snapshot(), [0, 0, 1, 2, 1, 1, 0], "TAB_COUNT telemetry - new tab, recount event ignored");
|
||||
ok(BrowserUsageTelemetry._lastRecordTabCount == oldLastRecordTabCount, "TAB_COUNT telemetry - _lastRecordTabCount unchanged");
|
||||
}
|
||||
|
||||
|
@ -184,7 +185,7 @@ add_task(async function test_tabsHistogram() {
|
|||
{
|
||||
let oldLastRecordTabCount = BrowserUsageTelemetry._lastRecordTabCount;
|
||||
openedTabs.push(await BrowserTestUtils.openNewForegroundTab(win.gBrowser, "about:blank"));
|
||||
checkTabCountHistogram(tabCountHist.snapshot(), {1: 0, 2: 1, 3: 2, 4: 1, 5: 1, 7: 1, 8: 0}, "TAB_COUNT telemetry - new tab, recount event included");
|
||||
checkTabCountHistogram(tabCountHist.snapshot(), [0, 0, 1, 2, 1, 1, 0, 1], "TAB_COUNT telemetry - new tab, recount event included");
|
||||
ok(BrowserUsageTelemetry._lastRecordTabCount != oldLastRecordTabCount, "TAB_COUNT telemetry - _lastRecordTabCount updated");
|
||||
ok(BrowserUsageTelemetry._lastRecordTabCount > Date.now() - MINIMUM_TAB_COUNT_INTERVAL_MS, "TAB_COUNT telemetry - _lastRecordTabCount invariant");
|
||||
}
|
||||
|
@ -195,7 +196,7 @@ add_task(async function test_tabsHistogram() {
|
|||
let oldLastRecordTabCount = BrowserUsageTelemetry._lastRecordTabCount;
|
||||
await BrowserTestUtils.loadURI(tab.linkedBrowser, "http://example.com/");
|
||||
await BrowserTestUtils.browserLoaded(tab.linkedBrowser);
|
||||
checkTabCountHistogram(tabCountHist.snapshot(), {1: 0, 2: 1, 3: 2, 4: 1, 5: 1, 7: 1, 8: 0}, "TAB_COUNT telemetry - page load, recount event ignored");
|
||||
checkTabCountHistogram(tabCountHist.snapshot(), [0, 0, 1, 2, 1, 1, 0, 1], "TAB_COUNT telemetry - page load, recount event ignored");
|
||||
ok(BrowserUsageTelemetry._lastRecordTabCount == oldLastRecordTabCount, "TAB_COUNT telemetry - _lastRecordTabCount unchanged");
|
||||
}
|
||||
|
||||
|
@ -205,7 +206,7 @@ add_task(async function test_tabsHistogram() {
|
|||
let oldLastRecordTabCount = BrowserUsageTelemetry._lastRecordTabCount;
|
||||
await BrowserTestUtils.loadURI(tab.linkedBrowser, "http://example.com/");
|
||||
await BrowserTestUtils.browserLoaded(tab.linkedBrowser);
|
||||
checkTabCountHistogram(tabCountHist.snapshot(), {1: 0, 2: 1, 3: 2, 4: 1, 5: 1, 7: 2, 8: 0}, "TAB_COUNT telemetry - page load, recount event included");
|
||||
checkTabCountHistogram(tabCountHist.snapshot(), [0, 0, 1, 2, 1, 1, 0, 2], "TAB_COUNT telemetry - page load, recount event included");
|
||||
ok(BrowserUsageTelemetry._lastRecordTabCount != oldLastRecordTabCount, "TAB_COUNT telemetry - _lastRecordTabCount updated");
|
||||
ok(BrowserUsageTelemetry._lastRecordTabCount > Date.now() - MINIMUM_TAB_COUNT_INTERVAL_MS, "TAB_COUNT telemetry - _lastRecordTabCount invariant");
|
||||
}
|
||||
|
|
|
@ -9,12 +9,12 @@ ChromeUtils.import("resource://testing-common/CustomizableUITestUtils.jsm", this
|
|||
let gCUITestUtils = new CustomizableUITestUtils(window);
|
||||
|
||||
function checkHistogramResults(resultIndexes, expected, histogram) {
|
||||
for (let [i, val] of Object.entries(resultIndexes.values)) {
|
||||
for (let i = 0; i < resultIndexes.counts.length; i++) {
|
||||
if (i == expected) {
|
||||
Assert.equal(val, 1,
|
||||
Assert.equal(resultIndexes.counts[i], 1,
|
||||
`expected counts should match for ${histogram} index ${i}`);
|
||||
} else {
|
||||
Assert.equal(!!val, false,
|
||||
Assert.equal(resultIndexes.counts[i], 0,
|
||||
`unexpected counts should be zero for ${histogram} index ${i}`);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,12 +15,12 @@ ChromeUtils.defineModuleGetter(this, "URLBAR_SELECTED_RESULT_METHODS",
|
|||
"resource:///modules/BrowserUsageTelemetry.jsm");
|
||||
|
||||
function checkHistogramResults(resultIndexes, expected, histogram) {
|
||||
for (let [i, val] of Object.entries(resultIndexes.values)) {
|
||||
for (let i = 0; i < resultIndexes.counts.length; i++) {
|
||||
if (i == expected) {
|
||||
Assert.equal(val, 1,
|
||||
Assert.equal(resultIndexes.counts[i], 1,
|
||||
`expected counts should match for ${histogram} index ${i}`);
|
||||
} else {
|
||||
Assert.equal(!!val, false,
|
||||
Assert.equal(resultIndexes.counts[i], 0,
|
||||
`unexpected counts should be zero for ${histogram} index ${i}`);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,5 +41,5 @@ function checkResults() {
|
|||
// - 2 "left" entries.
|
||||
// - 3 "right" entries.
|
||||
// - 2 "window" entries.
|
||||
checkTelemetry("DEVTOOLS_TOOLBOX_HOST", "", {0: 3, 1: 3, 2: 2, 4: 2, 5: 0}, "array");
|
||||
checkTelemetry("DEVTOOLS_TOOLBOX_HOST", "", [3, 3, 2, 0, 2, 0, 0, 0, 0, 0], "array");
|
||||
}
|
||||
|
|
|
@ -44,5 +44,6 @@ function checkResults() {
|
|||
// Check for:
|
||||
// - 1 CSS Grid Element
|
||||
checkTelemetry("DEVTOOLS_NUMBER_OF_CSS_GRIDS_IN_A_PAGE", "",
|
||||
{0: 0, 1: 1, 2: 0}, "array");
|
||||
[0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "array");
|
||||
}
|
||||
|
|
|
@ -39,18 +39,14 @@ add_task(async function() {
|
|||
function checkResults() {
|
||||
// For help generating these tests use generateTelemetryTests("DEVTOOLS_PERFTOOLS_")
|
||||
// here.
|
||||
checkTelemetry("DEVTOOLS_PERFTOOLS_RECORDING_COUNT", "", {0: 2, 1: 0}, "array");
|
||||
checkTelemetry("DEVTOOLS_PERFTOOLS_RECORDING_COUNT", "", [2, 0, 0], "array");
|
||||
checkTelemetry("DEVTOOLS_PERFTOOLS_RECORDING_DURATION_MS", "", null, "hasentries");
|
||||
checkTelemetry(
|
||||
"DEVTOOLS_PERFTOOLS_RECORDING_FEATURES_USED", "withMarkers", {0: 0, 1: 2, 2: 0},
|
||||
"array");
|
||||
"DEVTOOLS_PERFTOOLS_RECORDING_FEATURES_USED", "withMarkers", [0, 2, 0], "array");
|
||||
checkTelemetry(
|
||||
"DEVTOOLS_PERFTOOLS_RECORDING_FEATURES_USED", "withMemory", {0: 1, 1: 1, 2: 0},
|
||||
"array");
|
||||
"DEVTOOLS_PERFTOOLS_RECORDING_FEATURES_USED", "withMemory", [1, 1, 0], "array");
|
||||
checkTelemetry(
|
||||
"DEVTOOLS_PERFTOOLS_RECORDING_FEATURES_USED", "withAllocations", {0: 2, 1: 0},
|
||||
"array");
|
||||
"DEVTOOLS_PERFTOOLS_RECORDING_FEATURES_USED", "withAllocations", [2, 0, 0], "array");
|
||||
checkTelemetry(
|
||||
"DEVTOOLS_PERFTOOLS_RECORDING_FEATURES_USED", "withTicks", {0: 0, 1: 2, 2: 0},
|
||||
"array");
|
||||
"DEVTOOLS_PERFTOOLS_RECORDING_FEATURES_USED", "withTicks", [0, 2, 0], "array");
|
||||
}
|
||||
|
|
|
@ -44,8 +44,6 @@ add_task(async function() {
|
|||
function checkResults() {
|
||||
// For help generating these tests use generateTelemetryTests("DEVTOOLS_PERFTOOLS_")
|
||||
// here.
|
||||
checkTelemetry("DEVTOOLS_PERFTOOLS_RECORDING_IMPORT_FLAG", "", {0: 0, 1: 1, 2: 0},
|
||||
"array");
|
||||
checkTelemetry("DEVTOOLS_PERFTOOLS_RECORDING_EXPORT_FLAG", "", {0: 0, 1: 1, 2: 0},
|
||||
"array");
|
||||
checkTelemetry("DEVTOOLS_PERFTOOLS_RECORDING_IMPORT_FLAG", "", [0, 1, 0], "array");
|
||||
checkTelemetry("DEVTOOLS_PERFTOOLS_RECORDING_EXPORT_FLAG", "", [0, 1, 0], "array");
|
||||
}
|
||||
|
|
|
@ -41,17 +41,14 @@ add_task(async function() {
|
|||
function checkResults() {
|
||||
// For help generating these tests use generateTelemetryTests("DEVTOOLS_PERFTOOLS_")
|
||||
// here.
|
||||
checkTelemetry("DEVTOOLS_PERFTOOLS_CONSOLE_RECORDING_COUNT", "", {0: 1, 1: 0}, "array");
|
||||
checkTelemetry("DEVTOOLS_PERFTOOLS_CONSOLE_RECORDING_COUNT", "", [1, 0, 0], "array");
|
||||
checkTelemetry("DEVTOOLS_PERFTOOLS_RECORDING_DURATION_MS", "", null, "hasentries");
|
||||
checkTelemetry(
|
||||
"DEVTOOLS_PERFTOOLS_RECORDING_FEATURES_USED", "withMarkers", {0: 0, 1: 1, 2: 0},
|
||||
"array");
|
||||
"DEVTOOLS_PERFTOOLS_RECORDING_FEATURES_USED", "withMarkers", [0, 1, 0], "array");
|
||||
checkTelemetry(
|
||||
"DEVTOOLS_PERFTOOLS_RECORDING_FEATURES_USED", "withMemory", {0: 1, 1: 0}, "array");
|
||||
"DEVTOOLS_PERFTOOLS_RECORDING_FEATURES_USED", "withMemory", [1, 0, 0], "array");
|
||||
checkTelemetry(
|
||||
"DEVTOOLS_PERFTOOLS_RECORDING_FEATURES_USED", "withAllocations", {0: 1, 1: 0},
|
||||
"array");
|
||||
"DEVTOOLS_PERFTOOLS_RECORDING_FEATURES_USED", "withAllocations", [1, 0, 0], "array");
|
||||
checkTelemetry(
|
||||
"DEVTOOLS_PERFTOOLS_RECORDING_FEATURES_USED", "withTicks", {0: 0, 1: 1, 2: 0},
|
||||
"array");
|
||||
"DEVTOOLS_PERFTOOLS_RECORDING_FEATURES_USED", "withTicks", [0, 1, 0], "array");
|
||||
}
|
||||
|
|
|
@ -52,6 +52,6 @@ async function delayedClicks(toolbox, node, clicks) {
|
|||
function checkResults() {
|
||||
// For help generating these tests use generateTelemetryTests("DEVTOOLS_PAINTFLASHING_")
|
||||
// here.
|
||||
checkTelemetry("DEVTOOLS_PAINTFLASHING_OPENED_COUNT", "", {0: 2, 1: 0}, "array");
|
||||
checkTelemetry("DEVTOOLS_PAINTFLASHING_OPENED_COUNT", "", [2, 0, 0], "array");
|
||||
checkTelemetry("DEVTOOLS_PAINTFLASHING_TIME_ACTIVE_SECONDS", "", null, "hasentries");
|
||||
}
|
||||
|
|
|
@ -84,6 +84,6 @@ var delayedClicks = async function(node, clicks) {
|
|||
function checkResults() {
|
||||
// For help generating these tests use generateTelemetryTests("DEVTOOLS_RESPONSIVE_")
|
||||
// here.
|
||||
checkTelemetry("DEVTOOLS_RESPONSIVE_OPENED_COUNT", "", {0: 2, 1: 0}, "array");
|
||||
checkTelemetry("DEVTOOLS_RESPONSIVE_OPENED_COUNT", "", [2, 0, 0], "array");
|
||||
checkTelemetry("DEVTOOLS_RESPONSIVE_TIME_ACTIVE_SECONDS", "", null, "hasentries");
|
||||
}
|
||||
|
|
|
@ -97,5 +97,5 @@ function delayedClicks(node, clicks) {
|
|||
function checkResults() {
|
||||
// For help generating these tests use generateTelemetryTests("DEVTOOLS_SCRATCHPAD_")
|
||||
// here.
|
||||
checkTelemetry("DEVTOOLS_SCRATCHPAD_WINDOW_OPENED_COUNT", "", {0: 4, 1: 0}, "array");
|
||||
checkTelemetry("DEVTOOLS_SCRATCHPAD_WINDOW_OPENED_COUNT", "", [4, 0, 0], "array");
|
||||
}
|
||||
|
|
|
@ -20,9 +20,9 @@ add_task(async function() {
|
|||
function checkResults() {
|
||||
// For help generating these tests use generateTelemetryTests("DEVTOOLS_")
|
||||
// here.
|
||||
checkTelemetry("DEVTOOLS_TOOLBOX_OPENED_COUNT", "", {0: 1, 1: 0}, "array");
|
||||
checkTelemetry("DEVTOOLS_INSPECTOR_OPENED_COUNT", "", {0: 1, 1: 0}, "array");
|
||||
checkTelemetry("DEVTOOLS_RULEVIEW_OPENED_COUNT", "", {0: 1, 1: 0}, "array");
|
||||
checkTelemetry("DEVTOOLS_TOOLBOX_OPENED_COUNT", "", [1, 0, 0], "array");
|
||||
checkTelemetry("DEVTOOLS_INSPECTOR_OPENED_COUNT", "", [1, 0, 0], "array");
|
||||
checkTelemetry("DEVTOOLS_RULEVIEW_OPENED_COUNT", "", [1, 0, 0], "array");
|
||||
checkTelemetry("DEVTOOLS_TOOLBOX_TIME_ACTIVE_SECONDS", "", null, "hasentries");
|
||||
checkTelemetry("DEVTOOLS_INSPECTOR_TIME_ACTIVE_SECONDS", "", null, "hasentries");
|
||||
checkTelemetry("DEVTOOLS_RULEVIEW_TIME_ACTIVE_SECONDS", "", null, "hasentries");
|
||||
|
|
|
@ -154,11 +154,11 @@ function testSidebar(toolbox) {
|
|||
function checkResults() {
|
||||
// For help generating these tests use generateTelemetryTests("DEVTOOLS_")
|
||||
// here.
|
||||
checkTelemetry("DEVTOOLS_INSPECTOR_OPENED_COUNT", "", {0: 1, 1: 0}, "array");
|
||||
checkTelemetry("DEVTOOLS_RULEVIEW_OPENED_COUNT", "", {0: 1, 1: 0}, "array");
|
||||
checkTelemetry("DEVTOOLS_COMPUTEDVIEW_OPENED_COUNT", "", {0: 2, 1: 0}, "array");
|
||||
checkTelemetry("DEVTOOLS_LAYOUTVIEW_OPENED_COUNT", "", {0: 3, 1: 0}, "array");
|
||||
checkTelemetry("DEVTOOLS_FONTINSPECTOR_OPENED_COUNT", "", {0: 2, 1: 0}, "array");
|
||||
checkTelemetry("DEVTOOLS_INSPECTOR_OPENED_COUNT", "", [1, 0, 0], "array");
|
||||
checkTelemetry("DEVTOOLS_RULEVIEW_OPENED_COUNT", "", [1, 0, 0], "array");
|
||||
checkTelemetry("DEVTOOLS_COMPUTEDVIEW_OPENED_COUNT", "", [2, 0, 0], "array");
|
||||
checkTelemetry("DEVTOOLS_LAYOUTVIEW_OPENED_COUNT", "", [3, 0, 0], "array");
|
||||
checkTelemetry("DEVTOOLS_FONTINSPECTOR_OPENED_COUNT", "", [2, 0, 0], "array");
|
||||
checkTelemetry("DEVTOOLS_COMPUTEDVIEW_TIME_ACTIVE_SECONDS", "", null, "hasentries");
|
||||
checkTelemetry("DEVTOOLS_LAYOUTVIEW_TIME_ACTIVE_SECONDS", "", null, "hasentries");
|
||||
checkTelemetry("DEVTOOLS_FONTINSPECTOR_TIME_ACTIVE_SECONDS", "", null, "hasentries");
|
||||
|
|
|
@ -23,7 +23,7 @@ add_task(async function() {
|
|||
function checkResults() {
|
||||
// For help generating these tests use generateTelemetryTests("DEVTOOLS_TOOLBOX_")
|
||||
// here.
|
||||
checkTelemetry("DEVTOOLS_TOOLBOX_OPENED_COUNT", "", {0: 3, 1: 0}, "array");
|
||||
checkTelemetry("DEVTOOLS_TOOLBOX_OPENED_COUNT", "", [3, 0, 0], "array");
|
||||
checkTelemetry("DEVTOOLS_TOOLBOX_TIME_ACTIVE_SECONDS", "", null, "hasentries");
|
||||
checkTelemetry("DEVTOOLS_TOOLBOX_HOST", "", null, "hasentries");
|
||||
}
|
||||
|
|
|
@ -30,6 +30,6 @@ add_task(async function() {
|
|||
function checkResults() {
|
||||
// For help generating these tests use generateTelemetryTests("DEVTOOLS_CANVASDEBUGGER")
|
||||
// here.
|
||||
checkTelemetry("DEVTOOLS_CANVASDEBUGGER_OPENED_COUNT", "", {0: 2, 1: 0}, "array");
|
||||
checkTelemetry("DEVTOOLS_CANVASDEBUGGER_OPENED_COUNT", "", [2, 0, 0], "array");
|
||||
checkTelemetry("DEVTOOLS_CANVASDEBUGGER_TIME_ACTIVE_SECONDS", "", null, "hasentries");
|
||||
}
|
||||
|
|
|
@ -23,6 +23,6 @@ add_task(async function() {
|
|||
function checkResults() {
|
||||
// For help generating these tests use generateTelemetryTests("DEVTOOLS_INSPECTOR_")
|
||||
// here.
|
||||
checkTelemetry("DEVTOOLS_INSPECTOR_OPENED_COUNT", "", {0: 2, 1: 0}, "array");
|
||||
checkTelemetry("DEVTOOLS_INSPECTOR_OPENED_COUNT", "", [2, 0, 0], "array");
|
||||
checkTelemetry("DEVTOOLS_INSPECTOR_TIME_ACTIVE_SECONDS", "", null, "hasentries");
|
||||
}
|
||||
|
|
|
@ -23,6 +23,6 @@ add_task(async function() {
|
|||
function checkResults() {
|
||||
// For help generating these tests use generateTelemetryTests("DEVTOOLS_JSDEBUGGER_")
|
||||
// here.
|
||||
checkTelemetry("DEVTOOLS_JSDEBUGGER_OPENED_COUNT", "", {0: 2, 1: 0}, "array");
|
||||
checkTelemetry("DEVTOOLS_JSDEBUGGER_OPENED_COUNT", "", [2, 0, 0], "array");
|
||||
checkTelemetry("DEVTOOLS_JSDEBUGGER_TIME_ACTIVE_SECONDS", "", null, "hasentries");
|
||||
}
|
||||
|
|
|
@ -23,6 +23,6 @@ add_task(async function() {
|
|||
function checkResults() {
|
||||
// For help generating these tests use generateTelemetryTests("DEVTOOLS_JSPROFILER")
|
||||
// here.
|
||||
checkTelemetry("DEVTOOLS_JSPROFILER_OPENED_COUNT", "", {0: 2, 1: 0}, "array");
|
||||
checkTelemetry("DEVTOOLS_JSPROFILER_OPENED_COUNT", "", [2, 0, 0], "array");
|
||||
checkTelemetry("DEVTOOLS_JSPROFILER_TIME_ACTIVE_SECONDS", "", null, "hasentries");
|
||||
}
|
||||
|
|
|
@ -23,6 +23,6 @@ add_task(async function() {
|
|||
function checkResults() {
|
||||
// For help generating these tests use generateTelemetryTests("DEVTOOLS_NETMONITOR_")
|
||||
// here.
|
||||
checkTelemetry("DEVTOOLS_NETMONITOR_OPENED_COUNT", "", {0: 2, 1: 0}, "array");
|
||||
checkTelemetry("DEVTOOLS_NETMONITOR_OPENED_COUNT", "", [2, 0, 0], "array");
|
||||
checkTelemetry("DEVTOOLS_NETMONITOR_TIME_ACTIVE_SECONDS", "", null, "hasentries");
|
||||
}
|
||||
|
|
|
@ -23,6 +23,6 @@ add_task(async function() {
|
|||
function checkResults() {
|
||||
// For help generating these tests use generateTelemetryTests("DEVTOOLS_OPTIONS_")
|
||||
// here.
|
||||
checkTelemetry("DEVTOOLS_OPTIONS_OPENED_COUNT", "", {0: 2, 1: 0}, "array");
|
||||
checkTelemetry("DEVTOOLS_OPTIONS_OPENED_COUNT", "", [2, 0, 0], "array");
|
||||
checkTelemetry("DEVTOOLS_OPTIONS_TIME_ACTIVE_SECONDS", "", null, "hasentries");
|
||||
}
|
||||
|
|
|
@ -31,6 +31,6 @@ add_task(async function() {
|
|||
function checkResults() {
|
||||
// For help generating these tests use generateTelemetryTests("DEVTOOLS_SHADEREDITOR_")
|
||||
// here.
|
||||
checkTelemetry("DEVTOOLS_SHADEREDITOR_OPENED_COUNT", "", {0: 2, 1: 0}, "array");
|
||||
checkTelemetry("DEVTOOLS_SHADEREDITOR_OPENED_COUNT", "", [2, 0, 0], "array");
|
||||
checkTelemetry("DEVTOOLS_SHADEREDITOR_TIME_ACTIVE_SECONDS", "", null, "hasentries");
|
||||
}
|
||||
|
|
|
@ -23,6 +23,6 @@ add_task(async function() {
|
|||
function checkResults() {
|
||||
// For help generating these tests use generateTelemetryTests("DEVTOOLS_STORAGE_")
|
||||
// here.
|
||||
checkTelemetry("DEVTOOLS_STORAGE_OPENED_COUNT", "", {0: 2, 1: 0}, "array");
|
||||
checkTelemetry("DEVTOOLS_STORAGE_OPENED_COUNT", "", [2, 0, 0], "array");
|
||||
checkTelemetry("DEVTOOLS_STORAGE_TIME_ACTIVE_SECONDS", "", null, "hasentries");
|
||||
}
|
||||
|
|
|
@ -23,6 +23,6 @@ add_task(async function() {
|
|||
function checkResults() {
|
||||
// For help generating these tests use generateTelemetryTests("DEVTOOLS_STYLEEDITOR_")
|
||||
// here.
|
||||
checkTelemetry("DEVTOOLS_STYLEEDITOR_OPENED_COUNT", "", {0: 2, 1: 0}, "array");
|
||||
checkTelemetry("DEVTOOLS_STYLEEDITOR_OPENED_COUNT", "", [2, 0, 0], "array");
|
||||
checkTelemetry("DEVTOOLS_STYLEEDITOR_TIME_ACTIVE_SECONDS", "", null, "hasentries");
|
||||
}
|
||||
|
|
|
@ -30,6 +30,6 @@ add_task(async function() {
|
|||
function checkResults() {
|
||||
// For help generating these tests use generateTelemetryTests("DEVTOOLS_WEBAUDIOEDITOR")
|
||||
// here.
|
||||
checkTelemetry("DEVTOOLS_WEBAUDIOEDITOR_OPENED_COUNT", "", {0: 2, 1: 0}, "array");
|
||||
checkTelemetry("DEVTOOLS_WEBAUDIOEDITOR_OPENED_COUNT", "", [2, 0, 0], "array");
|
||||
checkTelemetry("DEVTOOLS_WEBAUDIOEDITOR_TIME_ACTIVE_SECONDS", "", null, "hasentries");
|
||||
}
|
||||
|
|
|
@ -23,6 +23,6 @@ add_task(async function() {
|
|||
function checkResults() {
|
||||
// For help generating these tests use generateTelemetryTests("DEVTOOLS_WEBCONSOLE_")
|
||||
// here.
|
||||
checkTelemetry("DEVTOOLS_WEBCONSOLE_OPENED_COUNT", "", {0: 2, 1: 0}, "array");
|
||||
checkTelemetry("DEVTOOLS_WEBCONSOLE_OPENED_COUNT", "", [2, 0, 0], "array");
|
||||
checkTelemetry("DEVTOOLS_WEBCONSOLE_TIME_ACTIVE_SECONDS", "", null, "hasentries");
|
||||
}
|
||||
|
|
|
@ -103,13 +103,13 @@ class TelemetryHelpers {
|
|||
const result = keyedHistogram[key];
|
||||
|
||||
if (result) {
|
||||
actual = result.values;
|
||||
actual = result.counts;
|
||||
} else {
|
||||
ok(false, `${histId}[${key}] exists`);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
actual = Services.telemetry.getHistogramById(histId).snapshot().values;
|
||||
actual = Services.telemetry.getHistogramById(histId).snapshot().counts;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -119,7 +119,7 @@ class TelemetryHelpers {
|
|||
is(JSON.stringify(actual), JSON.stringify(expected), msg);
|
||||
break;
|
||||
case "hasentries":
|
||||
const hasEntry = Object.values(actual).some(num => num > 0);
|
||||
const hasEntry = actual.some(num => num > 0);
|
||||
if (key) {
|
||||
ok(hasEntry, `${histId}["${key}"] has at least one entry.`);
|
||||
} else {
|
||||
|
|
|
@ -30,7 +30,10 @@ function validateHistogramEntryCount(aHistogramName, aExpectedCount) {
|
|||
let hist = Services.telemetry.getHistogramById(aHistogramName);
|
||||
let resultIndexes = hist.snapshot();
|
||||
|
||||
let entriesSeen = Object.values(resultIndexes.values).reduce((a,b) => a + b, 0);
|
||||
let entriesSeen = 0;
|
||||
for (let i = 0; i < resultIndexes.counts.length; i++) {
|
||||
entriesSeen += resultIndexes.counts[i];
|
||||
}
|
||||
|
||||
is(entriesSeen, aExpectedCount, "Expecting " + aExpectedCount + " histogram entries in " +
|
||||
aHistogramName);
|
||||
|
|
|
@ -26,6 +26,57 @@ const IS_CONTENT_PROCESS = (function() {
|
|||
return runtime.processType == Ci.nsIXULRuntime.PROCESS_TYPE_CONTENT;
|
||||
})();
|
||||
|
||||
/**
|
||||
* When reflecting a histogram into JS, Telemetry hands us an object
|
||||
* with the following properties:
|
||||
*
|
||||
* - min, max, histogram_type, sum, sum_squares_{lo,hi}: simple integers;
|
||||
* - counts: array of counts for histogram buckets;
|
||||
* - ranges: array of calculated bucket sizes.
|
||||
*
|
||||
* This format is not straightforward to read and potentially bulky
|
||||
* with lots of zeros in the counts array. Packing histograms makes
|
||||
* raw histograms easier to read and compresses the data a little bit.
|
||||
*
|
||||
* Returns an object:
|
||||
* { range: [min, max], bucket_count: <number of buckets>,
|
||||
* histogram_type: <histogram_type>, sum: <sum>,
|
||||
* values: { bucket1: count1, bucket2: count2, ... } }
|
||||
*/
|
||||
function packHistogram(hgram) {
|
||||
let r = hgram.ranges;
|
||||
let c = hgram.counts;
|
||||
let retgram = {
|
||||
range: [r[1], r[r.length - 1]],
|
||||
bucket_count: r.length,
|
||||
histogram_type: hgram.histogram_type,
|
||||
values: {},
|
||||
sum: hgram.sum,
|
||||
};
|
||||
|
||||
let first = true;
|
||||
let last = 0;
|
||||
|
||||
for (let i = 0; i < c.length; i++) {
|
||||
let value = c[i];
|
||||
if (!value)
|
||||
continue;
|
||||
|
||||
// add a lower bound
|
||||
if (i && first) {
|
||||
retgram.values[r[i - 1]] = 0;
|
||||
}
|
||||
first = false;
|
||||
last = i + 1;
|
||||
retgram.values[r[i]] = value;
|
||||
}
|
||||
|
||||
// add an upper bound
|
||||
if (last && last < c.length)
|
||||
retgram.values[r[last]] = 0;
|
||||
return retgram;
|
||||
}
|
||||
|
||||
var TelemetryUtils = {
|
||||
Preferences: Object.freeze({
|
||||
// General Preferences
|
||||
|
@ -273,7 +324,7 @@ var TelemetryUtils = {
|
|||
ret[process] = {};
|
||||
for (let [name, value] of Object.entries(histograms)) {
|
||||
if (testingMode || !name.startsWith("TELEMETRY_TEST_")) {
|
||||
ret[process][name] = value;
|
||||
ret[process][name] = packHistogram(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -322,7 +373,7 @@ var TelemetryUtils = {
|
|||
}
|
||||
ret[process][name] = {};
|
||||
for (let [key, hgram] of Object.entries(value)) {
|
||||
ret[process][name][key] = hgram;
|
||||
ret[process][name][key] = packHistogram(hgram);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -747,25 +747,16 @@ internal_GetHistogramAndSamples(const StaticMutexAutoLock& aLock,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reflect a histogram snapshot into a JavaScript object.
|
||||
* The returned histogram object will have the following properties:
|
||||
*
|
||||
* bucket_count - Number of buckets of this histogram
|
||||
* histogram_type - HISTOGRAM_EXPONENTIAL, HISTOGRAM_LINEAR, HISTOGRAM_BOOLEAN,
|
||||
* HISTOGRAM_FLAG, HISTOGRAM_COUNT, or HISTOGRAM_CATEGORICAL
|
||||
* sum - sum of the bucket contents
|
||||
* range - A 2-item array of minimum and maximum bucket size
|
||||
* values - Map from bucket start to the bucket's count
|
||||
*/
|
||||
nsresult
|
||||
internal_ReflectHistogramAndSamples(JSContext *cx,
|
||||
JS::Handle<JSObject*> obj,
|
||||
const HistogramInfo& aHistogramInfo,
|
||||
const HistogramSnapshotData& aSnapshot)
|
||||
{
|
||||
if (!(JS_DefineProperty(cx, obj, "bucket_count",
|
||||
aHistogramInfo.bucketCount, JSPROP_ENUMERATE)
|
||||
if (!(JS_DefineProperty(cx, obj, "min",
|
||||
aHistogramInfo.min, JSPROP_ENUMERATE)
|
||||
&& JS_DefineProperty(cx, obj, "max",
|
||||
aHistogramInfo.max, JSPROP_ENUMERATE)
|
||||
&& JS_DefineProperty(cx, obj, "histogram_type",
|
||||
aHistogramInfo.histogramType, JSPROP_ENUMERATE)
|
||||
&& JS_DefineProperty(cx, obj, "sum",
|
||||
|
@ -780,54 +771,29 @@ internal_ReflectHistogramAndSamples(JSContext *cx,
|
|||
MOZ_ASSERT(count == aSnapshot.mBucketRanges.Length(),
|
||||
"The number of buckets and the number of counts must match.");
|
||||
|
||||
// Create the "range" property and add it to the final object.
|
||||
JS::Rooted<JSObject*> rarray(cx, JS_NewArrayObject(cx, 2));
|
||||
if (rarray == nullptr
|
||||
|| !JS_DefineProperty(cx, obj, "range", rarray, JSPROP_ENUMERATE)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
// Add [min, max] into the range array
|
||||
if (!JS_DefineElement(cx, rarray, 0, aHistogramInfo.min, JSPROP_ENUMERATE)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
if (!JS_DefineElement(cx, rarray, 1, aHistogramInfo.max, JSPROP_ENUMERATE)) {
|
||||
// Create the "ranges" property and add it to the final object.
|
||||
JS::Rooted<JSObject*> rarray(cx, JS_NewArrayObject(cx, count));
|
||||
if (!rarray
|
||||
|| !JS_DefineProperty(cx, obj, "ranges", rarray, JSPROP_ENUMERATE)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
JS::Rooted<JSObject*> values(cx, JS_NewPlainObject(cx));
|
||||
if (values == nullptr
|
||||
|| !JS_DefineProperty(cx, obj, "values", values, JSPROP_ENUMERATE)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
bool first = true;
|
||||
size_t last = 0;
|
||||
|
||||
// Fill the "ranges" property.
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
auto value = aSnapshot.mBucketCounts[i];
|
||||
if (value == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (i > 0 && first) {
|
||||
auto range = aSnapshot.mBucketRanges[i - 1];
|
||||
if (!JS_DefineProperty(cx, values, nsPrintfCString("%d", range).get(), 0, JSPROP_ENUMERATE)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
first = false;
|
||||
last = i + 1;
|
||||
|
||||
auto range = aSnapshot.mBucketRanges[i];
|
||||
if (!JS_DefineProperty(cx, values, nsPrintfCString("%d", range).get(), value, JSPROP_ENUMERATE)) {
|
||||
if (!JS_DefineElement(cx, rarray, i, aSnapshot.mBucketRanges[i], JSPROP_ENUMERATE)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
if (last > 0 && last < count) {
|
||||
auto range = aSnapshot.mBucketRanges[last];
|
||||
if (!JS_DefineProperty(cx, values, nsPrintfCString("%d", range).get(), 0, JSPROP_ENUMERATE)) {
|
||||
JS::Rooted<JSObject*> counts_array(cx, JS_NewArrayObject(cx, count));
|
||||
if (!counts_array
|
||||
|| !JS_DefineProperty(cx, obj, "counts", counts_array, JSPROP_ENUMERATE)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// Fill the "counts" property.
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
if (!JS_DefineElement(cx, counts_array, i, aSnapshot.mBucketCounts[i], JSPROP_ENUMERATE)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,13 +56,15 @@ interface nsITelemetry : nsISupports
|
|||
* The returned structure looks like:
|
||||
* { "process": { "name1": histogramData1, "name2": histogramData2 }, ... }
|
||||
*
|
||||
* Each histogram is represented in a packed format and has the following properties:
|
||||
* bucket_count - Number of buckets of this histogram
|
||||
* Where histogramDataN has the following properties:
|
||||
* min - minimum bucket size
|
||||
* max - maximum bucket size
|
||||
* histogram_type - HISTOGRAM_EXPONENTIAL, HISTOGRAM_LINEAR, HISTOGRAM_BOOLEAN,
|
||||
* HISTOGRAM_FLAG, HISTOGRAM_COUNT, or HISTOGRAM_CATEGORICAL
|
||||
* counts - array representing contents of the buckets in the histogram
|
||||
* ranges - array with calculated bucket sizes
|
||||
* sum - sum of the bucket contents
|
||||
* range - A 2-item array of minimum and maximum bucket size
|
||||
* values - Map from bucket to the bucket's count
|
||||
* TODO(bug 1468761): Return packed histograms.
|
||||
*
|
||||
* @param aStoreName The name of the store to snapshot. Ignored at the moment.
|
||||
* @param aClearStore Whether to clear out the histograms in the named store after snapshotting.
|
||||
|
@ -106,15 +108,16 @@ interface nsITelemetry : nsISupports
|
|||
/**
|
||||
* Serializes the histograms from the given dataset to a JSON-style object.
|
||||
* The returned structure looks like:
|
||||
* { "process": { "name1": histogramData1, "name2": histogramData2 }, ... }
|
||||
* { process1: {name1: {histogramData1}, name2:{histogramData2}...}}
|
||||
*
|
||||
* Each histogram is represented in a packed format and has the following properties:
|
||||
* bucket_count - Number of buckets of this histogram
|
||||
* Where histogramDataN has the following properties:
|
||||
* min - minimum bucket size
|
||||
* max - maximum bucket size
|
||||
* histogram_type - HISTOGRAM_EXPONENTIAL, HISTOGRAM_LINEAR, HISTOGRAM_BOOLEAN,
|
||||
* HISTOGRAM_FLAG, HISTOGRAM_COUNT, or HISTOGRAM_CATEGORICAL
|
||||
* counts - array representing contents of the buckets in the histogram
|
||||
* ranges - array with calculated bucket sizes
|
||||
* sum - sum of the bucket contents
|
||||
* range - A 2-item array of minimum and maximum bucket size
|
||||
* values - Map from bucket to the bucket's count
|
||||
*
|
||||
* @param aDataset DATASET_RELEASE_CHANNEL_OPTOUT or DATASET_RELEASE_CHANNEL_OPTIN.
|
||||
* @param aClear Whether to clear out the histograms after snapshotting
|
||||
|
|
|
@ -166,15 +166,15 @@ TEST_F(TelemetryTestFixture, AccumulateCategoricalHistogram)
|
|||
JS::RootedValue histogram(cx.GetJSContext());
|
||||
GetProperty(cx.GetJSContext(), "TELEMETRY_TEST_CATEGORICAL", snapshot, &histogram);
|
||||
|
||||
// Get values object from histogram. Each entry in the object maps to a label in the histogram.
|
||||
JS::RootedValue values(cx.GetJSContext());
|
||||
GetProperty(cx.GetJSContext(), "values", histogram, &values);
|
||||
// Get counts array from histogram. Each entry in the array maps to a label in the histogram.
|
||||
JS::RootedValue counts(cx.GetJSContext());
|
||||
GetProperty(cx.GetJSContext(), "counts", histogram, &counts);
|
||||
|
||||
// Get the value for the label we care about
|
||||
JS::RootedValue value(cx.GetJSContext());
|
||||
GetElement(cx.GetJSContext(),
|
||||
static_cast<uint32_t>(Telemetry::LABELS_TELEMETRY_TEST_CATEGORICAL::CommonLabel),
|
||||
values, &value);
|
||||
counts, &value);
|
||||
|
||||
// Check that the value stored in the histogram matches with |kExpectedValue|
|
||||
uint32_t uValue = 0;
|
||||
|
@ -213,14 +213,14 @@ TEST_F(TelemetryTestFixture, AccumulateKeyedCategoricalHistogram)
|
|||
// Check that the sample histogram contains the values we expect
|
||||
JS::RootedValue sample(cx.GetJSContext());
|
||||
GetProperty(cx.GetJSContext(), "sample", histogram, &sample);
|
||||
// Get values object from sample. Each entry in the object maps to a label in the histogram.
|
||||
JS::RootedValue sampleValues(cx.GetJSContext());
|
||||
GetProperty(cx.GetJSContext(), "values", sample, &sampleValues);
|
||||
// Get counts array from the sample. Each entry in the array maps to a label in the histogram.
|
||||
JS::RootedValue sampleCounts(cx.GetJSContext());
|
||||
GetProperty(cx.GetJSContext(), "counts", sample, &sampleCounts);
|
||||
// Get the value for the label we care about
|
||||
JS::RootedValue sampleValue(cx.GetJSContext());
|
||||
GetElement(cx.GetJSContext(),
|
||||
static_cast<uint32_t>(Telemetry::LABELS_TELEMETRY_TEST_KEYED_CATEGORICAL::CommonLabel),
|
||||
sampleValues, &sampleValue);
|
||||
sampleCounts, &sampleValue);
|
||||
// Check that the value stored in the histogram matches with |kSampleExpectedValue|
|
||||
uint32_t uSampleValue = 0;
|
||||
JS::ToUint32(cx.GetJSContext(), sampleValue, &uSampleValue);
|
||||
|
@ -229,14 +229,14 @@ TEST_F(TelemetryTestFixture, AccumulateKeyedCategoricalHistogram)
|
|||
// Check that the other-sample histogram contains the values we expect
|
||||
JS::RootedValue otherSample(cx.GetJSContext());
|
||||
GetProperty(cx.GetJSContext(), "other-sample", histogram, &otherSample);
|
||||
// Get values object from the other-sample. Each entry in the object maps to a label in the histogram.
|
||||
JS::RootedValue otherValues(cx.GetJSContext());
|
||||
GetProperty(cx.GetJSContext(), "values", otherSample, &otherValues);
|
||||
// Get counts array from the other-sample. Each entry in the array maps to a label in the histogram.
|
||||
JS::RootedValue otherCounts(cx.GetJSContext());
|
||||
GetProperty(cx.GetJSContext(), "counts", otherSample, &otherCounts);
|
||||
// Get the value for the label we care about
|
||||
JS::RootedValue otherValue(cx.GetJSContext());
|
||||
GetElement(cx.GetJSContext(),
|
||||
static_cast<uint32_t>(Telemetry::LABELS_TELEMETRY_TEST_KEYED_CATEGORICAL::CommonLabel),
|
||||
otherValues, &otherValue);
|
||||
otherCounts, &otherValue);
|
||||
// Check that the value stored in the histogram matches with |kOtherSampleExpectedValue|
|
||||
uint32_t uOtherValue = 0;
|
||||
JS::ToUint32(cx.GetJSContext(), otherValue, &uOtherValue);
|
||||
|
@ -295,14 +295,14 @@ TEST_F(TelemetryTestFixture, AccumulateLinearHistogram_MultipleSamples)
|
|||
JS::RootedValue histogram(cx.GetJSContext());
|
||||
GetProperty(cx.GetJSContext(), "TELEMETRY_TEST_LINEAR", snapshot, &histogram);
|
||||
|
||||
// Get "values" object from histogram
|
||||
JS::RootedValue values(cx.GetJSContext());
|
||||
GetProperty(cx.GetJSContext(), "values", histogram, &values);
|
||||
// Get "counts" array from histogram
|
||||
JS::RootedValue counts(cx.GetJSContext());
|
||||
GetProperty(cx.GetJSContext(), "counts", histogram, &counts);
|
||||
|
||||
// Index 0 is only for values less than 'low'. Values within range start at index 1
|
||||
JS::RootedValue count(cx.GetJSContext());
|
||||
const uint32_t index = 1;
|
||||
GetElement(cx.GetJSContext(), index, values, &count);
|
||||
GetElement(cx.GetJSContext(), index, counts, &count);
|
||||
|
||||
// Check that this count matches with nSamples
|
||||
uint32_t uCount = 0;
|
||||
|
@ -331,20 +331,19 @@ TEST_F(TelemetryTestFixture, AccumulateLinearHistogram_DifferentSamples)
|
|||
JS::RootedValue histogram(cx.GetJSContext());
|
||||
GetProperty(cx.GetJSContext(), "TELEMETRY_TEST_LINEAR", snapshot, &histogram);
|
||||
|
||||
// Get values object from histogram
|
||||
JS::RootedValue values(cx.GetJSContext());
|
||||
GetProperty(cx.GetJSContext(), "values", histogram, &values);
|
||||
// Get counts array from histogram
|
||||
JS::RootedValue counts(cx.GetJSContext());
|
||||
GetProperty(cx.GetJSContext(), "counts", histogram, &counts);
|
||||
|
||||
// Get values in first and last buckets
|
||||
// Get counts in first and last buckets
|
||||
JS::RootedValue countFirst(cx.GetJSContext());
|
||||
JS::RootedValue countLast(cx.GetJSContext());
|
||||
const uint32_t firstIndex = 1;
|
||||
// Buckets are indexed by their start value
|
||||
const uint32_t lastIndex = INT32_MAX - 1;
|
||||
GetElement(cx.GetJSContext(), firstIndex, values, &countFirst);
|
||||
GetElement(cx.GetJSContext(), lastIndex, values, &countLast);
|
||||
const uint32_t lastIndex = 9;
|
||||
GetElement(cx.GetJSContext(), firstIndex, counts, &countFirst);
|
||||
GetElement(cx.GetJSContext(), lastIndex, counts, &countLast);
|
||||
|
||||
// Check that the values match
|
||||
// Check that the counts match
|
||||
uint32_t uCountFirst = 0;
|
||||
uint32_t uCountLast = 0;
|
||||
JS::ToUint32(cx.GetJSContext(), countFirst, &uCountFirst);
|
||||
|
@ -431,20 +430,19 @@ TEST_F(TelemetryTestFixture, TestKeyedLinearHistogram_MultipleSamples)
|
|||
ASSERT_TRUE(!expectedKeyData.isUndefined())
|
||||
<< "Cannot find the expected key in the histogram data";
|
||||
|
||||
// Get values object from 'testkey' histogram.
|
||||
JS::RootedValue values(cx.GetJSContext());
|
||||
GetProperty(cx.GetJSContext(), "values", expectedKeyData, &values);
|
||||
// Get counts array from 'testkey' histogram.
|
||||
JS::RootedValue counts(cx.GetJSContext());
|
||||
GetProperty(cx.GetJSContext(), "counts", expectedKeyData, &counts);
|
||||
|
||||
// Get values in first and last buckets.
|
||||
// Get counts in first and last buckets.
|
||||
JS::RootedValue countFirst(cx.GetJSContext());
|
||||
JS::RootedValue countLast(cx.GetJSContext());
|
||||
const uint32_t firstIndex = 1;
|
||||
// Buckets are indexed by their start value
|
||||
const uint32_t lastIndex = 250000;
|
||||
GetElement(cx.GetJSContext(), firstIndex, values, &countFirst);
|
||||
GetElement(cx.GetJSContext(), lastIndex, values, &countLast);
|
||||
const uint32_t lastIndex = 9;
|
||||
GetElement(cx.GetJSContext(), firstIndex, counts, &countFirst);
|
||||
GetElement(cx.GetJSContext(), lastIndex, counts, &countLast);
|
||||
|
||||
// Check that the values match.
|
||||
// Check that the counts match.
|
||||
uint32_t uCountFirst = 0;
|
||||
uint32_t uCountLast = 0;
|
||||
JS::ToUint32(cx.GetJSContext(), countFirst, &uCountFirst);
|
||||
|
@ -497,10 +495,10 @@ TEST_F(TelemetryTestFixture, TestKeyedKeysHistogram_MultipleSamples)
|
|||
ASSERT_TRUE(!testKeyData.isUndefined())
|
||||
<< "Cannot find the key 'testkey' in the histogram data";
|
||||
|
||||
JS::RootedValue values(cx.GetJSContext());
|
||||
GetProperty(cx.GetJSContext(), "values", testKeyData, &values);
|
||||
JS::RootedValue counts(cx.GetJSContext());
|
||||
GetProperty(cx.GetJSContext(), "counts", testKeyData, &counts);
|
||||
|
||||
// Get values in buckets 0,1,2
|
||||
// Get counts in buckets 0,1,2
|
||||
const uint32_t falseIndex = 0;
|
||||
const uint32_t trueIndex = 1;
|
||||
const uint32_t otherIndex = 2;
|
||||
|
@ -509,9 +507,9 @@ TEST_F(TelemetryTestFixture, TestKeyedKeysHistogram_MultipleSamples)
|
|||
JS::RootedValue countTrue(cx.GetJSContext());
|
||||
JS::RootedValue countOther(cx.GetJSContext());
|
||||
|
||||
GetElement(cx.GetJSContext(), falseIndex, values, &countFalse);
|
||||
GetElement(cx.GetJSContext(), trueIndex, values, &countTrue);
|
||||
GetElement(cx.GetJSContext(), otherIndex, values, &countOther);
|
||||
GetElement(cx.GetJSContext(), falseIndex, counts, &countFalse);
|
||||
GetElement(cx.GetJSContext(), trueIndex, counts, &countTrue);
|
||||
GetElement(cx.GetJSContext(), otherIndex, counts, &countOther);
|
||||
|
||||
uint32_t uCountFalse = 0;
|
||||
uint32_t uCountTrue = 0;
|
||||
|
@ -580,15 +578,15 @@ TEST_F(TelemetryTestFixture, AccumulateCategoricalHistogram_MultipleStringLabels
|
|||
JS::RootedValue histogram(cx.GetJSContext());
|
||||
GetProperty(cx.GetJSContext(), "TELEMETRY_TEST_CATEGORICAL", snapshot, &histogram);
|
||||
|
||||
// Get values object from histogram. Each entry in the object maps to a label in the histogram.
|
||||
JS::RootedValue values(cx.GetJSContext());
|
||||
GetProperty(cx.GetJSContext(), "values", histogram, &values);
|
||||
// Get counts array from histogram. Each entry in the array maps to a label in the histogram.
|
||||
JS::RootedValue counts(cx.GetJSContext());
|
||||
GetProperty(cx.GetJSContext(), "counts", histogram, &counts);
|
||||
|
||||
// Get the value for the label we care about
|
||||
JS::RootedValue value(cx.GetJSContext());
|
||||
GetElement(cx.GetJSContext(),
|
||||
static_cast<uint32_t>(Telemetry::LABELS_TELEMETRY_TEST_CATEGORICAL::CommonLabel),
|
||||
values, &value);
|
||||
counts, &value);
|
||||
|
||||
// Check that the value stored in the histogram matches with |kExpectedValue|
|
||||
uint32_t uValue = 0;
|
||||
|
@ -597,7 +595,7 @@ TEST_F(TelemetryTestFixture, AccumulateCategoricalHistogram_MultipleStringLabels
|
|||
|
||||
// Now we check for no accumulation when a bad label is present in the array.
|
||||
//
|
||||
// The 'values' property is not initialized unless data is accumulated so keeping another test
|
||||
// The 'counts' property is not initialized unless data is accumulated so keeping another test
|
||||
// to check for this case alone is wasteful as we will have to accumulate some data anyway.
|
||||
|
||||
const nsTArray<nsCString> badLabelArray({
|
||||
|
@ -613,13 +611,13 @@ TEST_F(TelemetryTestFixture, AccumulateCategoricalHistogram_MultipleStringLabels
|
|||
// Get our histogram from the snapshot
|
||||
GetProperty(cx.GetJSContext(), "TELEMETRY_TEST_CATEGORICAL", snapshot, &histogram);
|
||||
|
||||
// Get values array from histogram
|
||||
GetProperty(cx.GetJSContext(), "values", histogram, &values);
|
||||
// Get counts array from histogram
|
||||
GetProperty(cx.GetJSContext(), "counts", histogram, &counts);
|
||||
|
||||
// Get the value for the label we care about
|
||||
GetElement(cx.GetJSContext(),
|
||||
static_cast<uint32_t>(Telemetry::LABELS_TELEMETRY_TEST_CATEGORICAL::CommonLabel),
|
||||
values, &value);
|
||||
counts, &value);
|
||||
|
||||
// Check that the value stored in the histogram matches with |kExpectedValue|
|
||||
uValue = 0;
|
||||
|
@ -650,15 +648,15 @@ TEST_F(TelemetryTestFixture, AccumulateCategoricalHistogram_MultipleEnumValues)
|
|||
JS::RootedValue histogram(cx.GetJSContext());
|
||||
GetProperty(cx.GetJSContext(), "TELEMETRY_TEST_CATEGORICAL", snapshot, &histogram);
|
||||
|
||||
// Get values object from histogram. Each entry in the object maps to a label in the histogram.
|
||||
JS::RootedValue values(cx.GetJSContext());
|
||||
GetProperty(cx.GetJSContext(), "values", histogram, &values);
|
||||
// Get counts array from histogram. Each entry in the array maps to a label in the histogram.
|
||||
JS::RootedValue counts(cx.GetJSContext());
|
||||
GetProperty(cx.GetJSContext(), "counts", histogram, &counts);
|
||||
|
||||
// Get the value for the label we care about
|
||||
JS::RootedValue value(cx.GetJSContext());
|
||||
GetElement(cx.GetJSContext(),
|
||||
static_cast<uint32_t>(Telemetry::LABELS_TELEMETRY_TEST_CATEGORICAL::CommonLabel),
|
||||
values, &value);
|
||||
counts, &value);
|
||||
|
||||
// Check that the value stored in the histogram matches with |kExpectedValue|
|
||||
uint32_t uValue = 0;
|
||||
|
@ -695,15 +693,15 @@ TEST_F(TelemetryTestFixture, AccumulateKeyedCategoricalHistogram_MultipleEnumVal
|
|||
JS::RootedValue sample(cx.GetJSContext());
|
||||
GetProperty(cx.GetJSContext(), "sampleKey", histogram, &sample);
|
||||
|
||||
// Get values object from the sample. Each entry in the object maps to a label in the histogram.
|
||||
JS::RootedValue sampleKeyValues(cx.GetJSContext());
|
||||
GetProperty(cx.GetJSContext(), "values", sample, &sampleKeyValues);
|
||||
// Get counts array from the sample. Each entry in the array maps to a label in the histogram.
|
||||
JS::RootedValue sampleKeyCounts(cx.GetJSContext());
|
||||
GetProperty(cx.GetJSContext(), "counts", sample, &sampleKeyCounts);
|
||||
|
||||
// Get the count of CommonLabel
|
||||
JS::RootedValue commonLabelValue(cx.GetJSContext());
|
||||
GetElement(cx.GetJSContext(),
|
||||
static_cast<uint32_t>(Telemetry::LABELS_TELEMETRY_TEST_KEYED_CATEGORICAL::CommonLabel),
|
||||
sampleKeyValues, &commonLabelValue);
|
||||
sampleKeyCounts, &commonLabelValue);
|
||||
|
||||
// Check that the value stored in the histogram matches with |kExpectedCommonLabel|
|
||||
uint32_t uCommonLabelValue = 0;
|
||||
|
@ -716,7 +714,7 @@ TEST_F(TelemetryTestFixture, AccumulateKeyedCategoricalHistogram_MultipleEnumVal
|
|||
JS::RootedValue label2Value(cx.GetJSContext());
|
||||
GetElement(cx.GetJSContext(),
|
||||
static_cast<uint32_t>(Telemetry::LABELS_TELEMETRY_TEST_KEYED_CATEGORICAL::Label2),
|
||||
sampleKeyValues, &label2Value);
|
||||
sampleKeyCounts, &label2Value);
|
||||
|
||||
// Check that the value stored in the histogram matches with |kExpectedLabel2|
|
||||
uint32_t uLabel2Value = 0;
|
||||
|
|
|
@ -344,6 +344,10 @@ function setEmptyPrefWatchlist() {
|
|||
});
|
||||
}
|
||||
|
||||
function histogramValueCount(histogramSnapshot) {
|
||||
return histogramSnapshot.counts.reduce((a, b) => a + b);
|
||||
}
|
||||
|
||||
if (runningInParent) {
|
||||
// Set logging preferences for all the tests.
|
||||
Services.prefs.setCharPref("toolkit.telemetry.log.level", "Trace");
|
||||
|
|
|
@ -393,7 +393,7 @@ add_task(async function test_archiveCleanup() {
|
|||
h = Telemetry.getHistogramById("TELEMETRY_PING_SIZE_EXCEEDED_ARCHIVED").snapshot();
|
||||
Assert.equal(h.sum, 1, "Telemetry must report 1 oversized ping in the archive.");
|
||||
h = Telemetry.getHistogramById("TELEMETRY_DISCARDED_ARCHIVED_PINGS_SIZE_MB").snapshot();
|
||||
Assert.equal(h.values[archivedPingSizeMB], 1,
|
||||
Assert.equal(h.counts[archivedPingSizeMB], 1,
|
||||
"Telemetry must report the correct size for the oversized ping.");
|
||||
});
|
||||
|
||||
|
|
|
@ -64,10 +64,10 @@ function checkRegistrationFailure(failureType) {
|
|||
"There should be at least one parent histogram when checking for registration failures.");
|
||||
Assert.ok("TELEMETRY_EVENT_REGISTRATION_ERROR" in snapshot.parent,
|
||||
"TELEMETRY_EVENT_REGISTRATION_ERROR should exist when checking for registration failures.");
|
||||
let values = snapshot.parent.TELEMETRY_EVENT_REGISTRATION_ERROR.values;
|
||||
Assert.ok(!!values,
|
||||
"TELEMETRY_EVENT_REGISTRATION_ERROR's values should exist when checking for registration failures.");
|
||||
Assert.equal(values[failureType], 1, `Event registration ought to have failed due to type ${failureType}`);
|
||||
let counts = snapshot.parent.TELEMETRY_EVENT_REGISTRATION_ERROR.counts;
|
||||
Assert.ok(!!counts,
|
||||
"TELEMETRY_EVENT_REGISTRATION_ERROR's counts should exist when checking for registration failures.");
|
||||
Assert.equal(counts[failureType], 1, `Event registration ought to have failed due to type ${failureType}`);
|
||||
}
|
||||
|
||||
function checkRecordingFailure(failureType) {
|
||||
|
@ -76,10 +76,10 @@ function checkRecordingFailure(failureType) {
|
|||
"There should be at least one parent histogram when checking for recording failures.");
|
||||
Assert.ok("TELEMETRY_EVENT_RECORDING_ERROR" in snapshot.parent,
|
||||
"TELEMETRY_EVENT_RECORDING_ERROR should exist when checking for recording failures.");
|
||||
let values = snapshot.parent.TELEMETRY_EVENT_RECORDING_ERROR.values;
|
||||
Assert.ok(!!values,
|
||||
"TELEMETRY_EVENT_RECORDING_ERROR's values should exist when checking for recording failures.");
|
||||
Assert.equal(values[failureType], 1, `Event recording ought to have failed due to type ${failureType}`);
|
||||
let counts = snapshot.parent.TELEMETRY_EVENT_RECORDING_ERROR.counts;
|
||||
Assert.ok(!!counts,
|
||||
"TELEMETRY_EVENT_RECORDING_ERROR's counts should exist when checking for recording failures.");
|
||||
Assert.equal(counts[failureType], 1, `Event recording ought to have failed due to type ${failureType}`);
|
||||
}
|
||||
|
||||
add_task(async function test_event_summary_limit() {
|
||||
|
|
|
@ -3,11 +3,11 @@
|
|||
|
||||
function run_test() {
|
||||
let testFlag = Services.telemetry.getHistogramById("TELEMETRY_TEST_FLAG");
|
||||
deepEqual(testFlag.snapshot().values, {0: 1, 1: 0}, "Original value is correct");
|
||||
equal(JSON.stringify(testFlag.snapshot().counts), "[1,0,0]", "Original value is correct");
|
||||
testFlag.add(1);
|
||||
deepEqual(testFlag.snapshot().values, {0: 0, 1: 1, 2: 0}, "Value is correct after ping");
|
||||
equal(JSON.stringify(testFlag.snapshot().counts), "[0,1,0]", "Value is correct after ping.");
|
||||
testFlag.clear();
|
||||
deepEqual(testFlag.snapshot().values, {0: 1, 1: 0}, "Value is correct after calling clear()");
|
||||
equal(JSON.stringify(testFlag.snapshot().counts), "[1,0,0]", "Value is correct after calling clear()");
|
||||
testFlag.add(1);
|
||||
deepEqual(testFlag.snapshot().values, {0: 0, 1: 1, 2: 0}, "Value is correct after ping");
|
||||
equal(JSON.stringify(testFlag.snapshot().counts), "[0,1,0]", "Value is correct after ping.");
|
||||
}
|
||||
|
|
|
@ -37,35 +37,69 @@ function expect_success(f) {
|
|||
Assert.ok(succeeded);
|
||||
}
|
||||
|
||||
function compareHistograms(h1, h2) {
|
||||
let s1 = h1.snapshot();
|
||||
let s2 = h2.snapshot();
|
||||
|
||||
Assert.equal(s1.histogram_type, s2.histogram_type);
|
||||
Assert.equal(s1.min, s2.min);
|
||||
Assert.equal(s1.max, s2.max);
|
||||
Assert.equal(s1.sum, s2.sum);
|
||||
|
||||
Assert.equal(s1.counts.length, s2.counts.length);
|
||||
for (let i = 0; i < s1.counts.length; i++)
|
||||
Assert.equal(s1.counts[i], s2.counts[i]);
|
||||
|
||||
Assert.equal(s1.ranges.length, s2.ranges.length);
|
||||
for (let i = 0; i < s1.ranges.length; i++)
|
||||
Assert.equal(s1.ranges[i], s2.ranges[i]);
|
||||
}
|
||||
|
||||
function check_histogram(histogram_type, name, min, max, bucket_count) {
|
||||
var h = Telemetry.getHistogramById(name);
|
||||
h.add(0);
|
||||
var r = h.snapshot().ranges;
|
||||
var sum = 0;
|
||||
for (let i = 0;i < r.length;i++) {
|
||||
var v = r[i];
|
||||
sum += v;
|
||||
h.add(v);
|
||||
}
|
||||
var s = h.snapshot();
|
||||
Assert.equal(0, s.sum);
|
||||
// verify properties
|
||||
Assert.equal(sum, s.sum);
|
||||
|
||||
// there should be exactly one element per bucket
|
||||
for (let i of s.counts) {
|
||||
Assert.equal(i, 1);
|
||||
}
|
||||
var hgrams = Telemetry.snapshotHistograms(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN,
|
||||
false).parent;
|
||||
let gh = hgrams[name];
|
||||
Assert.equal(gh.histogram_type, histogram_type);
|
||||
|
||||
Assert.deepEqual(gh.range, [min, max]);
|
||||
Assert.equal(gh.min, min);
|
||||
Assert.equal(gh.max, max);
|
||||
|
||||
// Check that booleans work with nonboolean histograms
|
||||
h.add(false);
|
||||
h.add(true);
|
||||
s = Object.values(h.snapshot().values);
|
||||
Assert.deepEqual(s, [2, 1, 0]);
|
||||
s = h.snapshot().counts;
|
||||
Assert.equal(s[0], 2);
|
||||
Assert.equal(s[1], 2);
|
||||
|
||||
// Check that clearing works.
|
||||
h.clear();
|
||||
s = h.snapshot();
|
||||
Assert.deepEqual(s.values, {});
|
||||
for (var i of s.counts) {
|
||||
Assert.equal(i, 0);
|
||||
}
|
||||
Assert.equal(s.sum, 0);
|
||||
|
||||
h.add(0);
|
||||
h.add(1);
|
||||
var c = Object.values(h.snapshot().values);
|
||||
Assert.deepEqual(c, [1, 1, 0]);
|
||||
var c = h.snapshot().counts;
|
||||
Assert.equal(c[0], 1);
|
||||
Assert.equal(c[1], 1);
|
||||
}
|
||||
|
||||
// This MUST be the very first test of this file.
|
||||
|
@ -147,43 +181,44 @@ add_task(async function test_noSerialization() {
|
|||
|
||||
add_task(async function test_boolean_histogram() {
|
||||
var h = Telemetry.getHistogramById("TELEMETRY_TEST_BOOLEAN");
|
||||
var r = h.snapshot().range;
|
||||
var r = h.snapshot().ranges;
|
||||
// boolean histograms ignore numeric parameters
|
||||
Assert.deepEqual(r, [1, 2]);
|
||||
h.add(0);
|
||||
h.add(1);
|
||||
h.add(2);
|
||||
|
||||
Assert.equal(uneval(r), uneval([0, 1, 2]));
|
||||
for (var i = 0;i < r.length;i++) {
|
||||
var v = r[i];
|
||||
h.add(v);
|
||||
}
|
||||
h.add(true);
|
||||
h.add(false);
|
||||
var s = h.snapshot();
|
||||
Assert.equal(s.histogram_type, Telemetry.HISTOGRAM_BOOLEAN);
|
||||
// last bucket should always be 0 since .add parameters are normalized to either 0 or 1
|
||||
Assert.deepEqual(s.values, {0: 2, 1: 3, 2: 0});
|
||||
Assert.equal(s.counts[2], 0);
|
||||
Assert.equal(s.sum, 3);
|
||||
Assert.equal(s.counts[0], 2);
|
||||
});
|
||||
|
||||
add_task(async function test_flag_histogram() {
|
||||
var h = Telemetry.getHistogramById("TELEMETRY_TEST_FLAG");
|
||||
var r = h.snapshot().range;
|
||||
var r = h.snapshot().ranges;
|
||||
// Flag histograms ignore numeric parameters.
|
||||
Assert.deepEqual(r, [1, 2]);
|
||||
Assert.equal(uneval(r), uneval([0, 1, 2]));
|
||||
// Should already have a 0 counted.
|
||||
var v = h.snapshot().values;
|
||||
var c = h.snapshot().counts;
|
||||
var s = h.snapshot().sum;
|
||||
Assert.deepEqual(v, {0: 1, 1: 0});
|
||||
Assert.equal(uneval(c), uneval([1, 0, 0]));
|
||||
Assert.equal(s, 0);
|
||||
// Should switch counts.
|
||||
h.add(1);
|
||||
var v2 = h.snapshot().values;
|
||||
var c2 = h.snapshot().counts;
|
||||
var s2 = h.snapshot().sum;
|
||||
Assert.deepEqual(v2, {0: 0, 1: 1, 2: 0});
|
||||
Assert.equal(uneval(c2), uneval([0, 1, 0]));
|
||||
Assert.equal(s2, 1);
|
||||
// Should only switch counts once.
|
||||
h.add(1);
|
||||
var v3 = h.snapshot().values;
|
||||
var c3 = h.snapshot().counts;
|
||||
var s3 = h.snapshot().sum;
|
||||
Assert.deepEqual(v3, {0: 0, 1: 1, 2: 0});
|
||||
Assert.equal(uneval(c3), uneval([0, 1, 0]));
|
||||
Assert.equal(s3, 1);
|
||||
Assert.equal(h.snapshot().histogram_type, Telemetry.HISTOGRAM_FLAG);
|
||||
});
|
||||
|
@ -191,16 +226,16 @@ add_task(async function test_flag_histogram() {
|
|||
add_task(async function test_count_histogram() {
|
||||
let h = Telemetry.getHistogramById("TELEMETRY_TEST_COUNT2");
|
||||
let s = h.snapshot();
|
||||
Assert.deepEqual(s.range, [1, 2]);
|
||||
Assert.deepEqual(s.values, {});
|
||||
Assert.equal(uneval(s.ranges), uneval([0, 1, 2]));
|
||||
Assert.equal(uneval(s.counts), uneval([0, 0, 0]));
|
||||
Assert.equal(s.sum, 0);
|
||||
h.add();
|
||||
s = h.snapshot();
|
||||
Assert.deepEqual(s.values, {0: 1, 1: 0});
|
||||
Assert.equal(uneval(s.counts), uneval([1, 0, 0]));
|
||||
Assert.equal(s.sum, 1);
|
||||
h.add();
|
||||
s = h.snapshot();
|
||||
Assert.deepEqual(s.values, {0: 2, 1: 0});
|
||||
Assert.equal(uneval(s.counts), uneval([2, 0, 0]));
|
||||
Assert.equal(s.sum, 2);
|
||||
});
|
||||
|
||||
|
@ -215,10 +250,16 @@ add_task(async function test_categorical_histogram() {
|
|||
h1.add(s);
|
||||
}
|
||||
|
||||
// Categorical histograms default to 50 linear buckets.
|
||||
let expectedRanges = [];
|
||||
for (let i = 0; i < 51; ++i) {
|
||||
expectedRanges.push(i);
|
||||
}
|
||||
|
||||
let snapshot = h1.snapshot();
|
||||
Assert.equal(snapshot.sum, 6);
|
||||
Assert.deepEqual(snapshot.range, [1, 50]);
|
||||
Assert.deepEqual(snapshot.values, {0: 3, 1: 2, 2: 2, 3: 0});
|
||||
Assert.deepEqual(snapshot.ranges, expectedRanges);
|
||||
Assert.deepEqual(snapshot.counts.slice(0, 4), [3, 2, 2, 0]);
|
||||
|
||||
let h2 = Telemetry.getHistogramById("TELEMETRY_TEST_CATEGORICAL_OPTOUT");
|
||||
for (let v of ["CommonLabel", "CommonLabel", "Label4", "Label5", "Label6", 0, 1]) {
|
||||
|
@ -232,8 +273,8 @@ add_task(async function test_categorical_histogram() {
|
|||
|
||||
snapshot = h2.snapshot();
|
||||
Assert.equal(snapshot.sum, 7);
|
||||
Assert.deepEqual(snapshot.range, [1, 50]);
|
||||
Assert.deepEqual(snapshot.values, {0: 3, 1: 2, 2: 1, 3: 1, 4: 0});
|
||||
Assert.deepEqual(snapshot.ranges, expectedRanges);
|
||||
Assert.deepEqual(snapshot.counts.slice(0, 5), [3, 2, 1, 1, 0]);
|
||||
|
||||
// This histogram overrides the default of 50 values to 70.
|
||||
let h3 = Telemetry.getHistogramById("TELEMETRY_TEST_CATEGORICAL_NVALUES");
|
||||
|
@ -241,10 +282,16 @@ add_task(async function test_categorical_histogram() {
|
|||
h3.add(v);
|
||||
}
|
||||
|
||||
expectedRanges = [];
|
||||
for (let i = 0; i < 71; ++i) {
|
||||
expectedRanges.push(i);
|
||||
}
|
||||
|
||||
snapshot = h3.snapshot();
|
||||
Assert.equal(snapshot.sum, 3);
|
||||
Assert.deepEqual(snapshot.range, [1, 70]);
|
||||
Assert.deepEqual(snapshot.values, {0: 1, 1: 1, 2: 1, 3: 0});
|
||||
Assert.equal(snapshot.ranges.length, expectedRanges.length);
|
||||
Assert.deepEqual(snapshot.ranges, expectedRanges);
|
||||
Assert.deepEqual(snapshot.counts.slice(0, 4), [1, 1, 1, 0]);
|
||||
});
|
||||
|
||||
add_task(async function test_add_error_behaviour() {
|
||||
|
@ -306,7 +353,8 @@ add_task(async function test_getHistogramById() {
|
|||
var h = Telemetry.getHistogramById("CYCLE_COLLECTOR");
|
||||
var s = h.snapshot();
|
||||
Assert.equal(s.histogram_type, Telemetry.HISTOGRAM_EXPONENTIAL);
|
||||
Assert.deepEqual(s.range, [1, 10000]);
|
||||
Assert.equal(s.min, 1);
|
||||
Assert.equal(s.max, 10000);
|
||||
});
|
||||
|
||||
add_task(async function test_getSlowSQL() {
|
||||
|
@ -327,10 +375,10 @@ add_task(async function test_privateMode() {
|
|||
var orig = h.snapshot();
|
||||
Telemetry.canRecordExtended = false;
|
||||
h.add(1);
|
||||
Assert.deepEqual(orig, h.snapshot());
|
||||
Assert.equal(uneval(orig), uneval(h.snapshot()));
|
||||
Telemetry.canRecordExtended = true;
|
||||
h.add(1);
|
||||
Assert.notDeepEqual(orig, h.snapshot());
|
||||
Assert.notEqual(uneval(orig), uneval(h.snapshot()));
|
||||
});
|
||||
|
||||
// Check that telemetry records only when it is suppose to.
|
||||
|
@ -442,11 +490,12 @@ add_task(async function test_keyed_boolean_histogram() {
|
|||
let KEYS = numberRange(0, 2).map(i => "key" + (i + 1));
|
||||
KEYS.push("漢語");
|
||||
let histogramBase = {
|
||||
"range": [1, 2],
|
||||
"bucket_count": 3,
|
||||
"min": 1,
|
||||
"max": 2,
|
||||
"histogram_type": 2,
|
||||
"sum": 1,
|
||||
"values": {0: 0, 1: 1, 2: 0},
|
||||
"ranges": [0, 1, 2],
|
||||
"counts": [0, 1, 0],
|
||||
};
|
||||
let testHistograms = numberRange(0, 3).map(i => JSON.parse(JSON.stringify(histogramBase)));
|
||||
let testKeys = [];
|
||||
|
@ -472,7 +521,7 @@ add_task(async function test_keyed_boolean_histogram() {
|
|||
testKeys.push(key);
|
||||
testSnapShot[key] = testHistograms[2];
|
||||
testSnapShot[key].sum = 0;
|
||||
testSnapShot[key].values = {0: 1, 1: 0};
|
||||
testSnapShot[key].counts = [1, 0, 0];
|
||||
Assert.deepEqual(h.keys().sort(), testKeys);
|
||||
Assert.deepEqual(h.snapshot(), testSnapShot);
|
||||
|
||||
|
@ -489,11 +538,12 @@ add_task(async function test_keyed_count_histogram() {
|
|||
const KEYED_ID = "TELEMETRY_TEST_KEYED_COUNT";
|
||||
const KEYS = numberRange(0, 5).map(i => "key" + (i + 1));
|
||||
let histogramBase = {
|
||||
"range": [1, 2],
|
||||
"bucket_count": 3,
|
||||
"min": 1,
|
||||
"max": 2,
|
||||
"histogram_type": 4,
|
||||
"sum": 0,
|
||||
"values": {0: 1, 1: 0},
|
||||
"ranges": [0, 1, 2],
|
||||
"counts": [1, 0, 0],
|
||||
};
|
||||
let testHistograms = numberRange(0, 5).map(i => JSON.parse(JSON.stringify(histogramBase)));
|
||||
let testKeys = [];
|
||||
|
@ -508,7 +558,7 @@ add_task(async function test_keyed_count_histogram() {
|
|||
for (let k = 0; k < value; ++k) {
|
||||
h.add(key);
|
||||
}
|
||||
testHistograms[i].values[0] = value;
|
||||
testHistograms[i].counts[0] = value;
|
||||
testHistograms[i].sum = value;
|
||||
testSnapShot[key] = testHistograms[i];
|
||||
testKeys.push(key);
|
||||
|
@ -525,7 +575,7 @@ add_task(async function test_keyed_count_histogram() {
|
|||
let key = KEYS[4];
|
||||
h.add(key);
|
||||
testKeys.push(key);
|
||||
testHistograms[4].values[0] = 1;
|
||||
testHistograms[4].counts[0] = 1;
|
||||
testHistograms[4].sum = 1;
|
||||
testSnapShot[key] = testHistograms[4];
|
||||
|
||||
|
@ -565,6 +615,12 @@ add_task(async function test_keyed_categorical_histogram() {
|
|||
}
|
||||
}
|
||||
|
||||
// Categorical histograms default to 50 linear buckets.
|
||||
let expectedRanges = [];
|
||||
for (let i = 0; i < 51; ++i) {
|
||||
expectedRanges.push(i);
|
||||
}
|
||||
|
||||
// Check that the set of keys in the snapshot is what we expect.
|
||||
let snapshot = h.snapshot();
|
||||
let snapshotKeys = Object.keys(snapshot);
|
||||
|
@ -575,8 +631,8 @@ add_task(async function test_keyed_categorical_histogram() {
|
|||
for (let k of KEYS) {
|
||||
Assert.ok(k in snapshot);
|
||||
Assert.equal(snapshot[k].sum, 6);
|
||||
Assert.deepEqual(snapshot[k].range, [1, 50]);
|
||||
Assert.deepEqual(snapshot[k].values, {0: 3, 1: 2, 2: 2, 3: 0});
|
||||
Assert.deepEqual(snapshot[k].ranges, expectedRanges);
|
||||
Assert.deepEqual(snapshot[k].counts.slice(0, 4), [3, 2, 2, 0]);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -589,11 +645,12 @@ add_task(async function test_keyed_flag_histogram() {
|
|||
|
||||
let testSnapshot = {};
|
||||
testSnapshot[KEY] = {
|
||||
"range": [1, 2],
|
||||
"bucket_count": 3,
|
||||
"min": 1,
|
||||
"max": 2,
|
||||
"histogram_type": 3,
|
||||
"sum": 1,
|
||||
"values": {0: 0, 1: 1, 2: 0},
|
||||
"ranges": [0, 1, 2],
|
||||
"counts": [0, 1, 0],
|
||||
};
|
||||
|
||||
Assert.deepEqual(h.keys().sort(), [KEY]);
|
||||
|
@ -803,9 +860,9 @@ add_task(async function test_keyed_keys() {
|
|||
Assert.equal(Object.keys(snap).length, 2, "Only 2 keys must be recorded.");
|
||||
Assert.ok("testkey" in snap, "'testkey' must be recorded.");
|
||||
Assert.ok("thirdKey" in snap, "'thirdKey' must be recorded.");
|
||||
Assert.deepEqual(snap.testkey.values, {0: 0, 1: 1, 2: 0},
|
||||
Assert.deepEqual(snap.testkey.counts, [0, 1, 0],
|
||||
"'testkey' must contain the correct value.");
|
||||
Assert.deepEqual(snap.thirdKey.values, {0: 1, 1: 0},
|
||||
Assert.deepEqual(snap.thirdKey.counts, [1, 0, 0],
|
||||
"'thirdKey' must contain the correct value.");
|
||||
|
||||
// Keys that are not allowed must not be recorded.
|
||||
|
@ -837,11 +894,11 @@ add_task(async function test_count_multiple_samples() {
|
|||
Assert.equal(s1.sum, 0);
|
||||
// Ensure that no accumulations of 0-like values took place.
|
||||
// These accumulations won't increase the sum.
|
||||
Assert.deepEqual({}, s1.values);
|
||||
Assert.equal(s1.counts.reduce((acc, cur) => acc + cur), 0);
|
||||
|
||||
h.add(valid);
|
||||
let s2 = h.snapshot();
|
||||
Assert.deepEqual(s2.values, {0: 4, 1: 0});
|
||||
Assert.equal(uneval(s2.counts), uneval([4, 0, 0]));
|
||||
Assert.equal(s2.sum, 5);
|
||||
});
|
||||
|
||||
|
@ -856,12 +913,12 @@ add_task(async function test_categorical_multiple_samples() {
|
|||
h.add(valid.concat(invalid));
|
||||
let s1 = h.snapshot();
|
||||
Assert.equal(s1.sum, 0);
|
||||
Assert.deepEqual({}, s1.values);
|
||||
Assert.equal(s1.counts.reduce((acc, cur) => acc + cur), 0);
|
||||
|
||||
h.add(valid);
|
||||
let snapshot = h.snapshot();
|
||||
Assert.equal(snapshot.sum, 6);
|
||||
Assert.deepEqual(snapshot.values, {0: 3, 1: 2, 2: 2, 3: 0});
|
||||
Assert.deepEqual(snapshot.counts.slice(0, 4), [3, 2, 2, 0]);
|
||||
});
|
||||
|
||||
add_task(async function test_boolean_multiple_samples() {
|
||||
|
@ -876,11 +933,11 @@ add_task(async function test_boolean_multiple_samples() {
|
|||
h.add(valid.concat(invalid));
|
||||
let s1 = h.snapshot();
|
||||
Assert.equal(s1.sum, 0);
|
||||
Assert.deepEqual({}, s1.values);
|
||||
Assert.equal(s1.counts.reduce((acc, cur) => acc + cur), 0);
|
||||
|
||||
h.add(valid);
|
||||
let s = h.snapshot();
|
||||
Assert.deepEqual(s.values, {0: 2, 1: 3, 2: 0});
|
||||
Assert.deepEqual(s.counts, [2, 3, 0]);
|
||||
Assert.equal(s.sum, 3);
|
||||
});
|
||||
|
||||
|
@ -898,13 +955,14 @@ add_task(async function test_linear_multiple_samples() {
|
|||
h.add(valid.concat(invalid));
|
||||
let s1 = h.snapshot();
|
||||
Assert.equal(s1.sum, 0);
|
||||
Assert.deepEqual({}, s1.values);
|
||||
Assert.equal(s1.counts.reduce((acc, cur) => acc + cur), 0);
|
||||
|
||||
h.add(valid);
|
||||
let s2 = h.snapshot();
|
||||
// Values >= INT32_MAX are accumulated as INT32_MAX - 1
|
||||
Assert.equal(s2.sum, valid.reduce((acc, cur) => acc + cur) - 3);
|
||||
Assert.deepEqual(Object.values(s2.values), [1, 3, 2, 1]);
|
||||
Assert.equal(s2.counts[9], 1);
|
||||
Assert.deepEqual(s2.counts.slice(0, 3), [1, 3, 2]);
|
||||
});
|
||||
|
||||
add_task(async function test_keyed_no_arguments() {
|
||||
|
@ -946,11 +1004,11 @@ add_task(async function test_keyed_count_multiple_samples() {
|
|||
Assert.equal(s1.sum, 0);
|
||||
// Ensure that no accumulations of 0-like values took place.
|
||||
// These accumulations won't increase the sum.
|
||||
Assert.deepEqual({}, s1.values);
|
||||
Assert.equal(s1.counts.reduce((acc, cur) => acc + cur), 0);
|
||||
|
||||
h.add(key, valid);
|
||||
let s2 = h.snapshot(key);
|
||||
Assert.deepEqual(s2.values, {0: 4, 1: 0});
|
||||
Assert.equal(uneval(s2.counts), uneval([4, 0, 0]));
|
||||
Assert.equal(s2.sum, 5);
|
||||
});
|
||||
|
||||
|
@ -966,12 +1024,12 @@ add_task(async function test_keyed_categorical_multiple_samples() {
|
|||
h.add(key, valid.concat(invalid));
|
||||
let s1 = h.snapshot(key);
|
||||
Assert.equal(s1.sum, 0);
|
||||
Assert.deepEqual({}, s1.values);
|
||||
Assert.equal(s1.counts.reduce((acc, cur) => acc + cur), 0);
|
||||
|
||||
h.add(key, valid);
|
||||
let snapshot = h.snapshot(key);
|
||||
Assert.equal(snapshot.sum, 6);
|
||||
Assert.deepEqual(Object.values(snapshot.values), [3, 2, 2, 0]);
|
||||
Assert.deepEqual(snapshot.counts.slice(0, 4), [3, 2, 2, 0]);
|
||||
});
|
||||
|
||||
add_task(async function test_keyed_boolean_multiple_samples() {
|
||||
|
@ -987,11 +1045,11 @@ add_task(async function test_keyed_boolean_multiple_samples() {
|
|||
h.add(key, valid.concat(invalid));
|
||||
let s1 = h.snapshot(key);
|
||||
Assert.equal(s1.sum, 0);
|
||||
Assert.deepEqual({}, s1.values);
|
||||
Assert.equal(s1.counts.reduce((acc, cur) => acc + cur), 0);
|
||||
|
||||
h.add(key, valid);
|
||||
let s = h.snapshot(key);
|
||||
Assert.deepEqual(s.values, {0: 2, 1: 3, 2: 0});
|
||||
Assert.deepEqual(s.counts, [2, 3, 0]);
|
||||
Assert.equal(s.sum, 3);
|
||||
});
|
||||
|
||||
|
@ -1010,14 +1068,14 @@ add_task(async function test_keyed_linear_multiple_samples() {
|
|||
h.add(key, valid.concat(invalid));
|
||||
let s1 = h.snapshot(key);
|
||||
Assert.equal(s1.sum, 0);
|
||||
Assert.deepEqual({}, s1.values);
|
||||
Assert.equal(s1.counts.reduce((acc, cur) => acc + cur), 0);
|
||||
|
||||
h.add(key, valid);
|
||||
let s2 = h.snapshot(key);
|
||||
// Values >= INT32_MAX are accumulated as INT32_MAX - 1
|
||||
Assert.equal(s2.sum, valid.reduce((acc, cur) => acc + cur) - 3);
|
||||
Assert.deepEqual(s2.range, [1, 250000]);
|
||||
Assert.deepEqual(s2.values, {0: 1, 1: 3, 250000: 3});
|
||||
Assert.equal(s2.counts[9], 3);
|
||||
Assert.deepEqual(s2.counts.slice(0, 3), [1, 3, 0]);
|
||||
});
|
||||
|
||||
add_task(async function test_non_array_non_string_obj() {
|
||||
|
|
|
@ -78,7 +78,7 @@ var checkPingsSaved = async function(pingIds) {
|
|||
};
|
||||
|
||||
function histogramValueCount(h) {
|
||||
return Object.values(h.values).reduce((a, b) => a + b, 0);
|
||||
return h.counts.reduce((a, b) => a + b);
|
||||
}
|
||||
|
||||
add_task(async function test_setup() {
|
||||
|
@ -135,7 +135,7 @@ add_task(async function test_sendPendingPings() {
|
|||
Assert.equal(TelemetrySend.pendingPingCount, TYPE_A_COUNT + TYPE_B_COUNT,
|
||||
"Should have correct pending ping count");
|
||||
|
||||
Assert.deepEqual(histSuccess.snapshot().values, {},
|
||||
Assert.deepEqual(histSuccess.snapshot().counts, [0, 0, 0],
|
||||
"Should not have recorded any sending in histograms yet.");
|
||||
Assert.equal(histSendTimeSuccess.snapshot().sum, 0,
|
||||
"Should not have recorded any sending in histograms yet.");
|
||||
|
@ -166,7 +166,7 @@ add_task(async function test_sendPendingPings() {
|
|||
Assert.equal(countByType.get(TEST_TYPE_A), 10 - TYPE_B_COUNT,
|
||||
"Should have received the correct amount of type A pings");
|
||||
|
||||
Assert.deepEqual(histSuccess.snapshot().values, {0: 0, 1: 10, 2: 0},
|
||||
Assert.deepEqual(histSuccess.snapshot().counts, [0, 10, 0],
|
||||
"Should have recorded sending success in histograms.");
|
||||
Assert.equal(histogramValueCount(histSendTimeSuccess.snapshot()), 10,
|
||||
"Should have recorded successful send times in histograms.");
|
||||
|
@ -272,7 +272,7 @@ add_task(async function test_backoffTimeout() {
|
|||
Assert.equal(pingSendTimeout, MAX_BACKOFF_TIMEOUT, "Tick timeout should be capped");
|
||||
++sendAttempts;
|
||||
|
||||
Assert.deepEqual(histSuccess.snapshot().values, {0: sendAttempts, 1: 0},
|
||||
Assert.deepEqual(histSuccess.snapshot().counts, [sendAttempts, 0, 0],
|
||||
"Should have recorded sending failure in histograms.");
|
||||
Assert.equal(histSendTimeSuccess.snapshot().sum, 0,
|
||||
"Should not have recorded any sending success in histograms yet.");
|
||||
|
@ -309,7 +309,7 @@ add_task(async function test_backoffTimeout() {
|
|||
await TelemetrySend.testWaitOnOutgoingPings();
|
||||
Assert.equal(TelemetrySend.pendingPingCount, 0, "Should have no pending pings left");
|
||||
|
||||
Assert.deepEqual(histSuccess.snapshot().values, {0: sendAttempts, 1: 3, 2: 0},
|
||||
Assert.deepEqual(histSuccess.snapshot().counts, [sendAttempts, 3, 0],
|
||||
"Should have recorded sending failure in histograms.");
|
||||
Assert.greaterOrEqual(histSendTimeSuccess.snapshot().sum, 0,
|
||||
"Should have recorded sending success in histograms.");
|
||||
|
@ -341,7 +341,7 @@ add_task(async function test_discardBigPings() {
|
|||
|
||||
Assert.equal(histSizeExceeded.snapshot().sum, 0, "Telemetry must report no oversized ping submitted.");
|
||||
Assert.equal(histDiscardedSize.snapshot().sum, 0, "Telemetry must report no oversized pings.");
|
||||
Assert.deepEqual(histSuccess.snapshot().values, {0: 0, 1: 1, 2: 0}, "Should have recorded sending success.");
|
||||
Assert.deepEqual(histSuccess.snapshot().counts, [0, 1, 0], "Should have recorded sending success.");
|
||||
Assert.equal(histogramValueCount(histSendTimeSuccess.snapshot()), 1, "Should have recorded send success time.");
|
||||
Assert.greaterOrEqual(histSendTimeSuccess.snapshot().sum, 0, "Should have recorded send success time.");
|
||||
Assert.equal(histogramValueCount(histSendTimeFail.snapshot()), 0, "Should not have recorded send failure time.");
|
||||
|
@ -362,9 +362,9 @@ add_task(async function test_discardBigPings() {
|
|||
Assert.deepEqual(ping.payload.os, TelemetryHealthPing.OsInfo, "Should have correct os info.");
|
||||
|
||||
Assert.equal(histSizeExceeded.snapshot().sum, 1, "Telemetry must report 1 oversized ping submitted.");
|
||||
Assert.equal(histDiscardedSize.snapshot().values[2], 1, "Telemetry must report a 2MB, oversized, ping submitted.");
|
||||
Assert.equal(histDiscardedSize.snapshot().counts[2], 1, "Telemetry must report a 2MB, oversized, ping submitted.");
|
||||
|
||||
Assert.deepEqual(histSuccess.snapshot().values, {0: 0, 1: 2, 2: 0}, "Should have recorded sending success.");
|
||||
Assert.deepEqual(histSuccess.snapshot().counts, [0, 2, 0], "Should have recorded sending success.");
|
||||
Assert.equal(histogramValueCount(histSendTimeSuccess.snapshot()), 2, "Should have recorded send success time.");
|
||||
Assert.greaterOrEqual(histSendTimeSuccess.snapshot().sum, 0, "Should have recorded send success time.");
|
||||
Assert.equal(histogramValueCount(histSendTimeFail.snapshot()), 0, "Should not have recorded send failure time.");
|
||||
|
@ -384,7 +384,7 @@ add_task(async function test_largeButWithinLimit() {
|
|||
await TelemetrySend.testWaitOnOutgoingPings();
|
||||
await PingServer.promiseNextRequest();
|
||||
|
||||
Assert.deepEqual(histSuccess.snapshot().values, {0: 0, 1: 1, 2: 0}, "Should have sent large ping.");
|
||||
Assert.deepEqual(histSuccess.snapshot().counts, [0, 1, 0], "Should have sent large ping.");
|
||||
});
|
||||
|
||||
add_task(async function test_evictedOnServerErrors() {
|
||||
|
@ -414,7 +414,7 @@ add_task(async function test_evictedOnServerErrors() {
|
|||
|
||||
Assert.equal(histEvicted.snapshot().sum, 1,
|
||||
"Telemetry must report a ping evicted due to server errors");
|
||||
Assert.deepEqual(histSuccess.snapshot().values, {0: 0, 1: 1, 2: 0});
|
||||
Assert.deepEqual(histSuccess.snapshot().counts, [0, 1, 0]);
|
||||
Assert.equal(histogramValueCount(histSendTimeSuccess.snapshot()), 1);
|
||||
Assert.greaterOrEqual(histSendTimeSuccess.snapshot().sum, 0);
|
||||
Assert.equal(histogramValueCount(histSendTimeFail.snapshot()), 0);
|
||||
|
@ -434,7 +434,7 @@ add_task(async function test_evictedOnServerErrors() {
|
|||
// We should not have updated the error histogram.
|
||||
await TelemetrySend.testWaitOnOutgoingPings();
|
||||
Assert.equal(histEvicted.snapshot().sum, 1, "Telemetry must report only one ping evicted due to server errors");
|
||||
Assert.deepEqual(histSuccess.snapshot().values, {0: 0, 1: 2, 2: 0});
|
||||
Assert.deepEqual(histSuccess.snapshot().counts, [0, 2, 0]);
|
||||
Assert.equal(histogramValueCount(histSendTimeSuccess.snapshot()), 2);
|
||||
Assert.equal(histogramValueCount(histSendTimeFail.snapshot()), 0);
|
||||
});
|
||||
|
@ -459,7 +459,7 @@ add_task(async function test_tooLateToSend() {
|
|||
Assert.equal(pendingPings.length, 1, "Should have a pending ping in storage");
|
||||
Assert.equal(pendingPings[0].id, id, "Should have pended our test's ping");
|
||||
|
||||
Assert.equal(Telemetry.getHistogramById("TELEMETRY_SEND_FAILURE_TYPE").snapshot().values[7], 1,
|
||||
Assert.equal(Telemetry.getHistogramById("TELEMETRY_SEND_FAILURE_TYPE").snapshot().counts[7], 1,
|
||||
"Should have registered the failed attempt to send");
|
||||
|
||||
await TelemetryStorage.reset();
|
||||
|
|
|
@ -479,7 +479,7 @@ add_task(async function test_pendingPingsQuota() {
|
|||
h = Telemetry.getHistogramById("TELEMETRY_PING_SIZE_EXCEEDED_PENDING").snapshot();
|
||||
Assert.equal(h.sum, 1, "Telemetry must report 1 oversized ping in the pending pings directory.");
|
||||
h = Telemetry.getHistogramById("TELEMETRY_DISCARDED_PENDING_PINGS_SIZE_MB").snapshot();
|
||||
Assert.equal(h.values[2], 1, "Telemetry must report a 2MB, oversized, ping.");
|
||||
Assert.equal(h.counts[2], 1, "Telemetry must report a 2MB, oversized, ping.");
|
||||
|
||||
// Save the ping again to check if it gets pruned when scanning the pings directory.
|
||||
await TelemetryStorage.savePendingPing(OVERSIZED_PING);
|
||||
|
@ -494,7 +494,7 @@ add_task(async function test_pendingPingsQuota() {
|
|||
h = Telemetry.getHistogramById("TELEMETRY_PING_SIZE_EXCEEDED_PENDING").snapshot();
|
||||
Assert.equal(h.sum, 2, "Telemetry must report 1 oversized ping in the pending pings directory.");
|
||||
h = Telemetry.getHistogramById("TELEMETRY_DISCARDED_PENDING_PINGS_SIZE_MB").snapshot();
|
||||
Assert.equal(h.values[2], 2, "Telemetry must report two 2MB, oversized, pings.");
|
||||
Assert.equal(h.counts[2], 2, "Telemetry must report two 2MB, oversized, pings.");
|
||||
|
||||
Services.prefs.setBoolPref(TelemetryUtils.Preferences.FhrUploadEnabled, true);
|
||||
});
|
||||
|
|
|
@ -330,7 +330,7 @@ function checkPayload(payload, reason, successfulPings) {
|
|||
sum: 0,
|
||||
};
|
||||
let flag = payload.histograms[TELEMETRY_TEST_FLAG];
|
||||
Assert.deepEqual(flag, expected_flag);
|
||||
Assert.equal(uneval(flag), uneval(expected_flag));
|
||||
|
||||
// We should have a test count.
|
||||
const expected_count = {
|
||||
|
@ -341,7 +341,7 @@ function checkPayload(payload, reason, successfulPings) {
|
|||
sum: 1,
|
||||
};
|
||||
let count = payload.histograms[TELEMETRY_TEST_COUNT];
|
||||
Assert.deepEqual(count, expected_count);
|
||||
Assert.equal(uneval(count), uneval(expected_count));
|
||||
|
||||
// There should be one successful report from the previous telemetry ping.
|
||||
if (successfulPings > 0) {
|
||||
|
@ -353,7 +353,7 @@ function checkPayload(payload, reason, successfulPings) {
|
|||
sum: successfulPings,
|
||||
};
|
||||
let tc = payload.histograms[TELEMETRY_SUCCESS];
|
||||
Assert.deepEqual(tc, expected_tc);
|
||||
Assert.equal(uneval(tc), uneval(expected_tc));
|
||||
}
|
||||
|
||||
// The ping should include data from memory reporters. We can't check that
|
||||
|
|
|
@ -16,15 +16,15 @@ var originalCount1, originalCount2, originalCount3;
|
|||
function run_test() {
|
||||
let histogram = Telemetry.getHistogramById(HIST_NAME);
|
||||
let snapshot = histogram.snapshot();
|
||||
originalCount1 = Object.values(snapshot.values).reduce((a, b) => a += b, 0);
|
||||
originalCount1 = snapshot.counts.reduce((a, b) => a += b);
|
||||
|
||||
histogram = Telemetry.getHistogramById(HIST_NAME2);
|
||||
snapshot = histogram.snapshot();
|
||||
originalCount2 = Object.values(snapshot.values).reduce((a, b) => a += b, 0);
|
||||
originalCount2 = snapshot.counts.reduce((a, b) => a += b);
|
||||
|
||||
histogram = Telemetry.getKeyedHistogramById(KEYED_HIST.id);
|
||||
snapshot = histogram.snapshot(KEYED_HIST.key);
|
||||
originalCount3 = Object.values(snapshot.values).reduce((a, b) => a += b, 0);
|
||||
originalCount3 = snapshot.counts.reduce((a, b) => a += b);
|
||||
|
||||
Assert.ok(!TelemetryStopwatch.start(3));
|
||||
Assert.ok(!TelemetryStopwatch.start({}));
|
||||
|
@ -177,19 +177,19 @@ function run_test() {
|
|||
function finishTest() {
|
||||
let histogram = Telemetry.getHistogramById(HIST_NAME);
|
||||
let snapshot = histogram.snapshot();
|
||||
let newCount = Object.values(snapshot.values).reduce((a, b) => a += b, 0);
|
||||
let newCount = snapshot.counts.reduce((a, b) => a += b);
|
||||
|
||||
Assert.equal(newCount - originalCount1, 5, "The correct number of histograms were added for histogram 1.");
|
||||
|
||||
histogram = Telemetry.getHistogramById(HIST_NAME2);
|
||||
snapshot = histogram.snapshot();
|
||||
newCount = Object.values(snapshot.values).reduce((a, b) => a += b, 0);
|
||||
newCount = snapshot.counts.reduce((a, b) => a += b);
|
||||
|
||||
Assert.equal(newCount - originalCount2, 3, "The correct number of histograms were added for histogram 2.");
|
||||
|
||||
histogram = Telemetry.getKeyedHistogramById(KEYED_HIST.id);
|
||||
snapshot = histogram.snapshot(KEYED_HIST.key);
|
||||
newCount = Object.values(snapshot.values).reduce((a, b) => a += b, 0);
|
||||
newCount = snapshot.counts.reduce((a, b) => a += b);
|
||||
|
||||
Assert.equal(newCount - originalCount3, 2, "The correct number of histograms were added for histogram 3.");
|
||||
}
|
||||
|
|
|
@ -10,24 +10,28 @@ add_task(async function testHistogramPacking() {
|
|||
const HISTOGRAM_SNAPSHOT = {
|
||||
sample_process: {
|
||||
HISTOGRAM_1_DATA: {
|
||||
range: [1, 2],
|
||||
bucket_count: 3,
|
||||
histogram_type: 4,
|
||||
values: {
|
||||
"0": 1,
|
||||
"1": 0,
|
||||
},
|
||||
counts: [
|
||||
1, 0, 0,
|
||||
],
|
||||
ranges: [
|
||||
0, 1, 2,
|
||||
],
|
||||
max: 2,
|
||||
min: 1,
|
||||
sum: 1,
|
||||
histogram_type: 4,
|
||||
},
|
||||
TELEMETRY_TEST_HISTOGRAM_2_DATA: {
|
||||
range: [1, 2],
|
||||
bucket_count: 3,
|
||||
histogram_type: 4,
|
||||
values: {
|
||||
"0": 1,
|
||||
"1": 0,
|
||||
},
|
||||
counts: [
|
||||
1, 0, 0,
|
||||
],
|
||||
ranges: [
|
||||
0, 1, 2,
|
||||
],
|
||||
max: 2,
|
||||
min: 1,
|
||||
sum: 1,
|
||||
histogram_type: 4,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
@ -79,36 +83,42 @@ add_task(async function testKeyedHistogramPacking() {
|
|||
sample_process: {
|
||||
HISTOGRAM_1_DATA: {
|
||||
someKey: {
|
||||
range: [1, 2],
|
||||
bucket_count: 3,
|
||||
histogram_type: 4,
|
||||
values: {
|
||||
"0": 1,
|
||||
"1": 0,
|
||||
},
|
||||
counts: [
|
||||
1, 0, 0,
|
||||
],
|
||||
ranges: [
|
||||
0, 1, 2,
|
||||
],
|
||||
max: 2,
|
||||
min: 1,
|
||||
sum: 1,
|
||||
histogram_type: 4,
|
||||
},
|
||||
otherKey: {
|
||||
range: [1, 2],
|
||||
bucket_count: 3,
|
||||
histogram_type: 4,
|
||||
values: {
|
||||
"0": 1,
|
||||
"1": 0,
|
||||
},
|
||||
counts: [
|
||||
1, 0, 0,
|
||||
],
|
||||
ranges: [
|
||||
0, 1, 2,
|
||||
],
|
||||
max: 2,
|
||||
min: 1,
|
||||
sum: 1,
|
||||
histogram_type: 4,
|
||||
},
|
||||
},
|
||||
TELEMETRY_TEST_HISTOGRAM_2_DATA: {
|
||||
someKey: {
|
||||
range: [1, 2],
|
||||
bucket_count: 3,
|
||||
histogram_type: 4,
|
||||
values: {
|
||||
"0": 1,
|
||||
"1": 0,
|
||||
},
|
||||
counts: [
|
||||
1, 0, 0,
|
||||
],
|
||||
ranges: [
|
||||
0, 1, 2,
|
||||
],
|
||||
max: 2,
|
||||
min: 1,
|
||||
sum: 1,
|
||||
histogram_type: 4,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
Загрузка…
Ссылка в новой задаче