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

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

Issue 1256363002: Add support to increase a UMA histogram bucket by an aribitrary integer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: After rebase-update Created 5 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
« no previous file with comments | « base/metrics/histogram_base.h ('k') | base/metrics/sparse_histogram.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 #include "base/metrics/histogram.h" 5 #include "base/metrics/histogram.h"
6 6
7 #include <climits> 7 #include <climits>
8 #include <algorithm> 8 #include <algorithm>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 Histogram* histogram = static_cast<Histogram*>( 224 Histogram* histogram = static_cast<Histogram*>(
225 CustomHistogram::FactoryGet("2BucketsCustomHistogram", custom_ranges, 225 CustomHistogram::FactoryGet("2BucketsCustomHistogram", custom_ranges,
226 HistogramBase::kNoFlags)); 226 HistogramBase::kNoFlags));
227 const BucketRanges* ranges = histogram->bucket_ranges(); 227 const BucketRanges* ranges = histogram->bucket_ranges();
228 ASSERT_EQ(3u, ranges->size()); 228 ASSERT_EQ(3u, ranges->size());
229 EXPECT_EQ(0, ranges->range(0)); 229 EXPECT_EQ(0, ranges->range(0));
230 EXPECT_EQ(4, ranges->range(1)); 230 EXPECT_EQ(4, ranges->range(1));
231 EXPECT_EQ(HistogramBase::kSampleType_MAX, ranges->range(2)); 231 EXPECT_EQ(HistogramBase::kSampleType_MAX, ranges->range(2));
232 } 232 }
233 233
234 // Test the AddCount function.
235 TEST_F(HistogramTest, AddCountTest) {
236 const size_t kBucketCount = 50;
237 Histogram* histogram = static_cast<Histogram*>(
238 Histogram::FactoryGet("AddCountHistogram", 10, 100, kBucketCount,
239 HistogramBase::kNoFlags));
240
241 histogram->AddCount(20, 15);
242 histogram->AddCount(30, 14);
243
244 scoped_ptr<SampleVector> samples = histogram->SnapshotSampleVector();
245 EXPECT_EQ(29, samples->TotalCount());
246 EXPECT_EQ(15, samples->GetCount(20));
247 EXPECT_EQ(14, samples->GetCount(30));
248
249 histogram->AddCount(20, 25);
250 histogram->AddCount(30, 24);
251
252 scoped_ptr<SampleVector> samples2 = histogram->SnapshotSampleVector();
253 EXPECT_EQ(78, samples2->TotalCount());
254 EXPECT_EQ(40, samples2->GetCount(20));
255 EXPECT_EQ(38, samples2->GetCount(30));
256 }
257
234 // Make sure histogram handles out-of-bounds data gracefully. 258 // Make sure histogram handles out-of-bounds data gracefully.
235 TEST_F(HistogramTest, BoundsTest) { 259 TEST_F(HistogramTest, BoundsTest) {
236 const size_t kBucketCount = 50; 260 const size_t kBucketCount = 50;
237 Histogram* histogram = static_cast<Histogram*>( 261 Histogram* histogram = static_cast<Histogram*>(
238 Histogram::FactoryGet("Bounded", 10, 100, kBucketCount, 262 Histogram::FactoryGet("Bounded", 10, 100, kBucketCount,
239 HistogramBase::kNoFlags)); 263 HistogramBase::kNoFlags));
240 264
241 // Put two samples "out of bounds" above and below. 265 // Put two samples "out of bounds" above and below.
242 histogram->Add(5); 266 histogram->Add(5);
243 histogram->Add(-50); 267 histogram->Add(-50);
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 // CustomHistogram needs at least 1 valid range. 527 // CustomHistogram needs at least 1 valid range.
504 custom_ranges.clear(); 528 custom_ranges.clear();
505 custom_ranges.push_back(0); 529 custom_ranges.push_back(0);
506 EXPECT_DEATH(CustomHistogram::FactoryGet("BadRangesCustom3", custom_ranges, 530 EXPECT_DEATH(CustomHistogram::FactoryGet("BadRangesCustom3", custom_ranges,
507 HistogramBase::kNoFlags), 531 HistogramBase::kNoFlags),
508 ""); 532 "");
509 } 533 }
510 #endif 534 #endif
511 535
512 } // namespace base 536 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/histogram_base.h ('k') | base/metrics/sparse_histogram.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698