Bug 707320 - provide reflection for separate Histograms and SampleSets; r=taras
authorNathan Froyd <froydnj@mozilla.com>
Tue, 13 Dec 2011 12:03:30 -0500
changeset 86351 5a315a55ea7e3380354d9fa7b84f7f28b4d7ff71
parent 86350 8f06957d69d9fe5e48e048d0995ecf4e4c3a0aa1
child 86352 6c2b90a11ea8348c63590fc9e5cc3713c750885a
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstaras
bugs707320
milestone12.0a1
Bug 707320 - provide reflection for separate Histograms and SampleSets; r=taras
toolkit/components/telemetry/Telemetry.cpp
--- a/toolkit/components/telemetry/Telemetry.cpp
+++ b/toolkit/components/telemetry/Telemetry.cpp
@@ -222,21 +222,19 @@ FillRanges(JSContext *cx, JSObject *arra
 
 enum reflectStatus {
   REFLECT_OK,
   REFLECT_CORRUPT,
   REFLECT_FAILURE
 };
 
 enum reflectStatus
-ReflectHistogramSnapshot(JSContext *cx, JSObject *obj, Histogram *h)
+ReflectHistogramAndSamples(JSContext *cx, JSObject *obj, Histogram *h,
+                           const Histogram::SampleSet &ss)
 {
-  Histogram::SampleSet ss;
-  h->SnapshotSample(&ss);
-
   // We don't want to reflect corrupt histograms.
   if (h->FindCorruption(ss) != Histogram::NO_INCONSISTENCIES) {
     return REFLECT_CORRUPT;
   }
 
   JSObject *counts_array;
   JSObject *rarray;
   const size_t count = h->bucket_count();
@@ -255,16 +253,24 @@ ReflectHistogramSnapshot(JSContext *cx, 
   for (size_t i = 0; i < count; i++) {
     if (!JS_DefineElement(cx, counts_array, i, INT_TO_JSVAL(ss.counts(i)), NULL, NULL, JSPROP_ENUMERATE)) {
       return REFLECT_FAILURE;
     }
   }
   return REFLECT_OK;
 }
 
+enum reflectStatus
+ReflectHistogramSnapshot(JSContext *cx, JSObject *obj, Histogram *h)
+{
+  Histogram::SampleSet ss;
+  h->SnapshotSample(&ss);
+  return ReflectHistogramAndSamples(cx, obj, h, ss);
+}
+
 JSBool
 JSHistogram_Add(JSContext *cx, uintN argc, jsval *vp)
 {
   if (!argc) {
     JS_ReportError(cx, "Expected one argument");
     return JS_FALSE;
   }