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

Side by Side Diff: chrome/browser/metrics/subprocess_metrics_provider_unittest.cc

Issue 2224063002: Use persistent memory for receiving metrics from sub-processes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: create helper method; make test appear to be on UI thread Created 4 years, 4 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
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 "chrome/browser/metrics/subprocess_metrics_provider.h" 5 #include "chrome/browser/metrics/subprocess_metrics_provider.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.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_snapshot_manager.h" 12 #include "base/metrics/histogram_snapshot_manager.h"
13 #include "base/metrics/persistent_histogram_allocator.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 "content/public/test/test_browser_thread_bundle.h"
16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
17 18
18 namespace { 19 namespace {
19 20
20 const uint32_t TEST_MEMORY_SIZE = 64 << 10; // 64 KiB 21 const uint32_t TEST_MEMORY_SIZE = 64 << 10; // 64 KiB
21 22
22 class HistogramFlattenerDeltaRecorder : public base::HistogramFlattener { 23 class HistogramFlattenerDeltaRecorder : public base::HistogramFlattener {
23 public: 24 public:
24 HistogramFlattenerDeltaRecorder() {} 25 HistogramFlattenerDeltaRecorder() {}
25 26
(...skipping 23 matching lines...) Expand all
49 private: 50 private:
50 std::vector<std::string> recorded_delta_histogram_names_; 51 std::vector<std::string> recorded_delta_histogram_names_;
51 52
52 DISALLOW_COPY_AND_ASSIGN(HistogramFlattenerDeltaRecorder); 53 DISALLOW_COPY_AND_ASSIGN(HistogramFlattenerDeltaRecorder);
53 }; 54 };
54 55
55 } // namespace 56 } // namespace
56 57
57 class SubprocessMetricsProviderTest : public testing::Test { 58 class SubprocessMetricsProviderTest : public testing::Test {
58 protected: 59 protected:
59 SubprocessMetricsProviderTest() { 60 SubprocessMetricsProviderTest()
61 : thread_bundle_(content::TestBrowserThreadBundle::DEFAULT) {
60 // Get this first so it isn't created inside a persistent allocator. 62 // Get this first so it isn't created inside a persistent allocator.
61 base::PersistentHistogramAllocator::GetCreateHistogramResultHistogram(); 63 base::PersistentHistogramAllocator::GetCreateHistogramResultHistogram();
62 64
63 // MergeHistogramDeltas needs to be called beause it uses a histogram 65 // MergeHistogramDeltas needs to be called beause it uses a histogram
64 // macro which caches a pointer to a histogram. If not done before setting 66 // macro which caches a pointer to a histogram. If not done before setting
65 // a persistent global allocator, then it would point into memory that 67 // a persistent global allocator, then it would point into memory that
66 // will go away. 68 // will go away.
67 provider_.MergeHistogramDeltas(); 69 provider_.MergeHistogramDeltas();
68 70
69 // Create a dedicated StatisticsRecorder for this test. 71 // Create a dedicated StatisticsRecorder for this test.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 int id, 112 int id,
111 std::unique_ptr<base::PersistentHistogramAllocator> allocator) { 113 std::unique_ptr<base::PersistentHistogramAllocator> allocator) {
112 provider_.RegisterSubprocessAllocator(id, std::move(allocator)); 114 provider_.RegisterSubprocessAllocator(id, std::move(allocator));
113 } 115 }
114 116
115 void DeregisterSubprocessAllocator(int id) { 117 void DeregisterSubprocessAllocator(int id) {
116 provider_.DeregisterSubprocessAllocator(id); 118 provider_.DeregisterSubprocessAllocator(id);
117 } 119 }
118 120
119 private: 121 private:
122 // A thread-buldle makes the tests appear on the UI thread, something that is
Alexei Svitkine (slow) 2016/08/19 16:31:56 Nit: buldle -> bundle
bcwhite 2016/08/19 17:19:46 Done.
123 // checked in methods called from the SubprocessMetricsProvider class under
124 // test. This must be constructed before the |provider_| field.
125 content::TestBrowserThreadBundle thread_bundle_;
126
120 SubprocessMetricsProvider provider_; 127 SubprocessMetricsProvider provider_;
121 std::unique_ptr<base::StatisticsRecorder> test_recorder_; 128 std::unique_ptr<base::StatisticsRecorder> test_recorder_;
122 129
123 DISALLOW_COPY_AND_ASSIGN(SubprocessMetricsProviderTest); 130 DISALLOW_COPY_AND_ASSIGN(SubprocessMetricsProviderTest);
124 }; 131 };
125 132
126 TEST_F(SubprocessMetricsProviderTest, SnapshotMetrics) { 133 TEST_F(SubprocessMetricsProviderTest, SnapshotMetrics) {
127 base::HistogramBase* foo = base::Histogram::FactoryGet("foo", 1, 100, 10, 0); 134 base::HistogramBase* foo = base::Histogram::FactoryGet("foo", 1, 100, 10, 0);
128 base::HistogramBase* bar = base::Histogram::FactoryGet("bar", 1, 100, 10, 0); 135 base::HistogramBase* bar = base::Histogram::FactoryGet("bar", 1, 100, 10, 0);
129 base::HistogramBase* baz = base::Histogram::FactoryGet("baz", 1, 100, 10, 0); 136 base::HistogramBase* baz = base::Histogram::FactoryGet("baz", 1, 100, 10, 0);
(...skipping 24 matching lines...) Expand all
154 foo->Add(10); 161 foo->Add(10);
155 bar->Add(20); 162 bar->Add(20);
156 DeregisterSubprocessAllocator(123); 163 DeregisterSubprocessAllocator(123);
157 EXPECT_EQ(2U, GetSnapshotHistogramCount()); 164 EXPECT_EQ(2U, GetSnapshotHistogramCount());
158 165
159 // Further snapshots should be empty even if things have changed. 166 // Further snapshots should be empty even if things have changed.
160 foo->Add(10); 167 foo->Add(10);
161 bar->Add(20); 168 bar->Add(20);
162 EXPECT_EQ(0U, GetSnapshotHistogramCount()); 169 EXPECT_EQ(0U, GetSnapshotHistogramCount());
163 } 170 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698