| 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 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 702 // Create all histogram names in advance for accurate timing below. | 702 // Create all histogram names in advance for accurate timing below. |
| 703 std::vector<std::string> histogram_names; | 703 std::vector<std::string> histogram_names; |
| 704 for (int i = 0; i < kTestCreateCount; ++i) { | 704 for (int i = 0; i < kTestCreateCount; ++i) { |
| 705 histogram_names.push_back( | 705 histogram_names.push_back( |
| 706 StringPrintf("TestHistogram.%d", i % kTestCreateCount)); | 706 StringPrintf("TestHistogram.%d", i % kTestCreateCount)); |
| 707 } | 707 } |
| 708 | 708 |
| 709 // Calculate cost of creating histograms. | 709 // Calculate cost of creating histograms. |
| 710 TimeTicks create_start = TimeTicks::Now(); | 710 TimeTicks create_start = TimeTicks::Now(); |
| 711 for (int i = 0; i < kTestCreateCount; ++i) { | 711 for (int i = 0; i < kTestCreateCount; ++i) { |
| 712 Histogram::FactoryGet(histogram_names[i], 0, 100, 10, | 712 Histogram::FactoryGet(histogram_names[i], 1, 100, 10, |
| 713 HistogramBase::kNoFlags); | 713 HistogramBase::kNoFlags); |
| 714 } | 714 } |
| 715 TimeDelta create_ticks = TimeTicks::Now() - create_start; | 715 TimeDelta create_ticks = TimeTicks::Now() - create_start; |
| 716 int64_t create_ms = create_ticks.InMilliseconds(); | 716 int64_t create_ms = create_ticks.InMilliseconds(); |
| 717 | 717 |
| 718 VLOG(1) << kTestCreateCount << " histogram creations took " << create_ms | 718 VLOG(1) << kTestCreateCount << " histogram creations took " << create_ms |
| 719 << "ms or about " | 719 << "ms or about " |
| 720 << (create_ms * 1000000) / kTestCreateCount | 720 << (create_ms * 1000000) / kTestCreateCount |
| 721 << "ns each."; | 721 << "ns each."; |
| 722 | 722 |
| 723 // Calculate cost of looking up existing histograms. | 723 // Calculate cost of looking up existing histograms. |
| 724 TimeTicks lookup_start = TimeTicks::Now(); | 724 TimeTicks lookup_start = TimeTicks::Now(); |
| 725 for (int i = 0; i < kTestLookupCount; ++i) { | 725 for (int i = 0; i < kTestLookupCount; ++i) { |
| 726 // 6007 is co-prime with kTestCreateCount and so will do lookups in an | 726 // 6007 is co-prime with kTestCreateCount and so will do lookups in an |
| 727 // order less likely to be cacheable (but still hit them all) should the | 727 // order less likely to be cacheable (but still hit them all) should the |
| 728 // underlying storage use the exact histogram name as the key. | 728 // underlying storage use the exact histogram name as the key. |
| 729 const int i_mult = 6007; | 729 const int i_mult = 6007; |
| 730 static_assert(i_mult < INT_MAX / kTestCreateCount, "Multiplier too big"); | 730 static_assert(i_mult < INT_MAX / kTestCreateCount, "Multiplier too big"); |
| 731 int index = (i * i_mult) & (kTestCreateCount - 1); | 731 int index = (i * i_mult) & (kTestCreateCount - 1); |
| 732 Histogram::FactoryGet(histogram_names[index], 0, 100, 10, | 732 Histogram::FactoryGet(histogram_names[index], 1, 100, 10, |
| 733 HistogramBase::kNoFlags); | 733 HistogramBase::kNoFlags); |
| 734 } | 734 } |
| 735 TimeDelta lookup_ticks = TimeTicks::Now() - lookup_start; | 735 TimeDelta lookup_ticks = TimeTicks::Now() - lookup_start; |
| 736 int64_t lookup_ms = lookup_ticks.InMilliseconds(); | 736 int64_t lookup_ms = lookup_ticks.InMilliseconds(); |
| 737 | 737 |
| 738 VLOG(1) << kTestLookupCount << " histogram lookups took " << lookup_ms | 738 VLOG(1) << kTestLookupCount << " histogram lookups took " << lookup_ms |
| 739 << "ms or about " | 739 << "ms or about " |
| 740 << (lookup_ms * 1000000) / kTestLookupCount | 740 << (lookup_ms * 1000000) / kTestLookupCount |
| 741 << "ns each."; | 741 << "ns each."; |
| 742 | 742 |
| 743 // Calculate cost of accessing histograms. | 743 // Calculate cost of accessing histograms. |
| 744 HistogramBase* histogram = Histogram::FactoryGet( | 744 HistogramBase* histogram = Histogram::FactoryGet( |
| 745 histogram_names[0], 0, 100, 10, HistogramBase::kNoFlags); | 745 histogram_names[0], 1, 100, 10, HistogramBase::kNoFlags); |
| 746 ASSERT_TRUE(histogram); | 746 ASSERT_TRUE(histogram); |
| 747 TimeTicks add_start = TimeTicks::Now(); | 747 TimeTicks add_start = TimeTicks::Now(); |
| 748 for (int i = 0; i < kTestAddCount; ++i) | 748 for (int i = 0; i < kTestAddCount; ++i) |
| 749 histogram->Add(i & 127); | 749 histogram->Add(i & 127); |
| 750 TimeDelta add_ticks = TimeTicks::Now() - add_start; | 750 TimeDelta add_ticks = TimeTicks::Now() - add_start; |
| 751 int64_t add_ms = add_ticks.InMilliseconds(); | 751 int64_t add_ms = add_ticks.InMilliseconds(); |
| 752 | 752 |
| 753 VLOG(1) << kTestAddCount << " histogram adds took " << add_ms | 753 VLOG(1) << kTestAddCount << " histogram adds took " << add_ms |
| 754 << "ms or about " | 754 << "ms or about " |
| 755 << (add_ms * 1000000) / kTestAddCount | 755 << (add_ms * 1000000) / kTestAddCount |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 797 // CustomHistogram needs at least 1 valid range. | 797 // CustomHistogram needs at least 1 valid range. |
| 798 custom_ranges.clear(); | 798 custom_ranges.clear(); |
| 799 custom_ranges.push_back(0); | 799 custom_ranges.push_back(0); |
| 800 EXPECT_DEATH(CustomHistogram::FactoryGet("BadRangesCustom3", custom_ranges, | 800 EXPECT_DEATH(CustomHistogram::FactoryGet("BadRangesCustom3", custom_ranges, |
| 801 HistogramBase::kNoFlags), | 801 HistogramBase::kNoFlags), |
| 802 ""); | 802 ""); |
| 803 } | 803 } |
| 804 #endif | 804 #endif |
| 805 | 805 |
| 806 } // namespace base | 806 } // namespace base |
| OLD | NEW |