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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
195 for (int i = 0; i < 3; ++i) | 195 for (int i = 0; i < 3; ++i) |
196 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 196 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
197 MemoryDumpLevelOfDetail::DETAILED); | 197 MemoryDumpLevelOfDetail::DETAILED); |
198 DisableTracing(); | 198 DisableTracing(); |
199 | 199 |
200 mdm_->UnregisterDumpProvider(&mdp); | 200 mdm_->UnregisterDumpProvider(&mdp); |
201 | 201 |
202 // Finally check the unregister logic: the delegate will be invoked but not | 202 // Finally check the unregister logic: the delegate will be invoked but not |
203 // the dump provider, as it has been unregistered. | 203 // the dump provider, as it has been unregistered. |
204 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 204 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
205 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 205 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(3); |
206 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); | 206 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); |
207 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 207 |
208 MemoryDumpLevelOfDetail::DETAILED); | 208 for (int i = 0; i < 3; ++i) { |
209 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | |
210 MemoryDumpLevelOfDetail::DETAILED); | |
211 } | |
209 DisableTracing(); | 212 DisableTracing(); |
210 } | 213 } |
211 | 214 |
212 // Checks that requesting dumps with high level of detail actually propagates | 215 // Checks that requesting dumps with high level of detail actually propagates |
213 // the level of the detail properly to OnMemoryDump() call on dump providers. | 216 // the level of the detail properly to OnMemoryDump() call on dump providers. |
214 TEST_F(MemoryDumpManagerTest, CheckMemoryDumpArgs) { | 217 TEST_F(MemoryDumpManagerTest, CheckMemoryDumpArgs) { |
215 InitializeMemoryDumpManager(false /* is_coordinator */); | 218 InitializeMemoryDumpManager(false /* is_coordinator */); |
216 MockMemoryDumpProvider mdp; | 219 MockMemoryDumpProvider mdp; |
217 | 220 |
218 RegisterDumpProvider(&mdp); | 221 RegisterDumpProvider(&mdp); |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
569 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 572 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
570 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 573 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); |
571 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 574 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
572 MemoryDumpLevelOfDetail::DETAILED); | 575 MemoryDumpLevelOfDetail::DETAILED); |
573 ASSERT_EQ(1, on_memory_dump_call_count); | 576 ASSERT_EQ(1, on_memory_dump_call_count); |
574 ASSERT_EQ(true, last_callback_success_); | 577 ASSERT_EQ(true, last_callback_success_); |
575 | 578 |
576 DisableTracing(); | 579 DisableTracing(); |
577 } | 580 } |
578 | 581 |
582 // If a thread (with a dump provider living on it) is torn down during a dump | |
583 // its dump provider should be skipped but the dump itself shall succeed. | |
584 TEST_F(MemoryDumpManagerTest, TearDownThreadWhileDumping) { | |
585 InitializeMemoryDumpManager(false /* is_coordinator */); | |
586 ScopedVector<TestIOThread> threads; | |
Ruud van Asseldonk
2015/12/14 16:25:49
Scoped vectors are being removed in favour of |std
| |
587 ScopedVector<MockMemoryDumpProvider> mdps; | |
588 | |
589 for (int i = 0; i < 2; i++) { | |
590 threads.push_back(new TestIOThread(TestIOThread::kAutoStart)); | |
591 mdps.push_back(new MockMemoryDumpProvider()); | |
592 RegisterDumpProvider(mdps.back(), threads.back()->task_runner(), | |
593 kDefaultOptions); | |
594 } | |
595 | |
596 int on_memory_dump_call_count = 0; | |
597 | |
598 // When OnMemoryDump is called on either of the dump providers, it will | |
599 // tear down the thread of the other one. | |
600 for (MockMemoryDumpProvider* mdp : mdps) { | |
601 int other_idx = (mdps.front() == mdp); | |
602 TestIOThread* other_thread = threads[other_idx]; | |
603 auto on_dump = [other_thread, &on_memory_dump_call_count]( | |
604 const MemoryDumpArgs& args, ProcessMemoryDump* pmd) { | |
605 other_thread->Stop(); | |
606 on_memory_dump_call_count++; | |
607 return true; | |
608 }; | |
609 | |
610 // OnMemoryDump is called once for the provider that dumps first, and zero | |
611 // times for the other provider. | |
612 EXPECT_CALL(*mdp, OnMemoryDump(_, _)) | |
613 .Times(AtMost(1)) | |
614 .WillOnce(Invoke(on_dump)); | |
615 } | |
616 | |
617 last_callback_success_ = false; | |
618 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | |
619 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | |
620 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | |
621 MemoryDumpLevelOfDetail::DETAILED); | |
622 ASSERT_EQ(1, on_memory_dump_call_count); | |
623 ASSERT_EQ(true, last_callback_success_); | |
624 | |
625 DisableTracing(); | |
626 } | |
627 | |
579 // Checks that a NACK callback is invoked if RequestGlobalDump() is called when | 628 // Checks that a NACK callback is invoked if RequestGlobalDump() is called when |
580 // tracing is not enabled. | 629 // tracing is not enabled. |
581 TEST_F(MemoryDumpManagerTest, CallbackCalledOnFailure) { | 630 TEST_F(MemoryDumpManagerTest, CallbackCalledOnFailure) { |
582 InitializeMemoryDumpManager(false /* is_coordinator */); | 631 InitializeMemoryDumpManager(false /* is_coordinator */); |
583 MockMemoryDumpProvider mdp1; | 632 MockMemoryDumpProvider mdp1; |
584 RegisterDumpProvider(&mdp1); | 633 RegisterDumpProvider(&mdp1); |
585 | 634 |
586 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(0); | 635 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(0); |
587 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(0); | 636 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(0); |
588 | 637 |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
754 RunLoop run_loop; | 803 RunLoop run_loop; |
755 MemoryDumpCallback callback = | 804 MemoryDumpCallback callback = |
756 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter, Unretained(this), | 805 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter, Unretained(this), |
757 MessageLoop::current()->task_runner(), run_loop.QuitClosure()); | 806 MessageLoop::current()->task_runner(), run_loop.QuitClosure()); |
758 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 807 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
759 MemoryDumpLevelOfDetail::DETAILED, callback); | 808 MemoryDumpLevelOfDetail::DETAILED, callback); |
760 DisableTracing(); | 809 DisableTracing(); |
761 tracing_disabled_event.Signal(); | 810 tracing_disabled_event.Signal(); |
762 run_loop.Run(); | 811 run_loop.Run(); |
763 | 812 |
764 // RequestGlobalMemoryDump() should be NACK-ed because one of the threads | 813 // RequestGlobalMemoryDump() should still suceed even if some threads were |
765 // threads died before we had a chance to PostTask onto them. | 814 // torn down during the dump. |
766 EXPECT_FALSE(last_callback_success_); | 815 EXPECT_TRUE(last_callback_success_); |
767 } | 816 } |
768 | 817 |
769 TEST_F(MemoryDumpManagerTest, DumpOnBehalfOfOtherProcess) { | 818 TEST_F(MemoryDumpManagerTest, DumpOnBehalfOfOtherProcess) { |
770 using trace_analyzer::Query; | 819 using trace_analyzer::Query; |
771 | 820 |
772 InitializeMemoryDumpManager(false /* is_coordinator */); | 821 InitializeMemoryDumpManager(false /* is_coordinator */); |
773 | 822 |
774 // Standard provider with default options (create dump for current process). | 823 // Standard provider with default options (create dump for current process). |
775 MemoryDumpProvider::Options options; | 824 MemoryDumpProvider::Options options; |
776 MockMemoryDumpProvider mdp1; | 825 MockMemoryDumpProvider mdp1; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
817 ASSERT_EQ(1u, trace_analyzer::CountMatches(events, Query::EventPidIs(123))); | 866 ASSERT_EQ(1u, trace_analyzer::CountMatches(events, Query::EventPidIs(123))); |
818 ASSERT_EQ(1u, trace_analyzer::CountMatches(events, Query::EventPidIs(456))); | 867 ASSERT_EQ(1u, trace_analyzer::CountMatches(events, Query::EventPidIs(456))); |
819 ASSERT_EQ(1u, trace_analyzer::CountMatches( | 868 ASSERT_EQ(1u, trace_analyzer::CountMatches( |
820 events, Query::EventPidIs(GetCurrentProcId()))); | 869 events, Query::EventPidIs(GetCurrentProcId()))); |
821 ASSERT_EQ(events[0]->id, events[1]->id); | 870 ASSERT_EQ(events[0]->id, events[1]->id); |
822 ASSERT_EQ(events[0]->id, events[2]->id); | 871 ASSERT_EQ(events[0]->id, events[2]->id); |
823 } | 872 } |
824 | 873 |
825 } // namespace trace_event | 874 } // namespace trace_event |
826 } // namespace base | 875 } // namespace base |
OLD | NEW |