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 handles all histograms in the system. It provides a | 5 // StatisticsRecorder handles all histograms in the system. It provides a |
6 // general place for histograms to register, and supports a global API for | 6 // general place for histograms to register, and supports a global API for |
7 // accessing (i.e., dumping, or graphing) the data in all the histograms. | 7 // accessing (i.e., dumping, or graphing) the data in all the histograms. |
8 | 8 |
9 #ifndef BASE_METRICS_STATISTICS_RECORDER_H_ | 9 #ifndef BASE_METRICS_STATISTICS_RECORDER_H_ |
10 #define BASE_METRICS_STATISTICS_RECORDER_H_ | 10 #define BASE_METRICS_STATISTICS_RECORDER_H_ |
11 | 11 |
12 #include <list> | 12 #include <list> |
13 #include <map> | 13 #include <map> |
14 #include <string> | 14 #include <string> |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 #include "base/base_export.h" | 17 #include "base/base_export.h" |
18 #include "base/basictypes.h" | 18 #include "base/basictypes.h" |
19 #include "base/gtest_prod_util.h" | 19 #include "base/gtest_prod_util.h" |
20 #include "base/lazy_instance.h" | 20 #include "base/lazy_instance.h" |
21 | 21 |
22 namespace base { | 22 namespace base { |
23 | 23 |
24 class BucketRanges; | 24 class CachedRanges; |
25 class Histogram; | 25 class Histogram; |
26 class Lock; | 26 class Lock; |
27 | 27 |
28 class BASE_EXPORT StatisticsRecorder { | 28 class BASE_EXPORT StatisticsRecorder { |
29 public: | 29 public: |
30 typedef std::vector<Histogram*> Histograms; | 30 typedef std::vector<Histogram*> Histograms; |
31 | 31 |
32 // Initializes the StatisticsRecorder system. | 32 // Initializes the StatisticsRecorder system. |
33 static void Initialize(); | 33 static void Initialize(); |
34 | 34 |
35 // Find out if histograms can now be registered into our list. | 35 // Find out if histograms can now be registered into our list. |
36 static bool IsActive(); | 36 static bool IsActive(); |
37 | 37 |
38 // Register, or add a new histogram to the collection of statistics. If an | 38 // Register, or add a new histogram to the collection of statistics. If an |
39 // identically named histogram is already registered, then the argument | 39 // identically named histogram is already registered, then the argument |
40 // |histogram| will deleted. The returned value is always the registered | 40 // |histogram| will deleted. The returned value is always the registered |
41 // histogram (either the argument, or the pre-existing registered histogram). | 41 // histogram (either the argument, or the pre-existing registered histogram). |
42 static Histogram* RegisterOrDeleteDuplicate(Histogram* histogram); | 42 static Histogram* RegisterOrDeleteDuplicate(Histogram* histogram); |
43 | 43 |
44 // Register, or add a new bucket_ranges_ of |histogram|. If an identical | 44 // Register, or add a new cached_ranges_ of |histogram|. If an identical |
45 // bucket_ranges_ is already registered, then the bucket_ranges_ of | 45 // cached_ranges_ is already registered, then the cached_ranges_ of |
46 // |histogram| is deleted and the |histogram|'s bucket_ranges_ is reset to the | 46 // |histogram| is deleted and the |histogram|'s cached_ranges_ is reset to the |
47 // registered bucket_ranges_. The bucket_ranges_ of |histogram| is always the | 47 // registered cached_ranges_. The cached_ranges_ of |histogram| is always the |
48 // registered BucketRanges (either the argument's bucket_ranges_, or the | 48 // registered CachedRanges (either the argument's cached_ranges_, or the |
49 // pre-existing registered bucket_ranges_). | 49 // pre-existing registered cached_ranges_). |
50 static void RegisterOrDeleteDuplicateRanges(Histogram* histogram); | 50 static void RegisterOrDeleteDuplicateRanges(Histogram* histogram); |
51 | 51 |
52 // Method for collecting stats about histograms created in browser and | 52 // Method for collecting stats about histograms created in browser and |
53 // renderer processes. |suffix| is appended to histogram names. |suffix| could | 53 // renderer processes. |suffix| is appended to histogram names. |suffix| could |
54 // be either browser or renderer. | 54 // be either browser or renderer. |
55 static void CollectHistogramStats(const std::string& suffix); | 55 static void CollectHistogramStats(const std::string& suffix); |
56 | 56 |
57 // Methods for printing histograms. Only histograms which have query as | 57 // Methods for printing histograms. Only histograms which have query as |
58 // a substring are written to output (an empty string will process all | 58 // a substring are written to output (an empty string will process all |
59 // registered histograms). | 59 // registered histograms). |
(...skipping 14 matching lines...) Expand all Loading... |
74 // GetSnapshot copies some of the pointers to registered histograms into the | 74 // GetSnapshot copies some of the pointers to registered histograms into the |
75 // caller supplied vector (Histograms). Only histograms with names matching | 75 // caller supplied vector (Histograms). Only histograms with names matching |
76 // query are returned. The query must be a substring of histogram name for its | 76 // query are returned. The query must be a substring of histogram name for its |
77 // pointer to be copied. | 77 // pointer to be copied. |
78 static void GetSnapshot(const std::string& query, Histograms* snapshot); | 78 static void GetSnapshot(const std::string& query, Histograms* snapshot); |
79 | 79 |
80 private: | 80 private: |
81 // We keep all registered histograms in a map, from name to histogram. | 81 // We keep all registered histograms in a map, from name to histogram. |
82 typedef std::map<std::string, Histogram*> HistogramMap; | 82 typedef std::map<std::string, Histogram*> HistogramMap; |
83 | 83 |
84 // We keep all |bucket_ranges_| in a map, from checksum to a list of | 84 // We keep all |cached_ranges_| in a map, from checksum to a list of |
85 // |bucket_ranges_|. Checksum is calculated from the |ranges_| in | 85 // |cached_ranges_|. Checksum is calculated from the |ranges_| in |
86 // |bucket_ranges_|. | 86 // |cached_ranges_|. |
87 typedef std::map<uint32, std::list<BucketRanges*>*> RangesMap; | 87 typedef std::map<uint32, std::list<CachedRanges*>*> RangesMap; |
88 | 88 |
89 friend struct DefaultLazyInstanceTraits<StatisticsRecorder>; | 89 friend struct DefaultLazyInstanceTraits<StatisticsRecorder>; |
90 | 90 |
91 // Allow tests to access our innards for testing purposes. | 91 // Allow tests to access our innards for testing purposes. |
92 FRIEND_TEST_ALL_PREFIXES(HistogramTest, StartupShutdownTest); | 92 FRIEND_TEST_ALL_PREFIXES(HistogramTest, StartupShutdownTest); |
93 FRIEND_TEST_ALL_PREFIXES(HistogramTest, RecordedStartupTest); | 93 FRIEND_TEST_ALL_PREFIXES(HistogramTest, RecordedStartupTest); |
94 FRIEND_TEST_ALL_PREFIXES(HistogramTest, RangeTest); | 94 FRIEND_TEST_ALL_PREFIXES(HistogramTest, RangeTest); |
95 FRIEND_TEST_ALL_PREFIXES(HistogramTest, CustomRangeTest); | 95 FRIEND_TEST_ALL_PREFIXES(HistogramTest, CustomRangeTest); |
96 FRIEND_TEST_ALL_PREFIXES(HistogramTest, BucketRangesTest); | 96 FRIEND_TEST_ALL_PREFIXES(HistogramTest, CachedRangesTest); |
97 | 97 |
98 StatisticsRecorder(); | 98 StatisticsRecorder(); |
99 | 99 |
100 ~StatisticsRecorder(); | 100 ~StatisticsRecorder(); |
101 | 101 |
102 static HistogramMap* histograms_; | 102 static HistogramMap* histograms_; |
103 | 103 |
104 static RangesMap* ranges_; | 104 static RangesMap* ranges_; |
105 | 105 |
106 // lock protects access to the above map. | 106 // lock protects access to the above map. |
107 static base::Lock* lock_; | 107 static base::Lock* lock_; |
108 | 108 |
109 // Dump all known histograms to log. | 109 // Dump all known histograms to log. |
110 static bool dump_on_exit_; | 110 static bool dump_on_exit_; |
111 | 111 |
112 DISALLOW_COPY_AND_ASSIGN(StatisticsRecorder); | 112 DISALLOW_COPY_AND_ASSIGN(StatisticsRecorder); |
113 }; | 113 }; |
114 | 114 |
115 } // namespace base | 115 } // namespace base |
116 | 116 |
117 #endif // BASE_METRICS_STATISTICS_RECORDER_H_ | 117 #endif // BASE_METRICS_STATISTICS_RECORDER_H_ |
OLD | NEW |