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

Side by Side Diff: components/metrics/file_metrics_provider_unittest.cc

Issue 1738063002: Refactor histogram_persistence to be a class. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed final review comments by Alexei Created 4 years, 9 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 | « components/metrics/file_metrics_provider.cc ('k') | components/metrics/metrics_service.cc » ('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 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"
11 #include "base/metrics/histogram_flattener.h" 11 #include "base/metrics/histogram_flattener.h"
12 #include "base/metrics/histogram_persistence.h"
13 #include "base/metrics/histogram_snapshot_manager.h" 12 #include "base/metrics/histogram_snapshot_manager.h"
13 #include "base/metrics/persistent_histogram_allocator.h"
14 #include "base/metrics/persistent_memory_allocator.h" 14 #include "base/metrics/persistent_memory_allocator.h"
15 #include "base/metrics/statistics_recorder.h" 15 #include "base/metrics/statistics_recorder.h"
16 #include "base/test/test_simple_task_runner.h" 16 #include "base/test/test_simple_task_runner.h"
17 #include "base/thread_task_runner_handle.h" 17 #include "base/thread_task_runner_handle.h"
18 #include "components/metrics/metrics_pref_names.h" 18 #include "components/metrics/metrics_pref_names.h"
19 #include "components/prefs/pref_registry_simple.h" 19 #include "components/prefs/pref_registry_simple.h"
20 #include "components/prefs/testing_pref_service.h" 20 #include "components/prefs/testing_pref_service.h"
21 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
22 22
23 namespace { 23 namespace {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
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::GetCreateHistogramResultHistogram(); 106 base::PersistentHistogramAllocator::GetCreateHistogramResultHistogram();
107 107
108 base::SetPersistentHistogramMemoryAllocator( 108 base::PersistentHistogramAllocator::CreateGlobalAllocatorOnLocalMemory(
109 new base::LocalPersistentMemoryAllocator(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::PersistentMemoryAllocator> allocator( 117 scoped_ptr<base::PersistentHistogramAllocator> histogram_allocator =
118 base::ReleasePersistentHistogramMemoryAllocatorForTesting()); 118 base::PersistentHistogramAllocator::ReleaseGlobalAllocatorForTesting();
119 base::PersistentMemoryAllocator* allocator =
120 histogram_allocator->memory_allocator();
119 base::File writer(metrics_file(), 121 base::File writer(metrics_file(),
120 base::File::FLAG_CREATE | base::File::FLAG_WRITE); 122 base::File::FLAG_CREATE | base::File::FLAG_WRITE);
121 ASSERT_TRUE(writer.IsValid()); 123 ASSERT_TRUE(writer.IsValid());
122 ASSERT_EQ(static_cast<int>(allocator->used()), 124 ASSERT_EQ(static_cast<int>(allocator->used()),
123 writer.Write(0, (const char*)allocator->data(), 125 writer.Write(0, (const char*)allocator->data(),
124 allocator->used())); 126 allocator->used()));
125 } 127 }
126 128
127 // Register the file and allow the "checker" task to run. 129 // Register the file and allow the "checker" task to run.
128 ASSERT_TRUE(PathExists(metrics_file())); 130 ASSERT_TRUE(PathExists(metrics_file()));
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 HistogramFlattenerDeltaRecorder flattener; 183 HistogramFlattenerDeltaRecorder flattener;
182 base::HistogramSnapshotManager snapshot_manager(&flattener); 184 base::HistogramSnapshotManager snapshot_manager(&flattener);
183 snapshot_manager.StartDeltas(); 185 snapshot_manager.StartDeltas();
184 provider()->RecordHistogramSnapshots(&snapshot_manager); 186 provider()->RecordHistogramSnapshots(&snapshot_manager);
185 snapshot_manager.FinishDeltas(); 187 snapshot_manager.FinishDeltas();
186 EXPECT_EQ(2U, flattener.GetRecordedDeltaHistogramNames().size()); 188 EXPECT_EQ(2U, flattener.GetRecordedDeltaHistogramNames().size());
187 } 189 }
188 } 190 }
189 191
190 } // namespace metrics 192 } // namespace metrics
OLDNEW
« no previous file with comments | « components/metrics/file_metrics_provider.cc ('k') | components/metrics/metrics_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698