OLD | NEW |
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 <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 16 matching lines...) Expand all Loading... |
27 public: | 27 public: |
28 explicit HistogramSnapshotManager(HistogramFlattener* histogram_flattener); | 28 explicit HistogramSnapshotManager(HistogramFlattener* histogram_flattener); |
29 virtual ~HistogramSnapshotManager(); | 29 virtual ~HistogramSnapshotManager(); |
30 | 30 |
31 // Snapshot all histograms, and ask |histogram_flattener_| to record the | 31 // Snapshot all histograms, and ask |histogram_flattener_| to record the |
32 // delta. |flags_to_set| is used to set flags for each histogram. | 32 // delta. |flags_to_set| is used to set flags for each histogram. |
33 // |required_flags| is used to select histograms to be recorded. | 33 // |required_flags| is used to select histograms to be recorded. |
34 // Only histograms that have all the flags specified by the argument will be | 34 // Only histograms that have all the flags specified by the argument will be |
35 // chosen. If all histograms should be recorded, set it to | 35 // chosen. If all histograms should be recorded, set it to |
36 // |Histogram::kNoFlags|. | 36 // |Histogram::kNoFlags|. |
37 void PrepareDeltas(HistogramBase::Flags flags_to_set, | 37 template <class ForwardHistogramIterator> |
38 HistogramBase::Flags required_flags); | 38 void PrepareDeltas(ForwardHistogramIterator begin, |
| 39 ForwardHistogramIterator end, |
| 40 HistogramBase::Flags flags_to_set, |
| 41 HistogramBase::Flags required_flags) { |
| 42 for (ForwardHistogramIterator it = begin; it != end; ++it) { |
| 43 (*it)->SetFlags(flags_to_set); |
| 44 if (((*it)->flags() & required_flags) == required_flags) |
| 45 PrepareDelta(**it); |
| 46 } |
| 47 } |
39 | 48 |
40 private: | 49 private: |
41 // Snapshot this histogram, and record the delta. | 50 // Snapshot this histogram, and record the delta. |
42 void PrepareDelta(const HistogramBase& histogram); | 51 void PrepareDelta(const HistogramBase& histogram); |
43 | 52 |
44 // Try to detect and fix count inconsistency of logged samples. | 53 // Try to detect and fix count inconsistency of logged samples. |
45 void InspectLoggedSamplesInconsistency( | 54 void InspectLoggedSamplesInconsistency( |
46 const HistogramSamples& new_snapshot, | 55 const HistogramSamples& new_snapshot, |
47 HistogramSamples* logged_samples); | 56 HistogramSamples* logged_samples); |
48 | 57 |
49 // For histograms, track what we've already recorded (as a sample for | 58 // For histograms, track what we've already recorded (as a sample for |
50 // each histogram) so that we can record only the delta with the next log. | 59 // each histogram) so that we can record only the delta with the next log. |
51 // The information is indexed by the hash of the histogram name. | 60 // The information is indexed by the hash of the histogram name. |
52 std::map<uint64_t, HistogramSamples*> logged_samples_; | 61 std::map<uint64_t, HistogramSamples*> logged_samples_; |
53 | 62 |
54 // Set of histograms found to be corrupt and their problems, indexed | 63 // Set of histograms found to be corrupt and their problems, indexed |
55 // by the hash of the histogram name. | 64 // by the hash of the histogram name. |
56 std::map<uint64_t, int> inconsistencies_; | 65 std::map<uint64_t, int> inconsistencies_; |
57 | 66 |
58 // |histogram_flattener_| handles the logistics of recording the histogram | 67 // |histogram_flattener_| handles the logistics of recording the histogram |
59 // deltas. | 68 // deltas. |
60 HistogramFlattener* histogram_flattener_; // Weak. | 69 HistogramFlattener* histogram_flattener_; // Weak. |
61 | 70 |
62 DISALLOW_COPY_AND_ASSIGN(HistogramSnapshotManager); | 71 DISALLOW_COPY_AND_ASSIGN(HistogramSnapshotManager); |
63 }; | 72 }; |
64 | 73 |
65 } // namespace base | 74 } // namespace base |
66 | 75 |
67 #endif // BASE_METRICS_HISTOGRAM_SNAPSHOT_MANAGER_H_ | 76 #endif // BASE_METRICS_HISTOGRAM_SNAPSHOT_MANAGER_H_ |
OLD | NEW |