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 "base/metrics/histogram.h" | 5 #include "base/metrics/histogram.h" |
6 | 6 |
7 #include <limits.h> | 7 #include <limits.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 // Create all histogram names in advance for accurate timing below. | 607 // Create all histogram names in advance for accurate timing below. |
608 std::vector<std::string> histogram_names; | 608 std::vector<std::string> histogram_names; |
609 for (int i = 0; i < kTestCreateCount; ++i) { | 609 for (int i = 0; i < kTestCreateCount; ++i) { |
610 histogram_names.push_back( | 610 histogram_names.push_back( |
611 StringPrintf("TestHistogram.%d", i % kTestCreateCount)); | 611 StringPrintf("TestHistogram.%d", i % kTestCreateCount)); |
612 } | 612 } |
613 | 613 |
614 // Calculate cost of creating histograms. | 614 // Calculate cost of creating histograms. |
615 TimeTicks create_start = TimeTicks::Now(); | 615 TimeTicks create_start = TimeTicks::Now(); |
616 for (int i = 0; i < kTestCreateCount; ++i) { | 616 for (int i = 0; i < kTestCreateCount; ++i) { |
617 Histogram::FactoryGet(histogram_names[i], 0, 100, 10, | 617 Histogram::FactoryGet(histogram_names[i], 1, 100, 10, |
618 HistogramBase::kNoFlags); | 618 HistogramBase::kNoFlags); |
619 } | 619 } |
620 TimeDelta create_ticks = TimeTicks::Now() - create_start; | 620 TimeDelta create_ticks = TimeTicks::Now() - create_start; |
621 int64_t create_ms = create_ticks.InMilliseconds(); | 621 int64_t create_ms = create_ticks.InMilliseconds(); |
622 | 622 |
623 VLOG(1) << kTestCreateCount << " histogram creations took " << create_ms | 623 VLOG(1) << kTestCreateCount << " histogram creations took " << create_ms |
624 << "ms or about " | 624 << "ms or about " |
625 << (create_ms * 1000000) / kTestCreateCount | 625 << (create_ms * 1000000) / kTestCreateCount |
626 << "ns each."; | 626 << "ns each."; |
627 | 627 |
628 // Calculate cost of looking up existing histograms. | 628 // Calculate cost of looking up existing histograms. |
629 TimeTicks lookup_start = TimeTicks::Now(); | 629 TimeTicks lookup_start = TimeTicks::Now(); |
630 for (int i = 0; i < kTestLookupCount; ++i) { | 630 for (int i = 0; i < kTestLookupCount; ++i) { |
631 // 6007 is co-prime with kTestCreateCount and so will do lookups in an | 631 // 6007 is co-prime with kTestCreateCount and so will do lookups in an |
632 // order less likely to be cacheable (but still hit them all) should the | 632 // order less likely to be cacheable (but still hit them all) should the |
633 // underlying storage use the exact histogram name as the key. | 633 // underlying storage use the exact histogram name as the key. |
634 const int i_mult = 6007; | 634 const int i_mult = 6007; |
635 static_assert(i_mult < INT_MAX / kTestCreateCount, "Multiplier too big"); | 635 static_assert(i_mult < INT_MAX / kTestCreateCount, "Multiplier too big"); |
636 int index = (i * i_mult) & (kTestCreateCount - 1); | 636 int index = (i * i_mult) & (kTestCreateCount - 1); |
637 Histogram::FactoryGet(histogram_names[index], 0, 100, 10, | 637 Histogram::FactoryGet(histogram_names[index], 1, 100, 10, |
638 HistogramBase::kNoFlags); | 638 HistogramBase::kNoFlags); |
639 } | 639 } |
640 TimeDelta lookup_ticks = TimeTicks::Now() - lookup_start; | 640 TimeDelta lookup_ticks = TimeTicks::Now() - lookup_start; |
641 int64_t lookup_ms = lookup_ticks.InMilliseconds(); | 641 int64_t lookup_ms = lookup_ticks.InMilliseconds(); |
642 | 642 |
643 VLOG(1) << kTestLookupCount << " histogram lookups took " << lookup_ms | 643 VLOG(1) << kTestLookupCount << " histogram lookups took " << lookup_ms |
644 << "ms or about " | 644 << "ms or about " |
645 << (lookup_ms * 1000000) / kTestLookupCount | 645 << (lookup_ms * 1000000) / kTestLookupCount |
646 << "ns each."; | 646 << "ns each."; |
647 | 647 |
648 // Calculate cost of accessing histograms. | 648 // Calculate cost of accessing histograms. |
649 HistogramBase* histogram = Histogram::FactoryGet( | 649 HistogramBase* histogram = Histogram::FactoryGet( |
650 histogram_names[0], 0, 100, 10, HistogramBase::kNoFlags); | 650 histogram_names[0], 1, 100, 10, HistogramBase::kNoFlags); |
651 ASSERT_TRUE(histogram); | 651 ASSERT_TRUE(histogram); |
652 TimeTicks add_start = TimeTicks::Now(); | 652 TimeTicks add_start = TimeTicks::Now(); |
653 for (int i = 0; i < kTestAddCount; ++i) | 653 for (int i = 0; i < kTestAddCount; ++i) |
654 histogram->Add(i & 127); | 654 histogram->Add(i & 127); |
655 TimeDelta add_ticks = TimeTicks::Now() - add_start; | 655 TimeDelta add_ticks = TimeTicks::Now() - add_start; |
656 int64_t add_ms = add_ticks.InMilliseconds(); | 656 int64_t add_ms = add_ticks.InMilliseconds(); |
657 | 657 |
658 VLOG(1) << kTestAddCount << " histogram adds took " << add_ms | 658 VLOG(1) << kTestAddCount << " histogram adds took " << add_ms |
659 << "ms or about " | 659 << "ms or about " |
660 << (add_ms * 1000000) / kTestAddCount | 660 << (add_ms * 1000000) / kTestAddCount |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
702 // CustomHistogram needs at least 1 valid range. | 702 // CustomHistogram needs at least 1 valid range. |
703 custom_ranges.clear(); | 703 custom_ranges.clear(); |
704 custom_ranges.push_back(0); | 704 custom_ranges.push_back(0); |
705 EXPECT_DEATH(CustomHistogram::FactoryGet("BadRangesCustom3", custom_ranges, | 705 EXPECT_DEATH(CustomHistogram::FactoryGet("BadRangesCustom3", custom_ranges, |
706 HistogramBase::kNoFlags), | 706 HistogramBase::kNoFlags), |
707 ""); | 707 ""); |
708 } | 708 } |
709 #endif | 709 #endif |
710 | 710 |
711 } // namespace base | 711 } // namespace base |
OLD | NEW |