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

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

Issue 1779503002: Fix StatisticsRecorder to handle re-entry during tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: always do global UninitializeForTesting when uninitializing Created 4 years, 8 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/histogram_unittest.cc ('k') | base/metrics/statistics_recorder.h » ('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) 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 29 matching lines...) Expand all
40 void TearDown() override { 40 void TearDown() override {
41 if (allocator_) { 41 if (allocator_) {
42 ASSERT_FALSE(allocator_->IsFull()); 42 ASSERT_FALSE(allocator_->IsFull());
43 ASSERT_FALSE(allocator_->IsCorrupt()); 43 ASSERT_FALSE(allocator_->IsCorrupt());
44 } 44 }
45 UninitializeStatisticsRecorder(); 45 UninitializeStatisticsRecorder();
46 DestroyPersistentMemoryAllocator(); 46 DestroyPersistentMemoryAllocator();
47 } 47 }
48 48
49 void InitializeStatisticsRecorder() { 49 void InitializeStatisticsRecorder() {
50 StatisticsRecorder::ResetForTesting(); 50 DCHECK(!statistics_recorder_);
51 statistics_recorder_ = new StatisticsRecorder(); 51 statistics_recorder_.reset(new StatisticsRecorder());
52 } 52 }
53 53
54 void UninitializeStatisticsRecorder() { 54 void UninitializeStatisticsRecorder() {
55 delete statistics_recorder_; 55 statistics_recorder_.reset();
56 statistics_recorder_ = NULL;
57 } 56 }
58 57
59 void CreatePersistentMemoryAllocator() { 58 void CreatePersistentMemoryAllocator() {
60 // By getting the results-histogram before any persistent allocator 59 // By getting the results-histogram before any persistent allocator
61 // is attached, that histogram is guaranteed not to be stored in 60 // is attached, that histogram is guaranteed not to be stored in
62 // any persistent memory segment (which simplifies some tests). 61 // any persistent memory segment (which simplifies some tests).
63 GlobalHistogramAllocator::GetCreateHistogramResultHistogram(); 62 GlobalHistogramAllocator::GetCreateHistogramResultHistogram();
64 63
65 GlobalHistogramAllocator::CreateWithLocalMemory( 64 GlobalHistogramAllocator::CreateWithLocalMemory(
66 kAllocatorMemorySize, 0, "SparseHistogramAllocatorTest"); 65 kAllocatorMemorySize, 0, "SparseHistogramAllocatorTest");
67 allocator_ = GlobalHistogramAllocator::Get()->memory_allocator(); 66 allocator_ = GlobalHistogramAllocator::Get()->memory_allocator();
68 } 67 }
69 68
70 void DestroyPersistentMemoryAllocator() { 69 void DestroyPersistentMemoryAllocator() {
71 allocator_ = nullptr; 70 allocator_ = nullptr;
72 GlobalHistogramAllocator::ReleaseForTesting(); 71 GlobalHistogramAllocator::ReleaseForTesting();
73 } 72 }
74 73
75 std::unique_ptr<SparseHistogram> NewSparseHistogram(const std::string& name) { 74 std::unique_ptr<SparseHistogram> NewSparseHistogram(const std::string& name) {
76 return std::unique_ptr<SparseHistogram>(new SparseHistogram(name)); 75 return std::unique_ptr<SparseHistogram>(new SparseHistogram(name));
77 } 76 }
78 77
79 const bool use_persistent_histogram_allocator_; 78 const bool use_persistent_histogram_allocator_;
80 79
81 StatisticsRecorder* statistics_recorder_; 80 std::unique_ptr<StatisticsRecorder> statistics_recorder_;
82 PersistentMemoryAllocator* allocator_ = nullptr; 81 PersistentMemoryAllocator* allocator_ = nullptr;
83 82
84 private: 83 private:
85 DISALLOW_COPY_AND_ASSIGN(SparseHistogramTest); 84 DISALLOW_COPY_AND_ASSIGN(SparseHistogramTest);
86 }; 85 };
87 86
88 // Run all HistogramTest cases with both heap and persistent memory. 87 // Run all HistogramTest cases with both heap and persistent memory.
89 INSTANTIATE_TEST_CASE_P(HeapAndPersistent, 88 INSTANTIATE_TEST_CASE_P(HeapAndPersistent,
90 SparseHistogramTest, 89 SparseHistogramTest,
91 testing::Bool()); 90 testing::Bool());
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 TimeDelta add_ticks = TimeTicks::Now() - add_start; 271 TimeDelta add_ticks = TimeTicks::Now() - add_start;
273 int64_t add_ms = add_ticks.InMilliseconds(); 272 int64_t add_ms = add_ticks.InMilliseconds();
274 273
275 VLOG(1) << kTestAddCount << " histogram adds took " << add_ms 274 VLOG(1) << kTestAddCount << " histogram adds took " << add_ms
276 << "ms or about " 275 << "ms or about "
277 << (add_ms * 1000000) / kTestAddCount 276 << (add_ms * 1000000) / kTestAddCount
278 << "ns each."; 277 << "ns each.";
279 } 278 }
280 279
281 } // namespace base 280 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/histogram_unittest.cc ('k') | base/metrics/statistics_recorder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698