Bug 1282091 - Adjust the "scalars" format in the main ping. r=gfritzsche
authorAlessio Placitelli <alessio.placitelli@gmail.com>
Tue, 05 Jul 2016 02:35:00 +0200
changeset 303681 55e7347982396d56cecfe347c3f2d73562716216
parent 303680 32c95171d0da188c731d0570117d424483ed790e
child 303682 e3d304afd3f2bb3301374a37486f48174a367c27
push id19869
push useralessio.placitelli@gmail.com
push dateTue, 05 Jul 2016 14:59:59 +0000
treeherderfx-team@55e734798239 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgfritzsche
bugs1282091
milestone50.0a1
Bug 1282091 - Adjust the "scalars" format in the main ping. r=gfritzsche
toolkit/components/telemetry/TelemetrySession.jsm
toolkit/components/telemetry/tests/unit/test_TelemetrySession.js
toolkit/content/aboutTelemetry.js
--- a/toolkit/components/telemetry/TelemetrySession.jsm
+++ b/toolkit/components/telemetry/TelemetrySession.jsm
@@ -1253,31 +1253,37 @@ var Impl = {
     };
 
     // Payload common to chrome and content processes.
     let payloadObj = {
       ver: PAYLOAD_VERSION,
       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
     if (Telemetry.canRecordExtended) {
       payloadObj.chromeHangs = protect(() => Telemetry.chromeHangs);
       payloadObj.threadHangStats = protect(() => this.getThreadHangStats(Telemetry.threadHangStats));
       payloadObj.log = protect(() => TelemetryLog.entries());
       payloadObj.webrtc = protect(() => Telemetry.webrtcStats);
     }
 
     if (Utils.isContentProcess) {
       return payloadObj;
     }
 
+    // Set the scalars for the parent process.
+    payloadObj.processes = {
+      parent: {
+        scalars: protect(() => this.getScalars(isSubsession, clearSubsession)),
+      }
+    };
+
     // Additional payload for chrome process.
     payloadObj.info = info;
 
     // Add extended set measurements for chrome process.
     if (Telemetry.canRecordExtended) {
       payloadObj.slowSQL = protect(() => Telemetry.slowSQL);
       payloadObj.fileIOReports = protect(() => Telemetry.fileIOReports);
       payloadObj.lateWrites = protect(() => Telemetry.lateWrites);
--- a/toolkit/components/telemetry/tests/unit/test_TelemetrySession.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetrySession.js
@@ -237,23 +237,24 @@ function checkPayloadInfo(data) {
             "Payload must contain an allowed reason.");
 
   Assert.ok(Date.parse(data.subsessionStartDate) >= Date.parse(data.sessionStartDate));
   Assert.ok(data.profileSubsessionCounter >= data.subsessionCounter);
   Assert.ok(data.timezoneOffset >= -12*60, "The timezone must be in a valid range.");
   Assert.ok(data.timezoneOffset <= 12*60, "The timezone must be in a valid range.");
 }
 
-function checkScalars(payload) {
+function checkScalars(processes) {
   // 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.");
+  const parentProcess = processes.parent;
+  Assert.ok("scalars" in parentProcess, "The scalars section must be available in the parent process.");
+  Assert.equal(typeof parentProcess.scalars, "object", "The scalars entry must be an object.");
 
   // Check that we have valid scalar entries.
-  const scalars = payload.scalars;
+  const scalars = parentProcess.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") {
@@ -398,17 +399,19 @@ function checkPayload(payload, reason, s
       bucket_count: 3,
       histogram_type: 4,
       values: {0:1, 1:0},
       sum: 1,
     },
   };
   Assert.deepEqual(expected_keyed_count, keyedHistograms[TELEMETRY_TEST_KEYED_COUNT]);
 
-  checkScalars(payload);
+  Assert.ok("processes" in payload, "The payload must have a processes section.");
+  Assert.ok("parent" in payload.processes, "There must be at least a parent process.");
+  checkScalars(payload.processes);
 }
 
 function writeStringToFile(file, contents) {
   let ostream = Cc["@mozilla.org/network/safe-file-output-stream;1"]
                 .createInstance(Ci.nsIFileOutputStream);
   ostream.init(file, PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE,
 	       RW_OWNER, ostream.DEFER_OPEN);
   ostream.write(contents, contents.length);
@@ -603,47 +606,47 @@ add_task(function* test_checkSubsessionS
   // 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,
+    Assert.ok(name in subsession.processes.parent.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,
+  Assert.ok(Object.keys(classic.processes.parent.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,
+  Assert.equal(subsession.processes.parent.scalars[UINT_SCALAR], expectedUint,
                UINT_SCALAR + " must contain the expected value.");
-  Assert.equal(subsession.scalars[STRING_SCALAR], expectedString,
+  Assert.equal(subsession.processes.parent.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),
+    Assert.ok(!(name in subsession.processes.parent.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,
+  Assert.equal(subsession.processes.parent.scalars[UINT_SCALAR], expectedUint,
                UINT_SCALAR + " must contain the expected value.");
-  Assert.equal(subsession.scalars[STRING_SCALAR], expectedString,
+  Assert.equal(subsession.processes.parent.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.
     return;
   }
--- a/toolkit/content/aboutTelemetry.js
+++ b/toolkit/content/aboutTelemetry.js
@@ -1554,17 +1554,21 @@ var Scalars = {
   /**
    * Render the scalar data - if present - from the payload in a simple key-value table.
    * @param aPayload A payload object to render the data from.
    */
   render: function(aPayload) {
     let scalarsSection = document.getElementById("scalars");
     removeAllChildNodes(scalarsSection);
 
-    let scalars = aPayload.scalars;
+    if (!aPayload.processes || !aPayload.processes.parent) {
+      return;
+    }
+
+    let scalars = aPayload.processes.parent.scalars;
     const hasData = scalars && Object.keys(scalars).length > 0;
     setHasData("scalars-section", hasData);
     if (!hasData) {
       return;
     }
 
     const headingName = bundle.GetStringFromName("namesHeader");
     const headingValue = bundle.GetStringFromName("valuesHeader");