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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 static void GetHistograms(Histograms* output); | 63 static void GetHistograms(Histograms* output); |
64 | 64 |
65 // Method for extracting BucketRanges used by all histograms registered. | 65 // Method for extracting BucketRanges used by all histograms registered. |
66 static void GetBucketRanges(std::vector<const BucketRanges*>* output); | 66 static void GetBucketRanges(std::vector<const BucketRanges*>* output); |
67 | 67 |
68 // Find a histogram by name. It matches the exact name. This method is thread | 68 // Find a histogram by name. It matches the exact name. This method is thread |
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 with names matching | 73 // caller supplied vector (Histograms). Only histograms which have |query| as |
74 // query are returned. The query must be a substring of histogram name for its | 74 // a substring are copied (an empty string will process all registered |
75 // pointer to be copied. | 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 // We keep all registered histograms in a map, from name to histogram. | 79 // We keep all registered histograms in a map, from name to histogram. |
80 typedef std::map<std::string, HistogramBase*> HistogramMap; | 80 typedef std::map<std::string, HistogramBase*> HistogramMap; |
81 | 81 |
82 // We keep all |bucket_ranges_| in a map, from checksum to a list of | 82 // We keep all |bucket_ranges_| in a map, from checksum to a list of |
83 // |bucket_ranges_|. Checksum is calculated from the |ranges_| in | 83 // |bucket_ranges_|. Checksum is calculated from the |ranges_| in |
84 // |bucket_ranges_|. | 84 // |bucket_ranges_|. |
85 typedef std::map<uint32, std::list<const BucketRanges*>*> RangesMap; | 85 typedef std::map<uint32, std::list<const BucketRanges*>*> RangesMap; |
86 | 86 |
87 friend struct DefaultLazyInstanceTraits<StatisticsRecorder>; | 87 friend struct DefaultLazyInstanceTraits<StatisticsRecorder>; |
88 friend class HistogramBaseTest; | 88 friend class HistogramBaseTest; |
89 friend class HistogramTest; | 89 friend class HistogramTest; |
90 friend class SparseHistogramTest; | 90 friend class SparseHistogramTest; |
| 91 friend class StatisticsDeltaReaderTest; |
91 friend class StatisticsRecorderTest; | 92 friend class StatisticsRecorderTest; |
92 FRIEND_TEST_ALL_PREFIXES(HistogramDeltaSerializationTest, | 93 FRIEND_TEST_ALL_PREFIXES(HistogramDeltaSerializationTest, |
93 DeserializeHistogramAndAddSamples); | 94 DeserializeHistogramAndAddSamples); |
94 | 95 |
95 // The constructor just initializes static members. Usually client code should | 96 // The constructor just initializes static members. Usually client code should |
96 // use Initialize to do this. But in test code, you can friend this class and | 97 // use Initialize to do this. But in test code, you can friend this class and |
97 // call destructor/constructor to get a clean StatisticsRecorder. | 98 // call destructor/constructor to get a clean StatisticsRecorder. |
98 StatisticsRecorder(); | 99 StatisticsRecorder(); |
99 ~StatisticsRecorder(); | 100 ~StatisticsRecorder(); |
100 | 101 |
101 static void DumpHistogramsToVlog(void* instance); | 102 static void DumpHistogramsToVlog(void* instance); |
102 | 103 |
103 static HistogramMap* histograms_; | 104 static HistogramMap* histograms_; |
104 static RangesMap* ranges_; | 105 static RangesMap* ranges_; |
105 | 106 |
106 // Lock protects access to above maps. | 107 // Lock protects access to above maps. |
107 static base::Lock* lock_; | 108 static base::Lock* lock_; |
108 | 109 |
109 DISALLOW_COPY_AND_ASSIGN(StatisticsRecorder); | 110 DISALLOW_COPY_AND_ASSIGN(StatisticsRecorder); |
110 }; | 111 }; |
111 | 112 |
112 } // namespace base | 113 } // namespace base |
113 | 114 |
114 #endif // BASE_METRICS_STATISTICS_RECORDER_H_ | 115 #endif // BASE_METRICS_STATISTICS_RECORDER_H_ |
OLD | NEW |