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

Side by Side Diff: base/metrics/statistics_recorder.h

Issue 1471073007: Reorganize histograms for persistence. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@shmem-alloc
Patch Set: addressed some review comments by Alexei Created 5 years 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // StatisticsRecorder holds all Histograms and BucketRanges that are used by 5 // StatisticsRecorder holds all Histograms and BucketRanges that are used by
6 // Histograms in the system. It provides a general place for 6 // Histograms in the system. It provides a general place for
7 // Histograms/BucketRanges to register, and supports a global API for accessing 7 // Histograms/BucketRanges to register, and supports a global API for accessing
8 // (i.e., dumping, or graphing) the data. 8 // (i.e., dumping, or graphing) the data.
9 9
10 #ifndef BASE_METRICS_STATISTICS_RECORDER_H_ 10 #ifndef BASE_METRICS_STATISTICS_RECORDER_H_
(...skipping 10 matching lines...) Expand all
21 #include "base/gtest_prod_util.h" 21 #include "base/gtest_prod_util.h"
22 #include "base/lazy_instance.h" 22 #include "base/lazy_instance.h"
23 #include "base/metrics/histogram_base.h" 23 #include "base/metrics/histogram_base.h"
24 24
25 namespace base { 25 namespace base {
26 26
27 class BucketRanges; 27 class BucketRanges;
28 class Lock; 28 class Lock;
29 29
30 class BASE_EXPORT StatisticsRecorder { 30 class BASE_EXPORT StatisticsRecorder {
31 // We keep all registered histograms in a map, from name to histogram.
32 typedef std::map<uint64_t, HistogramBase*> HistogramMap;
Alexei Svitkine (slow) 2015/12/04 18:21:00 This should be in the private: section below. Also
bcwhite 2015/12/04 19:34:47 Done. It actually has to be up top so as to be pr
33
31 public: 34 public:
32 typedef std::vector<HistogramBase*> Histograms; 35 typedef std::vector<HistogramBase*> Histograms;
33 36
34 // Initializes the StatisticsRecorder system. Safe to call multiple times. 37 // Initializes the StatisticsRecorder system. Safe to call multiple times.
35 static void Initialize(); 38 static void Initialize();
36 39
37 // Find out if histograms can now be registered into our list. 40 // Find out if histograms can now be registered into our list.
38 static bool IsActive(); 41 static bool IsActive();
39 42
40 // Register, or add a new histogram to the collection of statistics. If an 43 // Register, or add a new histogram to the collection of statistics. If an
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 // ClearCallback clears any callback set on the histogram referred to by 91 // ClearCallback clears any callback set on the histogram referred to by
89 // |histogram_name|. This method is thread safe. 92 // |histogram_name|. This method is thread safe.
90 static void ClearCallback(const std::string& histogram_name); 93 static void ClearCallback(const std::string& histogram_name);
91 94
92 // FindCallback retrieves the callback for the histogram referred to by 95 // FindCallback retrieves the callback for the histogram referred to by
93 // |histogram_name|, or a null callback if no callback exists for this 96 // |histogram_name|, or a null callback if no callback exists for this
94 // histogram. This method is thread safe. 97 // histogram. This method is thread safe.
95 static OnSampleCallback FindCallback(const std::string& histogram_name); 98 static OnSampleCallback FindCallback(const std::string& histogram_name);
96 99
97 private: 100 private:
98 // HistogramNameRef holds a weak const ref to the name field of the associated
99 // Histogram object, allowing re-use of the underlying string storage for the
100 // map keys. The wrapper is required as using "const std::string&" as the key
101 // results in compile errors.
102 struct HistogramNameRef {
103 explicit HistogramNameRef(const std::string& name) : name_(name) {};
104
105 // Operator < is necessary to use this type as a std::map key.
106 bool operator<(const HistogramNameRef& other) const {
107 return name_ < other.name_;
108 }
109
110 // Weak, owned by the associated Histogram object.
111 const std::string& name_;
112 };
113
114 // We keep all registered histograms in a map, from name to histogram.
115 typedef std::map<HistogramNameRef, HistogramBase*> HistogramMap;
116
117 // We keep a map of callbacks to histograms, so that as histograms are 101 // We keep a map of callbacks to histograms, so that as histograms are
118 // created, we can set the callback properly. 102 // created, we can set the callback properly.
119 typedef std::map<std::string, OnSampleCallback> CallbackMap; 103 typedef std::map<std::string, OnSampleCallback> CallbackMap;
120 104
121 // We keep all |bucket_ranges_| in a map, from checksum to a list of 105 // We keep all |bucket_ranges_| in a map, from checksum to a list of
122 // |bucket_ranges_|. Checksum is calculated from the |ranges_| in 106 // |bucket_ranges_|. Checksum is calculated from the |ranges_| in
123 // |bucket_ranges_|. 107 // |bucket_ranges_|.
124 typedef std::map<uint32, std::list<const BucketRanges*>*> RangesMap; 108 typedef std::map<uint32, std::list<const BucketRanges*>*> RangesMap;
125 109
126 friend struct DefaultLazyInstanceTraits<StatisticsRecorder>; 110 friend struct DefaultLazyInstanceTraits<StatisticsRecorder>;
(...skipping 20 matching lines...) Expand all
147 131
148 // Lock protects access to above maps. 132 // Lock protects access to above maps.
149 static base::Lock* lock_; 133 static base::Lock* lock_;
150 134
151 DISALLOW_COPY_AND_ASSIGN(StatisticsRecorder); 135 DISALLOW_COPY_AND_ASSIGN(StatisticsRecorder);
152 }; 136 };
153 137
154 } // namespace base 138 } // namespace base
155 139
156 #endif // BASE_METRICS_STATISTICS_RECORDER_H_ 140 #endif // BASE_METRICS_STATISTICS_RECORDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698