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

Side by Side Diff: components/metrics/histogram_encoder_unittest.cc

Issue 769873003: Add UMA Histogram Manager to Cronet. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Build Raman's CL. Created 6 years 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 | « components/metrics/histogram_encoder.cc ('k') | components/metrics/metrics_log.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/metrics/histogram_encoder.h"
6
7 #include <string>
8
9 #include "base/basictypes.h"
10 #include "base/metrics/bucket_ranges.h"
11 #include "base/metrics/sample_vector.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 namespace metrics {
15
16 namespace {
17
18 class HistogramEncoderTest : public testing::Test {
19 public:
20 HistogramEncoderTest() {}
21
22 private:
23 DISALLOW_COPY_AND_ASSIGN(HistogramEncoderTest);
24 };
25
26 } // namespace
27
28 TEST_F(HistogramEncoderTest, HistogramBucketFields) {
29 // Create buckets: 1-5, 5-7, 7-8, 8-9, 9-10, 10-11, 11-12.
30 base::BucketRanges ranges(8);
31 ranges.set_range(0, 1);
32 ranges.set_range(1, 5);
33 ranges.set_range(2, 7);
34 ranges.set_range(3, 8);
35 ranges.set_range(4, 9);
36 ranges.set_range(5, 10);
37 ranges.set_range(6, 11);
38 ranges.set_range(7, 12);
39
40 base::SampleVector samples(&ranges);
41 samples.Accumulate(3, 1); // Bucket 1-5.
42 samples.Accumulate(6, 1); // Bucket 5-7.
43 samples.Accumulate(8, 1); // Bucket 8-9. (7-8 skipped)
44 samples.Accumulate(10, 1); // Bucket 10-11. (9-10 skipped)
45 samples.Accumulate(11, 1); // Bucket 11-12.
46
47 ChromeUserMetricsExtension uma_proto;
48 RecordHistogramDelta("Test", samples, &uma_proto);
49
50 const HistogramEventProto& histogram_proto =
51 uma_proto.histogram_event(uma_proto.histogram_event_size() - 1);
52
53 // Buckets with samples: 1-5, 5-7, 8-9, 10-11, 11-12.
54 // Should become: 1-/, 5-7, /-9, 10-/, /-12.
55 ASSERT_EQ(5, histogram_proto.bucket_size());
56
57 // 1-5 becomes 1-/ (max is same as next min).
58 EXPECT_TRUE(histogram_proto.bucket(0).has_min());
59 EXPECT_FALSE(histogram_proto.bucket(0).has_max());
60 EXPECT_EQ(1, histogram_proto.bucket(0).min());
61
62 // 5-7 stays 5-7 (no optimization possible).
63 EXPECT_TRUE(histogram_proto.bucket(1).has_min());
64 EXPECT_TRUE(histogram_proto.bucket(1).has_max());
65 EXPECT_EQ(5, histogram_proto.bucket(1).min());
66 EXPECT_EQ(7, histogram_proto.bucket(1).max());
67
68 // 8-9 becomes /-9 (min is same as max - 1).
69 EXPECT_FALSE(histogram_proto.bucket(2).has_min());
70 EXPECT_TRUE(histogram_proto.bucket(2).has_max());
71 EXPECT_EQ(9, histogram_proto.bucket(2).max());
72
73 // 10-11 becomes 10-/ (both optimizations apply, omit max is prioritized).
74 EXPECT_TRUE(histogram_proto.bucket(3).has_min());
75 EXPECT_FALSE(histogram_proto.bucket(3).has_max());
76 EXPECT_EQ(10, histogram_proto.bucket(3).min());
77
78 // 11-12 becomes /-12 (last record must keep max, min is same as max - 1).
79 EXPECT_FALSE(histogram_proto.bucket(4).has_min());
80 EXPECT_TRUE(histogram_proto.bucket(4).has_max());
81 EXPECT_EQ(12, histogram_proto.bucket(4).max());
82 }
83
84 } // namespace metrics
OLDNEW
« no previous file with comments | « components/metrics/histogram_encoder.cc ('k') | components/metrics/metrics_log.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698