Bug 1092219 - Fix keyedHistogram.add() passing the wrong argument to Histogram::Add(). r=froydnj
authorGeorg Fritzsche <georg.fritzsche@googlemail.com>
Fri, 31 Oct 2014 21:47:12 +0100
changeset 213455 238e8cc15a713faae792589f216b763521ca7c5c
parent 213454 0510281753433218960218bf8e14770a22a21e8b
child 213456 304be83fb3c6b643fc6971ef18b37ca1a4bf803b
push id51230
push usergeorg.fritzsche@googlemail.com
push dateFri, 31 Oct 2014 20:47:33 +0000
treeherdermozilla-inbound@44660ec332db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1092219
milestone36.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 1092219 - Fix keyedHistogram.add() passing the wrong argument to Histogram::Add(). r=froydnj
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
@@ -1308,17 +1308,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);
 }