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

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

Issue 10834011: Refactor of Histogram related code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 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 | Annotate | Revision Log
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 handles all histograms in the system. It provides a 5 // StatisticsRecorder holds all Histograms and BucketRanges that used by
jar (doing other things) 2012/08/01 00:26:10 nit: "that used" --> "that are used"
kaiwang 2012/08/01 04:13:21 Done.
6 // general place for histograms to register, and supports a global API for 6 // Histograms in the system. It provides a general place for
7 // accessing (i.e., dumping, or graphing) the data in all the histograms. 7 // Histograms/BucketRanges to register, and supports a global API for accessing
8 // (i.e., dumping, or graphing) the data.
8 9
9 #ifndef BASE_METRICS_STATISTICS_RECORDER_H_ 10 #ifndef BASE_METRICS_STATISTICS_RECORDER_H_
10 #define BASE_METRICS_STATISTICS_RECORDER_H_ 11 #define BASE_METRICS_STATISTICS_RECORDER_H_
11 12
12 #include <list> 13 #include <list>
13 #include <map> 14 #include <map>
14 #include <string> 15 #include <string>
15 #include <vector> 16 #include <vector>
16 17
17 #include "base/base_export.h" 18 #include "base/base_export.h"
(...skipping 16 matching lines...) Expand all
34 35
35 // Find out if histograms can now be registered into our list. 36 // Find out if histograms can now be registered into our list.
36 static bool IsActive(); 37 static bool IsActive();
37 38
38 // Register, or add a new histogram to the collection of statistics. If an 39 // Register, or add a new histogram to the collection of statistics. If an
39 // identically named histogram is already registered, then the argument 40 // identically named histogram is already registered, then the argument
40 // |histogram| will deleted. The returned value is always the registered 41 // |histogram| will deleted. The returned value is always the registered
41 // histogram (either the argument, or the pre-existing registered histogram). 42 // histogram (either the argument, or the pre-existing registered histogram).
42 static Histogram* RegisterOrDeleteDuplicate(Histogram* histogram); 43 static Histogram* RegisterOrDeleteDuplicate(Histogram* histogram);
43 44
44 // Register, or add a new bucket_ranges_ of |histogram|. If an identical 45 // Register, or add a new BucketRanges. If an identically BucketRanges is
45 // bucket_ranges_ is already registered, then the bucket_ranges_ of 46 // already registered, then the argument |ranges| will deleted. The returned
46 // |histogram| is deleted and the |histogram|'s bucket_ranges_ is reset to the 47 // value is always the registered BucketRanges (either the argument, or the
47 // registered bucket_ranges_. The bucket_ranges_ of |histogram| is always the 48 // pre-existing one).
48 // registered BucketRanges (either the argument's bucket_ranges_, or the 49 static const BucketRanges* RegisterOrDeleteDuplicateRanges(
49 // pre-existing registered bucket_ranges_). 50 const BucketRanges* ranges);
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).
60 static void WriteHTMLGraph(const std::string& query, std::string* output); 60 static void WriteHTMLGraph(const std::string& query, std::string* output);
61 static void WriteGraph(const std::string& query, std::string* output); 61 static void WriteGraph(const std::string& query, std::string* output);
62 62
63 // Method for extracting histograms which were marked for use by UMA. 63 // Method for extracting histograms which were marked for use by UMA.
64 static void GetHistograms(Histograms* output); 64 static void GetHistograms(Histograms* output);
65 65
66 // Method for extracting BucketRanges used by all histograms registered.
67 static void GetBucketRanges(std::vector<const BucketRanges*>* output);
68
66 // Find a histogram by name. It matches the exact name. This method is thread 69 // Find a histogram by name. It matches the exact name. This method is thread
67 // safe. It returns NULL if a matching histogram is not found. 70 // safe. It returns NULL if a matching histogram is not found.
68 static Histogram* FindHistogram(const std::string& name); 71 static Histogram* FindHistogram(const std::string& name);
69 72
70 static bool dump_on_exit() { return dump_on_exit_; } 73 static bool dump_on_exit() { return dump_on_exit_; }
71 74
72 static void set_dump_on_exit(bool enable) { dump_on_exit_ = enable; } 75 static void set_dump_on_exit(bool enable) { dump_on_exit_ = enable; }
73 76
74 // GetSnapshot copies some of the pointers to registered histograms into the 77 // GetSnapshot copies some of the pointers to registered histograms into the
75 // caller supplied vector (Histograms). Only histograms with names matching 78 // caller supplied vector (Histograms). Only histograms with names matching
76 // query are returned. The query must be a substring of histogram name for its 79 // query are returned. The query must be a substring of histogram name for its
77 // pointer to be copied. 80 // pointer to be copied.
78 static void GetSnapshot(const std::string& query, Histograms* snapshot); 81 static void GetSnapshot(const std::string& query, Histograms* snapshot);
79 82
80 private: 83 private:
81 // We keep all registered histograms in a map, from name to histogram. 84 // We keep all registered histograms in a map, from name to histogram.
82 typedef std::map<std::string, Histogram*> HistogramMap; 85 typedef std::map<std::string, Histogram*> HistogramMap;
83 86
84 // We keep all |bucket_ranges_| in a map, from checksum to a list of 87 // We keep all |bucket_ranges_| in a map, from checksum to a list of
85 // |bucket_ranges_|. Checksum is calculated from the |ranges_| in 88 // |bucket_ranges_|. Checksum is calculated from the |ranges_| in
86 // |bucket_ranges_|. 89 // |bucket_ranges_|.
87 typedef std::map<uint32, std::list<BucketRanges*>*> RangesMap; 90 typedef std::map<uint32, std::list<const BucketRanges*>*> RangesMap;
88 91
89 friend struct DefaultLazyInstanceTraits<StatisticsRecorder>; 92 friend struct DefaultLazyInstanceTraits<StatisticsRecorder>;
93 friend class StatisticsRecorderTest;
90 94
91 // Allow tests to access our innards for testing purposes. 95 // The constructor just initializes static members. Usually client code should
92 FRIEND_TEST_ALL_PREFIXES(HistogramTest, StartupShutdownTest); 96 // use Initialize to do this. But in test code, you can friend this class and
93 FRIEND_TEST_ALL_PREFIXES(HistogramTest, RecordedStartupTest); 97 // call destructor/constructor to get a clean StatisticsRecorder.
94 FRIEND_TEST_ALL_PREFIXES(HistogramTest, RangeTest);
95 FRIEND_TEST_ALL_PREFIXES(HistogramTest, CustomRangeTest);
96 FRIEND_TEST_ALL_PREFIXES(HistogramTest, BucketRangesTest);
97
98 StatisticsRecorder(); 98 StatisticsRecorder();
99
100 ~StatisticsRecorder(); 99 ~StatisticsRecorder();
101 100
102 static HistogramMap* histograms_; 101 static HistogramMap* histograms_;
103
104 static RangesMap* ranges_; 102 static RangesMap* ranges_;
105 103
106 // lock protects access to the above map. 104 // lock protects access to above maps.
jar (doing other things) 2012/08/01 00:26:10 nit: "Lock"
kaiwang 2012/08/01 04:13:21 Done.
107 static base::Lock* lock_; 105 static base::Lock* lock_;
108 106
109 // Dump all known histograms to log. 107 // Dump all known histograms to log.
110 static bool dump_on_exit_; 108 static bool dump_on_exit_;
111 109
112 DISALLOW_COPY_AND_ASSIGN(StatisticsRecorder); 110 DISALLOW_COPY_AND_ASSIGN(StatisticsRecorder);
113 }; 111 };
114 112
115 } // namespace base 113 } // namespace base
116 114
117 #endif // BASE_METRICS_STATISTICS_RECORDER_H_ 115 #endif // BASE_METRICS_STATISTICS_RECORDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698