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

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

Issue 794493002: Add UMA Histogram Manager to Cronet. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
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 "components/metrics/metrics_log.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace metrics {
16
17 TEST_F(HistogramEncoderTest, HistogramBucketFields) {
18 // Create buckets: 1-5, 5-7, 7-8, 8-9, 9-10, 10-11, 11-12.
19 base::BucketRanges ranges(8);
20 ranges.set_range(0, 1);
21 ranges.set_range(1, 5);
22 ranges.set_range(2, 7);
23 ranges.set_range(3, 8);
24 ranges.set_range(4, 9);
25 ranges.set_range(5, 10);
26 ranges.set_range(6, 11);
27 ranges.set_range(7, 12);
28
29 base::SampleVector samples(&ranges);
30 samples.Accumulate(3, 1); // Bucket 1-5.
31 samples.Accumulate(6, 1); // Bucket 5-7.
32 samples.Accumulate(8, 1); // Bucket 8-9. (7-8 skipped)
33 samples.Accumulate(10, 1); // Bucket 10-11. (9-10 skipped)
34 samples.Accumulate(11, 1); // Bucket 11-12.
35
36 TestMetricsServiceClient client;
37 TestingPrefServiceSimple prefs;
38 MetricsLog log("totally bogus client ID", 137, MetricsLog::ONGOING_LOG,
39 &client, &prefs);
40 ChromeUserMetricsExtension* uma_proto = log.uma_proto();
41 RecordHistogramDelta(uma_proto, "Test", samples);
42
43 const HistogramEventProto& histogram_proto =
44 uma_proto->histogram_event(uma_proto->histogram_event_size() - 1);
45
46 // Buckets with samples: 1-5, 5-7, 8-9, 10-11, 11-12.
47 // Should become: 1-/, 5-7, /-9, 10-/, /-12.
48 ASSERT_EQ(5, histogram_proto.bucket_size());
49
50 // 1-5 becomes 1-/ (max is same as next min).
51 EXPECT_TRUE(histogram_proto.bucket(0).has_min());
52 EXPECT_FALSE(histogram_proto.bucket(0).has_max());
53 EXPECT_EQ(1, histogram_proto.bucket(0).min());
54
55 // 5-7 stays 5-7 (no optimization possible).
56 EXPECT_TRUE(histogram_proto.bucket(1).has_min());
57 EXPECT_TRUE(histogram_proto.bucket(1).has_max());
58 EXPECT_EQ(5, histogram_proto.bucket(1).min());
59 EXPECT_EQ(7, histogram_proto.bucket(1).max());
60
61 // 8-9 becomes /-9 (min is same as max - 1).
62 EXPECT_FALSE(histogram_proto.bucket(2).has_min());
63 EXPECT_TRUE(histogram_proto.bucket(2).has_max());
64 EXPECT_EQ(9, histogram_proto.bucket(2).max());
65
66 // 10-11 becomes 10-/ (both optimizations apply, omit max is prioritized).
67 EXPECT_TRUE(histogram_proto.bucket(3).has_min());
68 EXPECT_FALSE(histogram_proto.bucket(3).has_max());
69 EXPECT_EQ(10, histogram_proto.bucket(3).min());
70
71 // 11-12 becomes /-12 (last record must keep max, min is same as max - 1).
72 EXPECT_FALSE(histogram_proto.bucket(4).has_min());
73 EXPECT_TRUE(histogram_proto.bucket(4).has_max());
74 EXPECT_EQ(12, histogram_proto.bucket(4).max());
75 }
76
77 } // namespace metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698