Bug 1278556 - Add scalar data from child processes to the main ping. r=chutten

MozReview-Commit-ID: Ed4cV4XieRq
This commit is contained in:
Alessio Placitelli 2017-01-16 06:10:00 +01:00
Родитель 932126d970
Коммит 1161e36b35
13 изменённых файлов: 306 добавлений и 62 удалений

Просмотреть файл

@ -61,8 +61,7 @@ let checkScalar = (scalars, scalarName, value, msg) => {
* Get a snapshot of the scalars and check them against the provided values.
*/
let checkScalars = (countsObject) => {
const scalars =
Services.telemetry.snapshotScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN);
const scalars = getParentProcessScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN);
// Check the expected values. Scalars that are never set must not be reported.
checkScalar(scalars, MAX_CONCURRENT_TABS, countsObject.maxTabs,
@ -184,8 +183,7 @@ add_task(function* test_URIAndDomainCounts() {
let checkCounts = (countsObject) => {
// Get a snapshot of the scalars and then clear them.
const scalars =
Services.telemetry.snapshotScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN);
const scalars = getParentProcessScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN);
checkScalar(scalars, TOTAL_URI_COUNT, countsObject.totalURIs,
"The URI scalar must contain the expected value.");
checkScalar(scalars, UNIQUE_DOMAINS_COUNT, countsObject.domainCount,

Просмотреть файл

@ -71,8 +71,7 @@ add_task(function* test_context_menu() {
searchItem.click();
info("Validate the search metrics.");
const scalars =
Services.telemetry.snapshotKeyedScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, false);
const scalars = getParentProcessScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true, false);
checkKeyedScalar(scalars, SCALAR_CONTEXT_MENU, "search", 1);
Assert.equal(Object.keys(scalars[SCALAR_CONTEXT_MENU]).length, 1,
"This search must only increment one entry in the scalar.");
@ -108,8 +107,7 @@ add_task(function* test_about_newtab() {
yield p;
// Check if the scalars contain the expected values.
const scalars =
Services.telemetry.snapshotKeyedScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, false);
const scalars = getParentProcessScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true, false);
checkKeyedScalar(scalars, SCALAR_ABOUT_NEWTAB, "search_enter", 1);
Assert.equal(Object.keys(scalars[SCALAR_ABOUT_NEWTAB]).length, 1,
"This search must only increment one entry in the scalar.");

Просмотреть файл

@ -71,8 +71,7 @@ add_task(function* test_abouthome_simpleQuery() {
yield p;
// Check if the scalars contain the expected values.
const scalars =
Services.telemetry.snapshotKeyedScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, false);
const scalars = getParentProcessScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true, false);
checkKeyedScalar(scalars, SCALAR_ABOUT_HOME, "search_enter", 1);
Assert.equal(Object.keys(scalars[SCALAR_ABOUT_HOME]).length, 1,
"This search must only increment one entry in the scalar.");

Просмотреть файл

@ -27,8 +27,7 @@ add_task(function* test_privateMode() {
yield BrowserTestUtils.browserLoaded(privateWin.gBrowser.selectedBrowser);
// Check that tab and window count is recorded.
const scalars =
Services.telemetry.snapshotScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN);
const scalars = getParentProcessScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN);
ok(!(TOTAL_URI_COUNT in scalars), "We should not track URIs in private mode.");
ok(!(UNFILTERED_URI_COUNT in scalars), "We should not track URIs in private mode.");
@ -76,8 +75,7 @@ add_task(function* test_sessionRestore() {
yield tabRestored;
// Check that the URI is not recorded.
const scalars =
Services.telemetry.snapshotScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN);
const scalars = getParentProcessScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN);
ok(!(TOTAL_URI_COUNT in scalars), "We should not track URIs from restored sessions.");
ok(!(UNFILTERED_URI_COUNT in scalars), "We should not track URIs from restored sessions.");

Просмотреть файл

@ -97,8 +97,7 @@ add_task(function* test_plainQuery() {
yield p;
// Check if the scalars contain the expected values.
const scalars =
Services.telemetry.snapshotKeyedScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, false);
const scalars = getParentProcessScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true, false);
checkKeyedScalar(scalars, SCALAR_SEARCHBAR, "search_enter", 1);
Assert.equal(Object.keys(scalars[SCALAR_SEARCHBAR]).length, 1,
"This search must only increment one entry in the scalar.");
@ -132,8 +131,7 @@ add_task(function* test_oneOff() {
yield p;
// Check if the scalars contain the expected values.
const scalars =
Services.telemetry.snapshotKeyedScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, false);
const scalars = getParentProcessScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true, false);
checkKeyedScalar(scalars, SCALAR_SEARCHBAR, "search_oneoff", 1);
Assert.equal(Object.keys(scalars[SCALAR_SEARCHBAR]).length, 1,
"This search must only increment one entry in the scalar.");
@ -178,8 +176,7 @@ add_task(function* test_suggestion() {
yield p;
// Check if the scalars contain the expected values.
const scalars =
Services.telemetry.snapshotKeyedScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, false);
const scalars = getParentProcessScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true, false);
checkKeyedScalar(scalars, SCALAR_SEARCHBAR, "search_suggestion", 1);
Assert.equal(Object.keys(scalars[SCALAR_SEARCHBAR]).length, 1,
"This search must only increment one entry in the scalar.");

Просмотреть файл

@ -116,8 +116,7 @@ add_task(function* test_simpleQuery() {
yield p;
// Check if the scalars contain the expected values.
const scalars =
Services.telemetry.snapshotKeyedScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, false);
const scalars = getParentProcessScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true, false);
checkKeyedScalar(scalars, SCALAR_URLBAR, "search_enter", 1);
Assert.equal(Object.keys(scalars[SCALAR_URLBAR]).length, 1,
"This search must only increment one entry in the scalar.");
@ -162,8 +161,7 @@ add_task(function* test_searchAlias() {
yield p;
// Check if the scalars contain the expected values.
const scalars =
Services.telemetry.snapshotKeyedScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, false);
const scalars = getParentProcessScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true, false);
checkKeyedScalar(scalars, SCALAR_URLBAR, "search_alias", 1);
Assert.equal(Object.keys(scalars[SCALAR_URLBAR]).length, 1,
"This search must only increment one entry in the scalar.");
@ -211,8 +209,7 @@ add_task(function* test_oneOff() {
yield p;
// Check if the scalars contain the expected values.
const scalars =
Services.telemetry.snapshotKeyedScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, false);
const scalars = getParentProcessScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true, false);
checkKeyedScalar(scalars, SCALAR_URLBAR, "search_oneoff", 1);
Assert.equal(Object.keys(scalars[SCALAR_URLBAR]).length, 1,
"This search must only increment one entry in the scalar.");
@ -271,8 +268,7 @@ add_task(function* test_suggestion() {
yield p;
// Check if the scalars contain the expected values.
const scalars =
Services.telemetry.snapshotKeyedScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, false);
const scalars = getParentProcessScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true, false);
checkKeyedScalar(scalars, SCALAR_URLBAR, "search_suggestion", 1);
Assert.equal(Object.keys(scalars[SCALAR_URLBAR]).length, 1,
"This search must only increment one entry in the scalar.");

Просмотреть файл

@ -95,6 +95,16 @@ function checkKeyedHistogram(h, key, expectedValue) {
Assert.equal(snapshot[key].sum, expectedValue, `The key ${key} must contain ${expectedValue}.`);
}
/**
* Return the scalars from the parent-process.
*/
function getParentProcessScalars(aChannel, aKeyed = false, aClear = false) {
const scalars = aKeyed ?
Services.telemetry.snapshotKeyedScalars(aChannel, aClear)["default"] :
Services.telemetry.snapshotScalars(aChannel, aClear)["default"];
return scalars || {};
}
function checkEvents(events, expectedEvents) {
if (!Services.telemetry.canRecordExtended) {
// Currently we only collect the tested events when extended Telemetry is enabled.

Просмотреть файл

@ -284,3 +284,39 @@ telemetry.test:
keyed: true
notification_emails:
- telemetry-client-dev@mozilla.com
record_in_processes:
- 'main'
- 'content'
content_only_uint:
bug_numbers:
- 1278556
description: A testing uint scalar; not meant to be touched.
expires: never
kind: uint
notification_emails:
- telemetry-client-dev@mozilla.com
record_in_processes:
- 'content'
all_processes_uint:
bug_numbers:
- 1278556
description: A testing uint scalar; not meant to be touched.
expires: never
kind: uint
notification_emails:
- telemetry-client-dev@mozilla.com
record_in_processes:
- 'all'
all_child_processes_string:
bug_numbers:
- 1278556
description: A testing string scalar; not meant to be touched.
expires: never
kind: string
notification_emails:
- telemetry-client-dev@mozilla.com
record_in_processes:
- 'all_childs'

Просмотреть файл

@ -47,6 +47,12 @@ const HISTOGRAM_SUFFIXES = {
GPU: "#gpu",
}
const INTERNAL_PROCESSES_NAMES = {
PARENT: "default",
CONTENT: "tab",
GPU: "gpu",
}
const ENVIRONMENT_CHANGE_LISTENER = "TelemetrySession::onEnvironmentChange";
const MS_IN_ONE_HOUR = 60 * 60 * 1000;
@ -978,7 +984,9 @@ var Impl = {
* @param {subsession} If true, then we collect the data for a subsession.
* @param {clearSubsession} If true, we need to clear the subsession.
* @param {keyed} Take a snapshot of keyed or non keyed scalars.
* @return {Object} The scalar data as a Javascript object.
* @return {Object} The scalar data as a Javascript object, including the
* data from child processes, in the following format:
* {'content': { 'scalarName': ... }, 'gpu': { ... } }
*/
getScalars(subsession, clearSubsession, keyed) {
this._log.trace("getScalars - subsession: " + subsession + ", clearSubsession: " +
@ -996,11 +1004,17 @@ var Impl = {
// Don't return the test scalars.
let ret = {};
for (let name in scalarsSnapshot) {
if (name.startsWith('telemetry.test') && this._testing == false) {
this._log.trace("getScalars - Skipping test scalar: " + name);
} else {
ret[name] = scalarsSnapshot[name];
for (let processName in scalarsSnapshot) {
for (let name in scalarsSnapshot[processName]) {
if (name.startsWith('telemetry.test') && this._testing == false) {
this._log.trace("getScalars - Skipping test scalar: " + name);
continue;
}
// Finally arrange the data in the returned object.
if (!(processName in ret)) {
ret[processName] = {};
}
ret[processName][name] = scalarsSnapshot[processName][name];
}
}
@ -1287,15 +1301,20 @@ var Impl = {
// Additional payload for chrome process.
let histograms = protect(() => this.getHistograms(isSubsession, clearSubsession), {});
let keyedHistograms = protect(() => this.getKeyedHistograms(isSubsession, clearSubsession), {});
let scalars = protect(() => this.getScalars(isSubsession, clearSubsession), {});
let keyedScalars = protect(() => this.getScalars(isSubsession, clearSubsession, true), {});
payloadObj.histograms = histograms[HISTOGRAM_SUFFIXES.PARENT] || {};
payloadObj.keyedHistograms = keyedHistograms[HISTOGRAM_SUFFIXES.PARENT] || {};
payloadObj.processes = {
parent: {
scalars: protect(() => this.getScalars(isSubsession, clearSubsession)),
keyedScalars: protect(() => this.getScalars(isSubsession, clearSubsession, true)),
scalars: scalars[INTERNAL_PROCESSES_NAMES.PARENT] || {},
keyedScalars: keyedScalars[INTERNAL_PROCESSES_NAMES.PARENT] || {},
events: protect(() => this.getEvents(isSubsession, clearSubsession)),
},
content: {
scalars: scalars[INTERNAL_PROCESSES_NAMES.CONTENT],
keyedScalars: keyedScalars[INTERNAL_PROCESSES_NAMES.CONTENT],
histograms: histograms[HISTOGRAM_SUFFIXES.CONTENT],
keyedHistograms: keyedHistograms[HISTOGRAM_SUFFIXES.CONTENT],
},
@ -1303,8 +1322,12 @@ var Impl = {
// Only include the GPU process if we've accumulated data for it.
if (HISTOGRAM_SUFFIXES.GPU in histograms ||
HISTOGRAM_SUFFIXES.GPU in keyedHistograms) {
HISTOGRAM_SUFFIXES.GPU in keyedHistograms ||
INTERNAL_PROCESSES_NAMES.GPU in scalars ||
INTERNAL_PROCESSES_NAMES.GPU in keyedScalars) {
payloadObj.processes.gpu = {
scalars: scalars[INTERNAL_PROCESSES_NAMES.GPU],
keyedScalars: keyedScalars[INTERNAL_PROCESSES_NAMES.GPU],
histograms: histograms[HISTOGRAM_SUFFIXES.GPU],
keyedHistograms: keyedHistograms[HISTOGRAM_SUFFIXES.GPU],
};

Просмотреть файл

@ -121,7 +121,14 @@ GetScalarsSnapshot(bool aKeyed, JSContext* aCx, JS::MutableHandle<JS::Value> aRe
ASSERT_EQ(rv, NS_OK) << "Creating a snapshot of the data must not fail.";
ASSERT_TRUE(scalarsSnapshot.isObject()) << "The snapshot must be an object.";
aResult.set(scalarsSnapshot);
// We currently only support scalars from the parent process in the gtests.
JS::RootedValue parentScalars(aCx);
JS::RootedObject scalarObj(aCx, &scalarsSnapshot.toObject());
// Don't complain if no scalars for the parent process can be found. Just
// return an empty object.
Unused << JS_GetProperty(aCx, scalarObj, "default", &parentScalars);
aResult.set(parentScalars);
}
} // Anonymous namespace.

Просмотреть файл

@ -0,0 +1,174 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
*/
Cu.import("resource://gre/modules/Services.jsm", this);
Cu.import("resource://gre/modules/TelemetryController.jsm", this);
Cu.import("resource://gre/modules/TelemetrySession.jsm", this);
Cu.import("resource://gre/modules/PromiseUtils.jsm", this);
Cu.import("resource://testing-common/ContentTaskUtils.jsm", this);
const MESSAGE_CHILD_TEST_DONE = "ChildTest:Done";
const PLATFORM_VERSION = "1.9.2";
const APP_VERSION = "1";
const APP_ID = "xpcshell@tests.mozilla.org";
const APP_NAME = "XPCShell";
const UINT_SCALAR = "telemetry.test.unsigned_int_kind";
const KEYED_UINT_SCALAR = "telemetry.test.keyed_unsigned_int";
const KEYED_BOOL_SCALAR = "telemetry.test.keyed_boolean_kind";
const CONTENT_ONLY_UINT_SCALAR = "telemetry.test.content_only_uint";
const ALL_PROCESSES_UINT_SCALAR = "telemetry.test.all_processes_uint";
const ALL_CHILD_PROCESSES_STRING_SCALAR = "telemetry.test.all_child_processes_string";
function run_child_test() {
// Attempt to set some scalar values from the "content" process.
// The next scalars are not allowed to be recorded in the content process.
Telemetry.scalarSet(UINT_SCALAR, 1);
Telemetry.keyedScalarSet(KEYED_UINT_SCALAR, "should-not-be-recorded", 1);
// The next scalars shou be recorded in only the content process.
Telemetry.scalarSet(CONTENT_ONLY_UINT_SCALAR, 37);
Telemetry.scalarSet(ALL_CHILD_PROCESSES_STRING_SCALAR, "all-child-processes");
// The next scalar will be recorded in the parent and content processes.
Telemetry.keyedScalarSet(KEYED_BOOL_SCALAR, "content-key", true);
Telemetry.keyedScalarSet(KEYED_BOOL_SCALAR, "content-key2", false);
Telemetry.scalarSet(ALL_PROCESSES_UINT_SCALAR, 37);
}
function setParentScalars() {
// The following scalars are not allowed to be recorded in the parent process.
Telemetry.scalarSet(CONTENT_ONLY_UINT_SCALAR, 15);
Telemetry.scalarSet(ALL_CHILD_PROCESSES_STRING_SCALAR, "all-child-processes");
// The next ones will be recorded only in the parent.
Telemetry.scalarSet(UINT_SCALAR, 15);
// This last batch will be available both in the parent and child processes.
Telemetry.keyedScalarSet(KEYED_BOOL_SCALAR, "parent-key", false);
Telemetry.scalarSet(ALL_PROCESSES_UINT_SCALAR, 37);
}
function checkParentScalars(processData) {
const scalars = processData.scalars;
const keyedScalars = processData.keyedScalars;
// Check the plain scalars, make sure we're only recording what we expect.
Assert.ok(!(CONTENT_ONLY_UINT_SCALAR in scalars),
"Scalars must not be recorded in other processes unless allowed.");
Assert.ok(!(ALL_CHILD_PROCESSES_STRING_SCALAR in scalars),
"Scalars must not be recorded in other processes unless allowed.");
Assert.ok(UINT_SCALAR in scalars,
`${UINT_SCALAR} must be recorded in the parent process.`);
Assert.equal(scalars[UINT_SCALAR], 15,
`${UINT_SCALAR} must have the correct value (parent process).`);
Assert.ok(ALL_PROCESSES_UINT_SCALAR in scalars,
`${ALL_PROCESSES_UINT_SCALAR} must be recorded in the parent process.`);
Assert.equal(scalars[ALL_PROCESSES_UINT_SCALAR], 37,
`${ALL_PROCESSES_UINT_SCALAR} must have the correct value (parent process).`);
// Now check the keyed scalars.
Assert.ok(KEYED_BOOL_SCALAR in keyedScalars,
`${KEYED_BOOL_SCALAR} must be recorded in the parent process.`);
Assert.ok('parent-key' in keyedScalars[KEYED_BOOL_SCALAR],
`${KEYED_BOOL_SCALAR} must be recorded in the parent process.`);
Assert.equal(Object.keys(keyedScalars[KEYED_BOOL_SCALAR]).length, 1,
`${KEYED_BOOL_SCALAR} must only contain the expected key in parent process.`);
Assert.equal(keyedScalars[KEYED_BOOL_SCALAR]['parent-key'], false,
`${KEYED_BOOL_SCALAR} must have the correct value (parent process).`);
}
function checkContentScalars(processData) {
const scalars = processData.scalars;
const keyedScalars = processData.keyedScalars;
// Check the plain scalars for the content process.
Assert.ok(!(UINT_SCALAR in scalars),
"Scalars must not be recorded in other processes unless allowed.");
Assert.ok(!(KEYED_UINT_SCALAR in keyedScalars),
"Keyed scalars must not be recorded in other processes unless allowed.");
Assert.ok(CONTENT_ONLY_UINT_SCALAR in scalars,
`${CONTENT_ONLY_UINT_SCALAR} must be recorded in the content process.`);
Assert.equal(scalars[CONTENT_ONLY_UINT_SCALAR], 37,
`${CONTENT_ONLY_UINT_SCALAR} must have the correct value (content process).`);
Assert.ok(ALL_CHILD_PROCESSES_STRING_SCALAR in scalars,
`${ALL_CHILD_PROCESSES_STRING_SCALAR} must be recorded in the content process.`);
Assert.equal(scalars[ALL_CHILD_PROCESSES_STRING_SCALAR], "all-child-processes",
`${ALL_CHILD_PROCESSES_STRING_SCALAR} must have the correct value (content process).`);
Assert.ok(ALL_PROCESSES_UINT_SCALAR in scalars,
`${ALL_PROCESSES_UINT_SCALAR} must be recorded in the content process.`);
Assert.equal(scalars[ALL_PROCESSES_UINT_SCALAR], 37,
`${ALL_PROCESSES_UINT_SCALAR} must have the correct value (content process).`);
// Check the keyed scalars.
Assert.ok(KEYED_BOOL_SCALAR in keyedScalars,
`${KEYED_BOOL_SCALAR} must be recorded in the content process.`);
Assert.ok('content-key' in keyedScalars[KEYED_BOOL_SCALAR],
`${KEYED_BOOL_SCALAR} must be recorded in the content process.`);
Assert.ok('content-key2' in keyedScalars[KEYED_BOOL_SCALAR],
`${KEYED_BOOL_SCALAR} must be recorded in the content process.`);
Assert.equal(keyedScalars[KEYED_BOOL_SCALAR]['content-key'], true,
`${KEYED_BOOL_SCALAR} must have the correct value (content process).`);
Assert.equal(keyedScalars[KEYED_BOOL_SCALAR]['content-key2'], false,
`${KEYED_BOOL_SCALAR} must have the correct value (content process).`);
Assert.equal(Object.keys(keyedScalars[KEYED_BOOL_SCALAR]).length, 2,
`${KEYED_BOOL_SCALAR} must contain the expected keys in content process.`);
}
/**
* This function waits until content scalars are reported into the
* scalar snapshot.
*/
function* waitForContentScalars() {
yield ContentTaskUtils.waitForCondition(() => {
const scalars =
Telemetry.snapshotScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN);
return Object.keys(scalars).includes("tab");
});
}
add_task(function*() {
if (!runningInParent) {
TelemetryController.testSetupContent();
run_child_test();
do_send_remote_message(MESSAGE_CHILD_TEST_DONE);
return;
}
// Setup.
do_get_profile(true);
loadAddonManager(APP_ID, APP_NAME, APP_VERSION, PLATFORM_VERSION);
Services.prefs.setBoolPref(PREF_TELEMETRY_ENABLED, true);
yield TelemetryController.testSetup();
if (runningInParent) {
setParentScalars();
// Make sure we don't generate unexpected pings due to pref changes.
yield setEmptyPrefWatchlist();
}
// Run test in child, don't wait for it to finish: just wait for the
// MESSAGE_CHILD_TEST_DONE.
run_test_in_child("test_ChildScalars.js");
yield do_await_remote_message(MESSAGE_CHILD_TEST_DONE);
// Once scalars are set by the content process, they don't immediately get
// sent to the parent process. Wait for the Telemetry IPC Timer to trigger
// and batch send the data back to the parent process.
yield waitForContentScalars();
// Get an "environment-changed" ping rather than a "test-ping", as
// scalar measurements are only supported in subsession pings.
const payload = TelemetrySession.getPayload("environment-change");
// Validate the scalar data.
Assert.ok("processes" in payload, "Should have processes section");
Assert.ok("content" in payload.processes, "Should have child process section");
Assert.ok("scalars" in payload.processes.content, "Child process section should have scalars.");
Assert.ok("keyedScalars" in payload.processes.content, "Child process section should have keyed scalars.");
checkParentScalars(payload.processes.parent);
checkContentScalars(payload.processes.content);
do_test_finished();
});

Просмотреть файл

@ -7,6 +7,13 @@ const STRING_SCALAR = "telemetry.test.string_kind";
const BOOLEAN_SCALAR = "telemetry.test.boolean_kind";
const KEYED_UINT_SCALAR = "telemetry.test.keyed_unsigned_int";
function getParentProcessScalars(aChannel, aKeyed = false, aClear = false) {
const scalars = aKeyed ?
Telemetry.snapshotKeyedScalars(aChannel, aClear)["default"] :
Telemetry.snapshotScalars(aChannel, aClear)["default"];
return scalars || {};
}
add_task(function* test_serializationFormat() {
Telemetry.clearScalars();
@ -18,9 +25,9 @@ add_task(function* test_serializationFormat() {
Telemetry.scalarSet(BOOLEAN_SCALAR, true);
Telemetry.keyedScalarSet(KEYED_UINT_SCALAR, "first_key", 1234);
// Get a snapshot of the scalars.
// Get a snapshot of the scalars for the main process (internally called "default").
const scalars =
Telemetry.snapshotScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN);
getParentProcessScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN);
// Check that they are serialized to the correct format.
Assert.equal(typeof(scalars[UINT_SCALAR]), "number",
@ -55,7 +62,7 @@ add_task(function* test_keyedSerializationFormat() {
// Get a snapshot of the scalars.
const keyedScalars =
Telemetry.snapshotKeyedScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN);
getParentProcessScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true);
Assert.ok(!(UINT_SCALAR in keyedScalars),
UINT_SCALAR + " must not be serialized with the keyed scalars.");
@ -103,13 +110,12 @@ add_task(function* test_nonexistingScalar() {
"Setting the maximum of a non keyed existing scalar must throw.");
// Get a snapshot of the scalars.
const scalars =
Telemetry.snapshotScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN);
const scalars = getParentProcessScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN);
Assert.ok(!(NON_EXISTING_SCALAR in scalars), "The non existing scalar must not be persisted.");
const keyedScalars =
Telemetry.snapshotKeyedScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN);
getParentProcessScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true);
Assert.ok(!(NON_EXISTING_SCALAR in keyedScalars),
"The non existing keyed scalar must not be persisted.");
@ -137,9 +143,9 @@ add_task(function* test_expiredScalar() {
// Get a snapshot of the scalars.
const scalars =
Telemetry.snapshotScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN);
getParentProcessScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN);
const keyedScalars =
Telemetry.snapshotKeyedScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN);
getParentProcessScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true);
Assert.ok(!(EXPIRED_SCALAR in scalars), "The expired scalar must not be persisted.");
Assert.equal(scalars[UNEXPIRED_SCALAR], expectedValue,
@ -151,7 +157,7 @@ add_task(function* test_expiredScalar() {
add_task(function* test_unsignedIntScalar() {
let checkScalar = (expectedValue) => {
const scalars =
Telemetry.snapshotScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN);
getParentProcessScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN);
Assert.equal(scalars[UINT_SCALAR], expectedValue,
UINT_SCALAR + " must contain the expected value.");
};
@ -209,7 +215,7 @@ add_task(function* test_unsignedIntScalar() {
add_task(function* test_stringScalar() {
let checkExpectedString = (expectedString) => {
const scalars =
Telemetry.snapshotScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN);
getParentProcessScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN);
Assert.equal(scalars[STRING_SCALAR], expectedString,
STRING_SCALAR + " must contain the expected string value.");
};
@ -250,7 +256,7 @@ add_task(function* test_stringScalar() {
add_task(function* test_booleanScalar() {
let checkExpectedBool = (expectedBoolean) => {
const scalars =
Telemetry.snapshotScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN);
getParentProcessScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN);
Assert.equal(scalars[BOOLEAN_SCALAR], expectedBoolean,
BOOLEAN_SCALAR + " must contain the expected boolean value.");
};
@ -299,14 +305,14 @@ add_task(function* test_scalarRecording() {
let checkValue = (scalarName, expectedValue) => {
const scalars =
Telemetry.snapshotScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN);
getParentProcessScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN);
Assert.equal(scalars[scalarName], expectedValue,
scalarName + " must contain the expected value.");
};
let checkNotSerialized = (scalarName) => {
const scalars =
Telemetry.snapshotScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN);
getParentProcessScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN);
Assert.ok(!(scalarName in scalars), scalarName + " was not recorded.");
};
@ -342,14 +348,14 @@ add_task(function* test_keyedScalarRecording() {
let checkValue = (scalarName, expectedValue) => {
const scalars =
Telemetry.snapshotKeyedScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN);
getParentProcessScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true);
Assert.equal(scalars[scalarName][testKey], expectedValue,
scalarName + " must contain the expected value.");
};
let checkNotSerialized = (scalarName) => {
const scalars =
Telemetry.snapshotKeyedScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN);
getParentProcessScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true);
Assert.ok(!(scalarName in scalars), scalarName + " was not recorded.");
};
@ -389,9 +395,9 @@ add_task(function* test_subsession() {
// Get a snapshot and reset the subsession. The value we set must be there.
let scalars =
Telemetry.snapshotScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true);
getParentProcessScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, false, true);
let keyedScalars =
Telemetry.snapshotKeyedScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true);
getParentProcessScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true, true);
Assert.equal(scalars[UINT_SCALAR], 3785,
UINT_SCALAR + " must contain the expected value.");
@ -405,9 +411,9 @@ add_task(function* test_subsession() {
// Get a new snapshot and reset the subsession again. Since no new value
// was set, the scalars should not be reported.
scalars =
Telemetry.snapshotScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true);
getParentProcessScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, false, true);
keyedScalars =
Telemetry.snapshotKeyedScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true);
getParentProcessScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true, true);
Assert.ok(!(UINT_SCALAR in scalars), UINT_SCALAR + " must be empty and not reported.");
Assert.ok(!(STRING_SCALAR in scalars), STRING_SCALAR + " must be empty and not reported.");
@ -437,7 +443,7 @@ add_task(function* test_keyed_uint() {
// Get a snapshot of the scalars and make sure the keys contain
// the correct values.
const keyedScalars =
Telemetry.snapshotKeyedScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN);
getParentProcessScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true);
for (let k = 0; k < 3; k++) {
const keyName = KEYS[k];
@ -467,7 +473,7 @@ add_task(function* test_keyed_boolean() {
// Get a snapshot of the scalars and make sure the keys contain
// the correct values.
let keyedScalars =
Telemetry.snapshotKeyedScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN);
getParentProcessScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true);
Assert.equal(keyedScalars[KEYED_BOOLEAN_TYPE][first_key], true,
"The key must contain the expected value.");
Assert.equal(keyedScalars[KEYED_BOOLEAN_TYPE][second_key], false,
@ -478,7 +484,7 @@ add_task(function* test_keyed_boolean() {
Telemetry.keyedScalarSet(KEYED_BOOLEAN_TYPE, second_key, true);
keyedScalars =
Telemetry.snapshotKeyedScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN);
getParentProcessScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true);
Assert.equal(keyedScalars[KEYED_BOOLEAN_TYPE][first_key], false,
"The key must contain the expected value.");
Assert.equal(keyedScalars[KEYED_BOOLEAN_TYPE][second_key], true,
@ -515,7 +521,7 @@ add_task(function* test_keyed_keys_length() {
// Make sure the key with the right length contains the expected value.
let keyedScalars =
Telemetry.snapshotKeyedScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN);
getParentProcessScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true);
Assert.equal(Object.keys(keyedScalars[KEYED_UINT_SCALAR]).length, 1,
"The keyed scalar must contain exactly 1 key.");
Assert.ok(NORMAL_KEY in keyedScalars[KEYED_UINT_SCALAR],
@ -557,7 +563,7 @@ add_task(function* test_keyed_max_keys() {
// Make sure all the keys except the last one are available and have the correct
// values.
let keyedScalars =
Telemetry.snapshotKeyedScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN);
getParentProcessScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true);
// Check that the keyed scalar only contain the first 100 keys.
const reportedKeysSet = new Set(Object.keys(keyedScalars[KEYED_UINT_SCALAR]));

Просмотреть файл

@ -55,6 +55,8 @@ run-sequentially = Bug 1046307, test can fail intermittently when CPU load is hi
[test_ChildHistograms.js]
skip-if = os == "android"
tags = addons
[test_ChildScalars.js]
skip-if = os == "android" # Disabled due to crashes (see bug 1331366)
[test_TelemetryReportingPolicy.js]
tags = addons
[test_TelemetryScalars.js]