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

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

Issue 12207058: Connect SparseHistogram with the rest of stats system (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix and add tests Created 7 years, 10 months 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 | Annotate | Revision Log
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"
11 #include "base/stl_util.h" 11 #include "base/stl_util.h"
12 12
13 using std::map; 13 using std::map;
14 using std::string; 14 using std::string;
15 15
16 namespace base { 16 namespace base {
17 17
18 HistogramSnapshotManager::HistogramSnapshotManager( 18 HistogramSnapshotManager::HistogramSnapshotManager(
19 HistogramFlattener* histogram_flattener) 19 HistogramFlattener* histogram_flattener)
20 : histogram_flattener_(histogram_flattener) { 20 : histogram_flattener_(histogram_flattener) {
21 DCHECK(histogram_flattener_); 21 DCHECK(histogram_flattener_);
22 } 22 }
23 23
24 HistogramSnapshotManager::~HistogramSnapshotManager() { 24 HistogramSnapshotManager::~HistogramSnapshotManager() {
25 STLDeleteValues(&logged_samples_); 25 STLDeleteValues(&logged_samples_);
26 } 26 }
27 27
28 void HistogramSnapshotManager::PrepareDeltas(Histogram::Flags flag_to_set, 28 void HistogramSnapshotManager::PrepareDeltas(HistogramBase::Flags flag_to_set,
29 bool record_only_uma) { 29 bool record_only_uma) {
30 StatisticsRecorder::Histograms histograms; 30 StatisticsRecorder::Histograms histograms;
31 StatisticsRecorder::GetHistograms(&histograms); 31 StatisticsRecorder::GetHistograms(&histograms);
32 for (StatisticsRecorder::Histograms::const_iterator it = histograms.begin(); 32 for (StatisticsRecorder::Histograms::const_iterator it = histograms.begin();
33 histograms.end() != it; 33 histograms.end() != it;
34 ++it) { 34 ++it) {
35 (*it)->SetFlags(flag_to_set); 35 (*it)->SetFlags(flag_to_set);
36 if (record_only_uma && 36 if (record_only_uma &&
37 0 == ((*it)->flags() & Histogram::kUmaTargetedHistogramFlag)) 37 0 == ((*it)->flags() & Histogram::kUmaTargetedHistogramFlag))
38 continue; 38 continue;
39 PrepareDelta(**it); 39 PrepareDelta(**it);
40 } 40 }
41 } 41 }
42 42
43 void HistogramSnapshotManager::PrepareDelta(const Histogram& histogram) { 43 void HistogramSnapshotManager::PrepareDelta(const HistogramBase& histogram) {
44 DCHECK(histogram_flattener_); 44 DCHECK(histogram_flattener_);
45 45
46 // Get up-to-date snapshot of sample stats. 46 // Get up-to-date snapshot of sample stats.
47 scoped_ptr<HistogramSamples> snapshot(histogram.SnapshotSamples()); 47 scoped_ptr<HistogramSamples> snapshot(histogram.SnapshotSamples());
48 const std::string& histogram_name = histogram.histogram_name(); 48 const std::string& histogram_name = histogram.histogram_name();
49 49
50 int corruption = histogram.FindCorruption(*snapshot); 50 int corruption = histogram.FindCorruption(*snapshot);
Ilya Sherman 2013/02/21 05:36:06 int32?
kaiwang 2013/02/27 04:39:42 Done.
51 51
52 // Crash if we detect that our histograms have been overwritten. This may be 52 // Crash if we detect that our histograms have been overwritten. This may be
53 // a fair distance from the memory smasher, but we hope to correlate these 53 // a fair distance from the memory smasher, but we hope to correlate these
54 // crashes with other events, such as plugins, or usage patterns, etc. 54 // crashes with other events, such as plugins, or usage patterns, etc.
55 if (Histogram::BUCKET_ORDER_ERROR & corruption) { 55 if (BUCKET_ORDER_ERROR & corruption) {
56 // The checksum should have caught this, so crash separately if it didn't. 56 // The checksum should have caught this, so crash separately if it didn't.
57 CHECK_NE(0, Histogram::RANGE_CHECKSUM_ERROR & corruption); 57 CHECK_NE(0, RANGE_CHECKSUM_ERROR & corruption);
58 CHECK(false); // Crash for the bucket order corruption. 58 CHECK(false); // Crash for the bucket order corruption.
59 } 59 }
60 // Checksum corruption might not have caused order corruption. 60 // Checksum corruption might not have caused order corruption.
61 CHECK_EQ(0, Histogram::RANGE_CHECKSUM_ERROR & corruption); 61 CHECK_EQ(0, RANGE_CHECKSUM_ERROR & corruption);
62 62
63 // Note, at this point corruption can only be COUNT_HIGH_ERROR or 63 // Note, at this point corruption can only be COUNT_HIGH_ERROR or
64 // COUNT_LOW_ERROR and they never arise together, so we don't need to extract 64 // COUNT_LOW_ERROR and they never arise together, so we don't need to extract
65 // bits from corruption. 65 // bits from corruption.
66 if (corruption) { 66 if (corruption) {
67 DLOG(ERROR) << "Histogram: " << histogram_name 67 DLOG(ERROR) << "Histogram: " << histogram_name
68 << " has data corruption: " << corruption; 68 << " has data corruption: " << corruption;
69 histogram_flattener_->InconsistencyDetected( 69 histogram_flattener_->InconsistencyDetected(
70 static_cast<Histogram::Inconsistencies>(corruption)); 70 static_cast<HistogramInconsistency>(corruption));
Ilya Sherman 2013/02/21 05:36:06 Seems like if you're willing to cast here, you mig
kaiwang 2013/02/27 04:39:42 the value FindCorruption returns can be a combinat
71 // Don't record corrupt data to metrics services. 71 // Don't record corrupt data to metrics services.
72 int old_corruption = inconsistencies_[histogram_name]; 72 int old_corruption = inconsistencies_[histogram_name];
73 if (old_corruption == (corruption | old_corruption)) 73 if (old_corruption == (corruption | old_corruption))
74 return; // We've already seen this corruption for this histogram. 74 return; // We've already seen this corruption for this histogram.
75 inconsistencies_[histogram_name] |= corruption; 75 inconsistencies_[histogram_name] |= corruption;
76 histogram_flattener_->UniqueInconsistencyDetected( 76 histogram_flattener_->UniqueInconsistencyDetected(
77 static_cast<Histogram::Inconsistencies>(corruption)); 77 static_cast<HistogramInconsistency>(corruption));
78 return; 78 return;
79 } 79 }
80 80
81 HistogramSamples* to_log; 81 HistogramSamples* to_log;
82 map<string, HistogramSamples*>::iterator it = 82 map<string, HistogramSamples*>::iterator it =
83 logged_samples_.find(histogram_name); 83 logged_samples_.find(histogram_name);
84 if (it == logged_samples_.end()) { 84 if (it == logged_samples_.end()) {
85 to_log = snapshot.release(); 85 to_log = snapshot.release();
86 86
87 // This histogram has not been logged before, add a new entry. 87 // This histogram has not been logged before, add a new entry.
(...skipping 20 matching lines...) Expand all
108 108
109 histogram_flattener_->InconsistencyDetectedInLoggedCount(discrepancy); 109 histogram_flattener_->InconsistencyDetectedInLoggedCount(discrepancy);
110 if (discrepancy > Histogram::kCommonRaceBasedCountMismatch) { 110 if (discrepancy > Histogram::kCommonRaceBasedCountMismatch) {
111 // Fix logged_samples. 111 // Fix logged_samples.
112 logged_samples->Subtract(*logged_samples); 112 logged_samples->Subtract(*logged_samples);
113 logged_samples->Add(new_snapshot); 113 logged_samples->Add(new_snapshot);
114 } 114 }
115 } 115 }
116 116
117 } // namespace base 117 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698