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

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

Issue 1891913002: Support saving browser metrics to disk and reading them during next run. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: removed some unnecessary includes Created 4 years, 7 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
« no previous file with comments | « base/metrics/histogram_base.h ('k') | base/metrics/histogram_snapshot_manager.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 #ifndef BASE_METRICS_HISTOGRAM_SNAPSHOT_MANAGER_H_ 5 #ifndef BASE_METRICS_HISTOGRAM_SNAPSHOT_MANAGER_H_
6 #define BASE_METRICS_HISTOGRAM_SNAPSHOT_MANAGER_H_ 6 #define BASE_METRICS_HISTOGRAM_SNAPSHOT_MANAGER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
(...skipping 22 matching lines...) Expand all
33 virtual ~HistogramSnapshotManager(); 33 virtual ~HistogramSnapshotManager();
34 34
35 // Snapshot all histograms, and ask |histogram_flattener_| to record the 35 // Snapshot all histograms, and ask |histogram_flattener_| to record the
36 // delta. |flags_to_set| is used to set flags for each histogram. 36 // delta. |flags_to_set| is used to set flags for each histogram.
37 // |required_flags| is used to select histograms to be recorded. 37 // |required_flags| is used to select histograms to be recorded.
38 // Only histograms that have all the flags specified by the argument will be 38 // Only histograms that have all the flags specified by the argument will be
39 // chosen. If all histograms should be recorded, set it to 39 // chosen. If all histograms should be recorded, set it to
40 // |Histogram::kNoFlags|. Though any "forward" iterator will work, the 40 // |Histogram::kNoFlags|. Though any "forward" iterator will work, the
41 // histograms over which it iterates *must* remain valid until this method 41 // histograms over which it iterates *must* remain valid until this method
42 // returns; the iterator cannot deallocate histograms once it iterates past 42 // returns; the iterator cannot deallocate histograms once it iterates past
43 // them. 43 // them and FinishDeltas() has been called after. StartDeltas() must be
44 // called before.
45 template <class ForwardHistogramIterator>
46 void PrepareDeltasWithoutStartFinish(ForwardHistogramIterator begin,
47 ForwardHistogramIterator end,
48 HistogramBase::Flags flags_to_set,
49 HistogramBase::Flags required_flags) {
50 for (ForwardHistogramIterator it = begin; it != end; ++it) {
51 (*it)->SetFlags(flags_to_set);
52 if (((*it)->flags() & required_flags) == required_flags)
53 PrepareDelta(*it);
54 }
55 }
56
57 // As above but also calls StartDeltas() and FinishDeltas().
44 template <class ForwardHistogramIterator> 58 template <class ForwardHistogramIterator>
45 void PrepareDeltas(ForwardHistogramIterator begin, 59 void PrepareDeltas(ForwardHistogramIterator begin,
46 ForwardHistogramIterator end, 60 ForwardHistogramIterator end,
47 HistogramBase::Flags flags_to_set, 61 HistogramBase::Flags flags_to_set,
48 HistogramBase::Flags required_flags) { 62 HistogramBase::Flags required_flags) {
49 StartDeltas(); 63 StartDeltas();
50 for (ForwardHistogramIterator it = begin; it != end; ++it) { 64 PrepareDeltasWithoutStartFinish(begin, end, flags_to_set, required_flags);
51 (*it)->SetFlags(flags_to_set);
52 if (((*it)->flags() & required_flags) == required_flags)
53 PrepareDelta(*it);
54 }
55 FinishDeltas(); 65 FinishDeltas();
56 } 66 }
57 67
58 // When the collection is not so simple as can be done using a single 68 // When the collection is not so simple as can be done using a single
59 // iterator, the steps can be performed separately. Call PerpareDelta() 69 // iterator, the steps can be performed separately. Call PerpareDelta()
60 // as many times as necessary with a single StartDeltas() before and 70 // as many times as necessary with a single StartDeltas() before and
61 // a single FinishDeltas() after. All passed histograms must live 71 // a single FinishDeltas() after. All passed histograms must live
62 // until FinishDeltas() completes. PrepareAbsolute() works the same 72 // until FinishDeltas() completes. PrepareAbsolute() works the same
63 // but assumes there were no previous logged values and no future deltas 73 // but assumes there were no previous logged values and no future deltas
64 // will be created (and thus can work on read-only histograms). 74 // will be created (and thus can work on read-only histograms).
75 // PrepareFinalDelta() works like PrepareDelta() except that it does
76 // not update the previous logged values and can thus be used with
77 // read-only files.
65 // Use Prepare*TakingOwnership() if it is desireable to have this class 78 // Use Prepare*TakingOwnership() if it is desireable to have this class
66 // automatically delete the histogram once it is "finished". 79 // automatically delete the histogram once it is "finished".
67 void StartDeltas(); 80 void StartDeltas();
68 void PrepareDelta(HistogramBase* histogram); 81 void PrepareDelta(HistogramBase* histogram);
69 void PrepareDeltaTakingOwnership(std::unique_ptr<HistogramBase> histogram); 82 void PrepareDeltaTakingOwnership(std::unique_ptr<HistogramBase> histogram);
70 void PrepareAbsolute(const HistogramBase* histogram); 83 void PrepareAbsolute(const HistogramBase* histogram);
71 void PrepareAbsoluteTakingOwnership( 84 void PrepareAbsoluteTakingOwnership(
72 std::unique_ptr<const HistogramBase> histogram); 85 std::unique_ptr<const HistogramBase> histogram);
86 void PrepareFinalDeltaTakingOwnership(
87 std::unique_ptr<const HistogramBase> histogram);
73 void FinishDeltas(); 88 void FinishDeltas();
74 89
75 private: 90 private:
76 FRIEND_TEST_ALL_PREFIXES(HistogramSnapshotManagerTest, CheckMerge); 91 FRIEND_TEST_ALL_PREFIXES(HistogramSnapshotManagerTest, CheckMerge);
77 92
78 // During a snapshot, samples are acquired and aggregated. This structure 93 // During a snapshot, samples are acquired and aggregated. This structure
79 // contains all the information collected for a given histogram. Once a 94 // contains all the information collected for a given histogram. Once a
80 // snapshot operation is finished, it is generally emptied except for 95 // snapshot operation is finished, it is generally emptied except for
81 // information that must persist from one report to the next, such as 96 // information that must persist from one report to the next, such as
82 // the "inconsistencies". 97 // the "inconsistencies".
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 // |histogram_flattener_| handles the logistics of recording the histogram 136 // |histogram_flattener_| handles the logistics of recording the histogram
122 // deltas. 137 // deltas.
123 HistogramFlattener* histogram_flattener_; // Weak. 138 HistogramFlattener* histogram_flattener_; // Weak.
124 139
125 DISALLOW_COPY_AND_ASSIGN(HistogramSnapshotManager); 140 DISALLOW_COPY_AND_ASSIGN(HistogramSnapshotManager);
126 }; 141 };
127 142
128 } // namespace base 143 } // namespace base
129 144
130 #endif // BASE_METRICS_HISTOGRAM_SNAPSHOT_MANAGER_H_ 145 #endif // BASE_METRICS_HISTOGRAM_SNAPSHOT_MANAGER_H_
OLDNEW
« no previous file with comments | « base/metrics/histogram_base.h ('k') | base/metrics/histogram_snapshot_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698