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

Side by Side Diff: base/trace_event/memory_dump_manager_unittest.cc

Issue 2694083005: memory-infra: Finish moving memory_infra from TracingController (Closed)
Patch Set: style: auto must not deduce to raw pointer Created 3 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 | « base/trace_event/memory_dump_manager.cc ('k') | chrome/browser/BUILD.gn » ('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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/trace_event/memory_dump_manager.h" 5 #include "base/trace_event/memory_dump_manager.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <vector> 10 #include <vector>
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 // |task| is executed. 112 // |task| is executed.
113 event.Wait(); 113 event.Wait();
114 } 114 }
115 115
116 } // namespace 116 } // namespace
117 117
118 // Testing MemoryDumpManagerDelegate which, by default, short-circuits dump 118 // Testing MemoryDumpManagerDelegate which, by default, short-circuits dump
119 // requests locally to the MemoryDumpManager instead of performing IPC dances. 119 // requests locally to the MemoryDumpManager instead of performing IPC dances.
120 class MemoryDumpManagerDelegateForTesting : public MemoryDumpManagerDelegate { 120 class MemoryDumpManagerDelegateForTesting : public MemoryDumpManagerDelegate {
121 public: 121 public:
122 MemoryDumpManagerDelegateForTesting() { 122 MemoryDumpManagerDelegateForTesting(bool is_coordinator)
123 : is_coordinator_(is_coordinator) {
123 ON_CALL(*this, RequestGlobalMemoryDump(_, _)) 124 ON_CALL(*this, RequestGlobalMemoryDump(_, _))
124 .WillByDefault(Invoke( 125 .WillByDefault(Invoke(
125 this, &MemoryDumpManagerDelegateForTesting::CreateProcessDump)); 126 this, &MemoryDumpManagerDelegateForTesting::CreateProcessDump));
126 } 127 }
127 128
128 MOCK_METHOD2(RequestGlobalMemoryDump, 129 MOCK_METHOD2(RequestGlobalMemoryDump,
129 void(const MemoryDumpRequestArgs& args, 130 void(const MemoryDumpRequestArgs& args,
130 const MemoryDumpCallback& callback)); 131 const MemoryDumpCallback& callback));
131 132
132 uint64_t GetTracingProcessId() const override { 133 bool IsCoordinator() const override { return is_coordinator_; }
133 NOTREACHED();
134 return MemoryDumpManager::kInvalidTracingProcessId;
135 }
136 134
137 // Promote the CreateProcessDump to public so it can be used by test fixtures. 135 // Promote the CreateProcessDump to public so it can be used by test fixtures.
138 using MemoryDumpManagerDelegate::CreateProcessDump; 136 using MemoryDumpManagerDelegate::CreateProcessDump;
137
138 private:
139 bool is_coordinator_;
139 }; 140 };
140 141
141 class MockMemoryDumpProvider : public MemoryDumpProvider { 142 class MockMemoryDumpProvider : public MemoryDumpProvider {
142 public: 143 public:
143 MOCK_METHOD0(Destructor, void()); 144 MOCK_METHOD0(Destructor, void());
144 MOCK_METHOD2(OnMemoryDump, 145 MOCK_METHOD2(OnMemoryDump,
145 bool(const MemoryDumpArgs& args, ProcessMemoryDump* pmd)); 146 bool(const MemoryDumpArgs& args, ProcessMemoryDump* pmd));
146 MOCK_METHOD1(PollFastMemoryTotal, void(uint64_t* memory_total)); 147 MOCK_METHOD1(PollFastMemoryTotal, void(uint64_t* memory_total));
147 MOCK_METHOD0(SuspendFastMemoryPolling, void()); 148 MOCK_METHOD0(SuspendFastMemoryPolling, void());
148 149
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 class MemoryDumpManagerTest : public testing::Test { 214 class MemoryDumpManagerTest : public testing::Test {
214 public: 215 public:
215 MemoryDumpManagerTest() : testing::Test(), kDefaultOptions() {} 216 MemoryDumpManagerTest() : testing::Test(), kDefaultOptions() {}
216 217
217 void SetUp() override { 218 void SetUp() override {
218 last_callback_success_ = false; 219 last_callback_success_ = false;
219 message_loop_.reset(new MessageLoop()); 220 message_loop_.reset(new MessageLoop());
220 mdm_.reset(new MemoryDumpManager()); 221 mdm_.reset(new MemoryDumpManager());
221 MemoryDumpManager::SetInstanceForTesting(mdm_.get()); 222 MemoryDumpManager::SetInstanceForTesting(mdm_.get());
222 ASSERT_EQ(mdm_.get(), MemoryDumpManager::GetInstance()); 223 ASSERT_EQ(mdm_.get(), MemoryDumpManager::GetInstance());
223 delegate_.reset(new MemoryDumpManagerDelegateForTesting);
224 } 224 }
225 225
226 void TearDown() override { 226 void TearDown() override {
227 MemoryDumpManager::SetInstanceForTesting(nullptr); 227 MemoryDumpManager::SetInstanceForTesting(nullptr);
228 delegate_.reset();
228 mdm_.reset(); 229 mdm_.reset();
229 delegate_.reset();
230 message_loop_.reset(); 230 message_loop_.reset();
231 TraceLog::DeleteForTesting(); 231 TraceLog::DeleteForTesting();
232 } 232 }
233 233
234 // Turns a Closure into a MemoryDumpCallback, keeping track of the callback 234 // Turns a Closure into a MemoryDumpCallback, keeping track of the callback
235 // result and taking care of posting the closure on the correct task runner. 235 // result and taking care of posting the closure on the correct task runner.
236 void DumpCallbackAdapter(scoped_refptr<SingleThreadTaskRunner> task_runner, 236 void DumpCallbackAdapter(scoped_refptr<SingleThreadTaskRunner> task_runner,
237 Closure closure, 237 Closure closure,
238 uint64_t dump_guid, 238 uint64_t dump_guid,
239 bool success) { 239 bool success) {
240 last_callback_success_ = success; 240 last_callback_success_ = success;
241 task_runner->PostTask(FROM_HERE, closure); 241 task_runner->PostTask(FROM_HERE, closure);
242 } 242 }
243 243
244 void PollFastMemoryTotal(uint64_t* memory_total) { 244 void PollFastMemoryTotal(uint64_t* memory_total) {
245 mdm_->PollFastMemoryTotal(memory_total); 245 mdm_->PollFastMemoryTotal(memory_total);
246 } 246 }
247 247
248 protected: 248 protected:
249 void InitializeMemoryDumpManager(bool is_coordinator) { 249 void InitializeMemoryDumpManager(bool is_coordinator) {
250 mdm_->set_dumper_registrations_ignored_for_testing(true); 250 mdm_->set_dumper_registrations_ignored_for_testing(true);
251 mdm_->Initialize(delegate_.get(), is_coordinator); 251 delegate_.reset(new MemoryDumpManagerDelegateForTesting(is_coordinator));
252 mdm_->Initialize(delegate_.get());
252 } 253 }
253 254
254 void RequestGlobalDumpAndWait(MemoryDumpType dump_type, 255 void RequestGlobalDumpAndWait(MemoryDumpType dump_type,
255 MemoryDumpLevelOfDetail level_of_detail) { 256 MemoryDumpLevelOfDetail level_of_detail) {
256 RunLoop run_loop; 257 RunLoop run_loop;
257 MemoryDumpCallback callback = 258 MemoryDumpCallback callback =
258 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter, Unretained(this), 259 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter, Unretained(this),
259 ThreadTaskRunnerHandle::Get(), run_loop.QuitClosure()); 260 ThreadTaskRunnerHandle::Get(), run_loop.QuitClosure());
260 mdm_->RequestGlobalDump(dump_type, level_of_detail, callback); 261 mdm_->RequestGlobalDump(dump_type, level_of_detail, callback);
261 run_loop.Run(); 262 run_loop.Run();
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 // began, it will still late-join the party (real use case: startup tracing). 891 // began, it will still late-join the party (real use case: startup tracing).
891 TEST_F(MemoryDumpManagerTest, InitializedAfterStartOfTracing) { 892 TEST_F(MemoryDumpManagerTest, InitializedAfterStartOfTracing) {
892 MockMemoryDumpProvider mdp; 893 MockMemoryDumpProvider mdp;
893 RegisterDumpProvider(&mdp, nullptr); 894 RegisterDumpProvider(&mdp, nullptr);
894 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); 895 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory);
895 896
896 // First check that a RequestGlobalDump() issued before the MemoryDumpManager 897 // First check that a RequestGlobalDump() issued before the MemoryDumpManager
897 // initialization gets NACK-ed cleanly. 898 // initialization gets NACK-ed cleanly.
898 { 899 {
899 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); 900 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0);
900 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(0);
901 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, 901 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED,
902 MemoryDumpLevelOfDetail::DETAILED); 902 MemoryDumpLevelOfDetail::DETAILED);
903 EXPECT_FALSE(last_callback_success_); 903 EXPECT_FALSE(last_callback_success_);
904 } 904 }
905 905
906 // Now late-initialize the MemoryDumpManager and check that the 906 // Now late-initialize the MemoryDumpManager and check that the
907 // RequestGlobalDump completes successfully. 907 // RequestGlobalDump completes successfully.
908 { 908 {
909 InitializeMemoryDumpManager(false /* is_coordinator */);
909 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(1); 910 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(1);
910 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); 911 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1);
911 InitializeMemoryDumpManager(false /* is_coordinator */);
912 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, 912 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED,
913 MemoryDumpLevelOfDetail::DETAILED); 913 MemoryDumpLevelOfDetail::DETAILED);
914 EXPECT_TRUE(last_callback_success_); 914 EXPECT_TRUE(last_callback_success_);
915 } 915 }
916 DisableTracing(); 916 DisableTracing();
917 } 917 }
918 918
919 // This test (and the MemoryDumpManagerTestCoordinator below) crystallizes the 919 // This test (and the MemoryDumpManagerTestCoordinator below) crystallizes the
920 // expectations of the chrome://tracing UI and chrome telemetry w.r.t. periodic 920 // expectations of the chrome://tracing UI and chrome telemetry w.r.t. periodic
921 // dumps in memory-infra, handling gracefully the transition between the legacy 921 // dumps in memory-infra, handling gracefully the transition between the legacy
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
1286 thread.Start(); 1286 thread.Start();
1287 RegisterDumpProvider(&mdp1, thread.task_runner(), kDefaultOptions, 1287 RegisterDumpProvider(&mdp1, thread.task_runner(), kDefaultOptions,
1288 "BlacklistTestDumpProvider"); 1288 "BlacklistTestDumpProvider");
1289 // Unregistering on wrong thread should not crash. 1289 // Unregistering on wrong thread should not crash.
1290 mdm_->UnregisterDumpProvider(&mdp1); 1290 mdm_->UnregisterDumpProvider(&mdp1);
1291 thread.Stop(); 1291 thread.Stop();
1292 } 1292 }
1293 1293
1294 } // namespace trace_event 1294 } // namespace trace_event
1295 } // namespace base 1295 } // namespace base
OLDNEW
« no previous file with comments | « base/trace_event/memory_dump_manager.cc ('k') | chrome/browser/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698