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

Side by Side Diff: base/metrics/sparse_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/sparse_histogram.cc ('k') | no next file » | 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/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
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, BasicTestAddCount) {
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->AddCount(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->AddCount(100, 15);
77 histogram->AddCount(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
65 TEST_F(SparseHistogramTest, MacroBasicTest) { 84 TEST_F(SparseHistogramTest, MacroBasicTest) {
66 UMA_HISTOGRAM_SPARSE_SLOWLY("Sparse", 100); 85 UMA_HISTOGRAM_SPARSE_SLOWLY("Sparse", 100);
67 UMA_HISTOGRAM_SPARSE_SLOWLY("Sparse", 200); 86 UMA_HISTOGRAM_SPARSE_SLOWLY("Sparse", 200);
68 UMA_HISTOGRAM_SPARSE_SLOWLY("Sparse", 100); 87 UMA_HISTOGRAM_SPARSE_SLOWLY("Sparse", 100);
69 88
70 StatisticsRecorder::Histograms histograms; 89 StatisticsRecorder::Histograms histograms;
71 StatisticsRecorder::GetHistograms(&histograms); 90 StatisticsRecorder::GetHistograms(&histograms);
72 91
73 ASSERT_EQ(1U, histograms.size()); 92 ASSERT_EQ(1U, histograms.size());
74 HistogramBase* sparse_histogram = histograms[0]; 93 HistogramBase* sparse_histogram = histograms[0];
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 140
122 int flag; 141 int flag;
123 EXPECT_TRUE(iter.ReadInt(&flag)); 142 EXPECT_TRUE(iter.ReadInt(&flag));
124 EXPECT_EQ(HistogramBase::kIPCSerializationSourceFlag, flag); 143 EXPECT_EQ(HistogramBase::kIPCSerializationSourceFlag, flag);
125 144
126 // No more data in the pickle. 145 // No more data in the pickle.
127 EXPECT_FALSE(iter.SkipBytes(1)); 146 EXPECT_FALSE(iter.SkipBytes(1));
128 } 147 }
129 148
130 } // namespace base 149 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/sparse_histogram.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698