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

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

Issue 10823137: 1. Add test for https://src.chromium.org/viewvc/chrome?view=rev&revision=149541 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | base/metrics/histogram_unittest.cc » ('j') | base/metrics/histogram_unittest.cc » ('J')
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 865 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 return true; 876 return true;
877 } 877 }
878 878
879 double CustomHistogram::GetBucketSize(Count current, size_t i) const { 879 double CustomHistogram::GetBucketSize(Count current, size_t i) const {
880 return 1; 880 return 1;
881 } 881 }
882 882
883 // static 883 // static
884 bool CustomHistogram::ValidateCustomRanges( 884 bool CustomHistogram::ValidateCustomRanges(
885 const vector<Sample>& custom_ranges) { 885 const vector<Sample>& custom_ranges) {
886 if (custom_ranges.size() < 1) 886 int valid_ranges = 0;
jar (doing other things) 2012/08/03 21:53:42 Suggest use boolean: bool valid_ranges = false; t
kaiwang 2012/08/03 22:15:53 Done.
887 return false;
888 for (size_t i = 0; i < custom_ranges.size(); i++) { 887 for (size_t i = 0; i < custom_ranges.size(); i++) {
889 Sample s = custom_ranges[i]; 888 Sample s = custom_ranges[i];
jar (doing other things) 2012/08/03 21:53:42 nit: (on existing code): Please use |sample| inste
kaiwang 2012/08/03 22:15:53 Done.
890 if (s < 0 || s > HistogramBase::kSampleType_MAX - 1) 889 if (s < 0 || s > HistogramBase::kSampleType_MAX - 1)
891 return false; 890 return false;
891 if (s != 0)
892 valid_ranges++;
892 } 893 }
893 return true; 894 return valid_ranges > 0;
894 } 895 }
895 896
896 // static 897 // static
897 BucketRanges* CustomHistogram::CreateBucketRangesFromCustomRanges( 898 BucketRanges* CustomHistogram::CreateBucketRangesFromCustomRanges(
898 const vector<Sample>& custom_ranges) { 899 const vector<Sample>& custom_ranges) {
899 // Remove the duplicates in the custom ranges array. 900 // Remove the duplicates in the custom ranges array.
900 vector<int> ranges = custom_ranges; 901 vector<int> ranges = custom_ranges;
901 ranges.push_back(0); // Ensure we have a zero value. 902 ranges.push_back(0); // Ensure we have a zero value.
902 ranges.push_back(HistogramBase::kSampleType_MAX); 903 ranges.push_back(HistogramBase::kSampleType_MAX);
903 std::sort(ranges.begin(), ranges.end()); 904 std::sort(ranges.begin(), ranges.end());
904 ranges.erase(std::unique(ranges.begin(), ranges.end()), ranges.end()); 905 ranges.erase(std::unique(ranges.begin(), ranges.end()), ranges.end());
905 906
906 BucketRanges* bucket_ranges = new BucketRanges(ranges.size()); 907 BucketRanges* bucket_ranges = new BucketRanges(ranges.size());
907 for (size_t i = 0; i < ranges.size(); i++) { 908 for (size_t i = 0; i < ranges.size(); i++) {
908 bucket_ranges->set_range(i, ranges[i]); 909 bucket_ranges->set_range(i, ranges[i]);
909 } 910 }
910 bucket_ranges->ResetChecksum(); 911 bucket_ranges->ResetChecksum();
911 return bucket_ranges; 912 return bucket_ranges;
912 } 913 }
913 914
914 } // namespace base 915 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/metrics/histogram_unittest.cc » ('j') | base/metrics/histogram_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698