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

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

Issue 1537743006: Persist setup metrics and have Chrome report them during UMA upload. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@shared-histograms
Patch Set: address (many) comments by Greg Created 4 years, 10 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
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>
11 #include <string> 11 #include <string>
12 #include <vector>
12 13
13 #include "base/gtest_prod_util.h" 14 #include "base/gtest_prod_util.h"
14 #include "base/macros.h" 15 #include "base/macros.h"
15 #include "base/metrics/histogram_base.h" 16 #include "base/metrics/histogram_base.h"
16 17
17 namespace base { 18 namespace base {
18 19
19 class HistogramSamples; 20 class HistogramSamples;
20 class HistogramFlattener; 21 class HistogramFlattener;
21 22
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 FinishDeltas(); 77 FinishDeltas();
77 } 78 }
78 79
79 // When the collection is not so simple as can be done using a single 80 // When the collection is not so simple as can be done using a single
80 // iterator, the steps can be performed separately. Call PerpareDelta() 81 // iterator, the steps can be performed separately. Call PerpareDelta()
81 // as many times as necessary with a single StartDeltas() before and 82 // as many times as necessary with a single StartDeltas() before and
82 // a single FinishDeltas() after. All passed histograms must live 83 // a single FinishDeltas() after. All passed histograms must live
83 // until FinishDeltas() completes. PrepareOnce() works the same 84 // until FinishDeltas() completes. PrepareOnce() works the same
84 // but assumes there were no previous logged values and no future deltas 85 // but assumes there were no previous logged values and no future deltas
85 // will be created (and thus can work on read-only histograms). 86 // will be created (and thus can work on read-only histograms).
87 // Use Prepare*TakingOwnership() if it is desireable to have this class
88 // automatically delete the histogram once it is "finished".
86 void StartDeltas(); 89 void StartDeltas();
87 void PrepareDelta(HistogramBase* histogram); 90 void PrepareDelta(HistogramBase* histogram);
91 void PrepareDeltaTakingOwnership(HistogramBase* histogram);
88 void PrepareOnce(const HistogramBase* histogram); 92 void PrepareOnce(const HistogramBase* histogram);
93 void PrepareOnceTakingOwnership(const HistogramBase* histogram);
89 void FinishDeltas(); 94 void FinishDeltas();
90 95
91 private: 96 private:
92 FRIEND_TEST_ALL_PREFIXES(HistogramSnapshotManagerTest, CheckMerge); 97 FRIEND_TEST_ALL_PREFIXES(HistogramSnapshotManagerTest, CheckMerge);
93 98
94 // Capture and hold samples from a histogram. This does all the heavy 99 // Capture and hold samples from a histogram. This does all the heavy
95 // lifting for PrepareDelta() and PrepareOnce(). 100 // lifting for PrepareDelta() and PrepareOnce().
96 void PrepareSamples(const HistogramBase* histogram, 101 void PrepareSamples(const HistogramBase* histogram,
97 scoped_ptr<HistogramSamples> samples); 102 scoped_ptr<HistogramSamples> samples,
103 bool take_ownership);
98 104
99 // Try to detect and fix count inconsistency of logged samples. 105 // Try to detect and fix count inconsistency of logged samples.
100 void InspectLoggedSamplesInconsistency( 106 void InspectLoggedSamplesInconsistency(
101 const HistogramSamples& new_snapshot, 107 const HistogramSamples& new_snapshot,
102 HistogramSamples* logged_samples); 108 HistogramSamples* logged_samples);
103 109
104 // For histograms, track what has been previously seen, indexed 110 // For histograms, track what has been previously seen, indexed
105 // by the hash of the histogram name. 111 // by the hash of the histogram name.
106 HashInfoMap known_histograms_; 112 HashInfoMap known_histograms_;
107 113
114 // Collection of histograms of which ownership has been passed to this
115 // object. They will be deleted by FinishDeltas().
116 std::vector<const HistogramBase*> owned_histograms_;
grt (UTC plus 2) 2016/02/08 18:09:18 use std::vector<scoped_ptr<HistogramBase>> here. c
bcwhite 2016/02/09 21:08:45 Done. Is this new? A lot of code uses STL utils
grt (UTC plus 2) 2016/02/10 16:01:53 It is fairly new, yes: https://groups.google.com/a
117
108 // Indicates if deltas are currently being prepared. 118 // Indicates if deltas are currently being prepared.
109 bool preparing_deltas_; 119 bool preparing_deltas_;
110 120
111 // |histogram_flattener_| handles the logistics of recording the histogram 121 // |histogram_flattener_| handles the logistics of recording the histogram
112 // deltas. 122 // deltas.
113 HistogramFlattener* histogram_flattener_; // Weak. 123 HistogramFlattener* histogram_flattener_; // Weak.
114 124
115 DISALLOW_COPY_AND_ASSIGN(HistogramSnapshotManager); 125 DISALLOW_COPY_AND_ASSIGN(HistogramSnapshotManager);
116 }; 126 };
117 127
118 } // namespace base 128 } // namespace base
119 129
120 #endif // BASE_METRICS_HISTOGRAM_SNAPSHOT_MANAGER_H_ 130 #endif // BASE_METRICS_HISTOGRAM_SNAPSHOT_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698