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/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; | |
14 using std::string; | |
15 | |
16 namespace base { | 13 namespace base { |
17 | 14 |
18 HistogramSnapshotManager::HistogramSnapshotManager( | 15 HistogramSnapshotManager::HistogramSnapshotManager( |
19 HistogramFlattener* histogram_flattener) | 16 HistogramFlattener* histogram_flattener) |
20 : histogram_flattener_(histogram_flattener) { | 17 : histogram_flattener_(histogram_flattener) { |
21 DCHECK(histogram_flattener_); | 18 DCHECK(histogram_flattener_); |
22 } | 19 } |
23 | 20 |
24 HistogramSnapshotManager::~HistogramSnapshotManager() { | 21 HistogramSnapshotManager::~HistogramSnapshotManager() { |
25 STLDeleteValues(&logged_samples_); | 22 STLDeleteValues(&logged_samples_); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 int old_corruption = inconsistencies_[histogram_name]; | 68 int old_corruption = inconsistencies_[histogram_name]; |
72 if (old_corruption == (corruption | old_corruption)) | 69 if (old_corruption == (corruption | old_corruption)) |
73 return; // We've already seen this corruption for this histogram. | 70 return; // We've already seen this corruption for this histogram. |
74 inconsistencies_[histogram_name] |= corruption; | 71 inconsistencies_[histogram_name] |= corruption; |
75 histogram_flattener_->UniqueInconsistencyDetected( | 72 histogram_flattener_->UniqueInconsistencyDetected( |
76 static_cast<HistogramBase::Inconsistency>(corruption)); | 73 static_cast<HistogramBase::Inconsistency>(corruption)); |
77 return; | 74 return; |
78 } | 75 } |
79 | 76 |
80 HistogramSamples* to_log; | 77 HistogramSamples* to_log; |
81 map<string, HistogramSamples*>::iterator it = | 78 std::map<std::string, HistogramSamples*>::iterator it = |
82 logged_samples_.find(histogram_name); | 79 logged_samples_.find(histogram_name); |
83 if (it == logged_samples_.end()) { | 80 if (it == logged_samples_.end()) { |
84 to_log = snapshot.release(); | 81 to_log = snapshot.release(); |
85 | 82 |
86 // This histogram has not been logged before, add a new entry. | 83 // This histogram has not been logged before, add a new entry. |
87 logged_samples_[histogram_name] = to_log; | 84 logged_samples_[histogram_name] = to_log; |
88 } else { | 85 } else { |
89 HistogramSamples* already_logged = it->second; | 86 HistogramSamples* already_logged = it->second; |
90 InspectLoggedSamplesInconsistency(*snapshot, already_logged); | 87 InspectLoggedSamplesInconsistency(*snapshot, already_logged); |
91 snapshot->Subtract(*already_logged); | 88 snapshot->Subtract(*already_logged); |
(...skipping 15 matching lines...) Expand all Loading... |
107 | 104 |
108 histogram_flattener_->InconsistencyDetectedInLoggedCount(discrepancy); | 105 histogram_flattener_->InconsistencyDetectedInLoggedCount(discrepancy); |
109 if (discrepancy > Histogram::kCommonRaceBasedCountMismatch) { | 106 if (discrepancy > Histogram::kCommonRaceBasedCountMismatch) { |
110 // Fix logged_samples. | 107 // Fix logged_samples. |
111 logged_samples->Subtract(*logged_samples); | 108 logged_samples->Subtract(*logged_samples); |
112 logged_samples->Add(new_snapshot); | 109 logged_samples->Add(new_snapshot); |
113 } | 110 } |
114 } | 111 } |
115 | 112 |
116 } // namespace base | 113 } // namespace base |
OLD | NEW |