OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "components/metrics/file_metrics_provider.h" | 5 #include "components/metrics/file_metrics_provider.h" |
6 | 6 |
7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
8 #include "base/files/memory_mapped_file.h" | 8 #include "base/files/memory_mapped_file.h" |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 | 96 |
97 DISALLOW_COPY_AND_ASSIGN(FileMetricsProviderTest); | 97 DISALLOW_COPY_AND_ASSIGN(FileMetricsProviderTest); |
98 }; | 98 }; |
99 | 99 |
100 | 100 |
101 TEST_F(FileMetricsProviderTest, AccessMetrics) { | 101 TEST_F(FileMetricsProviderTest, AccessMetrics) { |
102 ASSERT_FALSE(PathExists(metrics_file())); | 102 ASSERT_FALSE(PathExists(metrics_file())); |
103 | 103 |
104 { | 104 { |
105 // Get this first so it isn't created inside the persistent allocator. | 105 // Get this first so it isn't created inside the persistent allocator. |
106 base::PersistentHistogramAllocator::GetCreateHistogramResultHistogram(); | 106 base::GlobalHistogramAllocator::GetCreateHistogramResultHistogram(); |
107 | 107 |
108 base::PersistentHistogramAllocator::CreateGlobalAllocatorOnLocalMemory( | 108 base::GlobalHistogramAllocator::CreateWithLocalMemory( |
109 64 << 10, 0, kMetricsName); | 109 64 << 10, 0, kMetricsName); |
110 base::HistogramBase* foo = | 110 base::HistogramBase* foo = |
111 base::Histogram::FactoryGet("foo", 1, 100, 10, 0); | 111 base::Histogram::FactoryGet("foo", 1, 100, 10, 0); |
112 base::HistogramBase* bar = | 112 base::HistogramBase* bar = |
113 base::Histogram::FactoryGet("bar", 1, 100, 10, 0); | 113 base::Histogram::FactoryGet("bar", 1, 100, 10, 0); |
114 foo->Add(42); | 114 foo->Add(42); |
115 bar->Add(84); | 115 bar->Add(84); |
116 | 116 |
117 scoped_ptr<base::PersistentHistogramAllocator> histogram_allocator = | 117 scoped_ptr<base::PersistentHistogramAllocator> histogram_allocator = |
118 base::PersistentHistogramAllocator::ReleaseGlobalAllocatorForTesting(); | 118 base::GlobalHistogramAllocator::ReleaseForTesting(); |
119 base::PersistentMemoryAllocator* allocator = | 119 base::PersistentMemoryAllocator* allocator = |
120 histogram_allocator->memory_allocator(); | 120 histogram_allocator->memory_allocator(); |
121 base::File writer(metrics_file(), | 121 base::File writer(metrics_file(), |
122 base::File::FLAG_CREATE | base::File::FLAG_WRITE); | 122 base::File::FLAG_CREATE | base::File::FLAG_WRITE); |
123 ASSERT_TRUE(writer.IsValid()); | 123 ASSERT_TRUE(writer.IsValid()); |
124 ASSERT_EQ(static_cast<int>(allocator->used()), | 124 ASSERT_EQ(static_cast<int>(allocator->used()), |
125 writer.Write(0, (const char*)allocator->data(), | 125 writer.Write(0, (const char*)allocator->data(), |
126 allocator->used())); | 126 allocator->used())); |
127 } | 127 } |
128 | 128 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 HistogramFlattenerDeltaRecorder flattener; | 183 HistogramFlattenerDeltaRecorder flattener; |
184 base::HistogramSnapshotManager snapshot_manager(&flattener); | 184 base::HistogramSnapshotManager snapshot_manager(&flattener); |
185 snapshot_manager.StartDeltas(); | 185 snapshot_manager.StartDeltas(); |
186 provider()->RecordHistogramSnapshots(&snapshot_manager); | 186 provider()->RecordHistogramSnapshots(&snapshot_manager); |
187 snapshot_manager.FinishDeltas(); | 187 snapshot_manager.FinishDeltas(); |
188 EXPECT_EQ(2U, flattener.GetRecordedDeltaHistogramNames().size()); | 188 EXPECT_EQ(2U, flattener.GetRecordedDeltaHistogramNames().size()); |
189 } | 189 } |
190 } | 190 } |
191 | 191 |
192 } // namespace metrics | 192 } // namespace metrics |
OLD | NEW |