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

Side by Side Diff: base/metrics/sparse_histogram_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
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 <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 9
10 #include "base/metrics/histogram_base.h" 10 #include "base/metrics/histogram_base.h"
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 histogram->Add(i & 127); 320 histogram->Add(i & 127);
321 TimeDelta add_ticks = TimeTicks::Now() - add_start; 321 TimeDelta add_ticks = TimeTicks::Now() - add_start;
322 int64_t add_ms = add_ticks.InMilliseconds(); 322 int64_t add_ms = add_ticks.InMilliseconds();
323 323
324 VLOG(1) << kTestAddCount << " histogram adds took " << add_ms 324 VLOG(1) << kTestAddCount << " histogram adds took " << add_ms
325 << "ms or about " 325 << "ms or about "
326 << (add_ms * 1000000) / kTestAddCount 326 << (add_ms * 1000000) / kTestAddCount
327 << "ns each."; 327 << "ns each.";
328 } 328 }
329 329
330 TEST_P(SparseHistogramTest, ExtremeValues) {
331 static const struct {
332 Histogram::Sample sample;
333 int64_t expected_max;
334 } cases[] = {
335 // Note: We use -2147483647 - 1 rather than -2147483648 because the later
336 // is interpreted as - operator applied to 2147483648 and the latter can't
337 // be represented as an int32 and causes a warning.
338 {-2147483647 - 1, -2147483647LL},
339 {0, 1},
340 {2147483647, 2147483648LL},
341 };
342
343 for (size_t i = 0; i < arraysize(cases); ++i) {
344 HistogramBase* histogram =
345 SparseHistogram::FactoryGet(StringPrintf("ExtremeValues_%zu", i),
346 HistogramBase::kUmaTargetedHistogramFlag);
347 histogram->Add(cases[i].sample);
348
349 std::unique_ptr<HistogramSamples> snapshot = histogram->SnapshotSamples();
350 std::unique_ptr<SampleCountIterator> it = snapshot->Iterator();
351 ASSERT_FALSE(it->Done());
352
353 base::Histogram::Sample min;
354 int64_t max;
355 base::Histogram::Count count;
356 it->Get(&min, &max, &count);
357
358 EXPECT_EQ(1, count);
359 EXPECT_EQ(cases[i].sample, min);
360 EXPECT_EQ(cases[i].expected_max, max);
361
362 it->Next();
363 EXPECT_TRUE(it->Done());
364 }
365 }
366
330 } // namespace base 367 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/sparse_histogram.cc ('k') | chrome/browser/ui/webui/task_scheduler_internals/task_scheduler_internals_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698