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 17 matching lines...) Expand all Loading... |
28 } | 28 } |
29 | 29 |
30 void HistogramSnapshotManager::PrepareFinalDelta( | 30 void HistogramSnapshotManager::PrepareFinalDelta( |
31 const HistogramBase* histogram) { | 31 const HistogramBase* histogram) { |
32 PrepareSamples(histogram, histogram->SnapshotFinalDelta()); | 32 PrepareSamples(histogram, histogram->SnapshotFinalDelta()); |
33 } | 33 } |
34 | 34 |
35 void HistogramSnapshotManager::PrepareSamples( | 35 void HistogramSnapshotManager::PrepareSamples( |
36 const HistogramBase* histogram, | 36 const HistogramBase* histogram, |
37 std::unique_ptr<HistogramSamples> samples) { | 37 std::unique_ptr<HistogramSamples> samples) { |
| 38 DCHECK(thread_checker_.CalledOnValidThread()); |
38 DCHECK(histogram_flattener_); | 39 DCHECK(histogram_flattener_); |
39 | 40 |
40 // Get information known about this histogram. If it did not previously | 41 // Get information known about this histogram. If it did not previously |
41 // exist, one will be created and initialized. | 42 // exist, one will be created and initialized. |
42 SampleInfo* sample_info = &known_histograms_[histogram->name_hash()]; | 43 SampleInfo* sample_info = &known_histograms_[histogram->name_hash()]; |
43 | 44 |
44 // Crash if we detect that our histograms have been overwritten. This may be | 45 // Crash if we detect that our histograms have been overwritten. This may be |
45 // a fair distance from the memory smasher, but we hope to correlate these | 46 // a fair distance from the memory smasher, but we hope to correlate these |
46 // crashes with other events, such as plugins, or usage patterns, etc. | 47 // crashes with other events, such as plugins, or usage patterns, etc. |
47 uint32_t corruption = histogram->FindCorruption(*samples); | 48 uint32_t corruption = histogram->FindCorruption(*samples); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 sample_info->inconsistencies |= corruption; | 87 sample_info->inconsistencies |= corruption; |
87 histogram_flattener_->UniqueInconsistencyDetected( | 88 histogram_flattener_->UniqueInconsistencyDetected( |
88 static_cast<HistogramBase::Inconsistency>(corruption)); | 89 static_cast<HistogramBase::Inconsistency>(corruption)); |
89 return; | 90 return; |
90 } | 91 } |
91 | 92 |
92 if (samples->TotalCount() > 0) | 93 if (samples->TotalCount() > 0) |
93 histogram_flattener_->RecordDelta(*histogram, *samples); | 94 histogram_flattener_->RecordDelta(*histogram, *samples); |
94 } | 95 } |
95 | 96 |
96 void HistogramSnapshotManager::InspectLoggedSamplesInconsistency( | |
97 const HistogramSamples& new_snapshot, | |
98 HistogramSamples* logged_samples) { | |
99 HistogramBase::Count discrepancy = | |
100 logged_samples->TotalCount() - logged_samples->redundant_count(); | |
101 if (!discrepancy) | |
102 return; | |
103 | |
104 histogram_flattener_->InconsistencyDetectedInLoggedCount(discrepancy); | |
105 if (discrepancy > Histogram::kCommonRaceBasedCountMismatch) { | |
106 // Fix logged_samples. | |
107 logged_samples->Subtract(*logged_samples); | |
108 logged_samples->Add(new_snapshot); | |
109 } | |
110 } | |
111 | |
112 } // namespace base | 97 } // namespace base |
OLD | NEW |