| 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_ |
| 11 #define BASE_METRICS_STATISTICS_RECORDER_H_ | 11 #define BASE_METRICS_STATISTICS_RECORDER_H_ |
| 12 | 12 |
| 13 #include <stdint.h> | 13 #include <stdint.h> |
| 14 | 14 |
| 15 #include <list> | 15 #include <list> |
| 16 #include <map> | 16 #include <map> |
| 17 #include <memory> | 17 #include <memory> |
| 18 #include <string> | 18 #include <string> |
| 19 #include <vector> | 19 #include <vector> |
| 20 | 20 |
| 21 #include "base/base_export.h" | 21 #include "base/base_export.h" |
| 22 #include "base/callback.h" | 22 #include "base/callback.h" |
| 23 #include "base/gtest_prod_util.h" | 23 #include "base/gtest_prod_util.h" |
| 24 #include "base/lazy_instance.h" | 24 #include "base/lazy_instance.h" |
| 25 #include "base/macros.h" | 25 #include "base/macros.h" |
| 26 #include "base/metrics/histogram_base.h" | 26 #include "base/metrics/histogram_base.h" |
| 27 #include "base/strings/string_piece.h" | 27 #include "base/strings/string_piece.h" |
| 28 #include "base/synchronization/lock.h" |
| 28 | 29 |
| 29 namespace base { | 30 namespace base { |
| 30 | 31 |
| 31 class BucketRanges; | 32 class BucketRanges; |
| 32 class Lock; | |
| 33 | 33 |
| 34 class BASE_EXPORT StatisticsRecorder { | 34 class BASE_EXPORT StatisticsRecorder { |
| 35 public: | 35 public: |
| 36 // A class used as a key for the histogram map below. It always references | 36 // A class used as a key for the histogram map below. It always references |
| 37 // a string owned outside of this class, likely in the value of the map. | 37 // a string owned outside of this class, likely in the value of the map. |
| 38 class StringKey : public StringPiece { | 38 class StringKey : public StringPiece { |
| 39 public: | 39 public: |
| 40 // Constructs the StringKey using various sources. The source must live | 40 // Constructs the StringKey using various sources. The source must live |
| 41 // at least as long as the created object. | 41 // at least as long as the created object. |
| 42 StringKey(const std::string& str) : StringPiece(str) {} | 42 StringKey(const std::string& str) : StringPiece(str) {} |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 | 223 |
| 224 bool vlog_initialized_ = false; | 224 bool vlog_initialized_ = false; |
| 225 | 225 |
| 226 static void Reset(); | 226 static void Reset(); |
| 227 static void DumpHistogramsToVlog(void* instance); | 227 static void DumpHistogramsToVlog(void* instance); |
| 228 | 228 |
| 229 static HistogramMap* histograms_; | 229 static HistogramMap* histograms_; |
| 230 static CallbackMap* callbacks_; | 230 static CallbackMap* callbacks_; |
| 231 static RangesMap* ranges_; | 231 static RangesMap* ranges_; |
| 232 | 232 |
| 233 // Lock protects access to above maps. | 233 // Lock protects access to above maps. This is a LazyInstance to avoid races |
| 234 static base::Lock* lock_; | 234 // when the above methods are used before Initialize(). Previously each method |
| 235 // would do |if (!lock_) return;| which would race with |
| 236 // |lock_ = new Lock;| in StatisticsRecorder(). http://crbug.com/672852. |
| 237 static base::LazyInstance<base::Lock>::Leaky lock_; |
| 235 | 238 |
| 236 DISALLOW_COPY_AND_ASSIGN(StatisticsRecorder); | 239 DISALLOW_COPY_AND_ASSIGN(StatisticsRecorder); |
| 237 }; | 240 }; |
| 238 | 241 |
| 239 } // namespace base | 242 } // namespace base |
| 240 | 243 |
| 241 #endif // BASE_METRICS_STATISTICS_RECORDER_H_ | 244 #endif // BASE_METRICS_STATISTICS_RECORDER_H_ |
| OLD | NEW |