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

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:executable
## -0,0 +1 ##
+*
\ No newline at end of property
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 #pragma once
12
13 #include <list>
14 #include <vector>
15 #include <map>
jar (doing other things) 2012/07/02 23:59:15 nit: alphabetize
kaiwang 2012/07/03 00:22:22 Done.
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 // Collect the number of histograms created.
27 static uint32 number_of_histograms_ = 0;
28 // Collect the number of vectors saved because of caching ranges.
29 static uint32 number_of_vectors_saved_ = 0;
30 // Collect the number of ranges_ elements saved because of caching ranges.
31 static size_t saved_ranges_size_ = 0;
32
33 class BASE_EXPORT StatisticsRecorder {
34 public:
35 typedef std::vector<Histogram*> Histograms;
36
37 StatisticsRecorder();
38
39 ~StatisticsRecorder();
40
41 // Find out if histograms can now be registered into our list.
42 static bool IsActive();
43
44 // Register, or add a new histogram to the collection of statistics. If an
45 // identically named histogram is already registered, then the argument
46 // |histogram| will deleted. The returned value is always the registered
47 // histogram (either the argument, or the pre-existing registered histogram).
48 static Histogram* RegisterOrDeleteDuplicate(Histogram* histogram);
49
50 // Register, or add a new cached_ranges_ of |histogram|. If an identical
51 // cached_ranges_ is already registered, then the cached_ranges_ of
52 // |histogram| is deleted and the |histogram|'s cached_ranges_ is reset to the
53 // registered cached_ranges_. The cached_ranges_ of |histogram| is always the
54 // registered CachedRanges (either the argument's cached_ranges_, or the
55 // pre-existing registered cached_ranges_).
56 static void RegisterOrDeleteDuplicateRanges(Histogram* histogram);
57
58 // Method for collecting stats about histograms created in browser and
59 // renderer processes. |suffix| is appended to histogram names. |suffix| could
60 // be either browser or renderer.
61 static void CollectHistogramStats(const std::string& suffix);
62
63 // Methods for printing histograms. Only histograms which have query as
64 // a substring are written to output (an empty string will process all
65 // registered histograms).
66 static void WriteHTMLGraph(const std::string& query, std::string* output);
67 static void WriteGraph(const std::string& query, std::string* output);
68
69 // Method for extracting histograms which were marked for use by UMA.
70 static void GetHistograms(Histograms* output);
71
72 // Find a histogram by name. It matches the exact name. This method is thread
73 // safe. If a matching histogram is not found, then the |histogram| is
74 // not changed.
75 static bool FindHistogram(const std::string& query, Histogram** histogram);
76
77 static bool dump_on_exit() { return dump_on_exit_; }
78
79 static void set_dump_on_exit(bool enable) { dump_on_exit_ = enable; }
80
81 // GetSnapshot copies some of the pointers to registered histograms into the
82 // caller supplied vector (Histograms). Only histograms with names matching
83 // query are returned. The query must be a substring of histogram name for its
84 // pointer to be copied.
85 static void GetSnapshot(const std::string& query, Histograms* snapshot);
86
87
88 private:
89 // We keep all registered histograms in a map, from name to histogram.
90 typedef std::map<std::string, Histogram*> HistogramMap;
91
92 // We keep all |cached_ranges_| in a map, from checksum to a list of
93 // |cached_ranges_|. Checksum is calculated from the |ranges_| in
94 // |cached_ranges_|.
95 typedef std::map<uint32, std::list<CachedRanges*>*> RangesMap;
96
97 static HistogramMap* histograms_;
98
99 static RangesMap* ranges_;
100
101 // lock protects access to the above map.
102 static base::Lock* lock_;
103
104 // Dump all known histograms to log.
105 static bool dump_on_exit_;
106
107 DISALLOW_COPY_AND_ASSIGN(StatisticsRecorder);
108 };
109
110 } // namespace base
111
112 #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