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

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

Issue 10779040: Initialize StatisticsRecorder in Child Process to hold (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 5 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
« no previous file with comments | « no previous file | base/metrics/statistics_recorder.cc » ('j') | no next file with comments »
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 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 19
20 namespace base { 20 namespace base {
21 21
22 class CachedRanges; 22 class CachedRanges;
23 class Histogram; 23 class Histogram;
24 class Lock; 24 class Lock;
25 25
26 class BASE_EXPORT StatisticsRecorder { 26 class BASE_EXPORT StatisticsRecorder {
27 public: 27 public:
28 typedef std::vector<Histogram*> Histograms; 28 typedef std::vector<Histogram*> Histograms;
29 29
30 StatisticsRecorder(); 30 StatisticsRecorder();
jam 2012/07/18 05:14:17 if it's a singleton, then the constructor and dest
jar (doing other things) 2012/07/18 16:00:01 I think this was done to facilitate testability.
jam 2012/07/18 16:36:12 I think that would be better, because that enforce
ramant (doing other things) 2012/07/18 18:54:34 Done.
31 31
32 ~StatisticsRecorder(); 32 ~StatisticsRecorder();
33 33
34 // Initializes the StatisticsRecorder system.
35 static void Initialize();
36
34 // Find out if histograms can now be registered into our list. 37 // Find out if histograms can now be registered into our list.
35 static bool IsActive(); 38 static bool IsActive();
36 39
37 // Register, or add a new histogram to the collection of statistics. If an 40 // Register, or add a new histogram to the collection of statistics. If an
38 // identically named histogram is already registered, then the argument 41 // identically named histogram is already registered, then the argument
39 // |histogram| will deleted. The returned value is always the registered 42 // |histogram| will deleted. The returned value is always the registered
40 // histogram (either the argument, or the pre-existing registered histogram). 43 // histogram (either the argument, or the pre-existing registered histogram).
41 static Histogram* RegisterOrDeleteDuplicate(Histogram* histogram); 44 static Histogram* RegisterOrDeleteDuplicate(Histogram* histogram);
42 45
43 // Register, or add a new cached_ranges_ of |histogram|. If an identical 46 // Register, or add a new cached_ranges_ of |histogram|. If an identical
(...skipping 26 matching lines...) Expand all
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
81 private: 83 private:
82 // 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.
83 typedef std::map<std::string, Histogram*> HistogramMap; 85 typedef std::map<std::string, Histogram*> HistogramMap;
84 86
85 // We keep all |cached_ranges_| in a map, from checksum to a list of 87 // We keep all |cached_ranges_| in a map, from checksum to a list of
86 // |cached_ranges_|. Checksum is calculated from the |ranges_| in 88 // |cached_ranges_|. Checksum is calculated from the |ranges_| in
87 // |cached_ranges_|. 89 // |cached_ranges_|.
88 typedef std::map<uint32, std::list<CachedRanges*>*> RangesMap; 90 typedef std::map<uint32, std::list<CachedRanges*>*> RangesMap;
89 91
90 static HistogramMap* histograms_; 92 static HistogramMap* histograms_;
91 93
92 static RangesMap* ranges_; 94 static RangesMap* ranges_;
93 95
94 // lock protects access to the above map. 96 // lock protects access to the above map.
95 static base::Lock* lock_; 97 static base::Lock* lock_;
96 98
97 // Dump all known histograms to log. 99 // Dump all known histograms to log.
98 static bool dump_on_exit_; 100 static bool dump_on_exit_;
99 101
100 DISALLOW_COPY_AND_ASSIGN(StatisticsRecorder); 102 DISALLOW_COPY_AND_ASSIGN(StatisticsRecorder);
101 }; 103 };
102 104
103 } // namespace base 105 } // namespace base
104 106
105 #endif // BASE_METRICS_STATISTICS_RECORDER_H_ 107 #endif // BASE_METRICS_STATISTICS_RECORDER_H_
OLDNEW
« no previous file with comments | « no previous file | base/metrics/statistics_recorder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698