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

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

Issue 10703037: Move StatisticsRecorder out of histogram.cc/h for further refactoring. (Closed) Base URL: svn://svn.chromium.org/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 | « base/metrics/histogram_unittest.cc ('k') | 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')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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
5 // StatisticsRecorder handles all histograms in the system. It provides a
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.
8
9 #ifndef BASE_METRICS_STATISTICS_RECORDER_H_
10 #define BASE_METRICS_STATISTICS_RECORDER_H_
11
12 #include <list>
13 #include <map>
14 #include <string>
15 #include <vector>
16
17 #include "base/base_export.h"
18 #include "base/basictypes.h"
19
20 namespace base {
21
22 class CachedRanges;
23 class Histogram;
24 class Lock;
25
26 class BASE_EXPORT StatisticsRecorder {
27 public:
28 typedef std::vector<Histogram*> Histograms;
29
30 StatisticsRecorder();
31
32 ~StatisticsRecorder();
33
34 // Find out if histograms can now be registered into our list.
35 static bool IsActive();
36
37 // Register, or add a new histogram to the collection of statistics. If an
38 // identically named histogram is already registered, then the argument
39 // |histogram| will deleted. The returned value is always the registered
40 // histogram (either the argument, or the pre-existing registered histogram).
41 static Histogram* RegisterOrDeleteDuplicate(Histogram* histogram);
42
43 // Register, or add a new cached_ranges_ of |histogram|. If an identical
44 // cached_ranges_ is already registered, then the cached_ranges_ of
45 // |histogram| is deleted and the |histogram|'s cached_ranges_ is reset to the
46 // registered cached_ranges_. The cached_ranges_ of |histogram| is always the
47 // registered CachedRanges (either the argument's cached_ranges_, or the
48 // pre-existing registered cached_ranges_).
49 static void RegisterOrDeleteDuplicateRanges(Histogram* histogram);
50
51 // Method for collecting stats about histograms created in browser and
52 // renderer processes. |suffix| is appended to histogram names. |suffix| could
53 // be either browser or renderer.
54 static void CollectHistogramStats(const std::string& suffix);
55
56 // Methods for printing histograms. Only histograms which have query as
57 // a substring are written to output (an empty string will process all
58 // registered histograms).
59 static void WriteHTMLGraph(const std::string& query, std::string* output);
60 static void WriteGraph(const std::string& query, std::string* output);
61
62 // Method for extracting histograms which were marked for use by UMA.
63 static void GetHistograms(Histograms* output);
64
65 // Find a histogram by name. It matches the exact name. This method is thread
66 // safe. If a matching histogram is not found, then the |histogram| is
67 // not changed.
68 static bool FindHistogram(const std::string& query, Histogram** histogram);
69
70 static bool dump_on_exit() { return dump_on_exit_; }
71
72 static void set_dump_on_exit(bool enable) { dump_on_exit_ = enable; }
73
74 // GetSnapshot copies some of the pointers to registered histograms into the
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
77 // pointer to be copied.
78 static void GetSnapshot(const std::string& query, Histograms* snapshot);
79
80
81 private:
82 // We keep all registered histograms in a map, from name to histogram.
83 typedef std::map<std::string, Histogram*> HistogramMap;
84
85 // We keep all |cached_ranges_| in a map, from checksum to a list of
86 // |cached_ranges_|. Checksum is calculated from the |ranges_| in
87 // |cached_ranges_|.
88 typedef std::map<uint32, std::list<CachedRanges*>*> RangesMap;
89
90 static HistogramMap* histograms_;
91
92 static RangesMap* ranges_;
93
94 // lock protects access to the above map.
95 static base::Lock* lock_;
96
97 // Dump all known histograms to log.
98 static bool dump_on_exit_;
99
100 DISALLOW_COPY_AND_ASSIGN(StatisticsRecorder);
101 };
102
103 } // namespace base
104
105 #endif // BASE_METRICS_STATISTICS_RECORDER_H_
OLDNEW
« no previous file with comments | « base/metrics/histogram_unittest.cc ('k') | base/metrics/statistics_recorder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698