OLD | NEW |
---|---|
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/sparse_histogram.h" | 5 #include "base/metrics/sparse_histogram.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/metrics/histogram_base.h" | 10 #include "base/metrics/histogram_base.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
55 EXPECT_EQ(1, snapshot1->GetCount(100)); | 55 EXPECT_EQ(1, snapshot1->GetCount(100)); |
56 | 56 |
57 histogram->Add(100); | 57 histogram->Add(100); |
58 histogram->Add(101); | 58 histogram->Add(101); |
59 scoped_ptr<HistogramSamples> snapshot2(histogram->SnapshotSamples()); | 59 scoped_ptr<HistogramSamples> snapshot2(histogram->SnapshotSamples()); |
60 EXPECT_EQ(3, snapshot2->TotalCount()); | 60 EXPECT_EQ(3, snapshot2->TotalCount()); |
61 EXPECT_EQ(2, snapshot2->GetCount(100)); | 61 EXPECT_EQ(2, snapshot2->GetCount(100)); |
62 EXPECT_EQ(1, snapshot2->GetCount(101)); | 62 EXPECT_EQ(1, snapshot2->GetCount(101)); |
63 } | 63 } |
64 | 64 |
65 TEST_F(SparseHistogramTest, BasicTestMultiAdd) { | |
66 scoped_ptr<SparseHistogram> histogram(NewSparseHistogram("Sparse")); | |
67 scoped_ptr<HistogramSamples> snapshot(histogram->SnapshotSamples()); | |
68 EXPECT_EQ(0, snapshot->TotalCount()); | |
69 EXPECT_EQ(0, snapshot->sum()); | |
70 | |
71 histogram->MultiAdd(100, 15); | |
72 scoped_ptr<HistogramSamples> snapshot1(histogram->SnapshotSamples()); | |
73 EXPECT_EQ(15, snapshot1->TotalCount()); | |
74 EXPECT_EQ(15, snapshot1->GetCount(100)); | |
75 | |
76 histogram->MultiAdd(100, 15); | |
77 histogram->MultiAdd(101, 25); | |
78 scoped_ptr<HistogramSamples> snapshot2(histogram->SnapshotSamples()); | |
79 EXPECT_EQ(55, snapshot2->TotalCount()); | |
80 EXPECT_EQ(30, snapshot2->GetCount(100)); | |
81 EXPECT_EQ(25, snapshot2->GetCount(101)); | |
82 } | |
83 | |
84 | |
Alexei Svitkine (slow)
2015/07/31 15:39:27
Remove extra blank lines.
amohammadkhan
2015/08/03 17:30:43
Done.
| |
85 | |
65 TEST_F(SparseHistogramTest, MacroBasicTest) { | 86 TEST_F(SparseHistogramTest, MacroBasicTest) { |
66 UMA_HISTOGRAM_SPARSE_SLOWLY("Sparse", 100); | 87 UMA_HISTOGRAM_SPARSE_SLOWLY("Sparse", 100); |
67 UMA_HISTOGRAM_SPARSE_SLOWLY("Sparse", 200); | 88 UMA_HISTOGRAM_SPARSE_SLOWLY("Sparse", 200); |
68 UMA_HISTOGRAM_SPARSE_SLOWLY("Sparse", 100); | 89 UMA_HISTOGRAM_SPARSE_SLOWLY("Sparse", 100); |
69 | 90 |
70 StatisticsRecorder::Histograms histograms; | 91 StatisticsRecorder::Histograms histograms; |
71 StatisticsRecorder::GetHistograms(&histograms); | 92 StatisticsRecorder::GetHistograms(&histograms); |
72 | 93 |
73 ASSERT_EQ(1U, histograms.size()); | 94 ASSERT_EQ(1U, histograms.size()); |
74 HistogramBase* sparse_histogram = histograms[0]; | 95 HistogramBase* sparse_histogram = histograms[0]; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
121 | 142 |
122 int flag; | 143 int flag; |
123 EXPECT_TRUE(iter.ReadInt(&flag)); | 144 EXPECT_TRUE(iter.ReadInt(&flag)); |
124 EXPECT_EQ(HistogramBase::kIPCSerializationSourceFlag, flag); | 145 EXPECT_EQ(HistogramBase::kIPCSerializationSourceFlag, flag); |
125 | 146 |
126 // No more data in the pickle. | 147 // No more data in the pickle. |
127 EXPECT_FALSE(iter.SkipBytes(1)); | 148 EXPECT_FALSE(iter.SkipBytes(1)); |
128 } | 149 } |
129 | 150 |
130 } // namespace base | 151 } // namespace base |
OLD | NEW |