| 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/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/debug/alias.h" | 8 #include "base/debug/alias.h" |
| 9 #include "base/metrics/statistics_recorder.h" | 9 #include "base/metrics/statistics_recorder.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 // a fair distance from the memory smasher, but we hope to correlate these | 57 // a fair distance from the memory smasher, but we hope to correlate these |
| 58 // crashes with other events, such as plugins, or usage patterns, etc. | 58 // crashes with other events, such as plugins, or usage patterns, etc. |
| 59 if (Histogram::BUCKET_ORDER_ERROR & corruption) { | 59 if (Histogram::BUCKET_ORDER_ERROR & corruption) { |
| 60 // The checksum should have caught this, so crash separately if it didn't. | 60 // The checksum should have caught this, so crash separately if it didn't. |
| 61 CHECK_NE(0, Histogram::RANGE_CHECKSUM_ERROR & corruption); | 61 CHECK_NE(0, Histogram::RANGE_CHECKSUM_ERROR & corruption); |
| 62 CHECK(false); // Crash for the bucket order corruption. | 62 CHECK(false); // Crash for the bucket order corruption. |
| 63 } | 63 } |
| 64 // Checksum corruption might not have caused order corruption. | 64 // Checksum corruption might not have caused order corruption. |
| 65 CHECK_EQ(0, Histogram::RANGE_CHECKSUM_ERROR & corruption); | 65 CHECK_EQ(0, Histogram::RANGE_CHECKSUM_ERROR & corruption); |
| 66 | 66 |
| 67 // Note, at this point corruption can only be COUNT_HIGH_ERROR or |
| 68 // COUNT_LOW_ERROR and they never arise together, so we don't need to extract |
| 69 // bits from corruption. |
| 67 if (corruption) { | 70 if (corruption) { |
| 68 NOTREACHED(); | 71 NOTREACHED(); |
| 69 histogram_flattener_->InconsistencyDetected(corruption); | 72 histogram_flattener_->InconsistencyDetected( |
| 73 static_cast<Histogram::Inconsistencies>(corruption)); |
| 70 // Don't record corrupt data to metrics survices. | 74 // Don't record corrupt data to metrics survices. |
| 71 if (NULL == inconsistencies_.get()) | 75 if (NULL == inconsistencies_.get()) |
| 72 inconsistencies_.reset(new ProblemMap); | 76 inconsistencies_.reset(new ProblemMap); |
| 73 int old_corruption = (*inconsistencies_)[histogram_name]; | 77 int old_corruption = (*inconsistencies_)[histogram_name]; |
| 74 if (old_corruption == (corruption | old_corruption)) | 78 if (old_corruption == (corruption | old_corruption)) |
| 75 return; // We've already seen this corruption for this histogram. | 79 return; // We've already seen this corruption for this histogram. |
| 76 (*inconsistencies_)[histogram_name] |= corruption; | 80 (*inconsistencies_)[histogram_name] |= corruption; |
| 77 histogram_flattener_->UniqueInconsistencyDetected(corruption); | 81 histogram_flattener_->UniqueInconsistencyDetected( |
| 82 static_cast<Histogram::Inconsistencies>(corruption)); |
| 78 return; | 83 return; |
| 79 } | 84 } |
| 80 | 85 |
| 81 // Find the already recorded stats, or create an empty set. Remove from our | 86 // Find the already recorded stats, or create an empty set. Remove from our |
| 82 // snapshot anything that we've already recorded. | 87 // snapshot anything that we've already recorded. |
| 83 LoggedSampleMap::iterator it = logged_samples_.find(histogram_name); | 88 LoggedSampleMap::iterator it = logged_samples_.find(histogram_name); |
| 84 Histogram::SampleSet* already_logged; | 89 Histogram::SampleSet* already_logged; |
| 85 if (logged_samples_.end() == it) { | 90 if (logged_samples_.end() == it) { |
| 86 // Add new entry | 91 // Add new entry |
| 87 already_logged = &logged_samples_[histogram.histogram_name()]; | 92 already_logged = &logged_samples_[histogram.histogram_name()]; |
| 88 // Complete initialization. | 93 // Complete initialization. |
| 89 already_logged->Resize(histogram.bucket_count()); | 94 already_logged->Resize(histogram.bucket_count()); |
| 90 } else { | 95 } else { |
| 91 already_logged = &(it->second); | 96 already_logged = &(it->second); |
| 92 int64 discrepancy(already_logged->TotalCount() - | 97 int64 discrepancy(already_logged->TotalCount() - |
| 93 already_logged->redundant_count()); | 98 already_logged->redundant_count()); |
| 94 if (discrepancy) { | 99 if (discrepancy) { |
| 95 NOTREACHED(); // Already_logged has become corrupt. | 100 NOTREACHED(); // Already_logged has become corrupt. |
| 96 int problem = static_cast<int>(discrepancy); | 101 int problem = static_cast<int>(discrepancy); |
| 97 if (problem != discrepancy) | 102 if (problem != discrepancy) |
| 98 problem = INT_MAX; | 103 problem = INT_MAX; |
| 99 histogram_flattener_->SnapshotProblemResolved(problem); | 104 histogram_flattener_->InconsistencyDetectedInLoggedCount(problem); |
| 100 // With no valid baseline, we'll act like we've recorded everything in our | 105 // With no valid baseline, we'll act like we've recorded everything in our |
| 101 // snapshot. | 106 // snapshot. |
| 102 already_logged->Subtract(*already_logged); | 107 already_logged->Subtract(*already_logged); |
| 103 already_logged->Add(snapshot); | 108 already_logged->Add(snapshot); |
| 104 } | 109 } |
| 105 // Deduct any stats we've already logged from our snapshot. | 110 // Deduct any stats we've already logged from our snapshot. |
| 106 snapshot.Subtract(*already_logged); | 111 snapshot.Subtract(*already_logged); |
| 107 } | 112 } |
| 108 | 113 |
| 109 // Snapshot now contains only a delta to what we've already_logged. | 114 // Snapshot now contains only a delta to what we've already_logged. |
| 110 if (snapshot.redundant_count() > 0) { | 115 if (snapshot.redundant_count() > 0) { |
| 111 histogram_flattener_->RecordDelta(histogram, snapshot); | 116 histogram_flattener_->RecordDelta(histogram, snapshot); |
| 112 // Add new data into our running total. | 117 // Add new data into our running total. |
| 113 already_logged->Add(snapshot); | 118 already_logged->Add(snapshot); |
| 114 } | 119 } |
| 115 } | 120 } |
| 116 } // namespace base | 121 } // namespace base |
| OLD | NEW |