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 <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/debug/alias.h" | 9 #include "base/debug/alias.h" |
10 #include "base/metrics/histogram_flattener.h" | 10 #include "base/metrics/histogram_flattener.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 HistogramSnapshotManager::~HistogramSnapshotManager() { | 24 HistogramSnapshotManager::~HistogramSnapshotManager() { |
25 } | 25 } |
26 | 26 |
27 void HistogramSnapshotManager::StartDeltas() { | 27 void HistogramSnapshotManager::StartDeltas() { |
28 // Ensure that start/finish calls do not get nested. | 28 // Ensure that start/finish calls do not get nested. |
29 DCHECK(!preparing_deltas_); | 29 DCHECK(!preparing_deltas_); |
30 preparing_deltas_ = true; | 30 preparing_deltas_ = true; |
31 | 31 |
32 DCHECK(owned_histograms_.empty()); | 32 DCHECK(owned_histograms_.empty()); |
33 | 33 |
34 #ifdef DEBUG | 34 #if DCHECK_IS_ON() |
35 CHECK(!iter->second.histogram); | 35 for (const auto& hash_and_info : known_histograms_) { |
36 CHECK(!iter->second.accumulated_samples); | 36 DCHECK(!hash_and_info.second.histogram); |
37 CHECK(!(iter->second.inconsistencies & | 37 DCHECK(!hash_and_info.second.accumulated_samples); |
38 HistogramBase::NEW_INCONSISTENCY_FOUND)); | 38 DCHECK(!(hash_and_info.second.inconsistencies & |
| 39 HistogramBase::NEW_INCONSISTENCY_FOUND)); |
39 } | 40 } |
40 #endif | 41 #endif |
41 } | 42 } |
42 | 43 |
43 void HistogramSnapshotManager::PrepareDelta(HistogramBase* histogram) { | 44 void HistogramSnapshotManager::PrepareDelta(HistogramBase* histogram) { |
44 PrepareSamples(histogram, histogram->SnapshotDelta()); | 45 PrepareSamples(histogram, histogram->SnapshotDelta()); |
45 } | 46 } |
46 | 47 |
47 void HistogramSnapshotManager::PrepareDeltaTakingOwnership( | 48 void HistogramSnapshotManager::PrepareDeltaTakingOwnership( |
48 std::unique_ptr<HistogramBase> histogram) { | 49 std::unique_ptr<HistogramBase> histogram) { |
49 PrepareSamples(histogram.get(), histogram->SnapshotDelta()); | 50 PrepareSamples(histogram.get(), histogram->SnapshotDelta()); |
50 owned_histograms_.push_back(std::move(histogram)); | 51 owned_histograms_.push_back(std::move(histogram)); |
51 } | 52 } |
52 | 53 |
53 void HistogramSnapshotManager::PrepareAbsolute(const HistogramBase* histogram) { | 54 void HistogramSnapshotManager::PrepareAbsolute(const HistogramBase* histogram) { |
54 PrepareSamples(histogram, histogram->SnapshotSamples()); | 55 PrepareSamples(histogram, histogram->SnapshotSamples()); |
55 } | 56 } |
56 | 57 |
57 void HistogramSnapshotManager::PrepareAbsoluteTakingOwnership( | 58 void HistogramSnapshotManager::PrepareAbsoluteTakingOwnership( |
58 std::unique_ptr<const HistogramBase> histogram) { | 59 std::unique_ptr<const HistogramBase> histogram) { |
59 PrepareSamples(histogram.get(), histogram->SnapshotSamples()); | 60 PrepareSamples(histogram.get(), histogram->SnapshotSamples()); |
60 owned_histograms_.push_back(std::move(histogram)); | 61 owned_histograms_.push_back(std::move(histogram)); |
61 } | 62 } |
62 | 63 |
| 64 void HistogramSnapshotManager::PrepareFinalDeltaTakingOwnership( |
| 65 std::unique_ptr<const HistogramBase> histogram) { |
| 66 PrepareSamples(histogram.get(), histogram->SnapshotFinalDelta()); |
| 67 owned_histograms_.push_back(std::move(histogram)); |
| 68 } |
| 69 |
63 void HistogramSnapshotManager::FinishDeltas() { | 70 void HistogramSnapshotManager::FinishDeltas() { |
64 DCHECK(preparing_deltas_); | 71 DCHECK(preparing_deltas_); |
65 | 72 |
66 // Iterate over all known histograms to see what should be recorded. | 73 // Iterate over all known histograms to see what should be recorded. |
67 for (auto& hash_and_info : known_histograms_) { | 74 for (auto& hash_and_info : known_histograms_) { |
68 SampleInfo* sample_info = &hash_and_info.second; | 75 SampleInfo* sample_info = &hash_and_info.second; |
69 | 76 |
70 // First, record any histograms in which corruption was detected. | 77 // First, record any histograms in which corruption was detected. |
71 if (sample_info->inconsistencies & HistogramBase::NEW_INCONSISTENCY_FOUND) { | 78 if (sample_info->inconsistencies & HistogramBase::NEW_INCONSISTENCY_FOUND) { |
72 sample_info->inconsistencies &= ~HistogramBase::NEW_INCONSISTENCY_FOUND; | 79 sample_info->inconsistencies &= ~HistogramBase::NEW_INCONSISTENCY_FOUND; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 | 171 |
165 histogram_flattener_->InconsistencyDetectedInLoggedCount(discrepancy); | 172 histogram_flattener_->InconsistencyDetectedInLoggedCount(discrepancy); |
166 if (discrepancy > Histogram::kCommonRaceBasedCountMismatch) { | 173 if (discrepancy > Histogram::kCommonRaceBasedCountMismatch) { |
167 // Fix logged_samples. | 174 // Fix logged_samples. |
168 logged_samples->Subtract(*logged_samples); | 175 logged_samples->Subtract(*logged_samples); |
169 logged_samples->Add(new_snapshot); | 176 logged_samples->Add(new_snapshot); |
170 } | 177 } |
171 } | 178 } |
172 | 179 |
173 } // namespace base | 180 } // namespace base |
OLD | NEW |