OLD | NEW |
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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 // safe. It returns NULL if a matching histogram is not found. | 69 // safe. It returns NULL if a matching histogram is not found. |
70 static HistogramBase* FindHistogram(const std::string& name); | 70 static HistogramBase* FindHistogram(const std::string& name); |
71 | 71 |
72 // GetSnapshot copies some of the pointers to registered histograms into the | 72 // GetSnapshot copies some of the pointers to registered histograms into the |
73 // caller supplied vector (Histograms). Only histograms which have |query| as | 73 // caller supplied vector (Histograms). Only histograms which have |query| as |
74 // a substring are copied (an empty string will process all registered | 74 // a substring are copied (an empty string will process all registered |
75 // histograms). | 75 // histograms). |
76 static void GetSnapshot(const std::string& query, Histograms* snapshot); | 76 static void GetSnapshot(const std::string& query, Histograms* snapshot); |
77 | 77 |
78 private: | 78 private: |
| 79 // HistogramNameRef holds a weak const ref to the name field of the associated |
| 80 // Histogram object, allowing re-use of the underlying string storage for the |
| 81 // map keys. The wrapper is required as using "const std::string&" as the key |
| 82 // results in compile errors. |
| 83 struct HistogramNameRef { |
| 84 explicit HistogramNameRef(const std::string& name) : name_(name) {}; |
| 85 |
| 86 // Operator < is necessary to use this type as a std::map key. |
| 87 bool operator<(const HistogramNameRef& other) const { |
| 88 return name_ < other.name_; |
| 89 } |
| 90 |
| 91 // Weak, owned by the associated Histogram object. |
| 92 const std::string& name_; |
| 93 }; |
| 94 |
79 // We keep all registered histograms in a map, from name to histogram. | 95 // We keep all registered histograms in a map, from name to histogram. |
80 typedef std::map<std::string, HistogramBase*> HistogramMap; | 96 typedef std::map<HistogramNameRef, HistogramBase*> HistogramMap; |
81 | 97 |
82 // We keep all |bucket_ranges_| in a map, from checksum to a list of | 98 // We keep all |bucket_ranges_| in a map, from checksum to a list of |
83 // |bucket_ranges_|. Checksum is calculated from the |ranges_| in | 99 // |bucket_ranges_|. Checksum is calculated from the |ranges_| in |
84 // |bucket_ranges_|. | 100 // |bucket_ranges_|. |
85 typedef std::map<uint32, std::list<const BucketRanges*>*> RangesMap; | 101 typedef std::map<uint32, std::list<const BucketRanges*>*> RangesMap; |
86 | 102 |
87 friend struct DefaultLazyInstanceTraits<StatisticsRecorder>; | 103 friend struct DefaultLazyInstanceTraits<StatisticsRecorder>; |
88 friend class HistogramBaseTest; | 104 friend class HistogramBaseTest; |
89 friend class HistogramSnapshotManagerTest; | 105 friend class HistogramSnapshotManagerTest; |
90 friend class HistogramTest; | 106 friend class HistogramTest; |
(...skipping 16 matching lines...) Expand all Loading... |
107 | 123 |
108 // Lock protects access to above maps. | 124 // Lock protects access to above maps. |
109 static base::Lock* lock_; | 125 static base::Lock* lock_; |
110 | 126 |
111 DISALLOW_COPY_AND_ASSIGN(StatisticsRecorder); | 127 DISALLOW_COPY_AND_ASSIGN(StatisticsRecorder); |
112 }; | 128 }; |
113 | 129 |
114 } // namespace base | 130 } // namespace base |
115 | 131 |
116 #endif // BASE_METRICS_STATISTICS_RECORDER_H_ | 132 #endif // BASE_METRICS_STATISTICS_RECORDER_H_ |
OLD | NEW |