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

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

Issue 1267963002: [tracing] Throttle rate of heavy dumps and support to request light/heavy dumps (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@light_dumps
Patch Set: Fix win build. Created 5 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
« no previous file with comments | « base/trace_event/memory_dump_manager.cc ('k') | base/trace_event/memory_dump_request_args.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 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 "base/bind_helpers.h" 7 #include "base/bind_helpers.h"
8 #include "base/memory/scoped_vector.h" 8 #include "base/memory/scoped_vector.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
11 #include "base/thread_task_runner_handle.h" 11 #include "base/thread_task_runner_handle.h"
12 #include "base/threading/thread.h" 12 #include "base/threading/thread.h"
13 #include "base/trace_event/memory_dump_provider.h" 13 #include "base/trace_event/memory_dump_provider.h"
14 #include "base/trace_event/process_memory_dump.h" 14 #include "base/trace_event/process_memory_dump.h"
15 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 17
18 using testing::_; 18 using testing::_;
19 using testing::Between; 19 using testing::Between;
20 using testing::Invoke; 20 using testing::Invoke;
21 using testing::Return; 21 using testing::Return;
22 22
23 namespace base { 23 namespace base {
24 namespace trace_event { 24 namespace trace_event {
25 namespace {
26 MemoryDumpArgs high_detail_args = {MemoryDumpArgs::LEVEL_OF_DETAIL_HIGH};
27 MemoryDumpArgs low_detail_args = {MemoryDumpArgs::LEVEL_OF_DETAIL_LOW};
28 }
25 29
26 // Testing MemoryDumpManagerDelegate which short-circuits dump requests locally 30 // Testing MemoryDumpManagerDelegate which short-circuits dump requests locally
27 // instead of performing IPC dances. 31 // instead of performing IPC dances.
28 class MemoryDumpManagerDelegateForTesting : public MemoryDumpManagerDelegate { 32 class MemoryDumpManagerDelegateForTesting : public MemoryDumpManagerDelegate {
29 public: 33 public:
30 void RequestGlobalMemoryDump(const MemoryDumpRequestArgs& args, 34 void RequestGlobalMemoryDump(const MemoryDumpRequestArgs& args,
31 const MemoryDumpCallback& callback) override { 35 const MemoryDumpCallback& callback) override {
32 CreateProcessDump(args, callback); 36 CreateProcessDump(args, callback);
33 } 37 }
34 38
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 MemoryDumpManagerDelegateForTesting delegate_; 87 MemoryDumpManagerDelegateForTesting delegate_;
84 88
85 // We want our singleton torn down after each test. 89 // We want our singleton torn down after each test.
86 ShadowingAtExitManager at_exit_manager_; 90 ShadowingAtExitManager at_exit_manager_;
87 }; 91 };
88 92
89 class MockDumpProvider : public MemoryDumpProvider { 93 class MockDumpProvider : public MemoryDumpProvider {
90 public: 94 public:
91 MockDumpProvider() 95 MockDumpProvider()
92 : dump_provider_to_register_or_unregister(nullptr), 96 : dump_provider_to_register_or_unregister(nullptr),
93 last_session_state_(nullptr) {} 97 last_session_state_(nullptr),
98 level_of_detail_(MemoryDumpArgs::LEVEL_OF_DETAIL_HIGH) {}
94 99
95 // Ctor used by the RespectTaskRunnerAffinity test. 100 // Ctor used by the RespectTaskRunnerAffinity test.
96 explicit MockDumpProvider( 101 explicit MockDumpProvider(
97 const scoped_refptr<SingleThreadTaskRunner>& task_runner) 102 const scoped_refptr<SingleThreadTaskRunner>& task_runner)
98 : last_session_state_(nullptr), task_runner_(task_runner) {} 103 : last_session_state_(nullptr),
104 task_runner_(task_runner),
105 level_of_detail_(MemoryDumpArgs::LEVEL_OF_DETAIL_HIGH) {}
106
107 // Ctor used by CheckMemoryDumpArgs test.
108 explicit MockDumpProvider(const MemoryDumpArgs::LevelOfDetail level_of_detail)
109 : last_session_state_(nullptr), level_of_detail_(level_of_detail) {}
99 110
100 virtual ~MockDumpProvider() {} 111 virtual ~MockDumpProvider() {}
101 112
102 MOCK_METHOD2(OnMemoryDump, 113 MOCK_METHOD2(OnMemoryDump,
103 bool(const MemoryDumpArgs& args, ProcessMemoryDump* pmd)); 114 bool(const MemoryDumpArgs& args, ProcessMemoryDump* pmd));
104 115
105 // OnMemoryDump() override for the RespectTaskRunnerAffinity test. 116 // OnMemoryDump() override for the RespectTaskRunnerAffinity test.
106 bool OnMemoryDump_CheckTaskRunner(const MemoryDumpArgs& args, 117 bool OnMemoryDump_CheckTaskRunner(const MemoryDumpArgs& args,
107 ProcessMemoryDump* pmd) { 118 ProcessMemoryDump* pmd) {
108 EXPECT_TRUE(task_runner_->RunsTasksOnCurrentThread()); 119 EXPECT_TRUE(task_runner_->RunsTasksOnCurrentThread());
(...skipping 19 matching lines...) Expand all
128 } 139 }
129 140
130 // OnMemoryDump() override for the UnegisterDumperWhileDumping test. 141 // OnMemoryDump() override for the UnegisterDumperWhileDumping test.
131 bool OnMemoryDump_UnregisterDumpProvider(const MemoryDumpArgs& args, 142 bool OnMemoryDump_UnregisterDumpProvider(const MemoryDumpArgs& args,
132 ProcessMemoryDump* pmd) { 143 ProcessMemoryDump* pmd) {
133 MemoryDumpManager::GetInstance()->UnregisterDumpProvider( 144 MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
134 dump_provider_to_register_or_unregister); 145 dump_provider_to_register_or_unregister);
135 return true; 146 return true;
136 } 147 }
137 148
149 // OnMemoryDump() override for the CheckMemoryDumpArgs test.
150 bool OnMemoryDump_CheckMemoryDumpArgs(const MemoryDumpArgs& args,
151 ProcessMemoryDump* pmd) {
152 EXPECT_EQ(level_of_detail_, args.level_of_detail);
153 return true;
154 }
155
138 // Used by OnMemoryDump_(Un)RegisterExtraDumpProvider. 156 // Used by OnMemoryDump_(Un)RegisterExtraDumpProvider.
139 MemoryDumpProvider* dump_provider_to_register_or_unregister; 157 MemoryDumpProvider* dump_provider_to_register_or_unregister;
140 158
141 private: 159 private:
142 MemoryDumpSessionState* last_session_state_; 160 MemoryDumpSessionState* last_session_state_;
143 scoped_refptr<SingleThreadTaskRunner> task_runner_; 161 scoped_refptr<SingleThreadTaskRunner> task_runner_;
162 const MemoryDumpArgs::LevelOfDetail level_of_detail_;
144 }; 163 };
145 164
146 TEST_F(MemoryDumpManagerTest, SingleDumper) { 165 TEST_F(MemoryDumpManagerTest, SingleDumper) {
147 MockDumpProvider mdp; 166 MockDumpProvider mdp;
148 mdm_->RegisterDumpProvider(&mdp); 167 mdm_->RegisterDumpProvider(&mdp);
149 168
150 // Check that the dumper is not called if the memory category is not enabled. 169 // Check that the dumper is not called if the memory category is not enabled.
151 EnableTracing("foo-and-bar-but-not-memory"); 170 EnableTracing("foo-and-bar-but-not-memory");
152 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); 171 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0);
153 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED); 172 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
173 high_detail_args);
154 DisableTracing(); 174 DisableTracing();
155 175
156 // Now repeat enabling the memory category and check that the dumper is 176 // Now repeat enabling the memory category and check that the dumper is
157 // invoked this time. 177 // invoked this time.
158 EnableTracing(kTraceCategory); 178 EnableTracing(kTraceCategory);
159 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(3).WillRepeatedly(Return(true)); 179 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(3).WillRepeatedly(Return(true));
160 for (int i = 0; i < 3; ++i) 180 for (int i = 0; i < 3; ++i)
161 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED); 181 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
182 high_detail_args);
162 DisableTracing(); 183 DisableTracing();
163 184
164 mdm_->UnregisterDumpProvider(&mdp); 185 mdm_->UnregisterDumpProvider(&mdp);
165 186
166 // Finally check the unregister logic (no calls to the mdp after unregister). 187 // Finally check the unregister logic (no calls to the mdp after unregister).
167 EnableTracing(kTraceCategory); 188 EnableTracing(kTraceCategory);
168 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); 189 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0);
169 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED); 190 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
191 high_detail_args);
170 TraceLog::GetInstance()->SetDisabled(); 192 TraceLog::GetInstance()->SetDisabled();
171 } 193 }
172 194
195 TEST_F(MemoryDumpManagerTest, CheckMemoryDumpArgs) {
196 // Check that requesting dumps with high level of detail actually propagates
197 // to OnMemoryDump() call on dump providers.
198 MockDumpProvider mdp_high_detail(MemoryDumpArgs::LEVEL_OF_DETAIL_HIGH);
199 mdm_->RegisterDumpProvider(&mdp_high_detail);
200
201 EnableTracing(kTraceCategory);
202 EXPECT_CALL(mdp_high_detail, OnMemoryDump(_, _))
203 .Times(1)
204 .WillRepeatedly(
205 Invoke(&mdp_high_detail,
206 &MockDumpProvider::OnMemoryDump_CheckMemoryDumpArgs));
207 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
208 high_detail_args);
209 DisableTracing();
210 mdm_->UnregisterDumpProvider(&mdp_high_detail);
211
212 // Check that requesting dumps with low level of detail actually propagates to
213 // OnMemoryDump() call on dump providers.
214 MockDumpProvider mdp_low_detail(MemoryDumpArgs::LEVEL_OF_DETAIL_LOW);
215 mdm_->RegisterDumpProvider(&mdp_low_detail);
216
217 EnableTracing(kTraceCategory);
218 EXPECT_CALL(mdp_low_detail, OnMemoryDump(_, _))
219 .Times(1)
220 .WillRepeatedly(
221 Invoke(&mdp_low_detail,
222 &MockDumpProvider::OnMemoryDump_CheckMemoryDumpArgs));
223 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
224 low_detail_args);
225 DisableTracing();
226 mdm_->UnregisterDumpProvider(&mdp_low_detail);
227 }
228
173 TEST_F(MemoryDumpManagerTest, SharedSessionState) { 229 TEST_F(MemoryDumpManagerTest, SharedSessionState) {
174 MockDumpProvider mdp1; 230 MockDumpProvider mdp1;
175 MockDumpProvider mdp2; 231 MockDumpProvider mdp2;
176 mdm_->RegisterDumpProvider(&mdp1); 232 mdm_->RegisterDumpProvider(&mdp1);
177 mdm_->RegisterDumpProvider(&mdp2); 233 mdm_->RegisterDumpProvider(&mdp2);
178 234
179 EnableTracing(kTraceCategory); 235 EnableTracing(kTraceCategory);
180 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) 236 EXPECT_CALL(mdp1, OnMemoryDump(_, _))
181 .Times(2) 237 .Times(2)
182 .WillRepeatedly( 238 .WillRepeatedly(
183 Invoke(&mdp1, &MockDumpProvider::OnMemoryDump_CheckSessionState)); 239 Invoke(&mdp1, &MockDumpProvider::OnMemoryDump_CheckSessionState));
184 EXPECT_CALL(mdp2, OnMemoryDump(_, _)) 240 EXPECT_CALL(mdp2, OnMemoryDump(_, _))
185 .Times(2) 241 .Times(2)
186 .WillRepeatedly( 242 .WillRepeatedly(
187 Invoke(&mdp2, &MockDumpProvider::OnMemoryDump_CheckSessionState)); 243 Invoke(&mdp2, &MockDumpProvider::OnMemoryDump_CheckSessionState));
188 244
189 for (int i = 0; i < 2; ++i) 245 for (int i = 0; i < 2; ++i)
190 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED); 246 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
247 high_detail_args);
191 248
192 DisableTracing(); 249 DisableTracing();
193 } 250 }
194 251
195 TEST_F(MemoryDumpManagerTest, MultipleDumpers) { 252 TEST_F(MemoryDumpManagerTest, MultipleDumpers) {
196 MockDumpProvider mdp1; 253 MockDumpProvider mdp1;
197 MockDumpProvider mdp2; 254 MockDumpProvider mdp2;
198 255
199 // Enable only mdp1. 256 // Enable only mdp1.
200 mdm_->RegisterDumpProvider(&mdp1); 257 mdm_->RegisterDumpProvider(&mdp1);
201 EnableTracing(kTraceCategory); 258 EnableTracing(kTraceCategory);
202 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(1).WillRepeatedly(Return(true)); 259 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(1).WillRepeatedly(Return(true));
203 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).Times(0); 260 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).Times(0);
204 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED); 261 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
262 high_detail_args);
205 DisableTracing(); 263 DisableTracing();
206 264
207 // Invert: enable mdp1 and disable mdp2. 265 // Invert: enable mdp1 and disable mdp2.
208 mdm_->UnregisterDumpProvider(&mdp1); 266 mdm_->UnregisterDumpProvider(&mdp1);
209 mdm_->RegisterDumpProvider(&mdp2); 267 mdm_->RegisterDumpProvider(&mdp2);
210 EnableTracing(kTraceCategory); 268 EnableTracing(kTraceCategory);
211 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(0); 269 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(0);
212 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).Times(1).WillRepeatedly(Return(true)); 270 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).Times(1).WillRepeatedly(Return(true));
213 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED); 271 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
272 high_detail_args);
214 DisableTracing(); 273 DisableTracing();
215 274
216 // Enable both mdp1 and mdp2. 275 // Enable both mdp1 and mdp2.
217 mdm_->RegisterDumpProvider(&mdp1); 276 mdm_->RegisterDumpProvider(&mdp1);
218 EnableTracing(kTraceCategory); 277 EnableTracing(kTraceCategory);
219 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(1).WillRepeatedly(Return(true)); 278 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(1).WillRepeatedly(Return(true));
220 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).Times(1).WillRepeatedly(Return(true)); 279 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).Times(1).WillRepeatedly(Return(true));
221 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED); 280 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
281 high_detail_args);
222 DisableTracing(); 282 DisableTracing();
223 } 283 }
224 284
225 // Checks that the MemoryDumpManager respects the thread affinity when a 285 // Checks that the MemoryDumpManager respects the thread affinity when a
226 // MemoryDumpProvider specifies a task_runner(). The test starts creating 8 286 // MemoryDumpProvider specifies a task_runner(). The test starts creating 8
227 // threads and registering a MemoryDumpProvider on each of them. At each 287 // threads and registering a MemoryDumpProvider on each of them. At each
228 // iteration, one thread is removed, to check the live unregistration logic. 288 // iteration, one thread is removed, to check the live unregistration logic.
229 TEST_F(MemoryDumpManagerTest, RespectTaskRunnerAffinity) { 289 TEST_F(MemoryDumpManagerTest, RespectTaskRunnerAffinity) {
230 const uint32 kNumInitialThreads = 8; 290 const uint32 kNumInitialThreads = 8;
231 291
(...skipping 17 matching lines...) Expand all
249 309
250 EnableTracing(kTraceCategory); 310 EnableTracing(kTraceCategory);
251 311
252 while (!threads.empty()) { 312 while (!threads.empty()) {
253 last_callback_success_ = false; 313 last_callback_success_ = false;
254 { 314 {
255 RunLoop run_loop; 315 RunLoop run_loop;
256 MemoryDumpCallback callback = 316 MemoryDumpCallback callback =
257 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter, Unretained(this), 317 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter, Unretained(this),
258 MessageLoop::current()->task_runner(), run_loop.QuitClosure()); 318 MessageLoop::current()->task_runner(), run_loop.QuitClosure());
259 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, callback); 319 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
320 high_detail_args, callback);
260 // This nested message loop (|run_loop|) will be quit if and only if 321 // This nested message loop (|run_loop|) will be quit if and only if
261 // the RequestGlobalDump callback is invoked. 322 // the RequestGlobalDump callback is invoked.
262 run_loop.Run(); 323 run_loop.Run();
263 } 324 }
264 EXPECT_TRUE(last_callback_success_); 325 EXPECT_TRUE(last_callback_success_);
265 326
266 // Unregister a MDP and destroy one thread at each iteration to check the 327 // Unregister a MDP and destroy one thread at each iteration to check the
267 // live unregistration logic. The unregistration needs to happen on the same 328 // live unregistration logic. The unregistration needs to happen on the same
268 // thread the MDP belongs to. 329 // thread the MDP belongs to.
269 { 330 {
(...skipping 26 matching lines...) Expand all
296 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) 357 EXPECT_CALL(mdp1, OnMemoryDump(_, _))
297 .Times(MemoryDumpManager::kMaxConsecutiveFailuresCount) 358 .Times(MemoryDumpManager::kMaxConsecutiveFailuresCount)
298 .WillRepeatedly(Return(false)); 359 .WillRepeatedly(Return(false));
299 360
300 EXPECT_CALL(mdp2, OnMemoryDump(_, _)) 361 EXPECT_CALL(mdp2, OnMemoryDump(_, _))
301 .Times(1 + MemoryDumpManager::kMaxConsecutiveFailuresCount) 362 .Times(1 + MemoryDumpManager::kMaxConsecutiveFailuresCount)
302 .WillOnce(Return(false)) 363 .WillOnce(Return(false))
303 .WillRepeatedly(Return(true)); 364 .WillRepeatedly(Return(true));
304 for (int i = 0; i < 1 + MemoryDumpManager::kMaxConsecutiveFailuresCount; 365 for (int i = 0; i < 1 + MemoryDumpManager::kMaxConsecutiveFailuresCount;
305 i++) { 366 i++) {
306 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED); 367 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
368 high_detail_args);
307 } 369 }
308 370
309 DisableTracing(); 371 DisableTracing();
310 } 372 }
311 373
312 // Sneakily register an extra memory dump provider while an existing one is 374 // Sneakily register an extra memory dump provider while an existing one is
313 // dumping and expect it to take part in the already active tracing session. 375 // dumping and expect it to take part in the already active tracing session.
314 TEST_F(MemoryDumpManagerTest, RegisterDumperWhileDumping) { 376 TEST_F(MemoryDumpManagerTest, RegisterDumperWhileDumping) {
315 MockDumpProvider mdp1; 377 MockDumpProvider mdp1;
316 MockDumpProvider mdp2; 378 MockDumpProvider mdp2;
317 379
318 mdp1.dump_provider_to_register_or_unregister = &mdp2; 380 mdp1.dump_provider_to_register_or_unregister = &mdp2;
319 mdm_->RegisterDumpProvider(&mdp1); 381 mdm_->RegisterDumpProvider(&mdp1);
320 EnableTracing(kTraceCategory); 382 EnableTracing(kTraceCategory);
321 383
322 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) 384 EXPECT_CALL(mdp1, OnMemoryDump(_, _))
323 .Times(4) 385 .Times(4)
324 .WillOnce(Return(true)) 386 .WillOnce(Return(true))
325 .WillOnce(Invoke( 387 .WillOnce(Invoke(
326 &mdp1, &MockDumpProvider::OnMemoryDump_RegisterExtraDumpProvider)) 388 &mdp1, &MockDumpProvider::OnMemoryDump_RegisterExtraDumpProvider))
327 .WillRepeatedly(Return(true)); 389 .WillRepeatedly(Return(true));
328 390
329 // Depending on the insertion order (before or after mdp1), mdp2 might be 391 // Depending on the insertion order (before or after mdp1), mdp2 might be
330 // called also immediately after it gets registered. 392 // called also immediately after it gets registered.
331 EXPECT_CALL(mdp2, OnMemoryDump(_, _)) 393 EXPECT_CALL(mdp2, OnMemoryDump(_, _))
332 .Times(Between(2, 3)) 394 .Times(Between(2, 3))
333 .WillRepeatedly(Return(true)); 395 .WillRepeatedly(Return(true));
334 396
335 for (int i = 0; i < 4; i++) { 397 for (int i = 0; i < 4; i++) {
336 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED); 398 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
399 high_detail_args);
337 } 400 }
338 401
339 DisableTracing(); 402 DisableTracing();
340 } 403 }
341 404
342 // Like the above, but suddenly unregister the dump provider. 405 // Like the above, but suddenly unregister the dump provider.
343 TEST_F(MemoryDumpManagerTest, UnregisterDumperWhileDumping) { 406 TEST_F(MemoryDumpManagerTest, UnregisterDumperWhileDumping) {
344 MockDumpProvider mdp1; 407 MockDumpProvider mdp1;
345 MockDumpProvider mdp2; 408 MockDumpProvider mdp2;
346 409
347 mdm_->RegisterDumpProvider(&mdp1, ThreadTaskRunnerHandle::Get()); 410 mdm_->RegisterDumpProvider(&mdp1, ThreadTaskRunnerHandle::Get());
348 mdm_->RegisterDumpProvider(&mdp2, ThreadTaskRunnerHandle::Get()); 411 mdm_->RegisterDumpProvider(&mdp2, ThreadTaskRunnerHandle::Get());
349 mdp1.dump_provider_to_register_or_unregister = &mdp2; 412 mdp1.dump_provider_to_register_or_unregister = &mdp2;
350 EnableTracing(kTraceCategory); 413 EnableTracing(kTraceCategory);
351 414
352 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) 415 EXPECT_CALL(mdp1, OnMemoryDump(_, _))
353 .Times(4) 416 .Times(4)
354 .WillOnce(Return(true)) 417 .WillOnce(Return(true))
355 .WillOnce( 418 .WillOnce(
356 Invoke(&mdp1, &MockDumpProvider::OnMemoryDump_UnregisterDumpProvider)) 419 Invoke(&mdp1, &MockDumpProvider::OnMemoryDump_UnregisterDumpProvider))
357 .WillRepeatedly(Return(true)); 420 .WillRepeatedly(Return(true));
358 421
359 // Depending on the insertion order (before or after mdp1), mdp2 might have 422 // Depending on the insertion order (before or after mdp1), mdp2 might have
360 // been already called when OnMemoryDump_UnregisterDumpProvider happens. 423 // been already called when OnMemoryDump_UnregisterDumpProvider happens.
361 EXPECT_CALL(mdp2, OnMemoryDump(_, _)) 424 EXPECT_CALL(mdp2, OnMemoryDump(_, _))
362 .Times(Between(1, 2)) 425 .Times(Between(1, 2))
363 .WillRepeatedly(Return(true)); 426 .WillRepeatedly(Return(true));
364 427
365 for (int i = 0; i < 4; i++) { 428 for (int i = 0; i < 4; i++) {
366 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED); 429 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
430 high_detail_args);
367 } 431 }
368 432
369 DisableTracing(); 433 DisableTracing();
370 } 434 }
371 435
372 // Ensures that a NACK callback is invoked if RequestGlobalDump is called when 436 // Ensures that a NACK callback is invoked if RequestGlobalDump is called when
373 // tracing is not enabled. 437 // tracing is not enabled.
374 TEST_F(MemoryDumpManagerTest, CallbackCalledOnFailure) { 438 TEST_F(MemoryDumpManagerTest, CallbackCalledOnFailure) {
375 MockDumpProvider mdp1; 439 MockDumpProvider mdp1;
376 440
377 mdm_->RegisterDumpProvider(&mdp1); 441 mdm_->RegisterDumpProvider(&mdp1);
378 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(0); 442 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(0);
379 443
380 last_callback_success_ = true; 444 last_callback_success_ = true;
381 { 445 {
382 RunLoop run_loop; 446 RunLoop run_loop;
383 MemoryDumpCallback callback = 447 MemoryDumpCallback callback =
384 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter, Unretained(this), 448 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter, Unretained(this),
385 MessageLoop::current()->task_runner(), run_loop.QuitClosure()); 449 MessageLoop::current()->task_runner(), run_loop.QuitClosure());
386 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, callback); 450 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
451 high_detail_args, callback);
387 run_loop.Run(); 452 run_loop.Run();
388 } 453 }
389 EXPECT_FALSE(last_callback_success_); 454 EXPECT_FALSE(last_callback_success_);
390 } 455 }
391 456
392 } // namespace trace_event 457 } // namespace trace_event
393 } // namespace base 458 } // namespace base
OLDNEW
« no previous file with comments | « base/trace_event/memory_dump_manager.cc ('k') | base/trace_event/memory_dump_request_args.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698