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 // Histogram is an object that aggregates statistics, and can summarize them in | 5 // Histogram is an object that aggregates statistics, and can summarize them in |
6 // various forms, including ASCII graphical, HTML, and numerically (as a | 6 // various forms, including ASCII graphical, HTML, and numerically (as a |
7 // vector of numbers corresponding to each of the aggregating buckets). | 7 // vector of numbers corresponding to each of the aggregating buckets). |
8 // See header file for details and examples. | 8 // See header file for details and examples. |
9 | 9 |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 static_cast<int>(histogram_info.size())); | 259 static_cast<int>(histogram_info.size())); |
260 std::string histogram_name; | 260 std::string histogram_name; |
261 int declared_min; | 261 int declared_min; |
262 int declared_max; | 262 int declared_max; |
263 size_t bucket_count; | 263 size_t bucket_count; |
264 uint32 range_checksum; | 264 uint32 range_checksum; |
265 int histogram_type; | 265 int histogram_type; |
266 int pickle_flags; | 266 int pickle_flags; |
267 SampleSet sample; | 267 SampleSet sample; |
268 | 268 |
269 void* iter = NULL; | 269 PickleIterator iter(pickle); |
270 if (!pickle.ReadString(&iter, &histogram_name) || | 270 if (!iter.ReadString(&histogram_name) || |
271 !pickle.ReadInt(&iter, &declared_min) || | 271 !iter.ReadInt(&declared_min) || |
272 !pickle.ReadInt(&iter, &declared_max) || | 272 !iter.ReadInt(&declared_max) || |
273 !pickle.ReadSize(&iter, &bucket_count) || | 273 !iter.ReadSize(&bucket_count) || |
274 !pickle.ReadUInt32(&iter, &range_checksum) || | 274 !iter.ReadUInt32(&range_checksum) || |
275 !pickle.ReadInt(&iter, &histogram_type) || | 275 !iter.ReadInt(&histogram_type) || |
276 !pickle.ReadInt(&iter, &pickle_flags) || | 276 !iter.ReadInt(&pickle_flags) || |
277 !sample.Histogram::SampleSet::Deserialize(&iter, pickle)) { | 277 !sample.Histogram::SampleSet::Deserialize(&iter)) { |
278 DLOG(ERROR) << "Pickle error decoding Histogram: " << histogram_name; | 278 DLOG(ERROR) << "Pickle error decoding Histogram: " << histogram_name; |
279 return false; | 279 return false; |
280 } | 280 } |
281 | 281 |
282 DCHECK(pickle_flags & kIPCSerializationSourceFlag); | 282 DCHECK(pickle_flags & kIPCSerializationSourceFlag); |
283 // Since these fields may have come from an untrusted renderer, do additional | 283 // Since these fields may have come from an untrusted renderer, do additional |
284 // checks above and beyond those in Histogram::Initialize() | 284 // checks above and beyond those in Histogram::Initialize() |
285 if (declared_max <= 0 || declared_min <= 0 || declared_max < declared_min || | 285 if (declared_max <= 0 || declared_min <= 0 || declared_max < declared_min || |
286 INT_MAX / sizeof(Count) <= bucket_count || bucket_count < 2) { | 286 INT_MAX / sizeof(Count) <= bucket_count || bucket_count < 2) { |
287 DLOG(ERROR) << "Values error decoding Histogram: " << histogram_name; | 287 DLOG(ERROR) << "Values error decoding Histogram: " << histogram_name; |
288 return false; | 288 return false; |
289 } | 289 } |
290 | 290 |
291 Flags flags = static_cast<Flags>(pickle_flags & ~kIPCSerializationSourceFlag); | 291 Flags flags = static_cast<Flags>(pickle_flags & ~kIPCSerializationSourceFlag); |
292 | 292 |
293 DCHECK_NE(NOT_VALID_IN_RENDERER, histogram_type); | 293 DCHECK_NE(NOT_VALID_IN_RENDERER, histogram_type); |
294 | 294 |
295 Histogram* render_histogram(NULL); | 295 Histogram* render_histogram(NULL); |
296 | 296 |
297 if (histogram_type == HISTOGRAM) { | 297 if (histogram_type == HISTOGRAM) { |
298 render_histogram = Histogram::FactoryGet( | 298 render_histogram = Histogram::FactoryGet( |
299 histogram_name, declared_min, declared_max, bucket_count, flags); | 299 histogram_name, declared_min, declared_max, bucket_count, flags); |
300 } else if (histogram_type == LINEAR_HISTOGRAM) { | 300 } else if (histogram_type == LINEAR_HISTOGRAM) { |
301 render_histogram = LinearHistogram::FactoryGet( | 301 render_histogram = LinearHistogram::FactoryGet( |
302 histogram_name, declared_min, declared_max, bucket_count, flags); | 302 histogram_name, declared_min, declared_max, bucket_count, flags); |
303 } else if (histogram_type == BOOLEAN_HISTOGRAM) { | 303 } else if (histogram_type == BOOLEAN_HISTOGRAM) { |
304 render_histogram = BooleanHistogram::FactoryGet(histogram_name, flags); | 304 render_histogram = BooleanHistogram::FactoryGet(histogram_name, flags); |
305 } else if (histogram_type == CUSTOM_HISTOGRAM) { | 305 } else if (histogram_type == CUSTOM_HISTOGRAM) { |
306 std::vector<Histogram::Sample> sample_ranges(bucket_count); | 306 std::vector<Histogram::Sample> sample_ranges(bucket_count); |
307 if (!CustomHistogram::DeserializeRanges(&iter, pickle, &sample_ranges)) { | 307 if (!CustomHistogram::DeserializeRanges(&iter, &sample_ranges)) { |
308 DLOG(ERROR) << "Pickle error decoding ranges: " << histogram_name; | 308 DLOG(ERROR) << "Pickle error decoding ranges: " << histogram_name; |
309 return false; | 309 return false; |
310 } | 310 } |
311 render_histogram = | 311 render_histogram = |
312 CustomHistogram::FactoryGet(histogram_name, sample_ranges, flags); | 312 CustomHistogram::FactoryGet(histogram_name, sample_ranges, flags); |
313 } else { | 313 } else { |
314 DLOG(ERROR) << "Error Deserializing Histogram Unknown histogram_type: " | 314 DLOG(ERROR) << "Error Deserializing Histogram Unknown histogram_type: " |
315 << histogram_type; | 315 << histogram_type; |
316 return false; | 316 return false; |
317 } | 317 } |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
765 pickle->WriteInt64(redundant_count_); | 765 pickle->WriteInt64(redundant_count_); |
766 pickle->WriteSize(counts_.size()); | 766 pickle->WriteSize(counts_.size()); |
767 | 767 |
768 for (size_t index = 0; index < counts_.size(); ++index) { | 768 for (size_t index = 0; index < counts_.size(); ++index) { |
769 pickle->WriteInt(counts_[index]); | 769 pickle->WriteInt(counts_[index]); |
770 } | 770 } |
771 | 771 |
772 return true; | 772 return true; |
773 } | 773 } |
774 | 774 |
775 bool Histogram::SampleSet::Deserialize(void** iter, const Pickle& pickle) { | 775 bool Histogram::SampleSet::Deserialize(PickleIterator* iter) { |
776 DCHECK_EQ(counts_.size(), 0u); | 776 DCHECK_EQ(counts_.size(), 0u); |
777 DCHECK_EQ(sum_, 0); | 777 DCHECK_EQ(sum_, 0); |
778 DCHECK_EQ(redundant_count_, 0); | 778 DCHECK_EQ(redundant_count_, 0); |
779 | 779 |
780 size_t counts_size; | 780 size_t counts_size; |
781 | 781 |
782 if (!pickle.ReadInt64(iter, &sum_) || | 782 if (!iter->ReadInt64(&sum_) || |
783 !pickle.ReadInt64(iter, &redundant_count_) || | 783 !iter->ReadInt64(&redundant_count_) || |
784 !pickle.ReadSize(iter, &counts_size)) { | 784 !iter->ReadSize(&counts_size)) { |
785 return false; | 785 return false; |
786 } | 786 } |
787 | 787 |
788 if (counts_size == 0) | 788 if (counts_size == 0) |
789 return false; | 789 return false; |
790 | 790 |
791 int count = 0; | 791 int count = 0; |
792 for (size_t index = 0; index < counts_size; ++index) { | 792 for (size_t index = 0; index < counts_size; ++index) { |
793 int i; | 793 int i; |
794 if (!pickle.ReadInt(iter, &i)) | 794 if (!iter->ReadInt(&i)) |
795 return false; | 795 return false; |
796 counts_.push_back(i); | 796 counts_.push_back(i); |
797 count += i; | 797 count += i; |
798 } | 798 } |
799 DCHECK_EQ(count, redundant_count_); | 799 DCHECK_EQ(count, redundant_count_); |
800 return count == redundant_count_; | 800 return count == redundant_count_; |
801 } | 801 } |
802 | 802 |
803 //------------------------------------------------------------------------------ | 803 //------------------------------------------------------------------------------ |
804 // LinearHistogram: This histogram uses a traditional set of evenly spaced | 804 // LinearHistogram: This histogram uses a traditional set of evenly spaced |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1008 bool CustomHistogram::SerializeRanges(Pickle* pickle) const { | 1008 bool CustomHistogram::SerializeRanges(Pickle* pickle) const { |
1009 for (size_t i = 0; i < cached_ranges()->size(); ++i) { | 1009 for (size_t i = 0; i < cached_ranges()->size(); ++i) { |
1010 if (!pickle->WriteInt(cached_ranges()->ranges(i))) | 1010 if (!pickle->WriteInt(cached_ranges()->ranges(i))) |
1011 return false; | 1011 return false; |
1012 } | 1012 } |
1013 return true; | 1013 return true; |
1014 } | 1014 } |
1015 | 1015 |
1016 // static | 1016 // static |
1017 bool CustomHistogram::DeserializeRanges( | 1017 bool CustomHistogram::DeserializeRanges( |
1018 void** iter, const Pickle& pickle, std::vector<Histogram::Sample>* ranges) { | 1018 PickleIterator* iter, std::vector<Histogram::Sample>* ranges) { |
1019 for (size_t i = 0; i < ranges->size(); ++i) { | 1019 for (size_t i = 0; i < ranges->size(); ++i) { |
1020 if (!pickle.ReadInt(iter, &(*ranges)[i])) | 1020 if (!iter->ReadInt(&(*ranges)[i])) |
1021 return false; | 1021 return false; |
1022 } | 1022 } |
1023 return true; | 1023 return true; |
1024 } | 1024 } |
1025 | 1025 |
1026 void CustomHistogram::InitializedCustomBucketRange( | 1026 void CustomHistogram::InitializedCustomBucketRange( |
1027 const std::vector<Sample>& custom_ranges) { | 1027 const std::vector<Sample>& custom_ranges) { |
1028 DCHECK_GT(custom_ranges.size(), 1u); | 1028 DCHECK_GT(custom_ranges.size(), 1u); |
1029 DCHECK_EQ(custom_ranges[0], 0); | 1029 DCHECK_EQ(custom_ranges[0], 0); |
1030 DCHECK_LE(custom_ranges.size(), bucket_count()); | 1030 DCHECK_LE(custom_ranges.size(), bucket_count()); |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1324 | 1324 |
1325 // static | 1325 // static |
1326 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; | 1326 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; |
1327 // static | 1327 // static |
1328 StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = NULL; | 1328 StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = NULL; |
1329 // static | 1329 // static |
1330 base::Lock* StatisticsRecorder::lock_ = NULL; | 1330 base::Lock* StatisticsRecorder::lock_ = NULL; |
1331 // static | 1331 // static |
1332 bool StatisticsRecorder::dump_on_exit_ = false; | 1332 bool StatisticsRecorder::dump_on_exit_ = false; |
1333 } // namespace base | 1333 } // namespace base |
OLD | NEW |