kaiwang@chromium.org | 3c57dc6 | 2012-07-14 06:48:29 +0900 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
kaiwang@chromium.org | a97a5ae | 2012-08-02 06:34:08 +0900 | [diff] [blame] | 5 | // StatisticsRecorder holds all Histograms and BucketRanges that are used by |
| 6 | // Histograms in the system. It provides a general place for |
| 7 | // Histograms/BucketRanges to register, and supports a global API for accessing |
| 8 | // (i.e., dumping, or graphing) the data. |
kaiwang@chromium.org | 3c57dc6 | 2012-07-14 06:48:29 +0900 | [diff] [blame] | 9 | |
| 10 | #ifndef BASE_METRICS_STATISTICS_RECORDER_H_ |
| 11 | #define BASE_METRICS_STATISTICS_RECORDER_H_ |
| 12 | |
avi | a6a6a68 | 2015-12-27 07:15:14 +0900 | [diff] [blame] | 13 | #include <stdint.h> |
| 14 | |
bcwhite | b9b48bb | 2016-04-09 02:38:29 +0900 | [diff] [blame] | 15 | #include <memory> |
kaiwang@chromium.org | 3c57dc6 | 2012-07-14 06:48:29 +0900 | [diff] [blame] | 16 | #include <string> |
François Degros | 2a5c890 | 2017-12-19 10:58:49 +0900 | [diff] [blame] | 17 | #include <unordered_map> |
| 18 | #include <unordered_set> |
kaiwang@chromium.org | 3c57dc6 | 2012-07-14 06:48:29 +0900 | [diff] [blame] | 19 | #include <vector> |
| 20 | |
| 21 | #include "base/base_export.h" |
simonhatch | 91fbd4d | 2015-07-16 07:22:57 +0900 | [diff] [blame] | 22 | #include "base/callback.h" |
rtenneti@chromium.org | 00491d4 | 2012-07-20 04:17:32 +0900 | [diff] [blame] | 23 | #include "base/gtest_prod_util.h" |
| 24 | #include "base/lazy_instance.h" |
avi | a6a6a68 | 2015-12-27 07:15:14 +0900 | [diff] [blame] | 25 | #include "base/macros.h" |
bcwhite | 9b3ea23 | 2017-02-01 10:58:56 +0900 | [diff] [blame] | 26 | #include "base/memory/weak_ptr.h" |
simonhatch | 91fbd4d | 2015-07-16 07:22:57 +0900 | [diff] [blame] | 27 | #include "base/metrics/histogram_base.h" |
Ira Burak | 14aeed0 | 2017-09-13 22:43:28 +0900 | [diff] [blame] | 28 | #include "base/metrics/record_histogram_checker.h" |
bcwhite | 85fe1c8 | 2016-02-18 07:40:35 +0900 | [diff] [blame] | 29 | #include "base/strings/string_piece.h" |
gab | 4d4cd0c | 2016-12-13 07:36:39 +0900 | [diff] [blame] | 30 | #include "base/synchronization/lock.h" |
kaiwang@chromium.org | 3c57dc6 | 2012-07-14 06:48:29 +0900 | [diff] [blame] | 31 | |
| 32 | namespace base { |
| 33 | |
kaiwang@chromium.org | 7c4acad | 2012-07-26 05:02:48 +0900 | [diff] [blame] | 34 | class BucketRanges; |
Alexei Svitkine | 16c2760 | 2017-07-25 03:31:31 +0900 | [diff] [blame] | 35 | class HistogramSnapshotManager; |
kaiwang@chromium.org | 3c57dc6 | 2012-07-14 06:48:29 +0900 | [diff] [blame] | 36 | |
François Degros | bbe88cc | 2018-01-05 07:54:17 +0900 | [diff] [blame] | 37 | // In-memory recorder of usage statistics (aka metrics, aka histograms). |
| 38 | // |
François Degros | e983593 | 2018-01-08 07:42:27 +0900 | [diff] [blame] | 39 | // All the public methods are static and act on a global recorder. This global |
| 40 | // recorder is internally synchronized and all the static methods are thread |
| 41 | // safe. |
François Degros | bbe88cc | 2018-01-05 07:54:17 +0900 | [diff] [blame] | 42 | // |
| 43 | // StatisticsRecorder doesn't have any public constructor. For testing purpose, |
| 44 | // you can create a temporary recorder using the factory method |
| 45 | // CreateTemporaryForTesting(). This temporary recorder becomes the global one |
| 46 | // until deleted. When this temporary recorder is deleted, it restores the |
| 47 | // previous global one. |
kaiwang@chromium.org | 3c57dc6 | 2012-07-14 06:48:29 +0900 | [diff] [blame] | 48 | class BASE_EXPORT StatisticsRecorder { |
| 49 | public: |
bcwhite | 9b3ea23 | 2017-02-01 10:58:56 +0900 | [diff] [blame] | 50 | // An interface class that allows the StatisticsRecorder to forcibly merge |
| 51 | // histograms from providers when necessary. |
| 52 | class HistogramProvider { |
| 53 | public: |
| 54 | // Merges all histogram information into the global versions. |
| 55 | virtual void MergeHistogramDeltas() = 0; |
| 56 | }; |
| 57 | |
kaiwang@chromium.org | 7881e42 | 2013-03-01 12:53:25 +0900 | [diff] [blame] | 58 | typedef std::vector<HistogramBase*> Histograms; |
kaiwang@chromium.org | 3c57dc6 | 2012-07-14 06:48:29 +0900 | [diff] [blame] | 59 | |
François Degros | bbe88cc | 2018-01-05 07:54:17 +0900 | [diff] [blame] | 60 | // Restores the previous global recorder. |
| 61 | // |
| 62 | // When several temporary recorders are created using |
| 63 | // CreateTemporaryForTesting(), these recorders must be deleted in reverse |
| 64 | // order of creation. |
| 65 | // |
| 66 | // This method is thread safe. |
| 67 | // |
| 68 | // Precondition: The recorder being deleted is the current global recorder. |
bcwhite | 5d8f910 | 2016-03-17 02:25:41 +0900 | [diff] [blame] | 69 | ~StatisticsRecorder(); |
| 70 | |
François Degros | bbe88cc | 2018-01-05 07:54:17 +0900 | [diff] [blame] | 71 | // Registers a provider of histograms that can be called to merge those into |
| 72 | // the global recorder. Calls to ImportProvidedHistograms() will fetch from |
| 73 | // registered providers. |
| 74 | // |
| 75 | // This method is thread safe. |
bcwhite | 9b3ea23 | 2017-02-01 10:58:56 +0900 | [diff] [blame] | 76 | static void RegisterHistogramProvider( |
| 77 | const WeakPtr<HistogramProvider>& provider); |
| 78 | |
François Degros | bbe88cc | 2018-01-05 07:54:17 +0900 | [diff] [blame] | 79 | // Registers or adds a new histogram to the collection of statistics. If an |
kaiwang@chromium.org | 3c57dc6 | 2012-07-14 06:48:29 +0900 | [diff] [blame] | 80 | // identically named histogram is already registered, then the argument |
François Degros | bbe88cc | 2018-01-05 07:54:17 +0900 | [diff] [blame] | 81 | // |histogram| will be deleted. The returned value is always the registered |
kaiwang@chromium.org | 3c57dc6 | 2012-07-14 06:48:29 +0900 | [diff] [blame] | 82 | // histogram (either the argument, or the pre-existing registered histogram). |
François Degros | bbe88cc | 2018-01-05 07:54:17 +0900 | [diff] [blame] | 83 | // |
| 84 | // This method is thread safe. |
kaiwang@chromium.org | 7881e42 | 2013-03-01 12:53:25 +0900 | [diff] [blame] | 85 | static HistogramBase* RegisterOrDeleteDuplicate(HistogramBase* histogram); |
kaiwang@chromium.org | 3c57dc6 | 2012-07-14 06:48:29 +0900 | [diff] [blame] | 86 | |
François Degros | bbe88cc | 2018-01-05 07:54:17 +0900 | [diff] [blame] | 87 | // Registers or adds a new BucketRanges. If an equivalent BucketRanges is |
| 88 | // already registered, then the argument |ranges| will be deleted. The |
| 89 | // returned value is always the registered BucketRanges (either the argument, |
| 90 | // or the pre-existing one). |
| 91 | // |
| 92 | // This method is thread safe. |
kaiwang@chromium.org | a97a5ae | 2012-08-02 06:34:08 +0900 | [diff] [blame] | 93 | static const BucketRanges* RegisterOrDeleteDuplicateRanges( |
| 94 | const BucketRanges* ranges); |
kaiwang@chromium.org | 3c57dc6 | 2012-07-14 06:48:29 +0900 | [diff] [blame] | 95 | |
grt@chromium.org | e29d3e5 | 2013-11-15 03:33:53 +0900 | [diff] [blame] | 96 | // Methods for appending histogram data to a string. Only histograms which |
| 97 | // have |query| as a substring are written to |output| (an empty string will |
| 98 | // process all registered histograms). |
François Degros | bbe88cc | 2018-01-05 07:54:17 +0900 | [diff] [blame] | 99 | // |
| 100 | // These methods are thread safe. |
kaiwang@chromium.org | 3c57dc6 | 2012-07-14 06:48:29 +0900 | [diff] [blame] | 101 | static void WriteHTMLGraph(const std::string& query, std::string* output); |
| 102 | static void WriteGraph(const std::string& query, std::string* output); |
| 103 | |
Tarun Bansal | 9ba53ac | 2017-11-29 23:44:12 +0900 | [diff] [blame] | 104 | // Returns the histograms with |verbosity_level| as the serialization |
| 105 | // verbosity. |
François Degros | bbe88cc | 2018-01-05 07:54:17 +0900 | [diff] [blame] | 106 | // |
| 107 | // This method is thread safe. |
Tarun Bansal | 9ba53ac | 2017-11-29 23:44:12 +0900 | [diff] [blame] | 108 | static std::string ToJSON(JSONVerbosityLevel verbosity_level); |
grt@chromium.org | e29d3e5 | 2013-11-15 03:33:53 +0900 | [diff] [blame] | 109 | |
François Degros | bbe88cc | 2018-01-05 07:54:17 +0900 | [diff] [blame] | 110 | // Extracts histograms which were marked for use by UMA. |
François Degros | 2a5c890 | 2017-12-19 10:58:49 +0900 | [diff] [blame] | 111 | // |
| 112 | // This method is thread safe. |
kaiwang@chromium.org | 3c57dc6 | 2012-07-14 06:48:29 +0900 | [diff] [blame] | 113 | static void GetHistograms(Histograms* output); |
| 114 | |
François Degros | bbe88cc | 2018-01-05 07:54:17 +0900 | [diff] [blame] | 115 | // Extracts BucketRanges used by all histograms registered. |
kaiwang@chromium.org | a97a5ae | 2012-08-02 06:34:08 +0900 | [diff] [blame] | 116 | static void GetBucketRanges(std::vector<const BucketRanges*>* output); |
| 117 | |
François Degros | bbe88cc | 2018-01-05 07:54:17 +0900 | [diff] [blame] | 118 | // Finds a histogram by name. Matches the exact name. Returns a null pointer |
| 119 | // if a matching histogram is not found. |
François Degros | 2a5c890 | 2017-12-19 10:58:49 +0900 | [diff] [blame] | 120 | // |
| 121 | // This method is thread safe. |
bcwhite | 76dc963 | 2016-02-20 02:12:37 +0900 | [diff] [blame] | 122 | static HistogramBase* FindHistogram(base::StringPiece name); |
kaiwang@chromium.org | 3c57dc6 | 2012-07-14 06:48:29 +0900 | [diff] [blame] | 123 | |
François Degros | bbe88cc | 2018-01-05 07:54:17 +0900 | [diff] [blame] | 124 | // Imports histograms from providers. |
| 125 | // |
| 126 | // This method must be called on the UI thread. |
bcwhite | 9b3ea23 | 2017-02-01 10:58:56 +0900 | [diff] [blame] | 127 | static void ImportProvidedHistograms(); |
| 128 | |
Alexei Svitkine | 16c2760 | 2017-07-25 03:31:31 +0900 | [diff] [blame] | 129 | // Snapshots all histograms via |snapshot_manager|. |flags_to_set| is used to |
| 130 | // set flags for each histogram. |required_flags| is used to select |
| 131 | // histograms to be recorded. Only histograms that have all the flags |
| 132 | // specified by the argument will be chosen. If all histograms should be |
| 133 | // recorded, set it to |Histogram::kNoFlags|. |
| 134 | static void PrepareDeltas(bool include_persistent, |
| 135 | HistogramBase::Flags flags_to_set, |
| 136 | HistogramBase::Flags required_flags, |
| 137 | HistogramSnapshotManager* snapshot_manager); |
bcwhite | e93a801 | 2016-02-02 06:07:56 +0900 | [diff] [blame] | 138 | |
François Degros | bbe88cc | 2018-01-05 07:54:17 +0900 | [diff] [blame] | 139 | // Extracts registered histograms. Only histograms which have |query| as a |
| 140 | // substring are extracted. An empty query will extract all registered |
| 141 | // histograms. |
François Degros | 2a5c890 | 2017-12-19 10:58:49 +0900 | [diff] [blame] | 142 | // |
| 143 | // This method is thread safe. |
kaiwang@chromium.org | 3c57dc6 | 2012-07-14 06:48:29 +0900 | [diff] [blame] | 144 | static void GetSnapshot(const std::string& query, Histograms* snapshot); |
| 145 | |
simonhatch | 91fbd4d | 2015-07-16 07:22:57 +0900 | [diff] [blame] | 146 | typedef base::Callback<void(HistogramBase::Sample)> OnSampleCallback; |
| 147 | |
François Degros | bbe88cc | 2018-01-05 07:54:17 +0900 | [diff] [blame] | 148 | // Sets the callback to notify when a new sample is recorded on the histogram |
| 149 | // referred to by |histogram_name|. Can be called before or after the |
| 150 | // histogram is created. Returns whether the callback was successfully set. |
| 151 | // |
| 152 | // This method is thread safe. |
simonhatch | 91fbd4d | 2015-07-16 07:22:57 +0900 | [diff] [blame] | 153 | static bool SetCallback(const std::string& histogram_name, |
| 154 | const OnSampleCallback& callback); |
| 155 | |
François Degros | bbe88cc | 2018-01-05 07:54:17 +0900 | [diff] [blame] | 156 | // Clears any callback set on the histogram referred to by |histogram_name|. |
| 157 | // |
| 158 | // This method is thread safe. |
simonhatch | 91fbd4d | 2015-07-16 07:22:57 +0900 | [diff] [blame] | 159 | static void ClearCallback(const std::string& histogram_name); |
| 160 | |
François Degros | bbe88cc | 2018-01-05 07:54:17 +0900 | [diff] [blame] | 161 | // Retrieves the callback for the histogram referred to by |histogram_name|, |
| 162 | // or a null callback if no callback exists for this histogram. |
| 163 | // |
| 164 | // This method is thread safe. |
simonhatch | 91fbd4d | 2015-07-16 07:22:57 +0900 | [diff] [blame] | 165 | static OnSampleCallback FindCallback(const std::string& histogram_name); |
| 166 | |
bcwhite | 5d8f910 | 2016-03-17 02:25:41 +0900 | [diff] [blame] | 167 | // Returns the number of known histograms. |
François Degros | bbe88cc | 2018-01-05 07:54:17 +0900 | [diff] [blame] | 168 | // |
| 169 | // This method is thread safe. |
bcwhite | 5d8f910 | 2016-03-17 02:25:41 +0900 | [diff] [blame] | 170 | static size_t GetHistogramCount(); |
| 171 | |
boriay | 826ae20 | 2016-07-05 17:15:29 +0900 | [diff] [blame] | 172 | // Initializes logging histograms with --v=1. Safe to call multiple times. |
| 173 | // Is called from ctor but for browser it seems that it is more useful to |
| 174 | // start logging after statistics recorder, so we need to init log-on-shutdown |
| 175 | // later. |
François Degros | bbe88cc | 2018-01-05 07:54:17 +0900 | [diff] [blame] | 176 | // |
| 177 | // This method is thread safe. |
boriay | 826ae20 | 2016-07-05 17:15:29 +0900 | [diff] [blame] | 178 | static void InitLogOnShutdown(); |
| 179 | |
bcwhite | 85fe1c8 | 2016-02-18 07:40:35 +0900 | [diff] [blame] | 180 | // Removes a histogram from the internal set of known ones. This can be |
| 181 | // necessary during testing persistent histograms where the underlying |
| 182 | // memory is being released. |
François Degros | bbe88cc | 2018-01-05 07:54:17 +0900 | [diff] [blame] | 183 | // |
| 184 | // This method is thread safe. |
bcwhite | 85fe1c8 | 2016-02-18 07:40:35 +0900 | [diff] [blame] | 185 | static void ForgetHistogramForTesting(base::StringPiece name); |
| 186 | |
François Degros | bbe88cc | 2018-01-05 07:54:17 +0900 | [diff] [blame] | 187 | // Creates a temporary StatisticsRecorder object for testing purposes. All new |
| 188 | // histograms will be registered in it until it is destructed or pushed aside |
| 189 | // for the lifetime of yet another StatisticsRecorder object. The destruction |
| 190 | // of the returned object will re-activate the previous one. |
| 191 | // StatisticsRecorder objects must be deleted in the opposite order to which |
| 192 | // they're created. |
| 193 | // |
| 194 | // This method is thread safe. |
bcwhite | b98e785 | 2016-06-04 02:56:35 +0900 | [diff] [blame] | 195 | static std::unique_ptr<StatisticsRecorder> CreateTemporaryForTesting() |
| 196 | WARN_UNUSED_RESULT; |
| 197 | |
Ira Burak | 14aeed0 | 2017-09-13 22:43:28 +0900 | [diff] [blame] | 198 | // Sets the record checker for determining if a histogram should be recorded. |
| 199 | // Record checker doesn't affect any already recorded histograms, so this |
| 200 | // method must be called very early, before any threads have started. |
| 201 | // Record checker methods can be called on any thread, so they shouldn't |
| 202 | // mutate any state. |
François Degros | bbe88cc | 2018-01-05 07:54:17 +0900 | [diff] [blame] | 203 | // |
Ira Burak | 14aeed0 | 2017-09-13 22:43:28 +0900 | [diff] [blame] | 204 | // TODO(iburak): This is not yet hooked up to histogram recording |
| 205 | // infrastructure. |
| 206 | static void SetRecordChecker( |
| 207 | std::unique_ptr<RecordHistogramChecker> record_checker); |
| 208 | |
François Degros | bbe88cc | 2018-01-05 07:54:17 +0900 | [diff] [blame] | 209 | // Checks if the given histogram should be recorded based on the |
| 210 | // ShouldRecord() method of the record checker. If the record checker is not |
| 211 | // set, returns true. |
| 212 | // |
| 213 | // This method is thread safe. |
Ira Burak | 14aeed0 | 2017-09-13 22:43:28 +0900 | [diff] [blame] | 214 | static bool ShouldRecordHistogram(uint64_t histogram_hash); |
| 215 | |
kaiwang@chromium.org | 3c57dc6 | 2012-07-14 06:48:29 +0900 | [diff] [blame] | 216 | private: |
François Degros | 2a5c890 | 2017-12-19 10:58:49 +0900 | [diff] [blame] | 217 | typedef std::vector<WeakPtr<HistogramProvider>> HistogramProviders; |
| 218 | |
| 219 | typedef std::unordered_map<StringPiece, HistogramBase*, StringPieceHash> |
| 220 | HistogramMap; |
| 221 | |
simonhatch | 91fbd4d | 2015-07-16 07:22:57 +0900 | [diff] [blame] | 222 | // We keep a map of callbacks to histograms, so that as histograms are |
| 223 | // created, we can set the callback properly. |
François Degros | 2a5c890 | 2017-12-19 10:58:49 +0900 | [diff] [blame] | 224 | typedef std::unordered_map<std::string, OnSampleCallback> CallbackMap; |
simonhatch | 91fbd4d | 2015-07-16 07:22:57 +0900 | [diff] [blame] | 225 | |
François Degros | 2a5c890 | 2017-12-19 10:58:49 +0900 | [diff] [blame] | 226 | struct BucketRangesHash { |
| 227 | size_t operator()(const BucketRanges* a) const; |
| 228 | }; |
| 229 | |
| 230 | struct BucketRangesEqual { |
| 231 | bool operator()(const BucketRanges* a, const BucketRanges* b) const; |
| 232 | }; |
| 233 | |
| 234 | typedef std:: |
| 235 | unordered_set<const BucketRanges*, BucketRangesHash, BucketRangesEqual> |
| 236 | RangesMap; |
kaiwang@chromium.org | 3c57dc6 | 2012-07-14 06:48:29 +0900 | [diff] [blame] | 237 | |
boriay | 826ae20 | 2016-07-05 17:15:29 +0900 | [diff] [blame] | 238 | friend class StatisticsRecorderTest; |
Alexei Svitkine | 16c2760 | 2017-07-25 03:31:31 +0900 | [diff] [blame] | 239 | FRIEND_TEST_ALL_PREFIXES(StatisticsRecorderTest, IterationTest); |
| 240 | |
François Degros | e983593 | 2018-01-08 07:42:27 +0900 | [diff] [blame] | 241 | // Initializes the global recorder if it doesn't already exist. Safe to call |
| 242 | // multiple times. |
| 243 | // |
| 244 | // Precondition: The global lock is already acquired. |
| 245 | static void EnsureGlobalRecorderWhileLocked(); |
| 246 | |
François Degros | bbe88cc | 2018-01-05 07:54:17 +0900 | [diff] [blame] | 247 | // Fetches set of existing histograms. Ownership of the individual histograms |
Brian White | ee1cd70 | 2017-08-18 04:43:56 +0900 | [diff] [blame] | 248 | // remains with the StatisticsRecorder. |
François Degros | bbe88cc | 2018-01-05 07:54:17 +0900 | [diff] [blame] | 249 | // |
| 250 | // This method is thread safe. |
François Degros | 2a5c890 | 2017-12-19 10:58:49 +0900 | [diff] [blame] | 251 | static Histograms GetKnownHistograms(bool include_persistent); |
rtenneti@chromium.org | 00491d4 | 2012-07-20 04:17:32 +0900 | [diff] [blame] | 252 | |
François Degros | bbe88cc | 2018-01-05 07:54:17 +0900 | [diff] [blame] | 253 | // Gets histogram providers. |
| 254 | // |
| 255 | // This method is thread safe. |
| 256 | static HistogramProviders GetHistogramProviders(); |
| 257 | |
| 258 | // Imports histograms from global persistent memory. |
| 259 | // |
| 260 | // Precondition: The global lock must not be held during this call. |
bcwhite | 2265a68 | 2016-04-14 01:09:54 +0900 | [diff] [blame] | 261 | static void ImportGlobalPersistentHistograms(); |
| 262 | |
François Degros | bbe88cc | 2018-01-05 07:54:17 +0900 | [diff] [blame] | 263 | // Constructs a new StatisticsRecorder and sets it as the current global |
| 264 | // recorder. |
| 265 | // |
| 266 | // Precondition: The global lock is already acquired. |
rtenneti@chromium.org | 00491d4 | 2012-07-20 04:17:32 +0900 | [diff] [blame] | 267 | StatisticsRecorder(); |
rtenneti@chromium.org | 00491d4 | 2012-07-20 04:17:32 +0900 | [diff] [blame] | 268 | |
boriay | 826ae20 | 2016-07-05 17:15:29 +0900 | [diff] [blame] | 269 | // Initialize implementation but without lock. Caller should guard |
| 270 | // StatisticsRecorder by itself if needed (it isn't in unit tests). |
François Degros | bbe88cc | 2018-01-05 07:54:17 +0900 | [diff] [blame] | 271 | // |
| 272 | // Precondition: The global lock is already acquired. |
| 273 | static void InitLogOnShutdownWhileLocked(); |
boriay | 826ae20 | 2016-07-05 17:15:29 +0900 | [diff] [blame] | 274 | |
François Degros | bbe88cc | 2018-01-05 07:54:17 +0900 | [diff] [blame] | 275 | HistogramMap histograms_; |
| 276 | CallbackMap callbacks_; |
| 277 | RangesMap ranges_; |
| 278 | HistogramProviders providers_; |
| 279 | std::unique_ptr<RecordHistogramChecker> record_checker_; |
bcwhite | b9b48bb | 2016-04-09 02:38:29 +0900 | [diff] [blame] | 280 | |
François Degros | bbe88cc | 2018-01-05 07:54:17 +0900 | [diff] [blame] | 281 | // Previous global recorder that existed when this one was created. |
| 282 | StatisticsRecorder* previous_ = nullptr; |
boriay | 826ae20 | 2016-07-05 17:15:29 +0900 | [diff] [blame] | 283 | |
François Degros | bbe88cc | 2018-01-05 07:54:17 +0900 | [diff] [blame] | 284 | // Global lock for internal synchronization. |
| 285 | static LazyInstance<Lock>::Leaky lock_; |
tonyg@chromium.org | 4af9296 | 2013-05-02 12:09:25 +0900 | [diff] [blame] | 286 | |
François Degros | bbe88cc | 2018-01-05 07:54:17 +0900 | [diff] [blame] | 287 | // Current global recorder. This recorder is used by static methods. When a |
| 288 | // new global recorder is created by CreateTemporaryForTesting(), then the |
| 289 | // previous global recorder is referenced by top_->previous_. |
| 290 | static StatisticsRecorder* top_; |
kaiwang@chromium.org | 3c57dc6 | 2012-07-14 06:48:29 +0900 | [diff] [blame] | 291 | |
François Degros | bbe88cc | 2018-01-05 07:54:17 +0900 | [diff] [blame] | 292 | // Tracks whether InitLogOnShutdownWhileLocked() has registered a logging |
| 293 | // function that will be called when the program finishes. |
| 294 | static bool is_vlog_initialized_; |
kaiwang@chromium.org | 3c57dc6 | 2012-07-14 06:48:29 +0900 | [diff] [blame] | 295 | |
kaiwang@chromium.org | 3c57dc6 | 2012-07-14 06:48:29 +0900 | [diff] [blame] | 296 | DISALLOW_COPY_AND_ASSIGN(StatisticsRecorder); |
| 297 | }; |
| 298 | |
| 299 | } // namespace base |
| 300 | |
| 301 | #endif // BASE_METRICS_STATISTICS_RECORDER_H_ |