Bug 1092219 - Fix keyedHistogram.add() passing the wrong argument to Histogram::Add(). r=froydnj, a=lmandel
authorGeorg Fritzsche <georg.fritzsche@googlemail.com>
Fri, 31 Oct 2014 21:47:12 +0100
changeset 225908 aa11e337b8e3
parent 225907 3fe1e43c97b8
child 225909 e6db2f014e26
push id4063
push usergeorg.fritzsche@googlemail.com
push date2014-11-02 23:54 +0000
treeherdermozilla-beta@1ca39da5df9d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj, lmandel
bugs1092219
milestone34.0
Bug 1092219 - Fix keyedHistogram.add() passing the wrong argument to Histogram::Add(). r=froydnj, a=lmandel
toolkit/components/telemetry/Telemetry.cpp
toolkit/components/telemetry/tests/unit/test_nsITelemetry.js
--- a/toolkit/components/telemetry/Telemetry.cpp
+++ b/toolkit/components/telemetry/Telemetry.cpp
@@ -1263,17 +1263,17 @@ JSKeyedHistogram_Add(JSContext *cx, unsi
       return false;
     }
 
     if (!(args[1].isNumber() || args[1].isBoolean())) {
       JS_ReportError(cx, "Not a number");
       return false;
     }
 
-    if (!JS::ToInt32(cx, args[0], &value)) {
+    if (!JS::ToInt32(cx, args[1], &value)) {
       return false;
     }
   }
 
   Histogram* h = nullptr;
   nsresult rv = keyed->GetHistogram(NS_ConvertUTF16toUTF8(key), &h);
   if (NS_FAILED(rv)) {
     JS_ReportError(cx, "Failed to get histogram");
--- a/toolkit/components/telemetry/tests/unit/test_nsITelemetry.js
+++ b/toolkit/components/telemetry/tests/unit/test_nsITelemetry.js
@@ -390,21 +390,21 @@ function numberRange(lower, upper)
 function test_keyed_boolean_histogram()
 {
   const KEYED_ID = "test::keyed::boolean";
   const KEYS = ["key"+(i+1) for (i of numberRange(0, 3))];
   let histogramBase = {
     "min": 1,
     "max": 2,
     "histogram_type": 2,
-    "sum": 0,
-    "sum_squares_lo": 0,
+    "sum": 1,
+    "sum_squares_lo": 1,
     "sum_squares_hi": 0,
     "ranges": [0, 1, 2],
-    "counts": [1, 0, 0]
+    "counts": [0, 1, 0]
   };
   let testHistograms = [JSON.parse(JSON.stringify(histogramBase)) for (i of numberRange(0, 3))];
   let testKeys = [];
   let testSnapShot = {};
 
   let h = Telemetry.newKeyedHistogram(KEYED_ID, "never", Telemetry.HISTOGRAM_BOOLEAN);
   for (let i=0; i<2; ++i) {
     let key = KEYS[i];
@@ -419,16 +419,19 @@ function test_keyed_boolean_histogram()
   h = Telemetry.getKeyedHistogramById(KEYED_ID);
   Assert.deepEqual(h.keys().sort(), testKeys);
   Assert.deepEqual(h.snapshot(), testSnapShot);
 
   let key = KEYS[2];
   h.add(key, false);
   testKeys.push(key);
   testSnapShot[key] = testHistograms[2];
+  testSnapShot[key].sum = 0;
+  testSnapShot[key].sum_squares_lo = 0;
+  testSnapShot[key].counts = [1, 0, 0];
   Assert.deepEqual(h.keys().sort(), testKeys);
   Assert.deepEqual(h.snapshot(), testSnapShot);
 
   let allSnapshots = Telemetry.keyedHistogramSnapshots;
   Assert.deepEqual(allSnapshots[KEYED_ID], testSnapShot);
 
   h.clear();
   Assert.deepEqual(h.keys(), []);
@@ -490,16 +493,46 @@ function test_keyed_count_histogram()
   let allSnapshots = Telemetry.keyedHistogramSnapshots;
   Assert.deepEqual(allSnapshots[KEYED_ID], testSnapShot);
 
   h.clear();
   Assert.deepEqual(h.keys(), []);
   Assert.deepEqual(h.snapshot(), {});
 }
 
+function test_keyed_flag_histogram()
+{
+  const KEYED_ID = "test::keyed::flag";
+  let h = Telemetry.newKeyedHistogram(KEYED_ID, "never", Telemetry.HISTOGRAM_FLAG);
+
+  const KEY = "default";
+  h.add(KEY, true);
+
+  let testSnapshot = {};
+  testSnapshot[KEY] = {
+    "min": 1,
+    "max": 2,
+    "histogram_type": 3,
+    "sum": 1,
+    "sum_squares_lo": 1,
+    "sum_squares_hi": 0,
+    "ranges": [0, 1, 2],
+    "counts": [0, 1, 0]
+  };
+
+  Assert.deepEqual(h.keys().sort(), [KEY]);
+  Assert.deepEqual(h.snapshot(), testSnapshot);
+
+  let allSnapshots = Telemetry.keyedHistogramSnapshots;
+  Assert.deepEqual(allSnapshots[KEYED_ID], testSnapshot);
+
+  h.clear();
+  Assert.deepEqual(h.keys(), []);
+  Assert.deepEqual(h.snapshot(), {});
+}
 
 function test_keyed_histogram() {
   // Check that invalid names get rejected.
 
   let threw = false;
   try {
     Telemetry.newKeyedHistogram("test::invalid # histogram", "never", Telemetry.HISTOGRAM_BOOLEAN);
   } catch (e) {
@@ -516,16 +549,17 @@ function test_keyed_histogram() {
     threw = true;
   }
   Assert.ok(threw, "getKeyedHistogramById should have thrown");
 
   // Check specific keyed histogram types working properly.
 
   test_keyed_boolean_histogram();
   test_keyed_count_histogram();
+  test_keyed_flag_histogram();
 }
 
 function generateUUID() {
   let str = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator).generateUUID().toString();
   // strip {}
   return str.substring(1, str.length - 1);
 }