| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/metrics/histogram_base.h" | 8 #include "base/metrics/histogram_base.h" |
| 9 #include "base/metrics/histogram_samples.h" | 9 #include "base/metrics/histogram_samples.h" |
| 10 #include "base/metrics/sample_map.h" | 10 #include "base/metrics/sample_map.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 | 57 |
| 58 histogram->Add(100); | 58 histogram->Add(100); |
| 59 histogram->Add(101); | 59 histogram->Add(101); |
| 60 scoped_ptr<HistogramSamples> snapshot2(histogram->SnapshotSamples()); | 60 scoped_ptr<HistogramSamples> snapshot2(histogram->SnapshotSamples()); |
| 61 EXPECT_EQ(3, snapshot2->TotalCount()); | 61 EXPECT_EQ(3, snapshot2->TotalCount()); |
| 62 EXPECT_EQ(2, snapshot2->GetCount(100)); | 62 EXPECT_EQ(2, snapshot2->GetCount(100)); |
| 63 EXPECT_EQ(1, snapshot2->GetCount(101)); | 63 EXPECT_EQ(1, snapshot2->GetCount(101)); |
| 64 } | 64 } |
| 65 | 65 |
| 66 TEST_F(SparseHistogramTest, MacroBasicTest) { | 66 TEST_F(SparseHistogramTest, MacroBasicTest) { |
| 67 HISTOGRAM_SPARSE_SLOWLY("Sparse", 100); | 67 UMA_HISTOGRAM_SPARSE_SLOWLY("Sparse", 100); |
| 68 HISTOGRAM_SPARSE_SLOWLY("Sparse", 200); | 68 UMA_HISTOGRAM_SPARSE_SLOWLY("Sparse", 200); |
| 69 HISTOGRAM_SPARSE_SLOWLY("Sparse", 100); | 69 UMA_HISTOGRAM_SPARSE_SLOWLY("Sparse", 100); |
| 70 | 70 |
| 71 StatisticsRecorder::Histograms histograms; | 71 StatisticsRecorder::Histograms histograms; |
| 72 StatisticsRecorder::GetHistograms(&histograms); | 72 StatisticsRecorder::GetHistograms(&histograms); |
| 73 | 73 |
| 74 ASSERT_EQ(1U, histograms.size()); | 74 ASSERT_EQ(1U, histograms.size()); |
| 75 HistogramBase* sparse_histogram = histograms[0]; | 75 HistogramBase* sparse_histogram = histograms[0]; |
| 76 | 76 |
| 77 EXPECT_EQ(SPARSE_HISTOGRAM, sparse_histogram->GetHistogramType()); | 77 EXPECT_EQ(SPARSE_HISTOGRAM, sparse_histogram->GetHistogramType()); |
| 78 EXPECT_EQ("Sparse", sparse_histogram->histogram_name()); | 78 EXPECT_EQ("Sparse", sparse_histogram->histogram_name()); |
| 79 EXPECT_EQ(HistogramBase::kNoFlags, sparse_histogram->flags()); | 79 EXPECT_EQ(HistogramBase::kUmaTargetedHistogramFlag, |
| 80 sparse_histogram->flags()); |
| 80 | 81 |
| 81 scoped_ptr<HistogramSamples> samples = sparse_histogram->SnapshotSamples(); | 82 scoped_ptr<HistogramSamples> samples = sparse_histogram->SnapshotSamples(); |
| 82 EXPECT_EQ(3, samples->TotalCount()); | 83 EXPECT_EQ(3, samples->TotalCount()); |
| 83 EXPECT_EQ(2, samples->GetCount(100)); | 84 EXPECT_EQ(2, samples->GetCount(100)); |
| 84 EXPECT_EQ(1, samples->GetCount(200)); | 85 EXPECT_EQ(1, samples->GetCount(200)); |
| 85 } | 86 } |
| 86 | 87 |
| 87 TEST_F(SparseHistogramTest, MacroUmaTest) { | |
| 88 UMA_HISTOGRAM_SPARSE_SLOWLY("Uma", 100); | |
| 89 | |
| 90 StatisticsRecorder::Histograms histograms; | |
| 91 StatisticsRecorder::GetHistograms(&histograms); | |
| 92 | |
| 93 ASSERT_EQ(1U, histograms.size()); | |
| 94 HistogramBase* sparse_histogram = histograms[0]; | |
| 95 | |
| 96 EXPECT_EQ("Uma", sparse_histogram->histogram_name()); | |
| 97 EXPECT_EQ(HistogramBase::kUmaTargetedHistogramFlag, | |
| 98 sparse_histogram->flags()); | |
| 99 } | |
| 100 | |
| 101 TEST_F(SparseHistogramTest, MacroInLoopTest) { | 88 TEST_F(SparseHistogramTest, MacroInLoopTest) { |
| 102 // Unlike the macros in histogram.h, SparseHistogram macros can have a | 89 // Unlike the macros in histogram.h, SparseHistogram macros can have a |
| 103 // variable as histogram name. | 90 // variable as histogram name. |
| 104 for (int i = 0; i < 2; i++) { | 91 for (int i = 0; i < 2; i++) { |
| 105 std::string name = StringPrintf("Sparse%d", i + 1); | 92 std::string name = StringPrintf("Sparse%d", i + 1); |
| 106 UMA_HISTOGRAM_SPARSE_SLOWLY(name, 100); | 93 UMA_HISTOGRAM_SPARSE_SLOWLY(name, 100); |
| 107 } | 94 } |
| 108 | 95 |
| 109 StatisticsRecorder::Histograms histograms; | 96 StatisticsRecorder::Histograms histograms; |
| 110 StatisticsRecorder::GetHistograms(&histograms); | 97 StatisticsRecorder::GetHistograms(&histograms); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 135 | 122 |
| 136 int flag; | 123 int flag; |
| 137 EXPECT_TRUE(iter.ReadInt(&flag)); | 124 EXPECT_TRUE(iter.ReadInt(&flag)); |
| 138 EXPECT_EQ(HistogramBase::kIPCSerializationSourceFlag, flag); | 125 EXPECT_EQ(HistogramBase::kIPCSerializationSourceFlag, flag); |
| 139 | 126 |
| 140 // No more data in the pickle. | 127 // No more data in the pickle. |
| 141 EXPECT_FALSE(iter.SkipBytes(1)); | 128 EXPECT_FALSE(iter.SkipBytes(1)); |
| 142 } | 129 } |
| 143 | 130 |
| 144 } // namespace base | 131 } // namespace base |
| OLD | NEW |