| 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/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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 GlobalHistogramAllocator::CreateWithLocalMemory( | 66 GlobalHistogramAllocator::CreateWithLocalMemory( |
| 67 kAllocatorMemorySize, 0, "SparseHistogramAllocatorTest"); | 67 kAllocatorMemorySize, 0, "SparseHistogramAllocatorTest"); |
| 68 allocator_ = GlobalHistogramAllocator::Get()->memory_allocator(); | 68 allocator_ = GlobalHistogramAllocator::Get()->memory_allocator(); |
| 69 } | 69 } |
| 70 | 70 |
| 71 void DestroyPersistentMemoryAllocator() { | 71 void DestroyPersistentMemoryAllocator() { |
| 72 allocator_ = nullptr; | 72 allocator_ = nullptr; |
| 73 GlobalHistogramAllocator::ReleaseForTesting(); | 73 GlobalHistogramAllocator::ReleaseForTesting(); |
| 74 } | 74 } |
| 75 | 75 |
| 76 std::unique_ptr<SparseHistogram> NewSparseHistogram(const std::string& name) { | 76 std::unique_ptr<SparseHistogram> NewSparseHistogram(const char* name) { |
| 77 return std::unique_ptr<SparseHistogram>(new SparseHistogram(name)); | 77 return std::unique_ptr<SparseHistogram>(new SparseHistogram(name)); |
| 78 } | 78 } |
| 79 | 79 |
| 80 const bool use_persistent_histogram_allocator_; | 80 const bool use_persistent_histogram_allocator_; |
| 81 | 81 |
| 82 std::unique_ptr<StatisticsRecorder> statistics_recorder_; | 82 std::unique_ptr<StatisticsRecorder> statistics_recorder_; |
| 83 PersistentMemoryAllocator* allocator_ = nullptr; | 83 PersistentMemoryAllocator* allocator_ = nullptr; |
| 84 | 84 |
| 85 private: | 85 private: |
| 86 DISALLOW_COPY_AND_ASSIGN(SparseHistogramTest); | 86 DISALLOW_COPY_AND_ASSIGN(SparseHistogramTest); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 UMA_HISTOGRAM_SPARSE_SLOWLY("Sparse", 200); | 174 UMA_HISTOGRAM_SPARSE_SLOWLY("Sparse", 200); |
| 175 UMA_HISTOGRAM_SPARSE_SLOWLY("Sparse", 100); | 175 UMA_HISTOGRAM_SPARSE_SLOWLY("Sparse", 100); |
| 176 | 176 |
| 177 StatisticsRecorder::Histograms histograms; | 177 StatisticsRecorder::Histograms histograms; |
| 178 StatisticsRecorder::GetHistograms(&histograms); | 178 StatisticsRecorder::GetHistograms(&histograms); |
| 179 | 179 |
| 180 ASSERT_EQ(1U, histograms.size()); | 180 ASSERT_EQ(1U, histograms.size()); |
| 181 HistogramBase* sparse_histogram = histograms[0]; | 181 HistogramBase* sparse_histogram = histograms[0]; |
| 182 | 182 |
| 183 EXPECT_EQ(SPARSE_HISTOGRAM, sparse_histogram->GetHistogramType()); | 183 EXPECT_EQ(SPARSE_HISTOGRAM, sparse_histogram->GetHistogramType()); |
| 184 EXPECT_EQ("Sparse", sparse_histogram->histogram_name()); | 184 EXPECT_EQ("Sparse", StringPiece(sparse_histogram->histogram_name())); |
| 185 EXPECT_EQ( | 185 EXPECT_EQ( |
| 186 HistogramBase::kUmaTargetedHistogramFlag | | 186 HistogramBase::kUmaTargetedHistogramFlag | |
| 187 (use_persistent_histogram_allocator_ ? HistogramBase::kIsPersistent | 187 (use_persistent_histogram_allocator_ ? HistogramBase::kIsPersistent |
| 188 : 0), | 188 : 0), |
| 189 sparse_histogram->flags()); | 189 sparse_histogram->flags()); |
| 190 | 190 |
| 191 std::unique_ptr<HistogramSamples> samples = | 191 std::unique_ptr<HistogramSamples> samples = |
| 192 sparse_histogram->SnapshotSamples(); | 192 sparse_histogram->SnapshotSamples(); |
| 193 EXPECT_EQ(3, samples->TotalCount()); | 193 EXPECT_EQ(3, samples->TotalCount()); |
| 194 EXPECT_EQ(2, samples->GetCount(100)); | 194 EXPECT_EQ(2, samples->GetCount(100)); |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 } | 385 } |
| 386 | 386 |
| 387 TEST_P(SparseHistogramTest, HistogramNameHash) { | 387 TEST_P(SparseHistogramTest, HistogramNameHash) { |
| 388 const char kName[] = "TestName"; | 388 const char kName[] = "TestName"; |
| 389 HistogramBase* histogram = SparseHistogram::FactoryGet( | 389 HistogramBase* histogram = SparseHistogram::FactoryGet( |
| 390 kName, HistogramBase::kUmaTargetedHistogramFlag); | 390 kName, HistogramBase::kUmaTargetedHistogramFlag); |
| 391 EXPECT_EQ(histogram->name_hash(), HashMetricName(kName)); | 391 EXPECT_EQ(histogram->name_hash(), HashMetricName(kName)); |
| 392 } | 392 } |
| 393 | 393 |
| 394 } // namespace base | 394 } // namespace base |
| OLD | NEW |