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

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

Issue 10834011: Refactor of Histogram related code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 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/metrics/statistics_recorder.h" 7 #include "base/metrics/statistics_recorder.h"
8 8
9 using base::Histogram; 9 using base::Histogram;
10 using base::StatisticsRecorder; 10 using base::StatisticsRecorder;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 return; 69 return;
70 } 70 }
71 71
72 // Find the already recorded stats, or create an empty set. Remove from our 72 // Find the already recorded stats, or create an empty set. Remove from our
73 // snapshot anything that we've already recorded. 73 // snapshot anything that we've already recorded.
74 LoggedSampleMap::iterator it = logged_samples_.find(histogram_name); 74 LoggedSampleMap::iterator it = logged_samples_.find(histogram_name);
75 Histogram::SampleSet* already_logged; 75 Histogram::SampleSet* already_logged;
76 if (logged_samples_.end() == it) { 76 if (logged_samples_.end() == it) {
77 // Add new entry 77 // Add new entry
78 already_logged = &logged_samples_[histogram.histogram_name()]; 78 already_logged = &logged_samples_[histogram.histogram_name()];
79 already_logged->Resize(histogram); // Complete initialization. 79 // Complete initialization.
80 already_logged->Resize(histogram.bucket_count());
80 } else { 81 } else {
81 already_logged = &(it->second); 82 already_logged = &(it->second);
82 int64 discrepancy(already_logged->TotalCount() - 83 int64 discrepancy(already_logged->TotalCount() -
83 already_logged->redundant_count()); 84 already_logged->redundant_count());
84 if (discrepancy) { 85 if (discrepancy) {
85 NOTREACHED(); // Already_logged has become corrupt. 86 NOTREACHED(); // Already_logged has become corrupt.
86 int problem = static_cast<int>(discrepancy); 87 int problem = static_cast<int>(discrepancy);
87 if (problem != discrepancy) 88 if (problem != discrepancy)
88 problem = INT_MAX; 89 problem = INT_MAX;
89 histogram_flattener_->SnapshotProblemResolved(problem); 90 histogram_flattener_->SnapshotProblemResolved(problem);
90 // With no valid baseline, we'll act like we've recorded everything in our 91 // With no valid baseline, we'll act like we've recorded everything in our
91 // snapshot. 92 // snapshot.
92 already_logged->Subtract(*already_logged); 93 already_logged->Subtract(*already_logged);
93 already_logged->Add(snapshot); 94 already_logged->Add(snapshot);
94 } 95 }
95 // Deduct any stats we've already logged from our snapshot. 96 // Deduct any stats we've already logged from our snapshot.
96 snapshot.Subtract(*already_logged); 97 snapshot.Subtract(*already_logged);
97 } 98 }
98 99
99 // Snapshot now contains only a delta to what we've already_logged. 100 // Snapshot now contains only a delta to what we've already_logged.
100 if (snapshot.redundant_count() > 0) { 101 if (snapshot.redundant_count() > 0) {
101 histogram_flattener_->RecordDelta(histogram, snapshot); 102 histogram_flattener_->RecordDelta(histogram, snapshot);
102 // Add new data into our running total. 103 // Add new data into our running total.
103 already_logged->Add(snapshot); 104 already_logged->Add(snapshot);
104 } 105 }
105 } 106 }
106 } // namespace base 107 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698