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

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

Issue 601563003: Add Read/WriteSizeT() functions to the pickle layer, plus one consumer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix test failure Created 6 years, 2 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
« no previous file with comments | « no previous file | base/pickle.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // 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 19 matching lines...) Expand all
30 30
31 namespace base { 31 namespace base {
32 32
33 namespace { 33 namespace {
34 34
35 bool ReadHistogramArguments(PickleIterator* iter, 35 bool ReadHistogramArguments(PickleIterator* iter,
36 string* histogram_name, 36 string* histogram_name,
37 int* flags, 37 int* flags,
38 int* declared_min, 38 int* declared_min,
39 int* declared_max, 39 int* declared_max,
40 uint64* bucket_count, 40 size_t* bucket_count,
41 uint32* range_checksum) { 41 uint32* range_checksum) {
42 if (!iter->ReadString(histogram_name) || 42 if (!iter->ReadString(histogram_name) ||
43 !iter->ReadInt(flags) || 43 !iter->ReadInt(flags) ||
44 !iter->ReadInt(declared_min) || 44 !iter->ReadInt(declared_min) ||
45 !iter->ReadInt(declared_max) || 45 !iter->ReadInt(declared_max) ||
46 !iter->ReadUInt64(bucket_count) || 46 !iter->ReadSizeT(bucket_count) ||
47 !iter->ReadUInt32(range_checksum)) { 47 !iter->ReadUInt32(range_checksum)) {
48 DLOG(ERROR) << "Pickle error decoding Histogram: " << *histogram_name; 48 DLOG(ERROR) << "Pickle error decoding Histogram: " << *histogram_name;
49 return false; 49 return false;
50 } 50 }
51 51
52 // Since these fields may have come from an untrusted renderer, do additional 52 // Since these fields may have come from an untrusted renderer, do additional
53 // checks above and beyond those in Histogram::Initialize() 53 // checks above and beyond those in Histogram::Initialize()
54 if (*declared_max <= 0 || 54 if (*declared_max <= 0 ||
55 *declared_min <= 0 || 55 *declared_min <= 0 ||
56 *declared_max < *declared_min || 56 *declared_max < *declared_min ||
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 void Histogram::WriteAscii(string* output) const { 289 void Histogram::WriteAscii(string* output) const {
290 WriteAsciiImpl(true, "\n", output); 290 WriteAsciiImpl(true, "\n", output);
291 } 291 }
292 292
293 bool Histogram::SerializeInfoImpl(Pickle* pickle) const { 293 bool Histogram::SerializeInfoImpl(Pickle* pickle) const {
294 DCHECK(bucket_ranges()->HasValidChecksum()); 294 DCHECK(bucket_ranges()->HasValidChecksum());
295 return pickle->WriteString(histogram_name()) && 295 return pickle->WriteString(histogram_name()) &&
296 pickle->WriteInt(flags()) && 296 pickle->WriteInt(flags()) &&
297 pickle->WriteInt(declared_min()) && 297 pickle->WriteInt(declared_min()) &&
298 pickle->WriteInt(declared_max()) && 298 pickle->WriteInt(declared_max()) &&
299 pickle->WriteUInt64(bucket_count()) && 299 pickle->WriteSizeT(bucket_count()) &&
300 pickle->WriteUInt32(bucket_ranges()->checksum()); 300 pickle->WriteUInt32(bucket_ranges()->checksum());
301 } 301 }
302 302
303 Histogram::Histogram(const string& name, 303 Histogram::Histogram(const string& name,
304 Sample minimum, 304 Sample minimum,
305 Sample maximum, 305 Sample maximum,
306 const BucketRanges* ranges) 306 const BucketRanges* ranges)
307 : HistogramBase(name), 307 : HistogramBase(name),
308 bucket_ranges_(ranges), 308 bucket_ranges_(ranges),
309 declared_min_(minimum), 309 declared_min_(minimum),
(...skipping 29 matching lines...) Expand all
339 339
340 //------------------------------------------------------------------------------ 340 //------------------------------------------------------------------------------
341 // Private methods 341 // Private methods
342 342
343 // static 343 // static
344 HistogramBase* Histogram::DeserializeInfoImpl(PickleIterator* iter) { 344 HistogramBase* Histogram::DeserializeInfoImpl(PickleIterator* iter) {
345 string histogram_name; 345 string histogram_name;
346 int flags; 346 int flags;
347 int declared_min; 347 int declared_min;
348 int declared_max; 348 int declared_max;
349 uint64 bucket_count; 349 size_t bucket_count;
350 uint32 range_checksum; 350 uint32 range_checksum;
351 351
352 if (!ReadHistogramArguments(iter, &histogram_name, &flags, &declared_min, 352 if (!ReadHistogramArguments(iter, &histogram_name, &flags, &declared_min,
353 &declared_max, &bucket_count, &range_checksum)) { 353 &declared_max, &bucket_count, &range_checksum)) {
354 return NULL; 354 return NULL;
355 } 355 }
356 356
357 // Find or create the local version of the histogram in this process. 357 // Find or create the local version of the histogram in this process.
358 HistogramBase* histogram = Histogram::FactoryGet( 358 HistogramBase* histogram = Histogram::FactoryGet(
359 histogram_name, declared_min, declared_max, bucket_count, flags); 359 histogram_name, declared_min, declared_max, bucket_count, flags);
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 ranges->set_range(ranges->bucket_count(), HistogramBase::kSampleType_MAX); 627 ranges->set_range(ranges->bucket_count(), HistogramBase::kSampleType_MAX);
628 ranges->ResetChecksum(); 628 ranges->ResetChecksum();
629 } 629 }
630 630
631 // static 631 // static
632 HistogramBase* LinearHistogram::DeserializeInfoImpl(PickleIterator* iter) { 632 HistogramBase* LinearHistogram::DeserializeInfoImpl(PickleIterator* iter) {
633 string histogram_name; 633 string histogram_name;
634 int flags; 634 int flags;
635 int declared_min; 635 int declared_min;
636 int declared_max; 636 int declared_max;
637 uint64 bucket_count; 637 size_t bucket_count;
638 uint32 range_checksum; 638 uint32 range_checksum;
639 639
640 if (!ReadHistogramArguments(iter, &histogram_name, &flags, &declared_min, 640 if (!ReadHistogramArguments(iter, &histogram_name, &flags, &declared_min,
641 &declared_max, &bucket_count, &range_checksum)) { 641 &declared_max, &bucket_count, &range_checksum)) {
642 return NULL; 642 return NULL;
643 } 643 }
644 644
645 HistogramBase* histogram = LinearHistogram::FactoryGet( 645 HistogramBase* histogram = LinearHistogram::FactoryGet(
646 histogram_name, declared_min, declared_max, bucket_count, flags); 646 histogram_name, declared_min, declared_max, bucket_count, flags);
647 if (!ValidateRangeChecksum(*histogram, range_checksum)) { 647 if (!ValidateRangeChecksum(*histogram, range_checksum)) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 682
683 BooleanHistogram::BooleanHistogram(const string& name, 683 BooleanHistogram::BooleanHistogram(const string& name,
684 const BucketRanges* ranges) 684 const BucketRanges* ranges)
685 : LinearHistogram(name, 1, 2, ranges) {} 685 : LinearHistogram(name, 1, 2, ranges) {}
686 686
687 HistogramBase* BooleanHistogram::DeserializeInfoImpl(PickleIterator* iter) { 687 HistogramBase* BooleanHistogram::DeserializeInfoImpl(PickleIterator* iter) {
688 string histogram_name; 688 string histogram_name;
689 int flags; 689 int flags;
690 int declared_min; 690 int declared_min;
691 int declared_max; 691 int declared_max;
692 uint64 bucket_count; 692 size_t bucket_count;
693 uint32 range_checksum; 693 uint32 range_checksum;
694 694
695 if (!ReadHistogramArguments(iter, &histogram_name, &flags, &declared_min, 695 if (!ReadHistogramArguments(iter, &histogram_name, &flags, &declared_min,
696 &declared_max, &bucket_count, &range_checksum)) { 696 &declared_max, &bucket_count, &range_checksum)) {
697 return NULL; 697 return NULL;
698 } 698 }
699 699
700 HistogramBase* histogram = BooleanHistogram::FactoryGet( 700 HistogramBase* histogram = BooleanHistogram::FactoryGet(
701 histogram_name, flags); 701 histogram_name, flags);
702 if (!ValidateRangeChecksum(*histogram, range_checksum)) { 702 if (!ValidateRangeChecksum(*histogram, range_checksum)) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 double CustomHistogram::GetBucketSize(Count current, size_t i) const { 777 double CustomHistogram::GetBucketSize(Count current, size_t i) const {
778 return 1; 778 return 1;
779 } 779 }
780 780
781 // static 781 // static
782 HistogramBase* CustomHistogram::DeserializeInfoImpl(PickleIterator* iter) { 782 HistogramBase* CustomHistogram::DeserializeInfoImpl(PickleIterator* iter) {
783 string histogram_name; 783 string histogram_name;
784 int flags; 784 int flags;
785 int declared_min; 785 int declared_min;
786 int declared_max; 786 int declared_max;
787 uint64 bucket_count; 787 size_t bucket_count;
788 uint32 range_checksum; 788 uint32 range_checksum;
789 789
790 if (!ReadHistogramArguments(iter, &histogram_name, &flags, &declared_min, 790 if (!ReadHistogramArguments(iter, &histogram_name, &flags, &declared_min,
791 &declared_max, &bucket_count, &range_checksum)) { 791 &declared_max, &bucket_count, &range_checksum)) {
792 return NULL; 792 return NULL;
793 } 793 }
794 794
795 // First and last ranges are not serialized. 795 // First and last ranges are not serialized.
796 vector<Sample> sample_ranges(bucket_count - 1); 796 vector<Sample> sample_ranges(bucket_count - 1);
797 797
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 835
836 BucketRanges* bucket_ranges = new BucketRanges(ranges.size()); 836 BucketRanges* bucket_ranges = new BucketRanges(ranges.size());
837 for (size_t i = 0; i < ranges.size(); i++) { 837 for (size_t i = 0; i < ranges.size(); i++) {
838 bucket_ranges->set_range(i, ranges[i]); 838 bucket_ranges->set_range(i, ranges[i]);
839 } 839 }
840 bucket_ranges->ResetChecksum(); 840 bucket_ranges->ResetChecksum();
841 return bucket_ranges; 841 return bucket_ranges;
842 } 842 }
843 843
844 } // namespace base 844 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/pickle.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698