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/compiler_specific.h" | |
8 #include "base/debug/alias.h" | |
9 #include "base/metrics/statistics_recorder.h" | 7 #include "base/metrics/statistics_recorder.h" |
10 #include "base/string_util.h" | |
11 | 8 |
12 using base::Histogram; | 9 using base::Histogram; |
13 using base::StatisticsRecorder; | 10 using base::StatisticsRecorder; |
14 | 11 |
15 namespace base { | 12 namespace base { |
16 | 13 |
17 HistogramSnapshotManager::HistogramSnapshotManager( | 14 HistogramSnapshotManager::HistogramSnapshotManager( |
18 HistogramFlattener* histogram_flattener) | 15 HistogramFlattener* histogram_flattener) |
19 : histogram_flattener_(histogram_flattener) { | 16 : histogram_flattener_(histogram_flattener) { |
20 DCHECK(histogram_flattener_); | 17 DCHECK(histogram_flattener_); |
(...skipping 19 matching lines...) Expand all Loading... |
40 void HistogramSnapshotManager::PrepareDelta(const Histogram& histogram) { | 37 void HistogramSnapshotManager::PrepareDelta(const Histogram& histogram) { |
41 DCHECK(histogram_flattener_); | 38 DCHECK(histogram_flattener_); |
42 | 39 |
43 // Get up-to-date snapshot of sample stats. | 40 // Get up-to-date snapshot of sample stats. |
44 Histogram::SampleSet snapshot; | 41 Histogram::SampleSet snapshot; |
45 histogram.SnapshotSample(&snapshot); | 42 histogram.SnapshotSample(&snapshot); |
46 const std::string& histogram_name = histogram.histogram_name(); | 43 const std::string& histogram_name = histogram.histogram_name(); |
47 | 44 |
48 int corruption = histogram.FindCorruption(snapshot); | 45 int corruption = histogram.FindCorruption(snapshot); |
49 | 46 |
50 char histogram_name_buf[128]; | |
51 base::strlcpy(histogram_name_buf, | |
52 histogram_name.c_str(), | |
53 arraysize(histogram_name_buf)); | |
54 base::debug::Alias(histogram_name_buf); | |
55 | |
56 // Crash if we detect that our histograms have been overwritten. This may be | 47 // Crash if we detect that our histograms have been overwritten. This may be |
57 // a fair distance from the memory smasher, but we hope to correlate these | 48 // a fair distance from the memory smasher, but we hope to correlate these |
58 // crashes with other events, such as plugins, or usage patterns, etc. | 49 // crashes with other events, such as plugins, or usage patterns, etc. |
59 if (Histogram::BUCKET_ORDER_ERROR & corruption) { | 50 if (Histogram::BUCKET_ORDER_ERROR & corruption) { |
60 // The checksum should have caught this, so crash separately if it didn't. | 51 // The checksum should have caught this, so crash separately if it didn't. |
61 CHECK_NE(0, Histogram::RANGE_CHECKSUM_ERROR & corruption); | 52 CHECK_NE(0, Histogram::RANGE_CHECKSUM_ERROR & corruption); |
62 CHECK(false); // Crash for the bucket order corruption. | 53 CHECK(false); // Crash for the bucket order corruption. |
63 } | 54 } |
64 // Checksum corruption might not have caused order corruption. | 55 // Checksum corruption might not have caused order corruption. |
65 CHECK_EQ(0, Histogram::RANGE_CHECKSUM_ERROR & corruption); | 56 CHECK_EQ(0, Histogram::RANGE_CHECKSUM_ERROR & corruption); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 } | 98 } |
108 | 99 |
109 // 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. |
110 if (snapshot.redundant_count() > 0) { | 101 if (snapshot.redundant_count() > 0) { |
111 histogram_flattener_->RecordDelta(histogram, snapshot); | 102 histogram_flattener_->RecordDelta(histogram, snapshot); |
112 // Add new data into our running total. | 103 // Add new data into our running total. |
113 already_logged->Add(snapshot); | 104 already_logged->Add(snapshot); |
114 } | 105 } |
115 } | 106 } |
116 } // namespace base | 107 } // namespace base |
OLD | NEW |