Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2723)

Unified Diff: base/metrics/statistics_recorder.h

Issue 10834011: Refactor of Histogram related code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/metrics/statistics_recorder.h
===================================================================
--- base/metrics/statistics_recorder.h (revision 148055)
+++ base/metrics/statistics_recorder.h (working copy)
@@ -2,9 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// StatisticsRecorder handles all histograms in the system. It provides a
-// general place for histograms to register, and supports a global API for
-// accessing (i.e., dumping, or graphing) the data in all the histograms.
+// StatisticsRecorder holds all Histograms and BucketRanges that are used by
+// Histograms in the system. It provides a general place for
+// Histograms/BucketRanges to register, and supports a global API for accessing
+// (i.e., dumping, or graphing) the data.
#ifndef BASE_METRICS_STATISTICS_RECORDER_H_
#define BASE_METRICS_STATISTICS_RECORDER_H_
@@ -41,13 +42,12 @@
// histogram (either the argument, or the pre-existing registered histogram).
static Histogram* RegisterOrDeleteDuplicate(Histogram* histogram);
- // Register, or add a new bucket_ranges_ of |histogram|. If an identical
- // bucket_ranges_ is already registered, then the bucket_ranges_ of
- // |histogram| is deleted and the |histogram|'s bucket_ranges_ is reset to the
- // registered bucket_ranges_. The bucket_ranges_ of |histogram| is always the
- // registered BucketRanges (either the argument's bucket_ranges_, or the
- // pre-existing registered bucket_ranges_).
- static void RegisterOrDeleteDuplicateRanges(Histogram* histogram);
+ // Register, or add a new BucketRanges. If an identically BucketRanges is
+ // already registered, then the argument |ranges| will deleted. The returned
+ // value is always the registered BucketRanges (either the argument, or the
+ // pre-existing one).
+ static const BucketRanges* RegisterOrDeleteDuplicateRanges(
+ const BucketRanges* ranges);
// Method for collecting stats about histograms created in browser and
// renderer processes. |suffix| is appended to histogram names. |suffix| could
@@ -63,6 +63,9 @@
// Method for extracting histograms which were marked for use by UMA.
static void GetHistograms(Histograms* output);
+ // Method for extracting BucketRanges used by all histograms registered.
+ static void GetBucketRanges(std::vector<const BucketRanges*>* output);
+
// Find a histogram by name. It matches the exact name. This method is thread
// safe. It returns NULL if a matching histogram is not found.
static Histogram* FindHistogram(const std::string& name);
@@ -84,26 +87,21 @@
// 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<BucketRanges*>*> RangesMap;
+ typedef std::map<uint32, std::list<const BucketRanges*>*> RangesMap;
friend struct DefaultLazyInstanceTraits<StatisticsRecorder>;
+ friend class StatisticsRecorderTest;
- // Allow tests to access our innards for testing purposes.
- FRIEND_TEST_ALL_PREFIXES(HistogramTest, StartupShutdownTest);
- FRIEND_TEST_ALL_PREFIXES(HistogramTest, RecordedStartupTest);
- FRIEND_TEST_ALL_PREFIXES(HistogramTest, RangeTest);
- FRIEND_TEST_ALL_PREFIXES(HistogramTest, CustomRangeTest);
- FRIEND_TEST_ALL_PREFIXES(HistogramTest, BucketRangesTest);
-
+ // The constructor just initializes static members. Usually client code should
+ // use Initialize to do this. But in test code, you can friend this class and
+ // call destructor/constructor to get a clean StatisticsRecorder.
StatisticsRecorder();
-
~StatisticsRecorder();
static HistogramMap* histograms_;
-
static RangesMap* ranges_;
- // lock protects access to the above map.
+ // Lock protects access to above maps.
static base::Lock* lock_;
// Dump all known histograms to log.

Powered by Google App Engine
This is Rietveld 408576698