Bug 1166672 - Make about:telemetry work properly for optional ping sections. r=rvitillo a=sledru
authorGeorg Fritzsche <georg.fritzsche@googlemail.com>
Wed, 20 May 2015 20:22:38 +0700
changeset 275121 bf57d61e70fefc52e4c65bf89f9c515453497f69
parent 275120 7ebfb7f13d158a7a52f459ad5db2172f6aaf3f0e
child 275122 f79a0036add4078437e99b24895ae187b339a313
push id863
push userraliiev@mozilla.com
push dateMon, 03 Aug 2015 13:22:43 +0000
treeherdermozilla-release@f6321b14228d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrvitillo, sledru
bugs1166672
milestone40.0a2
Bug 1166672 - Make about:telemetry work properly for optional ping sections. r=rvitillo a=sledru
toolkit/content/aboutTelemetry.js
--- a/toolkit/content/aboutTelemetry.js
+++ b/toolkit/content/aboutTelemetry.js
@@ -483,19 +483,24 @@ let GeneralData = {
   },
 };
 
 let EnvironmentData = {
   /**
    * Renders the environment data
    */
   render: function(ping) {
-    setHasData("environment-data-section", true);
     let dataDiv = document.getElementById("environment-data");
     removeAllChildNodes(dataDiv);
+    const hasData = !!ping.environment;
+    setHasData("environment-data-section", hasData);
+    if (!hasData) {
+      return;
+    }
+
     let data = sectionalizeObject(ping.environment);
 
     for (let [section, sectionData] of data) {
       let table = document.createElement("table");
       let caption = document.createElement("caption");
       caption.appendChild(document.createTextNode(section + "\n"));
       table.appendChild(caption);
 
@@ -531,21 +536,22 @@ let EnvironmentData = {
 };
 
 let TelLog = {
   /**
    * Renders the telemetry log
    */
   render: function(aPing) {
     let entries = aPing.payload.log;
+    const hasData = entries && entries.length > 0;
+    setHasData("telemetry-log-section", hasData);
+    if (!hasData) {
+      return;
+    }
 
-    if(entries.length == 0) {
-        return;
-    }
-    setHasData("telemetry-log-section", true);
     let table = document.createElement("table");
 
     let caption = document.createElement("caption");
     let captionString = bundle.GetStringFromName("telemetryLogTitle");
     caption.appendChild(document.createTextNode(captionString + "\n"));
     table.appendChild(caption);
 
     let headings = document.createElement("tr");
@@ -599,27 +605,33 @@ let SlowSQL = {
    */
   render: function SlowSQL_render(aPing) {
     // We can add the debug SQL data to the current ping later.
     // However, we need to be careful to never send that debug data
     // out due to privacy concerns.
     // We want to show the actual ping data for archived pings,
     // so skip this there.
     let debugSlowSql = PingPicker.viewCurrentPingData && Preferences.get(PREF_DEBUG_SLOW_SQL, false);
+    let slowSql = debugSlowSql ? Telemetry.debugSlowSQL : aPing.payload.slowSQL;
+    if (!slowSql) {
+      setHasData("slow-sql-section", false);
+      return;
+    }
+
     let {mainThread, otherThreads} =
       debugSlowSql ? Telemetry.debugSlowSQL : aPing.payload.slowSQL;
 
     let mainThreadCount = Object.keys(mainThread).length;
     let otherThreadCount = Object.keys(otherThreads).length;
     if (mainThreadCount == 0 && otherThreadCount == 0) {
+      setHasData("slow-sql-section", false);
       return;
     }
 
     setHasData("slow-sql-section", true);
-
     if (debugSlowSql) {
       document.getElementById("sql-warning").classList.remove("hidden");
     }
 
     let slowSqlDiv = document.getElementById("slow-sql-tables");
     removeAllChildNodes(slowSqlDiv);
 
     // Main thread
@@ -857,16 +869,21 @@ let ChromeHangs = {
 
   symbolRequest: null,
 
   /**
    * Renders raw chrome hang data
    */
   render: function ChromeHangs_render(aPing) {
     let hangs = aPing.payload.chromeHangs;
+    setHasData("chrome-hangs-section", !!hangs);
+    if (!hangs) {
+      return;
+    }
+
     let stacks = hangs.stacks;
     let memoryMap = hangs.memoryMap;
 
     StackRenderer.renderStacks("chrome-hangs", stacks, memoryMap,
 			       (index) => this.renderHangHeader(aPing, index));
   },
 
   renderHangHeader: function ChromeHangs_renderHangHeader(aPing, aIndex) {
@@ -880,22 +897,24 @@ let ThreadHangStats = {
   /**
    * Renders raw thread hang stats data
    */
   render: function(aPing) {
     let div = document.getElementById("thread-hang-stats");
     removeAllChildNodes(div);
 
     let stats = aPing.payload.threadHangStats;
+    setHasData("thread-hang-stats-section", stats && (stats.length > 0));
+    if (!stats) {
+      return;
+    }
+
     stats.forEach((thread) => {
       div.appendChild(this.renderThread(thread));
     });
-    if (stats.length) {
-      setHasData("thread-hang-stats-section", true);
-    }
   },
 
   /**
    * Creates and fills data corresponding to a thread
    */
   renderThread: function(aThread) {
     let div = document.createElement("div");
 
@@ -1271,17 +1290,17 @@ let AddonDetails = {
   /**
    * Render the addon details section as a series of headers followed by key/value tables
    * @param aPing A ping object to render the data from.
    */
   render: function AddonDetails_render(aPing) {
     let addonSection = document.getElementById("addon-details");
     removeAllChildNodes(addonSection);
     let addonDetails = aPing.payload.addonDetails;
-    const hasData = Object.keys(addonDetails).length > 0;
+    const hasData = addonDetails && Object.keys(addonDetails).length > 0;
     setHasData("addon-details-section", hasData);
     if (!hasData) {
       return;
     }
 
     for (let provider in addonDetails) {
       let providerSection = document.createElement("h2");
       let titleText = bundle.formatStringFromName("addonProvider", [provider], 1);
@@ -1433,16 +1452,21 @@ function onLoad() {
 }
 
 let LateWritesSingleton = {
   renderHeader: function LateWritesSingleton_renderHeader(aIndex) {
     StackRenderer.renderHeader("late-writes", [aIndex + 1]);
   },
 
   renderLateWrites: function LateWritesSingleton_renderLateWrites(lateWrites) {
+    setHasData("late-writes-section", !!lateWrites);
+    if (!lateWrites) {
+      return;
+    }
+
     let stacks = lateWrites.stacks;
     let memoryMap = lateWrites.memoryMap;
     StackRenderer.renderStacks('late-writes', stacks, memoryMap,
                                LateWritesSingleton.renderHeader);
   }
 };
 
 /**
@@ -1516,17 +1540,17 @@ function displayPingData(ping) {
 
   // Render Addon details.
   AddonDetails.render(ping);
 
   // Show simple measurements
   let payload = ping.payload;
   let simpleMeasurements = sortStartupMilestones(payload.simpleMeasurements);
   let hasData = Object.keys(simpleMeasurements).length > 0;
-  setHasData("simple-measurements-section", true);
+  setHasData("simple-measurements-section", hasData);
   let simpleSection = document.getElementById("simple-measurements");
   removeAllChildNodes(simpleSection);
 
   if (hasData) {
     simpleSection.appendChild(KeyValueTable.render(simpleMeasurements,
                                                    keysHeader, valuesHeader));
   }
 
@@ -1580,21 +1604,21 @@ function displayPingData(ping) {
   }
 
   // Show addon histogram data
   let addonDiv = document.getElementById("addon-histograms");
   removeAllChildNodes(addonDiv);
 
   let addonHistogramsRendered = false;
   let addonData = payload.addonHistograms;
-  for (let [addon, histograms] of Iterator(addonData)) {
-    for (let [name, hgram] of Iterator(histograms)) {
-      addonHistogramsRendered = true;
-      Histogram.render(addonDiv, addon + ": " + name, hgram, {unpacked: true});
+  if (addonData) {
+    for (let [addon, histograms] of Iterator(addonData)) {
+      for (let [name, hgram] of Iterator(histograms)) {
+        addonHistogramsRendered = true;
+        Histogram.render(addonDiv, addon + ": " + name, hgram, {unpacked: true});
+      }
     }
   }
 
-  if (addonHistogramsRendered) {
-   setHasData("addon-histograms-section", true);
-  }
+  setHasData("addon-histograms-section", addonHistogramsRendered);
 }
 
 window.addEventListener("load", onLoad, false);