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 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 } | 363 } |
364 | 364 |
365 // Checks that the MemoryDumpManager respects the thread affinity when a | 365 // Checks that the MemoryDumpManager respects the thread affinity when a |
366 // MemoryDumpProvider specifies a task_runner(). The test starts creating 8 | 366 // MemoryDumpProvider specifies a task_runner(). The test starts creating 8 |
367 // threads and registering a MemoryDumpProvider on each of them. At each | 367 // threads and registering a MemoryDumpProvider on each of them. At each |
368 // iteration, one thread is removed, to check the live unregistration logic. | 368 // iteration, one thread is removed, to check the live unregistration logic. |
369 TEST_F(MemoryDumpManagerTest, RespectTaskRunnerAffinity) { | 369 TEST_F(MemoryDumpManagerTest, RespectTaskRunnerAffinity) { |
370 InitializeMemoryDumpManager(false /* is_coordinator */); | 370 InitializeMemoryDumpManager(false /* is_coordinator */); |
371 const uint32 kNumInitialThreads = 8; | 371 const uint32 kNumInitialThreads = 8; |
372 | 372 |
373 ScopedVector<Thread> threads; | 373 std::vector<scoped_ptr<Thread>> threads; |
374 ScopedVector<MockMemoryDumpProvider> mdps; | 374 std::vector<scoped_ptr<MockMemoryDumpProvider>> mdps; |
375 | 375 |
376 // Create the threads and setup the expectations. Given that at each iteration | 376 // Create the threads and setup the expectations. Given that at each iteration |
377 // we will pop out one thread/MemoryDumpProvider, each MDP is supposed to be | 377 // we will pop out one thread/MemoryDumpProvider, each MDP is supposed to be |
378 // invoked a number of times equal to its index. | 378 // invoked a number of times equal to its index. |
379 for (uint32 i = kNumInitialThreads; i > 0; --i) { | 379 for (uint32 i = kNumInitialThreads; i > 0; --i) { |
380 Thread* thread = new Thread("test thread"); | 380 threads.push_back(make_scoped_ptr(new Thread("test thread"))); |
381 threads.push_back(thread); | 381 auto thread = threads.back().get(); |
382 threads.back()->Start(); | 382 thread->Start(); |
383 scoped_refptr<SingleThreadTaskRunner> task_runner = thread->task_runner(); | 383 scoped_refptr<SingleThreadTaskRunner> task_runner = thread->task_runner(); |
384 MockMemoryDumpProvider* mdp = new MockMemoryDumpProvider(); | 384 mdps.push_back(make_scoped_ptr(new MockMemoryDumpProvider())); |
385 mdps.push_back(mdp); | 385 auto mdp = mdps.back().get(); |
386 RegisterDumpProvider(mdp, task_runner, kDefaultOptions); | 386 RegisterDumpProvider(mdp, task_runner, kDefaultOptions); |
387 EXPECT_CALL(*mdp, OnMemoryDump(_, _)) | 387 EXPECT_CALL(*mdp, OnMemoryDump(_, _)) |
388 .Times(i) | 388 .Times(i) |
389 .WillRepeatedly(Invoke( | 389 .WillRepeatedly(Invoke( |
390 [task_runner](const MemoryDumpArgs&, ProcessMemoryDump*) -> bool { | 390 [task_runner](const MemoryDumpArgs&, ProcessMemoryDump*) -> bool { |
391 EXPECT_TRUE(task_runner->RunsTasksOnCurrentThread()); | 391 EXPECT_TRUE(task_runner->RunsTasksOnCurrentThread()); |
392 return true; | 392 return true; |
393 })); | 393 })); |
394 } | 394 } |
395 | |
396 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 395 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
397 | 396 |
398 while (!threads.empty()) { | 397 while (!threads.empty()) { |
399 last_callback_success_ = false; | 398 last_callback_success_ = false; |
400 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 399 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); |
401 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 400 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
402 MemoryDumpLevelOfDetail::DETAILED); | 401 MemoryDumpLevelOfDetail::DETAILED); |
403 EXPECT_TRUE(last_callback_success_); | 402 EXPECT_TRUE(last_callback_success_); |
404 | 403 |
405 // Unregister a MDP and destroy one thread at each iteration to check the | 404 // Unregister a MDP and destroy one thread at each iteration to check the |
406 // live unregistration logic. The unregistration needs to happen on the same | 405 // live unregistration logic. The unregistration needs to happen on the same |
407 // thread the MDP belongs to. | 406 // thread the MDP belongs to. |
408 { | 407 { |
409 RunLoop run_loop; | 408 RunLoop run_loop; |
410 Closure unregistration = | 409 Closure unregistration = |
411 Bind(&MemoryDumpManager::UnregisterDumpProvider, | 410 Bind(&MemoryDumpManager::UnregisterDumpProvider, |
412 Unretained(mdm_.get()), Unretained(mdps.back())); | 411 Unretained(mdm_.get()), Unretained(mdps.back().get())); |
413 threads.back()->task_runner()->PostTaskAndReply(FROM_HERE, unregistration, | 412 threads.back()->task_runner()->PostTaskAndReply(FROM_HERE, unregistration, |
414 run_loop.QuitClosure()); | 413 run_loop.QuitClosure()); |
415 run_loop.Run(); | 414 run_loop.Run(); |
416 } | 415 } |
417 mdps.pop_back(); | 416 mdps.pop_back(); |
418 threads.back()->Stop(); | 417 threads.back()->Stop(); |
419 threads.pop_back(); | 418 threads.pop_back(); |
420 } | 419 } |
421 | 420 |
422 DisableTracing(); | 421 DisableTracing(); |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 ASSERT_EQ(1u, trace_analyzer::CountMatches(events, Query::EventPidIs(123))); | 818 ASSERT_EQ(1u, trace_analyzer::CountMatches(events, Query::EventPidIs(123))); |
820 ASSERT_EQ(1u, trace_analyzer::CountMatches(events, Query::EventPidIs(456))); | 819 ASSERT_EQ(1u, trace_analyzer::CountMatches(events, Query::EventPidIs(456))); |
821 ASSERT_EQ(1u, trace_analyzer::CountMatches( | 820 ASSERT_EQ(1u, trace_analyzer::CountMatches( |
822 events, Query::EventPidIs(GetCurrentProcId()))); | 821 events, Query::EventPidIs(GetCurrentProcId()))); |
823 ASSERT_EQ(events[0]->id, events[1]->id); | 822 ASSERT_EQ(events[0]->id, events[1]->id); |
824 ASSERT_EQ(events[0]->id, events[2]->id); | 823 ASSERT_EQ(events[0]->id, events[2]->id); |
825 } | 824 } |
826 | 825 |
827 } // namespace trace_event | 826 } // namespace trace_event |
828 } // namespace base | 827 } // namespace base |
OLD | NEW |