Bug 831748 - refactor duplicated code. r=froydnj.
authorRafael Ávila de Espíndola <respindola@mozilla.com>
Thu, 17 Jan 2013 10:25:44 -0500
changeset 119151 143e6064d88ce42ca87a8cb2a36f2b036beb51b9
parent 119150 c6f827a03d8834c1b528937b8fd2bc953fb710a8
child 119152 d01d7cb7693b7fe1db40858e0f7d90aae3231b33
push id24195
push userMs2ger@gmail.com
push dateSat, 19 Jan 2013 16:10:11 +0000
treeherderautoland@02e12a80aef9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs831748
milestone21.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 831748 - refactor duplicated code. r=froydnj.
toolkit/content/aboutTelemetry.js
toolkit/content/aboutTelemetry.xhtml
--- a/toolkit/content/aboutTelemetry.js
+++ b/toolkit/content/aboutTelemetry.js
@@ -253,50 +253,67 @@ let StackRenderer = {
    */
   renderStack: function StackRenderer_renderStack(aDiv, aStack) {
     aDiv.appendChild(document.createTextNode(this.stackTitle));
     let stackText = " " + aStack.join(" ");
     aDiv.appendChild(document.createTextNode(stackText));
 
     aDiv.appendChild(document.createElement("br"));
     aDiv.appendChild(document.createElement("br"));
+  },
+  renderStacks: function StackRenderer_renderStacks(aPrefix, aStacks,
+                                                    aMemoryMap, aRenderHeader) {
+    let div = document.getElementById(aPrefix + '-data');
+    clearDivData(div);
+
+    let fetchE = document.getElementById(aPrefix + '-fetch-symbols');
+    if (fetchE) {
+      fetchE.classList.remove("hidden");
+    }
+    let hideE = document.getElementById(aPrefix + '-hide-symbols');
+    if (hideE) {
+      hideE.classList.add("hidden");
+    }
+
+    if (aStacks.length == 0) {
+      showEmptySectionMessage(aPrefix + '-section');
+      return;
+    }
+
+    this.renderMemoryMap(div, aMemoryMap);
+
+    for (let i = 0; i < aStacks.length; ++i) {
+      let stack = aStacks[i];
+      aRenderHeader(i);
+      this.renderStack(div, stack)
+    }
   }
 };
 
 let ChromeHangs = {
 
   symbolRequest: null,
 
   errorMessage: bundle.GetStringFromName("errorFetchingSymbols"),
 
   /**
    * Renders raw chrome hang data
    */
   render: function ChromeHangs_render() {
-    let hangsDiv = document.getElementById("chrome-hangs-data");
-    clearDivData(hangsDiv);
-    document.getElementById("fetch-symbols").classList.remove("hidden");
-    document.getElementById("hide-symbols").classList.add("hidden");
-
     let hangs = Telemetry.chromeHangs;
     let stacks = hangs.stacks;
-    if (stacks.length == 0) {
-      showEmptySectionMessage("chrome-hangs-section");
-      return;
+    let memoryMap = hangs.memoryMap;
+    let durations = hangs.durations;
+    let div = document.getElementById("chrome-hangs-data");
+    function f(i) {
+      this.renderHangHeader(div, i + 1, durations[i]);
     }
 
-    let memoryMap = hangs.memoryMap;
-    StackRenderer.renderMemoryMap(hangsDiv, memoryMap);
-
-    let durations = hangs.durations;
-    for (let i = 0; i < stacks.length; ++i) {
-      let stack = stacks[i];
-      this.renderHangHeader(hangsDiv, i + 1, durations[i]);
-      StackRenderer.renderStack(hangsDiv, stack)
-    }
+    StackRenderer.renderStacks("chrome-hangs", stacks, memoryMap,
+			       f.bind(this));
   },
 
   /**
    * Renders the title of the hang: e.g. "Hang Report #1 (6 seconds)"
    *
    * @param aDiv Output div
    * @param aIndex The number of the hang
    * @param aDuration The duration of the hang
@@ -340,18 +357,18 @@ let ChromeHangs = {
   /**
    * Called when the 'readyState' of the XMLHttpRequest changes. We only care
    * about state 4 ("completed") - handling the response data.
    */
   handleSymbolResponse: function ChromeHangs_handleSymbolResponse() {
     if (this.symbolRequest.readyState != 4)
       return;
 
-    document.getElementById("fetch-symbols").classList.add("hidden");
-    document.getElementById("hide-symbols").classList.remove("hidden");
+    document.getElementById("chrome-hangs-fetch-symbols").classList.add("hidden");
+    document.getElementById("chrome-hangs-hide-symbols").classList.remove("hidden");
 
     let hangsDiv = document.getElementById("chrome-hangs-data");
     clearDivData(hangsDiv);
 
     if (this.symbolRequest.status != 200) {
       hangsDiv.appendChild(document.createTextNode(this.errorMessage));
       return;
     }
@@ -640,22 +657,22 @@ function setupListeners() {
   }, false);
 
   document.getElementById("toggle-telemetry").addEventListener("click",
     function () {
       let value = getPref(PREF_TELEMETRY_ENABLED, false);
       Services.prefs.setBoolPref(PREF_TELEMETRY_ENABLED, !value);
   }, false);
 
-  document.getElementById("fetch-symbols").addEventListener("click",
+  document.getElementById("chrome-hangs-fetch-symbols").addEventListener("click",
     function () {
       ChromeHangs.fetchSymbols();
   }, false);
 
-  document.getElementById("hide-symbols").addEventListener("click",
+  document.getElementById("chrome-hangs-hide-symbols").addEventListener("click",
     function () {
       ChromeHangs.render();
   }, false);
 
   // Clicking on the section name will toggle its state
   let sectionHeaders = document.getElementsByClassName("section-name");
   for (let sectionHeader of sectionHeaders) {
     sectionHeader.addEventListener("click", toggleSection, false);
@@ -710,33 +727,20 @@ function onLoad() {
   }
 
   // Get the Telemetry Ping payload
   Telemetry.asyncFetchTelemetryData(displayPingData);
 };
 
 let LateWritesSingleton = {
   renderLateWrites: function LateWritesSingleton_renderLateWrites(lateWrites) {
-    let writesDiv = document.getElementById("late-writes-data");
-    clearDivData(writesDiv);
-    // FIXME: Add symbolication support. Refactor with the chrome hang one.
-
     let stacks = lateWrites.stacks;
-    if (stacks.length == 0) {
-      showEmptySectionMessage("late-writes-section");
-      return;
-    }
-
     let memoryMap = lateWrites.memoryMap;
-    StackRenderer.renderMemoryMap(writesDiv, memoryMap);
-
-    for (let i = 0; i < stacks.length; ++i) {
-      let stack = stacks[i];
-      StackRenderer.renderStack(writesDiv, stack);
-    }
+    function f() {}
+    StackRenderer.renderStacks('late-writes', stacks, memoryMap, f);
   }
 };
 
 /**
  * Helper function for sorting the startup milestones in the Simple Measurements
  * section into temporal order.
  *
  * @param aSimpleMeasurements Telemetry ping's "Simple Measurements" data
--- a/toolkit/content/aboutTelemetry.xhtml
+++ b/toolkit/content/aboutTelemetry.xhtml
@@ -47,18 +47,18 @@
     </section>
 
     <section id="chrome-hangs-section" class="data-section">
       <h1 class="section-name">&aboutTelemetry.chromeHangsSection;</h1>
       <span class="toggle-caption">&aboutTelemetry.toggleOn;</span>
       <span class="toggle-caption hidden">&aboutTelemetry.toggleOff;</span>
       <span class="empty-caption hidden">&aboutTelemetry.emptySection;</span>
       <div id="chrome-hangs" class="data hidden">
-        <a id="fetch-symbols" href="javascript:">&aboutTelemetry.fetchSymbols;</a>
-        <a id="hide-symbols" class="hidden" href="javascript:">&aboutTelemetry.hideSymbols;</a>
+        <a id="chrome-hangs-fetch-symbols" href="javascript:">&aboutTelemetry.fetchSymbols;</a>
+        <a id="chrome-hangs-hide-symbols" class="hidden" href="javascript:">&aboutTelemetry.hideSymbols;</a>
         <br/>
         <br/>
         <div id="chrome-hangs-data">
         </div>
       </div>
     </section>
 
     <section id="histograms-section" class="data-section">