Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Side by Side Diff: base/metrics/histogram_snapshot_manager.cc

Issue 1471073007: Reorganize histograms for persistence. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@shmem-alloc
Patch Set: addressed review comments by Alexei Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/metrics/histogram_snapshot_manager.h ('k') | base/metrics/histogram_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/memory/scoped_ptr.h"
8 #include "base/metrics/histogram_flattener.h" 8 #include "base/metrics/histogram_flattener.h"
9 #include "base/metrics/histogram_samples.h" 9 #include "base/metrics/histogram_samples.h"
10 #include "base/metrics/statistics_recorder.h" 10 #include "base/metrics/statistics_recorder.h"
(...skipping 23 matching lines...) Expand all
34 if (((*it)->flags() & required_flags) == required_flags) 34 if (((*it)->flags() & required_flags) == required_flags)
35 PrepareDelta(**it); 35 PrepareDelta(**it);
36 } 36 }
37 } 37 }
38 38
39 void HistogramSnapshotManager::PrepareDelta(const HistogramBase& histogram) { 39 void HistogramSnapshotManager::PrepareDelta(const HistogramBase& histogram) {
40 DCHECK(histogram_flattener_); 40 DCHECK(histogram_flattener_);
41 41
42 // Get up-to-date snapshot of sample stats. 42 // Get up-to-date snapshot of sample stats.
43 scoped_ptr<HistogramSamples> snapshot(histogram.SnapshotSamples()); 43 scoped_ptr<HistogramSamples> snapshot(histogram.SnapshotSamples());
44 const std::string& histogram_name = histogram.histogram_name();
45
46 int corruption = histogram.FindCorruption(*snapshot);
47 44
48 // 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
49 // 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
50 // crashes with other events, such as plugins, or usage patterns, etc. 47 // crashes with other events, such as plugins, or usage patterns, etc.
48 int corruption = histogram.FindCorruption(*snapshot);
51 if (HistogramBase::BUCKET_ORDER_ERROR & corruption) { 49 if (HistogramBase::BUCKET_ORDER_ERROR & corruption) {
52 // The checksum should have caught this, so crash separately if it didn't. 50 // The checksum should have caught this, so crash separately if it didn't.
53 CHECK_NE(0, HistogramBase::RANGE_CHECKSUM_ERROR & corruption); 51 CHECK_NE(0, HistogramBase::RANGE_CHECKSUM_ERROR & corruption);
54 CHECK(false); // Crash for the bucket order corruption. 52 CHECK(false); // Crash for the bucket order corruption.
55 } 53 }
56 // Checksum corruption might not have caused order corruption. 54 // Checksum corruption might not have caused order corruption.
57 CHECK_EQ(0, HistogramBase::RANGE_CHECKSUM_ERROR & corruption); 55 CHECK_EQ(0, HistogramBase::RANGE_CHECKSUM_ERROR & corruption);
58 56
59 // Note, at this point corruption can only be COUNT_HIGH_ERROR or 57 // Note, at this point corruption can only be COUNT_HIGH_ERROR or
60 // COUNT_LOW_ERROR and they never arise together, so we don't need to extract 58 // COUNT_LOW_ERROR and they never arise together, so we don't need to extract
61 // bits from corruption. 59 // bits from corruption.
60 const uint64_t histogram_hash = histogram.name_hash();
62 if (corruption) { 61 if (corruption) {
63 DLOG(ERROR) << "Histogram: " << histogram_name 62 DLOG(ERROR) << "Histogram: " << histogram.histogram_name()
64 << " has data corruption: " << corruption; 63 << " has data corruption: " << corruption;
65 histogram_flattener_->InconsistencyDetected( 64 histogram_flattener_->InconsistencyDetected(
66 static_cast<HistogramBase::Inconsistency>(corruption)); 65 static_cast<HistogramBase::Inconsistency>(corruption));
67 // Don't record corrupt data to metrics services. 66 // Don't record corrupt data to metrics services.
68 int old_corruption = inconsistencies_[histogram_name]; 67 int old_corruption = inconsistencies_[histogram_hash];
69 if (old_corruption == (corruption | old_corruption)) 68 if (old_corruption == (corruption | old_corruption))
70 return; // We've already seen this corruption for this histogram. 69 return; // We've already seen this corruption for this histogram.
71 inconsistencies_[histogram_name] |= corruption; 70 inconsistencies_[histogram_hash] |= corruption;
72 histogram_flattener_->UniqueInconsistencyDetected( 71 histogram_flattener_->UniqueInconsistencyDetected(
73 static_cast<HistogramBase::Inconsistency>(corruption)); 72 static_cast<HistogramBase::Inconsistency>(corruption));
74 return; 73 return;
75 } 74 }
76 75
77 HistogramSamples* to_log; 76 HistogramSamples* to_log;
78 std::map<std::string, HistogramSamples*>::iterator it = 77 auto it = logged_samples_.find(histogram_hash);
79 logged_samples_.find(histogram_name);
80 if (it == logged_samples_.end()) { 78 if (it == logged_samples_.end()) {
81 to_log = snapshot.release(); 79 to_log = snapshot.release();
82 80
83 // This histogram has not been logged before, add a new entry. 81 // This histogram has not been logged before, add a new entry.
84 logged_samples_[histogram_name] = to_log; 82 logged_samples_[histogram_hash] = to_log;
85 } else { 83 } else {
86 HistogramSamples* already_logged = it->second; 84 HistogramSamples* already_logged = it->second;
87 InspectLoggedSamplesInconsistency(*snapshot, already_logged); 85 InspectLoggedSamplesInconsistency(*snapshot, already_logged);
88 snapshot->Subtract(*already_logged); 86 snapshot->Subtract(*already_logged);
89 already_logged->Add(*snapshot); 87 already_logged->Add(*snapshot);
90 to_log = snapshot.get(); 88 to_log = snapshot.get();
91 } 89 }
92 90
93 if (to_log->TotalCount() > 0) 91 if (to_log->TotalCount() > 0)
94 histogram_flattener_->RecordDelta(histogram, *to_log); 92 histogram_flattener_->RecordDelta(histogram, *to_log);
95 } 93 }
96 94
97 void HistogramSnapshotManager::InspectLoggedSamplesInconsistency( 95 void HistogramSnapshotManager::InspectLoggedSamplesInconsistency(
98 const HistogramSamples& new_snapshot, 96 const HistogramSamples& new_snapshot,
99 HistogramSamples* logged_samples) { 97 HistogramSamples* logged_samples) {
100 HistogramBase::Count discrepancy = 98 HistogramBase::Count discrepancy =
101 logged_samples->TotalCount() - logged_samples->redundant_count(); 99 logged_samples->TotalCount() - logged_samples->redundant_count();
102 if (!discrepancy) 100 if (!discrepancy)
103 return; 101 return;
104 102
105 histogram_flattener_->InconsistencyDetectedInLoggedCount(discrepancy); 103 histogram_flattener_->InconsistencyDetectedInLoggedCount(discrepancy);
106 if (discrepancy > Histogram::kCommonRaceBasedCountMismatch) { 104 if (discrepancy > Histogram::kCommonRaceBasedCountMismatch) {
107 // Fix logged_samples. 105 // Fix logged_samples.
108 logged_samples->Subtract(*logged_samples); 106 logged_samples->Subtract(*logged_samples);
109 logged_samples->Add(new_snapshot); 107 logged_samples->Add(new_snapshot);
110 } 108 }
111 } 109 }
112 110
113 } // namespace base 111 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/histogram_snapshot_manager.h ('k') | base/metrics/histogram_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698