OLD | NEW |
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" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 | 65 |
66 void DumpCallbackAdapter(scoped_refptr<SingleThreadTaskRunner> task_runner, | 66 void DumpCallbackAdapter(scoped_refptr<SingleThreadTaskRunner> task_runner, |
67 Closure closure, | 67 Closure closure, |
68 uint64 dump_guid, | 68 uint64 dump_guid, |
69 bool success) { | 69 bool success) { |
70 last_callback_success_ = success; | 70 last_callback_success_ = success; |
71 task_runner->PostTask(FROM_HERE, closure); | 71 task_runner->PostTask(FROM_HERE, closure); |
72 } | 72 } |
73 | 73 |
74 protected: | 74 protected: |
75 const char* kTraceCategory = MemoryDumpManager::kTraceCategoryForTesting; | |
76 | |
77 void EnableTracing(const char* category) { | 75 void EnableTracing(const char* category) { |
78 TraceLog::GetInstance()->SetEnabled( | 76 TraceLog::GetInstance()->SetEnabled( |
79 TraceConfig(category, ""), TraceLog::RECORDING_MODE); | 77 TraceConfig(category, ""), TraceLog::RECORDING_MODE); |
80 } | 78 } |
81 | 79 |
82 void DisableTracing() { TraceLog::GetInstance()->SetDisabled(); } | 80 void DisableTracing() { TraceLog::GetInstance()->SetDisabled(); } |
83 | 81 |
84 scoped_ptr<MemoryDumpManager> mdm_; | 82 scoped_ptr<MemoryDumpManager> mdm_; |
85 bool last_callback_success_; | 83 bool last_callback_success_; |
86 | 84 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 | 168 |
171 // 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. |
172 EnableTracing("foo-and-bar-but-not-memory"); | 170 EnableTracing("foo-and-bar-but-not-memory"); |
173 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); | 171 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); |
174 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 172 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
175 high_detail_args); | 173 high_detail_args); |
176 DisableTracing(); | 174 DisableTracing(); |
177 | 175 |
178 // 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 |
179 // invoked this time. | 177 // invoked this time. |
180 EnableTracing(kTraceCategory); | 178 EnableTracing(MemoryDumpManager::kTraceCategory); |
181 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(3).WillRepeatedly(Return(true)); | 179 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(3).WillRepeatedly(Return(true)); |
182 for (int i = 0; i < 3; ++i) | 180 for (int i = 0; i < 3; ++i) |
183 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 181 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
184 high_detail_args); | 182 high_detail_args); |
185 DisableTracing(); | 183 DisableTracing(); |
186 | 184 |
187 mdm_->UnregisterDumpProvider(&mdp); | 185 mdm_->UnregisterDumpProvider(&mdp); |
188 | 186 |
189 // 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). |
190 EnableTracing(kTraceCategory); | 188 EnableTracing(MemoryDumpManager::kTraceCategory); |
191 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); | 189 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); |
192 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 190 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
193 high_detail_args); | 191 high_detail_args); |
194 TraceLog::GetInstance()->SetDisabled(); | 192 TraceLog::GetInstance()->SetDisabled(); |
195 } | 193 } |
196 | 194 |
197 TEST_F(MemoryDumpManagerTest, CheckMemoryDumpArgs) { | 195 TEST_F(MemoryDumpManagerTest, CheckMemoryDumpArgs) { |
198 // Check that requesting dumps with high level of detail actually propagates | 196 // Check that requesting dumps with high level of detail actually propagates |
199 // to OnMemoryDump() call on dump providers. | 197 // to OnMemoryDump() call on dump providers. |
200 MockDumpProvider mdp_high_detail(MemoryDumpArgs::LevelOfDetail::HIGH); | 198 MockDumpProvider mdp_high_detail(MemoryDumpArgs::LevelOfDetail::HIGH); |
201 mdm_->RegisterDumpProvider(&mdp_high_detail); | 199 mdm_->RegisterDumpProvider(&mdp_high_detail); |
202 | 200 |
203 EnableTracing(kTraceCategory); | 201 EnableTracing(MemoryDumpManager::kTraceCategory); |
204 EXPECT_CALL(mdp_high_detail, OnMemoryDump(_, _)) | 202 EXPECT_CALL(mdp_high_detail, OnMemoryDump(_, _)) |
205 .Times(1) | 203 .Times(1) |
206 .WillRepeatedly( | 204 .WillRepeatedly( |
207 Invoke(&mdp_high_detail, | 205 Invoke(&mdp_high_detail, |
208 &MockDumpProvider::OnMemoryDump_CheckMemoryDumpArgs)); | 206 &MockDumpProvider::OnMemoryDump_CheckMemoryDumpArgs)); |
209 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 207 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
210 high_detail_args); | 208 high_detail_args); |
211 DisableTracing(); | 209 DisableTracing(); |
212 mdm_->UnregisterDumpProvider(&mdp_high_detail); | 210 mdm_->UnregisterDumpProvider(&mdp_high_detail); |
213 | 211 |
214 // Check that requesting dumps with low level of detail actually propagates to | 212 // Check that requesting dumps with low level of detail actually propagates to |
215 // OnMemoryDump() call on dump providers. | 213 // OnMemoryDump() call on dump providers. |
216 MockDumpProvider mdp_low_detail(MemoryDumpArgs::LevelOfDetail::LOW); | 214 MockDumpProvider mdp_low_detail(MemoryDumpArgs::LevelOfDetail::LOW); |
217 mdm_->RegisterDumpProvider(&mdp_low_detail); | 215 mdm_->RegisterDumpProvider(&mdp_low_detail); |
218 | 216 |
219 EnableTracing(kTraceCategory); | 217 EnableTracing(MemoryDumpManager::kTraceCategory); |
220 EXPECT_CALL(mdp_low_detail, OnMemoryDump(_, _)) | 218 EXPECT_CALL(mdp_low_detail, OnMemoryDump(_, _)) |
221 .Times(1) | 219 .Times(1) |
222 .WillRepeatedly( | 220 .WillRepeatedly( |
223 Invoke(&mdp_low_detail, | 221 Invoke(&mdp_low_detail, |
224 &MockDumpProvider::OnMemoryDump_CheckMemoryDumpArgs)); | 222 &MockDumpProvider::OnMemoryDump_CheckMemoryDumpArgs)); |
225 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 223 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
226 low_detail_args); | 224 low_detail_args); |
227 DisableTracing(); | 225 DisableTracing(); |
228 mdm_->UnregisterDumpProvider(&mdp_low_detail); | 226 mdm_->UnregisterDumpProvider(&mdp_low_detail); |
229 } | 227 } |
230 | 228 |
231 TEST_F(MemoryDumpManagerTest, SharedSessionState) { | 229 TEST_F(MemoryDumpManagerTest, SharedSessionState) { |
232 MockDumpProvider mdp1; | 230 MockDumpProvider mdp1; |
233 MockDumpProvider mdp2; | 231 MockDumpProvider mdp2; |
234 mdm_->RegisterDumpProvider(&mdp1); | 232 mdm_->RegisterDumpProvider(&mdp1); |
235 mdm_->RegisterDumpProvider(&mdp2); | 233 mdm_->RegisterDumpProvider(&mdp2); |
236 | 234 |
237 EnableTracing(kTraceCategory); | 235 EnableTracing(MemoryDumpManager::kTraceCategory); |
238 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) | 236 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) |
239 .Times(2) | 237 .Times(2) |
240 .WillRepeatedly( | 238 .WillRepeatedly( |
241 Invoke(&mdp1, &MockDumpProvider::OnMemoryDump_CheckSessionState)); | 239 Invoke(&mdp1, &MockDumpProvider::OnMemoryDump_CheckSessionState)); |
242 EXPECT_CALL(mdp2, OnMemoryDump(_, _)) | 240 EXPECT_CALL(mdp2, OnMemoryDump(_, _)) |
243 .Times(2) | 241 .Times(2) |
244 .WillRepeatedly( | 242 .WillRepeatedly( |
245 Invoke(&mdp2, &MockDumpProvider::OnMemoryDump_CheckSessionState)); | 243 Invoke(&mdp2, &MockDumpProvider::OnMemoryDump_CheckSessionState)); |
246 | 244 |
247 for (int i = 0; i < 2; ++i) | 245 for (int i = 0; i < 2; ++i) |
248 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 246 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
249 high_detail_args); | 247 high_detail_args); |
250 | 248 |
251 DisableTracing(); | 249 DisableTracing(); |
252 } | 250 } |
253 | 251 |
254 TEST_F(MemoryDumpManagerTest, MultipleDumpers) { | 252 TEST_F(MemoryDumpManagerTest, MultipleDumpers) { |
255 MockDumpProvider mdp1; | 253 MockDumpProvider mdp1; |
256 MockDumpProvider mdp2; | 254 MockDumpProvider mdp2; |
257 | 255 |
258 // Enable only mdp1. | 256 // Enable only mdp1. |
259 mdm_->RegisterDumpProvider(&mdp1); | 257 mdm_->RegisterDumpProvider(&mdp1); |
260 EnableTracing(kTraceCategory); | 258 EnableTracing(MemoryDumpManager::kTraceCategory); |
261 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(1).WillRepeatedly(Return(true)); | 259 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(1).WillRepeatedly(Return(true)); |
262 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).Times(0); | 260 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).Times(0); |
263 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 261 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
264 high_detail_args); | 262 high_detail_args); |
265 DisableTracing(); | 263 DisableTracing(); |
266 | 264 |
267 // Invert: enable mdp1 and disable mdp2. | 265 // Invert: enable mdp1 and disable mdp2. |
268 mdm_->UnregisterDumpProvider(&mdp1); | 266 mdm_->UnregisterDumpProvider(&mdp1); |
269 mdm_->RegisterDumpProvider(&mdp2); | 267 mdm_->RegisterDumpProvider(&mdp2); |
270 EnableTracing(kTraceCategory); | 268 EnableTracing(MemoryDumpManager::kTraceCategory); |
271 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(0); | 269 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(0); |
272 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).Times(1).WillRepeatedly(Return(true)); | 270 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).Times(1).WillRepeatedly(Return(true)); |
273 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 271 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
274 high_detail_args); | 272 high_detail_args); |
275 DisableTracing(); | 273 DisableTracing(); |
276 | 274 |
277 // Enable both mdp1 and mdp2. | 275 // Enable both mdp1 and mdp2. |
278 mdm_->RegisterDumpProvider(&mdp1); | 276 mdm_->RegisterDumpProvider(&mdp1); |
279 EnableTracing(kTraceCategory); | 277 EnableTracing(MemoryDumpManager::kTraceCategory); |
280 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(1).WillRepeatedly(Return(true)); | 278 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(1).WillRepeatedly(Return(true)); |
281 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).Times(1).WillRepeatedly(Return(true)); | 279 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).Times(1).WillRepeatedly(Return(true)); |
282 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 280 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
283 high_detail_args); | 281 high_detail_args); |
284 DisableTracing(); | 282 DisableTracing(); |
285 } | 283 } |
286 | 284 |
287 // Verify that whether OnMemoryDump is called depends only on the current | 285 // Verify that whether OnMemoryDump is called depends only on the current |
288 // registration state and not on previous registrations and dumps. | 286 // registration state and not on previous registrations and dumps. |
289 TEST_F(MemoryDumpManagerTest, RegistrationConsistency) { | 287 TEST_F(MemoryDumpManagerTest, RegistrationConsistency) { |
290 MockDumpProvider mdp; | 288 MockDumpProvider mdp; |
291 | 289 |
292 mdm_->RegisterDumpProvider(&mdp); | 290 mdm_->RegisterDumpProvider(&mdp); |
293 | 291 |
294 { | 292 { |
295 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(1); | 293 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(1); |
296 EnableTracing(kTraceCategory); | 294 EnableTracing(MemoryDumpManager::kTraceCategory); |
297 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 295 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
298 high_detail_args); | 296 high_detail_args); |
299 DisableTracing(); | 297 DisableTracing(); |
300 } | 298 } |
301 | 299 |
302 mdm_->UnregisterDumpProvider(&mdp); | 300 mdm_->UnregisterDumpProvider(&mdp); |
303 | 301 |
304 { | 302 { |
305 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); | 303 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); |
306 EnableTracing(kTraceCategory); | 304 EnableTracing(MemoryDumpManager::kTraceCategory); |
307 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 305 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
308 high_detail_args); | 306 high_detail_args); |
309 DisableTracing(); | 307 DisableTracing(); |
310 } | 308 } |
311 | 309 |
312 mdm_->RegisterDumpProvider(&mdp); | 310 mdm_->RegisterDumpProvider(&mdp); |
313 mdm_->UnregisterDumpProvider(&mdp); | 311 mdm_->UnregisterDumpProvider(&mdp); |
314 | 312 |
315 { | 313 { |
316 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); | 314 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); |
317 EnableTracing(kTraceCategory); | 315 EnableTracing(MemoryDumpManager::kTraceCategory); |
318 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 316 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
319 high_detail_args); | 317 high_detail_args); |
320 DisableTracing(); | 318 DisableTracing(); |
321 } | 319 } |
322 | 320 |
323 mdm_->RegisterDumpProvider(&mdp); | 321 mdm_->RegisterDumpProvider(&mdp); |
324 mdm_->UnregisterDumpProvider(&mdp); | 322 mdm_->UnregisterDumpProvider(&mdp); |
325 mdm_->RegisterDumpProvider(&mdp); | 323 mdm_->RegisterDumpProvider(&mdp); |
326 | 324 |
327 { | 325 { |
328 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(1); | 326 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(1); |
329 EnableTracing(kTraceCategory); | 327 EnableTracing(MemoryDumpManager::kTraceCategory); |
330 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 328 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
331 high_detail_args); | 329 high_detail_args); |
332 DisableTracing(); | 330 DisableTracing(); |
333 } | 331 } |
334 } | 332 } |
335 | 333 |
336 // Checks that the MemoryDumpManager respects the thread affinity when a | 334 // Checks that the MemoryDumpManager respects the thread affinity when a |
337 // MemoryDumpProvider specifies a task_runner(). The test starts creating 8 | 335 // MemoryDumpProvider specifies a task_runner(). The test starts creating 8 |
338 // threads and registering a MemoryDumpProvider on each of them. At each | 336 // threads and registering a MemoryDumpProvider on each of them. At each |
339 // iteration, one thread is removed, to check the live unregistration logic. | 337 // iteration, one thread is removed, to check the live unregistration logic. |
(...skipping 11 matching lines...) Expand all Loading... |
351 threads.back()->Start(); | 349 threads.back()->Start(); |
352 mdps.push_back(new MockDumpProvider(threads.back()->task_runner())); | 350 mdps.push_back(new MockDumpProvider(threads.back()->task_runner())); |
353 MockDumpProvider* mdp = mdps.back(); | 351 MockDumpProvider* mdp = mdps.back(); |
354 mdm_->RegisterDumpProvider(mdp, threads.back()->task_runner()); | 352 mdm_->RegisterDumpProvider(mdp, threads.back()->task_runner()); |
355 EXPECT_CALL(*mdp, OnMemoryDump(_, _)) | 353 EXPECT_CALL(*mdp, OnMemoryDump(_, _)) |
356 .Times(i) | 354 .Times(i) |
357 .WillRepeatedly( | 355 .WillRepeatedly( |
358 Invoke(mdp, &MockDumpProvider::OnMemoryDump_CheckTaskRunner)); | 356 Invoke(mdp, &MockDumpProvider::OnMemoryDump_CheckTaskRunner)); |
359 } | 357 } |
360 | 358 |
361 EnableTracing(kTraceCategory); | 359 EnableTracing(MemoryDumpManager::kTraceCategory); |
362 | 360 |
363 while (!threads.empty()) { | 361 while (!threads.empty()) { |
364 last_callback_success_ = false; | 362 last_callback_success_ = false; |
365 { | 363 { |
366 RunLoop run_loop; | 364 RunLoop run_loop; |
367 MemoryDumpCallback callback = | 365 MemoryDumpCallback callback = |
368 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter, Unretained(this), | 366 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter, Unretained(this), |
369 MessageLoop::current()->task_runner(), run_loop.QuitClosure()); | 367 MessageLoop::current()->task_runner(), run_loop.QuitClosure()); |
370 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 368 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
371 high_detail_args, callback); | 369 high_detail_args, callback); |
(...skipping 24 matching lines...) Expand all Loading... |
396 } | 394 } |
397 | 395 |
398 // Enable both dump providers, make sure that mdp gets disabled after 3 failures | 396 // Enable both dump providers, make sure that mdp gets disabled after 3 failures |
399 // and not disabled after 1. | 397 // and not disabled after 1. |
400 TEST_F(MemoryDumpManagerTest, DisableFailingDumpers) { | 398 TEST_F(MemoryDumpManagerTest, DisableFailingDumpers) { |
401 MockDumpProvider mdp1; | 399 MockDumpProvider mdp1; |
402 MockDumpProvider mdp2; | 400 MockDumpProvider mdp2; |
403 | 401 |
404 mdm_->RegisterDumpProvider(&mdp1); | 402 mdm_->RegisterDumpProvider(&mdp1); |
405 mdm_->RegisterDumpProvider(&mdp2); | 403 mdm_->RegisterDumpProvider(&mdp2); |
406 EnableTracing(kTraceCategory); | 404 EnableTracing(MemoryDumpManager::kTraceCategory); |
407 | 405 |
408 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) | 406 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) |
409 .Times(MemoryDumpManager::kMaxConsecutiveFailuresCount) | 407 .Times(MemoryDumpManager::kMaxConsecutiveFailuresCount) |
410 .WillRepeatedly(Return(false)); | 408 .WillRepeatedly(Return(false)); |
411 | 409 |
412 EXPECT_CALL(mdp2, OnMemoryDump(_, _)) | 410 EXPECT_CALL(mdp2, OnMemoryDump(_, _)) |
413 .Times(1 + MemoryDumpManager::kMaxConsecutiveFailuresCount) | 411 .Times(1 + MemoryDumpManager::kMaxConsecutiveFailuresCount) |
414 .WillOnce(Return(false)) | 412 .WillOnce(Return(false)) |
415 .WillRepeatedly(Return(true)); | 413 .WillRepeatedly(Return(true)); |
416 for (int i = 0; i < 1 + MemoryDumpManager::kMaxConsecutiveFailuresCount; | 414 for (int i = 0; i < 1 + MemoryDumpManager::kMaxConsecutiveFailuresCount; |
417 i++) { | 415 i++) { |
418 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 416 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
419 high_detail_args); | 417 high_detail_args); |
420 } | 418 } |
421 | 419 |
422 DisableTracing(); | 420 DisableTracing(); |
423 } | 421 } |
424 | 422 |
425 // Sneakily register an extra memory dump provider while an existing one is | 423 // Sneakily register an extra memory dump provider while an existing one is |
426 // dumping and expect it to take part in the already active tracing session. | 424 // dumping and expect it to take part in the already active tracing session. |
427 TEST_F(MemoryDumpManagerTest, RegisterDumperWhileDumping) { | 425 TEST_F(MemoryDumpManagerTest, RegisterDumperWhileDumping) { |
428 MockDumpProvider mdp1; | 426 MockDumpProvider mdp1; |
429 MockDumpProvider mdp2; | 427 MockDumpProvider mdp2; |
430 | 428 |
431 mdp1.dump_provider_to_register_or_unregister = &mdp2; | 429 mdp1.dump_provider_to_register_or_unregister = &mdp2; |
432 mdm_->RegisterDumpProvider(&mdp1); | 430 mdm_->RegisterDumpProvider(&mdp1); |
433 EnableTracing(kTraceCategory); | 431 EnableTracing(MemoryDumpManager::kTraceCategory); |
434 | 432 |
435 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) | 433 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) |
436 .Times(4) | 434 .Times(4) |
437 .WillOnce(Return(true)) | 435 .WillOnce(Return(true)) |
438 .WillOnce(Invoke( | 436 .WillOnce(Invoke( |
439 &mdp1, &MockDumpProvider::OnMemoryDump_RegisterExtraDumpProvider)) | 437 &mdp1, &MockDumpProvider::OnMemoryDump_RegisterExtraDumpProvider)) |
440 .WillRepeatedly(Return(true)); | 438 .WillRepeatedly(Return(true)); |
441 | 439 |
442 // Depending on the insertion order (before or after mdp1), mdp2 might be | 440 // Depending on the insertion order (before or after mdp1), mdp2 might be |
443 // called also immediately after it gets registered. | 441 // called also immediately after it gets registered. |
(...skipping 10 matching lines...) Expand all Loading... |
454 } | 452 } |
455 | 453 |
456 // Like the above, but suddenly unregister the dump provider. | 454 // Like the above, but suddenly unregister the dump provider. |
457 TEST_F(MemoryDumpManagerTest, UnregisterDumperWhileDumping) { | 455 TEST_F(MemoryDumpManagerTest, UnregisterDumperWhileDumping) { |
458 MockDumpProvider mdp1; | 456 MockDumpProvider mdp1; |
459 MockDumpProvider mdp2; | 457 MockDumpProvider mdp2; |
460 | 458 |
461 mdm_->RegisterDumpProvider(&mdp1, ThreadTaskRunnerHandle::Get()); | 459 mdm_->RegisterDumpProvider(&mdp1, ThreadTaskRunnerHandle::Get()); |
462 mdm_->RegisterDumpProvider(&mdp2, ThreadTaskRunnerHandle::Get()); | 460 mdm_->RegisterDumpProvider(&mdp2, ThreadTaskRunnerHandle::Get()); |
463 mdp1.dump_provider_to_register_or_unregister = &mdp2; | 461 mdp1.dump_provider_to_register_or_unregister = &mdp2; |
464 EnableTracing(kTraceCategory); | 462 EnableTracing(MemoryDumpManager::kTraceCategory); |
465 | 463 |
466 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) | 464 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) |
467 .Times(4) | 465 .Times(4) |
468 .WillOnce(Return(true)) | 466 .WillOnce(Return(true)) |
469 .WillOnce( | 467 .WillOnce( |
470 Invoke(&mdp1, &MockDumpProvider::OnMemoryDump_UnregisterDumpProvider)) | 468 Invoke(&mdp1, &MockDumpProvider::OnMemoryDump_UnregisterDumpProvider)) |
471 .WillRepeatedly(Return(true)); | 469 .WillRepeatedly(Return(true)); |
472 | 470 |
473 // Depending on the insertion order (before or after mdp1), mdp2 might have | 471 // Depending on the insertion order (before or after mdp1), mdp2 might have |
474 // been already called when OnMemoryDump_UnregisterDumpProvider happens. | 472 // been already called when OnMemoryDump_UnregisterDumpProvider happens. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 EXPECT_CALL(*mdp, OnMemoryDump(_, _)) | 517 EXPECT_CALL(*mdp, OnMemoryDump(_, _)) |
520 .Times(AtMost(1)) | 518 .Times(AtMost(1)) |
521 .WillOnce(Invoke(on_dump)); | 519 .WillOnce(Invoke(on_dump)); |
522 } | 520 } |
523 | 521 |
524 last_callback_success_ = false; | 522 last_callback_success_ = false; |
525 MemoryDumpCallback callback = | 523 MemoryDumpCallback callback = |
526 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter, Unretained(this), | 524 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter, Unretained(this), |
527 MessageLoop::current()->task_runner(), run_loop.QuitClosure()); | 525 MessageLoop::current()->task_runner(), run_loop.QuitClosure()); |
528 | 526 |
529 EnableTracing(kTraceCategory); | 527 EnableTracing(MemoryDumpManager::kTraceCategory); |
530 MemoryDumpRequestArgs request_args = {0, MemoryDumpType::EXPLICITLY_TRIGGERED, | 528 MemoryDumpRequestArgs request_args = {0, MemoryDumpType::EXPLICITLY_TRIGGERED, |
531 high_detail_args}; | 529 high_detail_args}; |
532 mdm_->CreateProcessDump(request_args, callback); | 530 mdm_->CreateProcessDump(request_args, callback); |
533 | 531 |
534 run_loop.Run(); | 532 run_loop.Run(); |
535 | 533 |
536 ASSERT_EQ(1, on_memory_dump_call_count); | 534 ASSERT_EQ(1, on_memory_dump_call_count); |
537 ASSERT_EQ(true, last_callback_success_); | 535 ASSERT_EQ(true, last_callback_success_); |
538 | 536 |
539 DisableTracing(); | 537 DisableTracing(); |
(...skipping 15 matching lines...) Expand all Loading... |
555 MessageLoop::current()->task_runner(), run_loop.QuitClosure()); | 553 MessageLoop::current()->task_runner(), run_loop.QuitClosure()); |
556 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 554 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
557 high_detail_args, callback); | 555 high_detail_args, callback); |
558 run_loop.Run(); | 556 run_loop.Run(); |
559 } | 557 } |
560 EXPECT_FALSE(last_callback_success_); | 558 EXPECT_FALSE(last_callback_success_); |
561 } | 559 } |
562 | 560 |
563 } // namespace trace_event | 561 } // namespace trace_event |
564 } // namespace base | 562 } // namespace base |
OLD | NEW |