Bug 1276196 - Add scalars to the main ping payload. r=gfritzsche

This commit is contained in:
Alessio Placitelli 2016-06-24 08:58:00 +02:00
Родитель f882637f17
Коммит d961e1211b
3 изменённых файлов: 117 добавлений и 0 удалений

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

@ -964,6 +964,31 @@ var Impl = {
return ret;
},
getScalars: function (subsession, clearSubsession) {
this._log.trace("getScalars - subsession: " + subsession + ", clearSubsession: " + clearSubsession);
if (!subsession) {
// We only support scalars for subsessions.
this._log.trace("getScalars - We only support scalars in subsessions.");
return {};
}
let scalarsSnapshot =
Telemetry.snapshotScalars(this.getDatasetType(), clearSubsession);
// 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];
}
}
return ret;
},
getThreadHangStats: function getThreadHangStats(stats) {
this._log.trace("getThreadHangStats");
@ -1233,6 +1258,7 @@ var Impl = {
simpleMeasurements: simpleMeasurements,
histograms: protect(() => this.getHistograms(isSubsession, clearSubsession)),
keyedHistograms: protect(() => this.getKeyedHistograms(isSubsession, clearSubsession)),
scalars: protect(() => this.getScalars(isSubsession, clearSubsession)),
};
// Add extended set measurements common to chrome & content processes

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

@ -52,6 +52,7 @@ Structure::
// The following properties may all be null if we fail to collect them.
histograms: {...},
keyedHistograms: {...},
scalars: {...},
chromeHangs: {...},
threadHangStats: [...],
log: [...],
@ -182,6 +183,10 @@ This section contains the keyed histograms available for the current platform.
As of Firefox 48, this section does not contain empty keyed histograms anymore.
scalars
----------
This section contains the :doc:`scalars` that are valid for the current platform. Scalars are not created nor submitted if no data was added to them, and are only reported with subsession pings. Their type and format is described by the ``Scalars.yaml`` file. Its most recent version is available `here <https://dxr.mozilla.org/mozilla-central/source/toolkit/components/telemetry/Scalars.yaml>`_. The ``info.revision`` field indicates the revision of the file that describes the reported scalars.
threadHangStats
---------------
Contains the statistics about the hangs in main and background threads. Note that hangs in this section capture the [C++ pseudostack](https://developer.mozilla.org/en-US/docs/Mozilla/Performance/Profiling_with_the_Built-in_Profiler#Native_stack_vs._Pseudo_stack) and an incomplete JS stack, which is not 100% precise.

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

@ -242,6 +242,30 @@ function checkPayloadInfo(data) {
Assert.ok(data.timezoneOffset <= 12*60, "The timezone must be in a valid range.");
}
function checkScalars(payload) {
// Check that the scalars section is available in the ping payload.
Assert.ok("scalars" in payload, "The scalars section must be available in the payload.");
Assert.equal(typeof payload.scalars, "object", "The scalars entry must be an object.");
// Check that we have valid scalar entries.
const scalars = payload.scalars;
for (let name in scalars) {
Assert.equal(typeof name, "string", "Scalar names must be strings.");
// Check if the value is of a supported type.
const valueType = typeof(scalars[name]);
if (valueType === "string") {
Assert.ok(scalars[name].length <= 50,
"String values can't have more than 50 characters");
} else if (valueType === "number") {
Assert.ok(scalars[name] >= 0,
"We only support unsigned integer values in scalars.");
} else {
Assert.ok(false,
name + " contains an unsupported value type (" + valueType + ")");
}
}
}
function checkPayload(payload, reason, successfulPings, savedPings) {
Assert.ok("info" in payload, "Payload must contain an info section.");
checkPayloadInfo(payload.info);
@ -378,6 +402,8 @@ function checkPayload(payload, reason, successfulPings, savedPings) {
},
};
Assert.deepEqual(expected_keyed_count, keyedHistograms[TELEMETRY_TEST_KEYED_COUNT]);
checkScalars(payload);
}
function writeStringToFile(file, contents) {
@ -556,6 +582,66 @@ add_task(function* test_saveLoadPing() {
checkPayload(pings[1].payload, REASON_SAVED_SESSION, 0, 0);
});
add_task(function* test_checkSubsessionScalars() {
if (gIsAndroid) {
// We don't support subsessions yet on Android.
return;
}
// Clear the scalars.
Telemetry.clearScalars();
yield TelemetryController.testReset();
// Set some scalars.
const UINT_SCALAR = "telemetry.test.unsigned_int_kind";
const STRING_SCALAR = "telemetry.test.string_kind";
let expectedUint = 37;
let expectedString = "Test value. Yay.";
Telemetry.scalarSet(UINT_SCALAR, expectedUint);
Telemetry.scalarSet(STRING_SCALAR, expectedString);
// Check that scalars are not available in classic pings but are in subsession
// pings. Also clear the subsession.
let classic = TelemetrySession.getPayload();
let subsession = TelemetrySession.getPayload("environment-change", true);
const TEST_SCALARS = [ UINT_SCALAR, STRING_SCALAR ];
for (let name of TEST_SCALARS) {
// Scalar must be reported in subsession pings (e.g. main).
Assert.ok(name in subsession.scalars,
name + " must be reported in a subsession ping.");
}
// No scalar must be reported in classic pings (e.g. saved-session).
Assert.ok(Object.keys(classic.scalars).length == 0,
"Scalars must not be reported in a classic ping.");
// And make sure that we're getting the right values in the
// subsession ping.
Assert.equal(subsession.scalars[UINT_SCALAR], expectedUint,
UINT_SCALAR + " must contain the expected value.");
Assert.equal(subsession.scalars[STRING_SCALAR], expectedString,
STRING_SCALAR + " must contain the expected value.");
// Since we cleared the subsession in the last getPayload(), check that
// breaking subsessions clears the scalars.
subsession = TelemetrySession.getPayload("environment-change");
for (let name of TEST_SCALARS) {
Assert.ok(!(name in subsession.scalars),
name + " must be cleared with the new subsession.");
}
// Check if setting the scalars again works as expected.
expectedUint = 85;
expectedString = "A creative different value";
Telemetry.scalarSet(UINT_SCALAR, expectedUint);
Telemetry.scalarSet(STRING_SCALAR, expectedString);
subsession = TelemetrySession.getPayload("environment-change");
Assert.equal(subsession.scalars[UINT_SCALAR], expectedUint,
UINT_SCALAR + " must contain the expected value.");
Assert.equal(subsession.scalars[STRING_SCALAR], expectedString,
STRING_SCALAR + " must contain the expected value.");
});
add_task(function* test_checkSubsessionHistograms() {
if (gIsAndroid) {
// We don't support subsessions yet on Android.