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

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 some 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
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(); 44 const std::string& histogram_name = histogram.histogram_name();
Alexei Svitkine (slow) 2015/12/04 18:21:00 Inline this into the DLOG(ERROR) since that's the
bcwhite 2015/12/04 19:34:46 Done.
45 const uint64_t histogram_id = histogram.name_hash();
Alexei Svitkine (slow) 2015/12/04 18:21:00 Nit: Move this closer to where it's first used - i
bcwhite 2015/12/04 19:34:47 Done.
45 46
46 int corruption = histogram.FindCorruption(*snapshot); 47 int corruption = histogram.FindCorruption(*snapshot);
47 48
48 // Crash if we detect that our histograms have been overwritten. This may be 49 // 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 50 // 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. 51 // crashes with other events, such as plugins, or usage patterns, etc.
51 if (HistogramBase::BUCKET_ORDER_ERROR & corruption) { 52 if (HistogramBase::BUCKET_ORDER_ERROR & corruption) {
52 // The checksum should have caught this, so crash separately if it didn't. 53 // The checksum should have caught this, so crash separately if it didn't.
53 CHECK_NE(0, HistogramBase::RANGE_CHECKSUM_ERROR & corruption); 54 CHECK_NE(0, HistogramBase::RANGE_CHECKSUM_ERROR & corruption);
54 CHECK(false); // Crash for the bucket order corruption. 55 CHECK(false); // Crash for the bucket order corruption.
55 } 56 }
56 // Checksum corruption might not have caused order corruption. 57 // Checksum corruption might not have caused order corruption.
57 CHECK_EQ(0, HistogramBase::RANGE_CHECKSUM_ERROR & corruption); 58 CHECK_EQ(0, HistogramBase::RANGE_CHECKSUM_ERROR & corruption);
58 59
59 // Note, at this point corruption can only be COUNT_HIGH_ERROR or 60 // 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 61 // COUNT_LOW_ERROR and they never arise together, so we don't need to extract
61 // bits from corruption. 62 // bits from corruption.
62 if (corruption) { 63 if (corruption) {
63 DLOG(ERROR) << "Histogram: " << histogram_name 64 DLOG(ERROR) << "Histogram: " << histogram_name
64 << " has data corruption: " << corruption; 65 << " has data corruption: " << corruption;
65 histogram_flattener_->InconsistencyDetected( 66 histogram_flattener_->InconsistencyDetected(
66 static_cast<HistogramBase::Inconsistency>(corruption)); 67 static_cast<HistogramBase::Inconsistency>(corruption));
67 // Don't record corrupt data to metrics services. 68 // Don't record corrupt data to metrics services.
68 int old_corruption = inconsistencies_[histogram_name]; 69 int old_corruption = inconsistencies_[histogram_id];
69 if (old_corruption == (corruption | old_corruption)) 70 if (old_corruption == (corruption | old_corruption))
70 return; // We've already seen this corruption for this histogram. 71 return; // We've already seen this corruption for this histogram.
71 inconsistencies_[histogram_name] |= corruption; 72 inconsistencies_[histogram_id] |= corruption;
72 histogram_flattener_->UniqueInconsistencyDetected( 73 histogram_flattener_->UniqueInconsistencyDetected(
73 static_cast<HistogramBase::Inconsistency>(corruption)); 74 static_cast<HistogramBase::Inconsistency>(corruption));
74 return; 75 return;
75 } 76 }
76 77
77 HistogramSamples* to_log; 78 HistogramSamples* to_log;
78 std::map<std::string, HistogramSamples*>::iterator it = 79 std::map<uint64_t, HistogramSamples*>::iterator it =
79 logged_samples_.find(histogram_name); 80 logged_samples_.find(histogram_id);
Alexei Svitkine (slow) 2015/12/04 18:21:00 nit: auto it =
bcwhite 2015/12/04 19:34:47 Done.
80 if (it == logged_samples_.end()) { 81 if (it == logged_samples_.end()) {
81 to_log = snapshot.release(); 82 to_log = snapshot.release();
82 83
83 // This histogram has not been logged before, add a new entry. 84 // This histogram has not been logged before, add a new entry.
84 logged_samples_[histogram_name] = to_log; 85 logged_samples_[histogram_id] = to_log;
85 } else { 86 } else {
86 HistogramSamples* already_logged = it->second; 87 HistogramSamples* already_logged = it->second;
87 InspectLoggedSamplesInconsistency(*snapshot, already_logged); 88 InspectLoggedSamplesInconsistency(*snapshot, already_logged);
88 snapshot->Subtract(*already_logged); 89 snapshot->Subtract(*already_logged);
89 already_logged->Add(*snapshot); 90 already_logged->Add(*snapshot);
90 to_log = snapshot.get(); 91 to_log = snapshot.get();
91 } 92 }
92 93
93 if (to_log->TotalCount() > 0) 94 if (to_log->TotalCount() > 0)
94 histogram_flattener_->RecordDelta(histogram, *to_log); 95 histogram_flattener_->RecordDelta(histogram, *to_log);
95 } 96 }
96 97
97 void HistogramSnapshotManager::InspectLoggedSamplesInconsistency( 98 void HistogramSnapshotManager::InspectLoggedSamplesInconsistency(
98 const HistogramSamples& new_snapshot, 99 const HistogramSamples& new_snapshot,
99 HistogramSamples* logged_samples) { 100 HistogramSamples* logged_samples) {
100 HistogramBase::Count discrepancy = 101 HistogramBase::Count discrepancy =
101 logged_samples->TotalCount() - logged_samples->redundant_count(); 102 logged_samples->TotalCount() - logged_samples->redundant_count();
102 if (!discrepancy) 103 if (!discrepancy)
103 return; 104 return;
104 105
105 histogram_flattener_->InconsistencyDetectedInLoggedCount(discrepancy); 106 histogram_flattener_->InconsistencyDetectedInLoggedCount(discrepancy);
106 if (discrepancy > Histogram::kCommonRaceBasedCountMismatch) { 107 if (discrepancy > Histogram::kCommonRaceBasedCountMismatch) {
107 // Fix logged_samples. 108 // Fix logged_samples.
108 logged_samples->Subtract(*logged_samples); 109 logged_samples->Subtract(*logged_samples);
109 logged_samples->Add(new_snapshot); 110 logged_samples->Add(new_snapshot);
110 } 111 }
111 } 112 }
112 113
113 } // namespace base 114 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698