summaryrefslogtreecommitdiff
path: root/base/metrics/statistics_recorder.h
diff options
context:
space:
mode:
Diffstat (limited to 'base/metrics/statistics_recorder.h')
-rw-r--r--base/metrics/statistics_recorder.h37
1 files changed, 32 insertions, 5 deletions
diff --git a/base/metrics/statistics_recorder.h b/base/metrics/statistics_recorder.h
index b523057596..b1d182e93e 100644
--- a/base/metrics/statistics_recorder.h
+++ b/base/metrics/statistics_recorder.h
@@ -10,20 +10,23 @@
#ifndef BASE_METRICS_STATISTICS_RECORDER_H_
#define BASE_METRICS_STATISTICS_RECORDER_H_
+#include <stdint.h>
+
#include <list>
#include <map>
#include <string>
#include <vector>
#include "base/base_export.h"
-#include "base/basictypes.h"
+#include "base/callback.h"
#include "base/gtest_prod_util.h"
#include "base/lazy_instance.h"
+#include "base/macros.h"
+#include "base/metrics/histogram_base.h"
namespace base {
class BucketRanges;
-class HistogramBase;
class Lock;
class BASE_EXPORT StatisticsRecorder {
@@ -75,14 +78,37 @@ class BASE_EXPORT StatisticsRecorder {
// histograms).
static void GetSnapshot(const std::string& query, Histograms* snapshot);
+ typedef base::Callback<void(HistogramBase::Sample)> OnSampleCallback;
+
+ // SetCallback sets the callback to notify when a new sample is recorded on
+ // the histogram referred to by |histogram_name|. The call to this method can
+ // be be done before or after the histogram is created. This method is thread
+ // safe. The return value is whether or not the callback was successfully set.
+ static bool SetCallback(const std::string& histogram_name,
+ const OnSampleCallback& callback);
+
+ // ClearCallback clears any callback set on the histogram referred to by
+ // |histogram_name|. This method is thread safe.
+ static void ClearCallback(const std::string& histogram_name);
+
+ // FindCallback retrieves the callback for the histogram referred to by
+ // |histogram_name|, or a null callback if no callback exists for this
+ // histogram. This method is thread safe.
+ static OnSampleCallback FindCallback(const std::string& histogram_name);
+
private:
- // We keep all registered histograms in a map, from name to histogram.
- typedef std::map<std::string, HistogramBase*> HistogramMap;
+ // We keep all registered histograms in a map, indexed by the hash of the
+ // name of the histogram.
+ typedef std::map<uint64_t, HistogramBase*> HistogramMap;
+
+ // We keep a map of callbacks to histograms, so that as histograms are
+ // created, we can set the callback properly.
+ typedef std::map<std::string, OnSampleCallback> CallbackMap;
// We keep all |bucket_ranges_| in a map, from checksum to a list of
// |bucket_ranges_|. Checksum is calculated from the |ranges_| in
// |bucket_ranges_|.
- typedef std::map<uint32, std::list<const BucketRanges*>*> RangesMap;
+ typedef std::map<uint32_t, std::list<const BucketRanges*>*> RangesMap;
friend struct DefaultLazyInstanceTraits<StatisticsRecorder>;
friend class HistogramBaseTest;
@@ -103,6 +129,7 @@ class BASE_EXPORT StatisticsRecorder {
static void DumpHistogramsToVlog(void* instance);
static HistogramMap* histograms_;
+ static CallbackMap* callbacks_;
static RangesMap* ranges_;
// Lock protects access to above maps.