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

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

Issue 1748403003: Log histograms on shutdown when verbose logging is on (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 unified diff | Download patch
« no previous file with comments | « no previous file | base/metrics/statistics_recorder.cc » ('j') | base/metrics/statistics_recorder.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 123
124 // ClearCallback clears any callback set on the histogram referred to by 124 // ClearCallback clears any callback set on the histogram referred to by
125 // |histogram_name|. This method is thread safe. 125 // |histogram_name|. This method is thread safe.
126 static void ClearCallback(const std::string& histogram_name); 126 static void ClearCallback(const std::string& histogram_name);
127 127
128 // FindCallback retrieves the callback for the histogram referred to by 128 // FindCallback retrieves the callback for the histogram referred to by
129 // |histogram_name|, or a null callback if no callback exists for this 129 // |histogram_name|, or a null callback if no callback exists for this
130 // histogram. This method is thread safe. 130 // histogram. This method is thread safe.
131 static OnSampleCallback FindCallback(const std::string& histogram_name); 131 static OnSampleCallback FindCallback(const std::string& histogram_name);
132 132
133 // Initializes logging histograms with --v=1. Safe to call several times.
134 // Is called from ctor but for browser it seems that it is more useful to
135 // start logging after statistics recorder, so we need to init log-on-shutdown
136 // later.
137 static void InitLogOnShutdown();
138
139 static bool VLogInitializedForTesting();
140
133 // Clears all of the known histograms and resets static variables to a 141 // Clears all of the known histograms and resets static variables to a
134 // state that allows a new initialization. 142 // state that allows a new initialization.
135 static void ResetForTesting(); 143 static void ResetForTesting();
136 144
137 // Removes a histogram from the internal set of known ones. This can be 145 // Removes a histogram from the internal set of known ones. This can be
138 // necessary during testing persistent histograms where the underlying 146 // necessary during testing persistent histograms where the underlying
139 // memory is being released. 147 // memory is being released.
140 static void ForgetHistogramForTesting(base::StringPiece name); 148 static void ForgetHistogramForTesting(base::StringPiece name);
141 149
142 private: 150 private:
143 // We keep a map of callbacks to histograms, so that as histograms are 151 // We keep a map of callbacks to histograms, so that as histograms are
144 // created, we can set the callback properly. 152 // created, we can set the callback properly.
145 typedef std::map<std::string, OnSampleCallback> CallbackMap; 153 typedef std::map<std::string, OnSampleCallback> CallbackMap;
146 154
147 // We keep all |bucket_ranges_| in a map, from checksum to a list of 155 // We keep all |bucket_ranges_| in a map, from checksum to a list of
148 // |bucket_ranges_|. Checksum is calculated from the |ranges_| in 156 // |bucket_ranges_|. Checksum is calculated from the |ranges_| in
149 // |bucket_ranges_|. 157 // |bucket_ranges_|.
150 typedef std::map<uint32_t, std::list<const BucketRanges*>*> RangesMap; 158 typedef std::map<uint32_t, std::list<const BucketRanges*>*> RangesMap;
151 159
152 friend struct DefaultLazyInstanceTraits<StatisticsRecorder>; 160 friend struct DefaultLazyInstanceTraits<StatisticsRecorder>;
153 friend class HistogramBaseTest; 161 friend class HistogramBaseTest;
154 friend class HistogramSnapshotManagerTest; 162 friend class HistogramSnapshotManagerTest;
155 friend class HistogramTest; 163 friend class HistogramTest;
156 friend class JsonPrefStoreTest; 164 friend class JsonPrefStoreTest;
157 friend class SharedHistogramTest; 165 friend class SharedHistogramTest;
158 friend class SparseHistogramTest; 166 friend class SparseHistogramTest;
159 friend class StatisticsRecorderTest; 167 friend class StatisticsRecorderTest;
168 friend class StatisticsRecorderLoggingTestBase;
160 FRIEND_TEST_ALL_PREFIXES(HistogramDeltaSerializationTest, 169 FRIEND_TEST_ALL_PREFIXES(HistogramDeltaSerializationTest,
161 DeserializeHistogramAndAddSamples); 170 DeserializeHistogramAndAddSamples);
162 171
163 // The constructor just initializes static members. Usually client code should 172 // The constructor just initializes static members. Usually client code should
164 // use Initialize to do this. But in test code, you can friend this class and 173 // use Initialize to do this. But in test code, you can friend this class and
165 // call destructor/constructor to get a clean StatisticsRecorder. 174 // call destructor/constructor to get a clean StatisticsRecorder.
166 StatisticsRecorder(); 175 StatisticsRecorder();
167 ~StatisticsRecorder(); 176 ~StatisticsRecorder();
168 177
178 void InitLogOnShutdownWithoutLock();
179
169 static void Reset(); 180 static void Reset();
170 static void DumpHistogramsToVlog(void* instance); 181 static void DumpHistogramsToVlog(void* instance);
171 182
172 static HistogramMap* histograms_; 183 static HistogramMap* histograms_;
173 static CallbackMap* callbacks_; 184 static CallbackMap* callbacks_;
174 static RangesMap* ranges_; 185 static RangesMap* ranges_;
175 186
176 // Lock protects access to above maps. 187 // Lock protects access to above maps.
177 static base::Lock* lock_; 188 static base::Lock* lock_;
178 189
179 DISALLOW_COPY_AND_ASSIGN(StatisticsRecorder); 190 DISALLOW_COPY_AND_ASSIGN(StatisticsRecorder);
180 }; 191 };
181 192
182 } // namespace base 193 } // namespace base
183 194
184 #endif // BASE_METRICS_STATISTICS_RECORDER_H_ 195 #endif // BASE_METRICS_STATISTICS_RECORDER_H_
OLDNEW
« no previous file with comments | « no previous file | base/metrics/statistics_recorder.cc » ('j') | base/metrics/statistics_recorder.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698