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 #include "base/metrics/histogram_snapshot_manager.h" | 5 #include "base/metrics/histogram_snapshot_manager.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include <memory> |
| 8 |
8 #include "base/metrics/histogram_flattener.h" | 9 #include "base/metrics/histogram_flattener.h" |
9 #include "base/metrics/histogram_samples.h" | 10 #include "base/metrics/histogram_samples.h" |
10 #include "base/metrics/statistics_recorder.h" | 11 #include "base/metrics/statistics_recorder.h" |
11 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
12 | 13 |
13 namespace base { | 14 namespace base { |
14 | 15 |
15 HistogramSnapshotManager::HistogramSnapshotManager( | 16 HistogramSnapshotManager::HistogramSnapshotManager( |
16 HistogramFlattener* histogram_flattener) | 17 HistogramFlattener* histogram_flattener) |
17 : preparing_deltas_(false), | 18 : preparing_deltas_(false), |
(...skipping 18 matching lines...) Expand all Loading... |
36 HistogramBase::NEW_INCONSISTENCY_FOUND)); | 37 HistogramBase::NEW_INCONSISTENCY_FOUND)); |
37 } | 38 } |
38 #endif | 39 #endif |
39 } | 40 } |
40 | 41 |
41 void HistogramSnapshotManager::PrepareDelta(HistogramBase* histogram) { | 42 void HistogramSnapshotManager::PrepareDelta(HistogramBase* histogram) { |
42 PrepareSamples(histogram, histogram->SnapshotDelta()); | 43 PrepareSamples(histogram, histogram->SnapshotDelta()); |
43 } | 44 } |
44 | 45 |
45 void HistogramSnapshotManager::PrepareDeltaTakingOwnership( | 46 void HistogramSnapshotManager::PrepareDeltaTakingOwnership( |
46 scoped_ptr<HistogramBase> histogram) { | 47 std::unique_ptr<HistogramBase> histogram) { |
47 PrepareSamples(histogram.get(), histogram->SnapshotDelta()); | 48 PrepareSamples(histogram.get(), histogram->SnapshotDelta()); |
48 owned_histograms_.push_back(std::move(histogram)); | 49 owned_histograms_.push_back(std::move(histogram)); |
49 } | 50 } |
50 | 51 |
51 void HistogramSnapshotManager::PrepareAbsolute(const HistogramBase* histogram) { | 52 void HistogramSnapshotManager::PrepareAbsolute(const HistogramBase* histogram) { |
52 PrepareSamples(histogram, histogram->SnapshotSamples()); | 53 PrepareSamples(histogram, histogram->SnapshotSamples()); |
53 } | 54 } |
54 | 55 |
55 void HistogramSnapshotManager::PrepareAbsoluteTakingOwnership( | 56 void HistogramSnapshotManager::PrepareAbsoluteTakingOwnership( |
56 scoped_ptr<const HistogramBase> histogram) { | 57 std::unique_ptr<const HistogramBase> histogram) { |
57 PrepareSamples(histogram.get(), histogram->SnapshotSamples()); | 58 PrepareSamples(histogram.get(), histogram->SnapshotSamples()); |
58 owned_histograms_.push_back(std::move(histogram)); | 59 owned_histograms_.push_back(std::move(histogram)); |
59 } | 60 } |
60 | 61 |
61 void HistogramSnapshotManager::FinishDeltas() { | 62 void HistogramSnapshotManager::FinishDeltas() { |
62 DCHECK(preparing_deltas_); | 63 DCHECK(preparing_deltas_); |
63 | 64 |
64 // Iterate over all known histograms to see what should be recorded. | 65 // Iterate over all known histograms to see what should be recorded. |
65 for (auto& hash_and_info : known_histograms_) { | 66 for (auto& hash_and_info : known_histograms_) { |
66 SampleInfo* sample_info = &hash_and_info.second; | 67 SampleInfo* sample_info = &hash_and_info.second; |
(...skipping 22 matching lines...) Expand all Loading... |
89 // is only required to keep it alive until FinishDeltas() completes. | 90 // is only required to keep it alive until FinishDeltas() completes. |
90 sample_info->histogram = nullptr; | 91 sample_info->histogram = nullptr; |
91 } | 92 } |
92 | 93 |
93 owned_histograms_.clear(); | 94 owned_histograms_.clear(); |
94 preparing_deltas_ = false; | 95 preparing_deltas_ = false; |
95 } | 96 } |
96 | 97 |
97 void HistogramSnapshotManager::PrepareSamples( | 98 void HistogramSnapshotManager::PrepareSamples( |
98 const HistogramBase* histogram, | 99 const HistogramBase* histogram, |
99 scoped_ptr<HistogramSamples> samples) { | 100 std::unique_ptr<HistogramSamples> samples) { |
100 DCHECK(histogram_flattener_); | 101 DCHECK(histogram_flattener_); |
101 | 102 |
102 // Get information known about this histogram. | 103 // Get information known about this histogram. |
103 SampleInfo* sample_info = &known_histograms_[histogram->name_hash()]; | 104 SampleInfo* sample_info = &known_histograms_[histogram->name_hash()]; |
104 if (sample_info->histogram) { | 105 if (sample_info->histogram) { |
105 DCHECK_EQ(sample_info->histogram->histogram_name(), | 106 DCHECK_EQ(sample_info->histogram->histogram_name(), |
106 histogram->histogram_name()) << "hash collision"; | 107 histogram->histogram_name()) << "hash collision"; |
107 } else { | 108 } else { |
108 // First time this histogram has been seen; datafill. | 109 // First time this histogram has been seen; datafill. |
109 sample_info->histogram = histogram; | 110 sample_info->histogram = histogram; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 | 159 |
159 histogram_flattener_->InconsistencyDetectedInLoggedCount(discrepancy); | 160 histogram_flattener_->InconsistencyDetectedInLoggedCount(discrepancy); |
160 if (discrepancy > Histogram::kCommonRaceBasedCountMismatch) { | 161 if (discrepancy > Histogram::kCommonRaceBasedCountMismatch) { |
161 // Fix logged_samples. | 162 // Fix logged_samples. |
162 logged_samples->Subtract(*logged_samples); | 163 logged_samples->Subtract(*logged_samples); |
163 logged_samples->Add(new_snapshot); | 164 logged_samples->Add(new_snapshot); |
164 } | 165 } |
165 } | 166 } |
166 | 167 |
167 } // namespace base | 168 } // namespace base |
OLD | NEW |