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

Side by Side Diff: base/metrics/persistent_sample_map_unittest.cc

Issue 2853853002: Fix overflow when logging MaxInt32 to a sparse histogram. (Closed)
Patch Set: Address comments. Created 3 years, 7 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/persistent_sample_map.cc ('k') | base/metrics/sample_map.cc » ('j') | 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) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 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/persistent_sample_map.h" 5 #include "base/metrics/persistent_sample_map.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/metrics/persistent_histogram_allocator.h" 10 #include "base/metrics/persistent_histogram_allocator.h"
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 HistogramSamples::LocalMetadata meta; 157 HistogramSamples::LocalMetadata meta;
158 PersistentSampleMap samples(1, allocator.get(), &meta); 158 PersistentSampleMap samples(1, allocator.get(), &meta);
159 samples.Accumulate(1, 100); 159 samples.Accumulate(1, 100);
160 samples.Accumulate(2, 200); 160 samples.Accumulate(2, 200);
161 samples.Accumulate(4, -300); 161 samples.Accumulate(4, -300);
162 samples.Accumulate(5, 0); 162 samples.Accumulate(5, 0);
163 163
164 std::unique_ptr<SampleCountIterator> it = samples.Iterator(); 164 std::unique_ptr<SampleCountIterator> it = samples.Iterator();
165 165
166 HistogramBase::Sample min; 166 HistogramBase::Sample min;
167 HistogramBase::Sample max; 167 int64_t max;
168 HistogramBase::Count count; 168 HistogramBase::Count count;
169 169
170 it->Get(&min, &max, &count); 170 it->Get(&min, &max, &count);
171 EXPECT_EQ(1, min); 171 EXPECT_EQ(1, min);
172 EXPECT_EQ(2, max); 172 EXPECT_EQ(2, max);
173 EXPECT_EQ(100, count); 173 EXPECT_EQ(100, count);
174 EXPECT_FALSE(it->GetBucketIndex(NULL)); 174 EXPECT_FALSE(it->GetBucketIndex(NULL));
175 175
176 it->Next(); 176 it->Next();
177 it->Get(&min, &max, &count); 177 it->Get(&min, &max, &count);
(...skipping 29 matching lines...) Expand all
207 samples2.Accumulate(5, 1); 207 samples2.Accumulate(5, 1);
208 samples2.Accumulate(20, 4); 208 samples2.Accumulate(20, 4);
209 samples2.Accumulate(25, 5); 209 samples2.Accumulate(25, 5);
210 210
211 samples1.Subtract(samples2); 211 samples1.Subtract(samples2);
212 212
213 std::unique_ptr<SampleCountIterator> it = samples1.Iterator(); 213 std::unique_ptr<SampleCountIterator> it = samples1.Iterator();
214 EXPECT_FALSE(it->Done()); 214 EXPECT_FALSE(it->Done());
215 215
216 HistogramBase::Sample min; 216 HistogramBase::Sample min;
217 HistogramBase::Sample max; 217 int64_t max;
218 HistogramBase::Count count; 218 HistogramBase::Count count;
219 219
220 it->Get(&min, &max, &count); 220 it->Get(&min, &max, &count);
221 EXPECT_EQ(10, min); 221 EXPECT_EQ(10, min);
222 EXPECT_EQ(11, max); 222 EXPECT_EQ(11, max);
223 EXPECT_EQ(2, count); 223 EXPECT_EQ(2, count);
224 224
225 it->Next(); 225 it->Next();
226 EXPECT_FALSE(it->Done()); 226 EXPECT_FALSE(it->Done());
227 227
(...skipping 10 matching lines...) Expand all
238 std::unique_ptr<PersistentHistogramAllocator> allocator = 238 std::unique_ptr<PersistentHistogramAllocator> allocator =
239 CreateHistogramAllocator(64 << 10); // 64 KiB 239 CreateHistogramAllocator(64 << 10); // 64 KiB
240 HistogramSamples::LocalMetadata meta; 240 HistogramSamples::LocalMetadata meta;
241 PersistentSampleMap samples(1, allocator.get(), &meta); 241 PersistentSampleMap samples(1, allocator.get(), &meta);
242 242
243 std::unique_ptr<SampleCountIterator> it = samples.Iterator(); 243 std::unique_ptr<SampleCountIterator> it = samples.Iterator();
244 244
245 EXPECT_TRUE(it->Done()); 245 EXPECT_TRUE(it->Done());
246 246
247 HistogramBase::Sample min; 247 HistogramBase::Sample min;
248 HistogramBase::Sample max; 248 int64_t max;
249 HistogramBase::Count count; 249 HistogramBase::Count count;
250 EXPECT_DCHECK_DEATH(it->Get(&min, &max, &count)); 250 EXPECT_DCHECK_DEATH(it->Get(&min, &max, &count));
251 251
252 EXPECT_DCHECK_DEATH(it->Next()); 252 EXPECT_DCHECK_DEATH(it->Next());
253 253
254 samples.Accumulate(1, 100); 254 samples.Accumulate(1, 100);
255 it = samples.Iterator(); 255 it = samples.Iterator();
256 EXPECT_FALSE(it->Done()); 256 EXPECT_FALSE(it->Done());
257 } 257 }
258 258
259 } // namespace 259 } // namespace
260 } // namespace base 260 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/persistent_sample_map.cc ('k') | base/metrics/sample_map.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698