| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 // Test of Histogram class | 5 // Test of Histogram class |
| 6 | 6 |
| 7 #include "base/histogram.h" | 7 #include "base/histogram.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/time.h" | 10 #include "base/time.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 using base::TimeDelta; | 13 using base::TimeDelta; |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 class HistogramTest : public testing::Test { | 17 class HistogramTest : public testing::Test { |
| 18 }; | 18 }; |
| 19 | 19 |
| 20 // Check for basic syntax and use. | 20 // Check for basic syntax and use. |
| 21 TEST(HistogramTest, StartupShutdownTest) { | 21 TEST(HistogramTest, StartupShutdownTest) { |
| 22 // Try basic construction | 22 // Try basic construction |
| 23 Histogram histogram(L"TestHistogram", 1, 1000, 10); | 23 Histogram histogram("TestHistogram", 1, 1000, 10); |
| 24 Histogram histogram1(L"Test1Histogram", 1, 1000, 10); | 24 Histogram histogram1("Test1Histogram", 1, 1000, 10); |
| 25 | 25 |
| 26 LinearHistogram linear_histogram(L"TestLinearHistogram", 1, 1000, 10); | 26 LinearHistogram linear_histogram("TestLinearHistogram", 1, 1000, 10); |
| 27 LinearHistogram linear_histogram1(L"Test1LinearHistogram", 1, 1000, 10); | 27 LinearHistogram linear_histogram1("Test1LinearHistogram", 1, 1000, 10); |
| 28 | 28 |
| 29 // Use standard macros (but with fixed samples) | 29 // Use standard macros (but with fixed samples) |
| 30 HISTOGRAM_TIMES(L"Test2Histogram", TimeDelta::FromDays(1)); | 30 HISTOGRAM_TIMES("Test2Histogram", TimeDelta::FromDays(1)); |
| 31 HISTOGRAM_COUNTS(L"Test3Histogram", 30); | 31 HISTOGRAM_COUNTS("Test3Histogram", 30); |
| 32 | 32 |
| 33 DHISTOGRAM_TIMES(L"Test4Histogram", TimeDelta::FromDays(1)); | 33 DHISTOGRAM_TIMES("Test4Histogram", TimeDelta::FromDays(1)); |
| 34 DHISTOGRAM_COUNTS(L"Test5Histogram", 30); | 34 DHISTOGRAM_COUNTS("Test5Histogram", 30); |
| 35 | 35 |
| 36 ASSET_HISTOGRAM_COUNTS(L"Test6Histogram", 129); | 36 ASSET_HISTOGRAM_COUNTS("Test6Histogram", 129); |
| 37 | 37 |
| 38 // Try to construct samples. | 38 // Try to construct samples. |
| 39 Histogram::SampleSet sample1; | 39 Histogram::SampleSet sample1; |
| 40 Histogram::SampleSet sample2; | 40 Histogram::SampleSet sample2; |
| 41 | 41 |
| 42 // Use copy constructor of SampleSet | 42 // Use copy constructor of SampleSet |
| 43 sample1 = sample2; | 43 sample1 = sample2; |
| 44 Histogram::SampleSet sample3(sample1); | 44 Histogram::SampleSet sample3(sample1); |
| 45 | 45 |
| 46 // Finally test a statistics recorder, without really using it. | 46 // Finally test a statistics recorder, without really using it. |
| 47 StatisticsRecorder recorder; | 47 StatisticsRecorder recorder; |
| 48 } | 48 } |
| 49 | 49 |
| 50 // Repeat with a recorder present to register with. | 50 // Repeat with a recorder present to register with. |
| 51 TEST(HistogramTest, RecordedStartupTest) { | 51 TEST(HistogramTest, RecordedStartupTest) { |
| 52 // Test a statistics recorder, by letting histograms register. | 52 // Test a statistics recorder, by letting histograms register. |
| 53 StatisticsRecorder recorder; // This initializes the global state. | 53 StatisticsRecorder recorder; // This initializes the global state. |
| 54 | 54 |
| 55 StatisticsRecorder::Histograms histograms; | 55 StatisticsRecorder::Histograms histograms; |
| 56 EXPECT_EQ(0U, histograms.size()); | 56 EXPECT_EQ(0U, histograms.size()); |
| 57 StatisticsRecorder::GetHistograms(&histograms); // Load up lists | 57 StatisticsRecorder::GetHistograms(&histograms); // Load up lists |
| 58 EXPECT_EQ(0U, histograms.size()); | 58 EXPECT_EQ(0U, histograms.size()); |
| 59 | 59 |
| 60 // Try basic construction | 60 // Try basic construction |
| 61 Histogram histogram(L"TestHistogram", 1, 1000, 10); | 61 Histogram histogram("TestHistogram", 1, 1000, 10); |
| 62 histograms.clear(); | 62 histograms.clear(); |
| 63 StatisticsRecorder::GetHistograms(&histograms); // Load up lists | 63 StatisticsRecorder::GetHistograms(&histograms); // Load up lists |
| 64 EXPECT_EQ(1U, histograms.size()); | 64 EXPECT_EQ(1U, histograms.size()); |
| 65 Histogram histogram1(L"Test1Histogram", 1, 1000, 10); | 65 Histogram histogram1("Test1Histogram", 1, 1000, 10); |
| 66 histograms.clear(); | 66 histograms.clear(); |
| 67 StatisticsRecorder::GetHistograms(&histograms); // Load up lists | 67 StatisticsRecorder::GetHistograms(&histograms); // Load up lists |
| 68 EXPECT_EQ(2U, histograms.size()); | 68 EXPECT_EQ(2U, histograms.size()); |
| 69 | 69 |
| 70 LinearHistogram linear_histogram(L"TestLinearHistogram", 1, 1000, 10); | 70 LinearHistogram linear_histogram("TestLinearHistogram", 1, 1000, 10); |
| 71 LinearHistogram linear_histogram1(L"Test1LinearHistogram", 1, 1000, 10); | 71 LinearHistogram linear_histogram1("Test1LinearHistogram", 1, 1000, 10); |
| 72 histograms.clear(); | 72 histograms.clear(); |
| 73 StatisticsRecorder::GetHistograms(&histograms); // Load up lists | 73 StatisticsRecorder::GetHistograms(&histograms); // Load up lists |
| 74 EXPECT_EQ(4U, histograms.size()); | 74 EXPECT_EQ(4U, histograms.size()); |
| 75 | 75 |
| 76 // Use standard macros (but with fixed samples) | 76 // Use standard macros (but with fixed samples) |
| 77 HISTOGRAM_TIMES(L"Test2Histogram", TimeDelta::FromDays(1)); | 77 HISTOGRAM_TIMES("Test2Histogram", TimeDelta::FromDays(1)); |
| 78 HISTOGRAM_COUNTS(L"Test3Histogram", 30); | 78 HISTOGRAM_COUNTS("Test3Histogram", 30); |
| 79 histograms.clear(); | 79 histograms.clear(); |
| 80 StatisticsRecorder::GetHistograms(&histograms); // Load up lists | 80 StatisticsRecorder::GetHistograms(&histograms); // Load up lists |
| 81 EXPECT_EQ(6U, histograms.size()); | 81 EXPECT_EQ(6U, histograms.size()); |
| 82 | 82 |
| 83 ASSET_HISTOGRAM_COUNTS(L"TestAssetHistogram", 1000); | 83 ASSET_HISTOGRAM_COUNTS("TestAssetHistogram", 1000); |
| 84 histograms.clear(); | 84 histograms.clear(); |
| 85 StatisticsRecorder::GetHistograms(&histograms); // Load up lists | 85 StatisticsRecorder::GetHistograms(&histograms); // Load up lists |
| 86 EXPECT_EQ(7U, histograms.size()); | 86 EXPECT_EQ(7U, histograms.size()); |
| 87 | 87 |
| 88 DHISTOGRAM_TIMES(L"Test4Histogram", TimeDelta::FromDays(1)); | 88 DHISTOGRAM_TIMES("Test4Histogram", TimeDelta::FromDays(1)); |
| 89 DHISTOGRAM_COUNTS(L"Test5Histogram", 30); | 89 DHISTOGRAM_COUNTS("Test5Histogram", 30); |
| 90 histograms.clear(); | 90 histograms.clear(); |
| 91 StatisticsRecorder::GetHistograms(&histograms); // Load up lists | 91 StatisticsRecorder::GetHistograms(&histograms); // Load up lists |
| 92 #ifndef NDEBUG | 92 #ifndef NDEBUG |
| 93 EXPECT_EQ(9U, histograms.size()); | 93 EXPECT_EQ(9U, histograms.size()); |
| 94 #else | 94 #else |
| 95 EXPECT_EQ(7U, histograms.size()); | 95 EXPECT_EQ(7U, histograms.size()); |
| 96 #endif | 96 #endif |
| 97 } | 97 } |
| 98 | 98 |
| 99 TEST(HistogramTest, RangeTest) { | 99 TEST(HistogramTest, RangeTest) { |
| 100 StatisticsRecorder recorder; | 100 StatisticsRecorder recorder; |
| 101 StatisticsRecorder::Histograms histograms; | 101 StatisticsRecorder::Histograms histograms; |
| 102 | 102 |
| 103 recorder.GetHistograms(&histograms); | 103 recorder.GetHistograms(&histograms); |
| 104 EXPECT_EQ(0U, histograms.size()); | 104 EXPECT_EQ(0U, histograms.size()); |
| 105 | 105 |
| 106 Histogram histogram(L"Histogram", 1, 64, 8); // As mentioned in header file. | 106 Histogram histogram("Histogram", 1, 64, 8); // As mentioned in header file. |
| 107 // Check that we got a nice exponential when there was enough rooom. | 107 // Check that we got a nice exponential when there was enough rooom. |
| 108 EXPECT_EQ(0, histogram.ranges(0)); | 108 EXPECT_EQ(0, histogram.ranges(0)); |
| 109 int power_of_2 = 1; | 109 int power_of_2 = 1; |
| 110 for (int i = 1; i < 8; i++) { | 110 for (int i = 1; i < 8; i++) { |
| 111 EXPECT_EQ(power_of_2, histogram.ranges(i)); | 111 EXPECT_EQ(power_of_2, histogram.ranges(i)); |
| 112 power_of_2 *= 2; | 112 power_of_2 *= 2; |
| 113 } | 113 } |
| 114 EXPECT_EQ(INT_MAX, histogram.ranges(8)); | 114 EXPECT_EQ(INT_MAX, histogram.ranges(8)); |
| 115 | 115 |
| 116 Histogram short_histogram(L"Histogram Shortened", 1, 7, 8); | 116 Histogram short_histogram("Histogram Shortened", 1, 7, 8); |
| 117 // Check that when the number of buckets is short, we get a linear histogram | 117 // Check that when the number of buckets is short, we get a linear histogram |
| 118 // for lack of space to do otherwise. | 118 // for lack of space to do otherwise. |
| 119 for (int i = 0; i < 8; i++) | 119 for (int i = 0; i < 8; i++) |
| 120 EXPECT_EQ(i, short_histogram.ranges(i)); | 120 EXPECT_EQ(i, short_histogram.ranges(i)); |
| 121 EXPECT_EQ(INT_MAX, short_histogram.ranges(8)); | 121 EXPECT_EQ(INT_MAX, short_histogram.ranges(8)); |
| 122 | 122 |
| 123 LinearHistogram linear_histogram(L"Linear", 1, 7, 8); | 123 LinearHistogram linear_histogram("Linear", 1, 7, 8); |
| 124 // We also get a nice linear set of bucket ranges when we ask for it | 124 // We also get a nice linear set of bucket ranges when we ask for it |
| 125 for (int i = 0; i < 8; i++) | 125 for (int i = 0; i < 8; i++) |
| 126 EXPECT_EQ(i, linear_histogram.ranges(i)); | 126 EXPECT_EQ(i, linear_histogram.ranges(i)); |
| 127 EXPECT_EQ(INT_MAX, linear_histogram.ranges(8)); | 127 EXPECT_EQ(INT_MAX, linear_histogram.ranges(8)); |
| 128 | 128 |
| 129 LinearHistogram linear_broad_histogram(L"Linear widened", 2, 14, 8); | 129 LinearHistogram linear_broad_histogram("Linear widened", 2, 14, 8); |
| 130 // ...but when the list has more space, then the ranges naturally spread out. | 130 // ...but when the list has more space, then the ranges naturally spread out. |
| 131 for (int i = 0; i < 8; i++) | 131 for (int i = 0; i < 8; i++) |
| 132 EXPECT_EQ(2 * i, linear_broad_histogram.ranges(i)); | 132 EXPECT_EQ(2 * i, linear_broad_histogram.ranges(i)); |
| 133 EXPECT_EQ(INT_MAX, linear_broad_histogram.ranges(8)); | 133 EXPECT_EQ(INT_MAX, linear_broad_histogram.ranges(8)); |
| 134 | 134 |
| 135 ThreadSafeHistogram threadsafe_histogram(L"ThreadSafe", 1, 32, 15); | 135 ThreadSafeHistogram threadsafe_histogram("ThreadSafe", 1, 32, 15); |
| 136 // When space is a little tight, we transition from linear to exponential. | 136 // When space is a little tight, we transition from linear to exponential. |
| 137 // This is what happens in both the basic histogram, and the threadsafe | 137 // This is what happens in both the basic histogram, and the threadsafe |
| 138 // variant (which is derived). | 138 // variant (which is derived). |
| 139 EXPECT_EQ(0, threadsafe_histogram.ranges(0)); | 139 EXPECT_EQ(0, threadsafe_histogram.ranges(0)); |
| 140 EXPECT_EQ(1, threadsafe_histogram.ranges(1)); | 140 EXPECT_EQ(1, threadsafe_histogram.ranges(1)); |
| 141 EXPECT_EQ(2, threadsafe_histogram.ranges(2)); | 141 EXPECT_EQ(2, threadsafe_histogram.ranges(2)); |
| 142 EXPECT_EQ(3, threadsafe_histogram.ranges(3)); | 142 EXPECT_EQ(3, threadsafe_histogram.ranges(3)); |
| 143 EXPECT_EQ(4, threadsafe_histogram.ranges(4)); | 143 EXPECT_EQ(4, threadsafe_histogram.ranges(4)); |
| 144 EXPECT_EQ(5, threadsafe_histogram.ranges(5)); | 144 EXPECT_EQ(5, threadsafe_histogram.ranges(5)); |
| 145 EXPECT_EQ(6, threadsafe_histogram.ranges(6)); | 145 EXPECT_EQ(6, threadsafe_histogram.ranges(6)); |
| 146 EXPECT_EQ(7, threadsafe_histogram.ranges(7)); | 146 EXPECT_EQ(7, threadsafe_histogram.ranges(7)); |
| 147 EXPECT_EQ(9, threadsafe_histogram.ranges(8)); | 147 EXPECT_EQ(9, threadsafe_histogram.ranges(8)); |
| 148 EXPECT_EQ(11, threadsafe_histogram.ranges(9)); | 148 EXPECT_EQ(11, threadsafe_histogram.ranges(9)); |
| 149 EXPECT_EQ(14, threadsafe_histogram.ranges(10)); | 149 EXPECT_EQ(14, threadsafe_histogram.ranges(10)); |
| 150 EXPECT_EQ(17, threadsafe_histogram.ranges(11)); | 150 EXPECT_EQ(17, threadsafe_histogram.ranges(11)); |
| 151 EXPECT_EQ(21, threadsafe_histogram.ranges(12)); | 151 EXPECT_EQ(21, threadsafe_histogram.ranges(12)); |
| 152 EXPECT_EQ(26, threadsafe_histogram.ranges(13)); | 152 EXPECT_EQ(26, threadsafe_histogram.ranges(13)); |
| 153 EXPECT_EQ(32, threadsafe_histogram.ranges(14)); | 153 EXPECT_EQ(32, threadsafe_histogram.ranges(14)); |
| 154 EXPECT_EQ(INT_MAX, threadsafe_histogram.ranges(15)); | 154 EXPECT_EQ(INT_MAX, threadsafe_histogram.ranges(15)); |
| 155 | 155 |
| 156 recorder.GetHistograms(&histograms); | 156 recorder.GetHistograms(&histograms); |
| 157 EXPECT_EQ(5U, histograms.size()); | 157 EXPECT_EQ(5U, histograms.size()); |
| 158 } | 158 } |
| 159 | 159 |
| 160 // Make sure histogram handles out-of-bounds data gracefully. | 160 // Make sure histogram handles out-of-bounds data gracefully. |
| 161 TEST(HistogramTest, BoundsTest) { | 161 TEST(HistogramTest, BoundsTest) { |
| 162 const size_t kBucketCount = 50; | 162 const size_t kBucketCount = 50; |
| 163 Histogram histogram(L"Bounded", 10, 100, kBucketCount); | 163 Histogram histogram("Bounded", 10, 100, kBucketCount); |
| 164 | 164 |
| 165 // Put two samples "out of bounds" above and below. | 165 // Put two samples "out of bounds" above and below. |
| 166 histogram.Add(5); | 166 histogram.Add(5); |
| 167 histogram.Add(-50); | 167 histogram.Add(-50); |
| 168 | 168 |
| 169 histogram.Add(100); | 169 histogram.Add(100); |
| 170 histogram.Add(10000); | 170 histogram.Add(10000); |
| 171 | 171 |
| 172 // Verify they landed in the underflow, and overflow buckets. | 172 // Verify they landed in the underflow, and overflow buckets. |
| 173 Histogram::SampleSet sample; | 173 Histogram::SampleSet sample; |
| 174 histogram.SnapshotSample(&sample); | 174 histogram.SnapshotSample(&sample); |
| 175 EXPECT_EQ(2, sample.counts(0)); | 175 EXPECT_EQ(2, sample.counts(0)); |
| 176 EXPECT_EQ(0, sample.counts(1)); | 176 EXPECT_EQ(0, sample.counts(1)); |
| 177 size_t array_size = histogram.bucket_count(); | 177 size_t array_size = histogram.bucket_count(); |
| 178 EXPECT_EQ(kBucketCount, array_size); | 178 EXPECT_EQ(kBucketCount, array_size); |
| 179 EXPECT_EQ(0, sample.counts(array_size - 2)); | 179 EXPECT_EQ(0, sample.counts(array_size - 2)); |
| 180 EXPECT_EQ(2, sample.counts(array_size - 1)); | 180 EXPECT_EQ(2, sample.counts(array_size - 1)); |
| 181 } | 181 } |
| 182 | 182 |
| 183 // Check to be sure samples land as expected is "correct" buckets. | 183 // Check to be sure samples land as expected is "correct" buckets. |
| 184 TEST(HistogramTest, BucketPlacementTest) { | 184 TEST(HistogramTest, BucketPlacementTest) { |
| 185 Histogram histogram(L"Histogram", 1, 64, 8); // As mentioned in header file. | 185 Histogram histogram("Histogram", 1, 64, 8); // As mentioned in header file. |
| 186 | 186 |
| 187 // Check that we got a nice exponential since there was enough rooom. | 187 // Check that we got a nice exponential since there was enough rooom. |
| 188 EXPECT_EQ(0, histogram.ranges(0)); | 188 EXPECT_EQ(0, histogram.ranges(0)); |
| 189 int power_of_2 = 1; | 189 int power_of_2 = 1; |
| 190 for (int i = 1; i < 8; i++) { | 190 for (int i = 1; i < 8; i++) { |
| 191 EXPECT_EQ(power_of_2, histogram.ranges(i)); | 191 EXPECT_EQ(power_of_2, histogram.ranges(i)); |
| 192 power_of_2 *= 2; | 192 power_of_2 *= 2; |
| 193 } | 193 } |
| 194 EXPECT_EQ(INT_MAX, histogram.ranges(8)); | 194 EXPECT_EQ(INT_MAX, histogram.ranges(8)); |
| 195 | 195 |
| 196 // Add i+1 samples to the i'th bucket. | 196 // Add i+1 samples to the i'th bucket. |
| 197 histogram.Add(0); | 197 histogram.Add(0); |
| 198 power_of_2 = 1; | 198 power_of_2 = 1; |
| 199 for (int i = 1; i < 8; i++) { | 199 for (int i = 1; i < 8; i++) { |
| 200 for (int j = 0; j <= i; j++) | 200 for (int j = 0; j <= i; j++) |
| 201 histogram.Add(power_of_2); | 201 histogram.Add(power_of_2); |
| 202 power_of_2 *= 2; | 202 power_of_2 *= 2; |
| 203 } | 203 } |
| 204 // Leave overflow bucket empty. | 204 // Leave overflow bucket empty. |
| 205 | 205 |
| 206 // Check to see that the bucket counts reflect our additions. | 206 // Check to see that the bucket counts reflect our additions. |
| 207 Histogram::SampleSet sample; | 207 Histogram::SampleSet sample; |
| 208 histogram.SnapshotSample(&sample); | 208 histogram.SnapshotSample(&sample); |
| 209 EXPECT_EQ(INT_MAX, histogram.ranges(8)); | 209 EXPECT_EQ(INT_MAX, histogram.ranges(8)); |
| 210 for (int i = 0; i < 8; i++) | 210 for (int i = 0; i < 8; i++) |
| 211 EXPECT_EQ(i + 1, sample.counts(i)); | 211 EXPECT_EQ(i + 1, sample.counts(i)); |
| 212 } | 212 } |
| 213 | 213 |
| 214 static const wchar_t* kAssetTestHistogramName = L"AssetCountTest"; | 214 static const char kAssetTestHistogramName[] = "AssetCountTest"; |
| 215 static const wchar_t* kAssetTestDebugHistogramName = L"DAssetCountTest"; | 215 static const char kAssetTestDebugHistogramName[] = "DAssetCountTest"; |
| 216 void AssetCountFunction(int sample) { | 216 void AssetCountFunction(int sample) { |
| 217 ASSET_HISTOGRAM_COUNTS(kAssetTestHistogramName, sample); | 217 ASSET_HISTOGRAM_COUNTS(kAssetTestHistogramName, sample); |
| 218 DASSET_HISTOGRAM_COUNTS(kAssetTestDebugHistogramName, sample); | 218 DASSET_HISTOGRAM_COUNTS(kAssetTestDebugHistogramName, sample); |
| 219 } | 219 } |
| 220 // Check that asset can be added and removed from buckets. | 220 // Check that asset can be added and removed from buckets. |
| 221 TEST(HistogramTest, AssetCountTest) { | 221 TEST(HistogramTest, AssetCountTest) { |
| 222 // Start up a recorder system to identify all histograms. | 222 // Start up a recorder system to identify all histograms. |
| 223 StatisticsRecorder recorder; | 223 StatisticsRecorder recorder; |
| 224 | 224 |
| 225 // Call through the macro to instantiate the static variables. | 225 // Call through the macro to instantiate the static variables. |
| 226 AssetCountFunction(100); // Put a sample in the bucket for 100. | 226 AssetCountFunction(100); // Put a sample in the bucket for 100. |
| 227 | 227 |
| 228 // Find the histogram. | 228 // Find the histogram. |
| 229 StatisticsRecorder::Histograms histogram_list; | 229 StatisticsRecorder::Histograms histogram_list; |
| 230 StatisticsRecorder::GetHistograms(&histogram_list); | 230 StatisticsRecorder::GetHistograms(&histogram_list); |
| 231 ASSERT_NE(0U, histogram_list.size()); | 231 ASSERT_NE(0U, histogram_list.size()); |
| 232 std::string ascii_name = WideToASCII(kAssetTestHistogramName); | |
| 233 std::string debug_ascii_name = WideToASCII(kAssetTestDebugHistogramName); | |
| 234 const Histogram* our_histogram = NULL; | 232 const Histogram* our_histogram = NULL; |
| 235 const Histogram* our_debug_histogram = NULL; | 233 const Histogram* our_debug_histogram = NULL; |
| 236 for (StatisticsRecorder::Histograms::iterator it = histogram_list.begin(); | 234 for (StatisticsRecorder::Histograms::iterator it = histogram_list.begin(); |
| 237 it != histogram_list.end(); | 235 it != histogram_list.end(); |
| 238 ++it) { | 236 ++it) { |
| 239 if (!(*it)->histogram_name().compare(ascii_name)) | 237 if (!(*it)->histogram_name().compare(kAssetTestHistogramName)) |
| 240 our_histogram = *it; | 238 our_histogram = *it; |
| 241 else if (!(*it)->histogram_name().compare(debug_ascii_name)) { | 239 else if (!(*it)->histogram_name().compare(kAssetTestDebugHistogramName)) { |
| 242 our_debug_histogram = *it; | 240 our_debug_histogram = *it; |
| 243 } | 241 } |
| 244 } | 242 } |
| 245 ASSERT_TRUE(our_histogram); | 243 ASSERT_TRUE(our_histogram); |
| 246 #ifndef NDEBUG | 244 #ifndef NDEBUG |
| 247 EXPECT_TRUE(our_debug_histogram); | 245 EXPECT_TRUE(our_debug_histogram); |
| 248 #else | 246 #else |
| 249 EXPECT_FALSE(our_debug_histogram); | 247 EXPECT_FALSE(our_debug_histogram); |
| 250 #endif | 248 #endif |
| 251 // Verify it has a 1 in exactly one bucket (where we put the sample). | 249 // Verify it has a 1 in exactly one bucket (where we put the sample). |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 AssetCountFunction(-100); // Remove a sample from the bucket for 100. | 285 AssetCountFunction(-100); // Remove a sample from the bucket for 100. |
| 288 our_debug_histogram->SnapshotSample(&sample); // Extract data set. | 286 our_debug_histogram->SnapshotSample(&sample); // Extract data set. |
| 289 | 287 |
| 290 // Verify that the bucket is now empty, as are all the other buckets. | 288 // Verify that the bucket is now empty, as are all the other buckets. |
| 291 for (size_t i = 0; i < our_debug_histogram->bucket_count(); ++i) { | 289 for (size_t i = 0; i < our_debug_histogram->bucket_count(); ++i) { |
| 292 EXPECT_EQ(0, sample.counts(i)) << "extra count in bucket " << i; | 290 EXPECT_EQ(0, sample.counts(i)) << "extra count in bucket " << i; |
| 293 } | 291 } |
| 294 } | 292 } |
| 295 | 293 |
| 296 } // namespace | 294 } // namespace |
| 297 | |
| OLD | NEW |