Bug 673292. Provide raw histogram data to c++ consumers. r=jmuizelaar
authorTaras Glek <tglek@mozilla.com>
Fri, 05 Aug 2011 09:53:48 -0400
changeset 76755 6d88b1cca4b370cca8f9532c560565dd5decd99b
parent 76754 9e238421b8f666fd1b4c831d11fe770209ec2509
child 76756 0f7583869bbd5f8cd4731f0d9f805a965fbe31a2
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
reviewersjmuizelaar
bugs673292
milestone9.0a1
Bug 673292. Provide raw histogram data to c++ consumers. r=jmuizelaar This will be useful for manually controlling histogram values instead of just acummulating.
toolkit/components/telemetry/Telemetry.cpp
toolkit/components/telemetry/Telemetry.h
--- a/toolkit/components/telemetry/Telemetry.cpp
+++ b/toolkit/components/telemetry/Telemetry.cpp
@@ -144,17 +144,17 @@ GetHistogramByEnumId(Telemetry::ID id, H
   if (h) {
     *ret = h;
     return NS_OK;
   }
 
   const TelemetryHistogram &p = gHistograms[id];
   nsresult rv = HistogramGet(p.id, p.min, p.max, p.bucketCount, p.histogramType, &h);
   if (NS_FAILED(rv))
-    return NS_ERROR_FAILURE;
+    return rv;
 
   *ret = knownHistograms[id] = h;
   return NS_OK;
 }
 
 bool
 FillRanges(JSContext *cx, JSObject *array, Histogram *h)
 {
@@ -406,16 +406,24 @@ Accumulate(ID aHistogram, PRUint32 aSamp
     return;
   }
   Histogram *h;
   nsresult rv = GetHistogramByEnumId(aHistogram, &h);
   if (NS_SUCCEEDED(rv))
     h->Add(aSample);
 }
 
+base::Histogram*
+GetHistogramById(ID id)
+{
+  Histogram *h = NULL;
+  GetHistogramByEnumId(id, &h);
+  return h;
+}
+
 } // namespace Telemetry
 } // namespace mozilla
 
 NSMODULE_DEFN(nsTelemetryModule) = &kTelemetryModule;
 
 /**
  * The XRE_TelemetryAdd function is to be used by embedding applications
  * that can't use mozilla::Telemetry::Accumulate() directly.
--- a/toolkit/components/telemetry/Telemetry.h
+++ b/toolkit/components/telemetry/Telemetry.h
@@ -37,16 +37,20 @@
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef Telemetry_h__
 #define Telemetry_h__
 
 #include "mozilla/TimeStamp.h"
 #include "mozilla/AutoRestore.h"
 
+namespace base {
+  class Histogram;
+}
+
 namespace mozilla {
 namespace Telemetry {
 
 enum ID {
 #define HISTOGRAM(name, a, b, c, d, e) name,
 
 #include "TelemetryHistograms.h"
 
@@ -57,16 +61,21 @@ HistogramCount
 /**
  * Adds sample to a histogram defined in TelemetryHistograms.h
  *
  * @param id - histogram id
  * @param sample - value to record.
  */
 void Accumulate(ID id, PRUint32 sample);
 
+/**
+ * Return a raw Histogram for direct manipulation for users who can not use Accumulate().
+ */
+base::Histogram* GetHistogramById(ID id);
+
 template<ID id>
 class AutoTimer {
 public:
   AutoTimer(MOZILLA_GUARD_OBJECT_NOTIFIER_ONLY_PARAM)
     : start(TimeStamp::Now())
   {
     MOZILLA_GUARD_OBJECT_NOTIFIER_INIT;
   }