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/statistics_recorder.h" | 5 #include "base/metrics/statistics_recorder.h" |
6 | 6 |
7 #include "base/debug/leak_annotations.h" | 7 #include "base/debug/leak_annotations.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 } else { | 114 } else { |
115 delete histogram; // We already have one by this name. | 115 delete histogram; // We already have one by this name. |
116 histogram = it->second; | 116 histogram = it->second; |
117 } | 117 } |
118 return histogram; | 118 return histogram; |
119 } | 119 } |
120 | 120 |
121 // static | 121 // static |
122 void StatisticsRecorder::RegisterOrDeleteDuplicateRanges(Histogram* histogram) { | 122 void StatisticsRecorder::RegisterOrDeleteDuplicateRanges(Histogram* histogram) { |
123 DCHECK(histogram); | 123 DCHECK(histogram); |
124 CachedRanges* histogram_ranges = histogram->cached_ranges(); | 124 BucketRanges* histogram_ranges = histogram->bucket_ranges(); |
125 DCHECK(histogram_ranges); | 125 DCHECK(histogram_ranges); |
126 uint32 checksum = histogram->range_checksum(); | 126 uint32 checksum = histogram->range_checksum(); |
127 histogram_ranges->SetRangeChecksum(checksum); | 127 histogram_ranges->set_checksum(checksum); |
128 | 128 |
129 RangesMap::iterator ranges_it = ranges_->find(checksum); | 129 RangesMap::iterator ranges_it = ranges_->find(checksum); |
130 if (ranges_->end() == ranges_it) { | 130 if (ranges_->end() == ranges_it) { |
131 // Register the new CachedRanges. | 131 // Register the new BucketRanges. |
132 std::list<CachedRanges*>* checksum_matching_list( | 132 std::list<BucketRanges*>* checksum_matching_list( |
133 new std::list<CachedRanges*>()); | 133 new std::list<BucketRanges*>()); |
134 checksum_matching_list->push_front(histogram_ranges); | 134 checksum_matching_list->push_front(histogram_ranges); |
135 (*ranges_)[checksum] = checksum_matching_list; | 135 (*ranges_)[checksum] = checksum_matching_list; |
136 return; | 136 return; |
137 } | 137 } |
138 | 138 |
139 // Use the registered CachedRanges if the registered CachedRanges has same | 139 // Use the registered BucketRanges if the registered BucketRanges has same |
140 // ranges_ as |histogram|'s CachedRanges. | 140 // ranges_ as |histogram|'s BucketRanges. |
141 std::list<CachedRanges*>* checksum_matching_list = ranges_it->second; | 141 std::list<BucketRanges*>* checksum_matching_list = ranges_it->second; |
142 std::list<CachedRanges*>::iterator checksum_matching_list_it; | 142 std::list<BucketRanges*>::iterator checksum_matching_list_it; |
143 for (checksum_matching_list_it = checksum_matching_list->begin(); | 143 for (checksum_matching_list_it = checksum_matching_list->begin(); |
144 checksum_matching_list_it != checksum_matching_list->end(); | 144 checksum_matching_list_it != checksum_matching_list->end(); |
145 ++checksum_matching_list_it) { | 145 ++checksum_matching_list_it) { |
146 CachedRanges* existing_histogram_ranges = *checksum_matching_list_it; | 146 BucketRanges* existing_histogram_ranges = *checksum_matching_list_it; |
147 DCHECK(existing_histogram_ranges); | 147 DCHECK(existing_histogram_ranges); |
148 if (existing_histogram_ranges->Equals(histogram_ranges)) { | 148 if (existing_histogram_ranges->Equals(histogram_ranges)) { |
149 histogram->set_cached_ranges(existing_histogram_ranges); | 149 histogram->set_bucket_ranges(existing_histogram_ranges); |
150 ++number_of_vectors_saved_; | 150 ++number_of_vectors_saved_; |
151 saved_ranges_size_ += histogram_ranges->size(); | 151 saved_ranges_size_ += histogram_ranges->size(); |
152 delete histogram_ranges; | 152 delete histogram_ranges; |
153 return; | 153 return; |
154 } | 154 } |
155 } | 155 } |
156 | 156 |
157 // We haven't found a CachedRanges which has the same ranges. Register the | 157 // We haven't found a BucketRanges which has the same ranges. Register the |
158 // new CachedRanges. | 158 // new BucketRanges. |
159 DCHECK(checksum_matching_list_it == checksum_matching_list->end()); | 159 DCHECK(checksum_matching_list_it == checksum_matching_list->end()); |
160 checksum_matching_list->push_front(histogram_ranges); | 160 checksum_matching_list->push_front(histogram_ranges); |
161 } | 161 } |
162 | 162 |
163 // static | 163 // static |
164 void StatisticsRecorder::CollectHistogramStats(const std::string& suffix) { | 164 void StatisticsRecorder::CollectHistogramStats(const std::string& suffix) { |
165 static int uma_upload_attempt = 0; | 165 static int uma_upload_attempt = 0; |
166 ++uma_upload_attempt; | 166 ++uma_upload_attempt; |
167 if (uma_upload_attempt == 1) { | 167 if (uma_upload_attempt == 1) { |
168 UMA_HISTOGRAM_COUNTS_10000( | 168 UMA_HISTOGRAM_COUNTS_10000( |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 // static | 288 // static |
289 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; | 289 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; |
290 // static | 290 // static |
291 StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = NULL; | 291 StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = NULL; |
292 // static | 292 // static |
293 base::Lock* StatisticsRecorder::lock_ = NULL; | 293 base::Lock* StatisticsRecorder::lock_ = NULL; |
294 // static | 294 // static |
295 bool StatisticsRecorder::dump_on_exit_ = false; | 295 bool StatisticsRecorder::dump_on_exit_ = false; |
296 | 296 |
297 } // namespace base | 297 } // namespace base |
OLD | NEW |