| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 995 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1006 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)) | 1006 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)) |
| 1007 .Times(AnyNumber()); | 1007 .Times(AnyNumber()); |
| 1008 | 1008 |
| 1009 EnableTracingWithTraceConfig( | 1009 EnableTracingWithTraceConfig( |
| 1010 TraceConfigMemoryTestUtil::GetTraceConfig_PeriodicTriggers( | 1010 TraceConfigMemoryTestUtil::GetTraceConfig_PeriodicTriggers( |
| 1011 kLightDumpPeriodMs, kHeavyDumpPeriodMs)); | 1011 kLightDumpPeriodMs, kHeavyDumpPeriodMs)); |
| 1012 run_loop.Run(); | 1012 run_loop.Run(); |
| 1013 DisableTracing(); | 1013 DisableTracing(); |
| 1014 } | 1014 } |
| 1015 | 1015 |
| 1016 // Tests against race conditions that can happen if tracing is disabled before | |
| 1017 // the CreateProcessDump() call. Real-world regression: crbug.com/580295 . | |
| 1018 TEST_F(MemoryDumpManagerTest, DisableTracingRightBeforeStartOfDump) { | |
| 1019 base::WaitableEvent tracing_disabled_event( | |
| 1020 WaitableEvent::ResetPolicy::AUTOMATIC, | |
| 1021 WaitableEvent::InitialState::NOT_SIGNALED); | |
| 1022 InitializeMemoryDumpManager(false /* is_coordinator */); | |
| 1023 | |
| 1024 std::unique_ptr<Thread> mdp_thread(new Thread("test thread")); | |
| 1025 mdp_thread->Start(); | |
| 1026 | |
| 1027 // Create both same-thread MDP and another MDP with dedicated thread | |
| 1028 MockMemoryDumpProvider mdp1; | |
| 1029 RegisterDumpProvider(&mdp1, nullptr); | |
| 1030 MockMemoryDumpProvider mdp2; | |
| 1031 RegisterDumpProvider(&mdp2, mdp_thread->task_runner(), kDefaultOptions); | |
| 1032 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | |
| 1033 | |
| 1034 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)) | |
| 1035 .WillOnce(Invoke([this](const MemoryDumpRequestArgs& args, | |
| 1036 const GlobalMemoryDumpCallback& callback) { | |
| 1037 DisableTracing(); | |
| 1038 ProcessMemoryDumpCallback process_callback = | |
| 1039 Bind(&ProcessDumpCallbackAdapter, callback); | |
| 1040 mdm_->CreateProcessDump(args, process_callback); | |
| 1041 })); | |
| 1042 | |
| 1043 // If tracing is disabled for current session CreateProcessDump() should NOT | |
| 1044 // request dumps from providers. Real-world regression: crbug.com/600570 . | |
| 1045 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(0); | |
| 1046 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).Times(0); | |
| 1047 | |
| 1048 last_callback_success_ = true; | |
| 1049 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | |
| 1050 MemoryDumpLevelOfDetail::DETAILED); | |
| 1051 EXPECT_FALSE(last_callback_success_); | |
| 1052 } | |
| 1053 | |
| 1054 TEST_F(MemoryDumpManagerTest, DumpOnBehalfOfOtherProcess) { | 1016 TEST_F(MemoryDumpManagerTest, DumpOnBehalfOfOtherProcess) { |
| 1055 using trace_analyzer::Query; | 1017 using trace_analyzer::Query; |
| 1056 | 1018 |
| 1057 InitializeMemoryDumpManager(false /* is_coordinator */); | 1019 InitializeMemoryDumpManager(false /* is_coordinator */); |
| 1058 | 1020 |
| 1059 // Standard provider with default options (create dump for current process). | 1021 // Standard provider with default options (create dump for current process). |
| 1060 MemoryDumpProvider::Options options; | 1022 MemoryDumpProvider::Options options; |
| 1061 MockMemoryDumpProvider mdp1; | 1023 MockMemoryDumpProvider mdp1; |
| 1062 RegisterDumpProvider(&mdp1, nullptr, options); | 1024 RegisterDumpProvider(&mdp1, nullptr, options); |
| 1063 | 1025 |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1277 // successful we also managed to add the dump to the trace. | 1239 // successful we also managed to add the dump to the trace. |
| 1278 EXPECT_FALSE(last_callback_success_); | 1240 EXPECT_FALSE(last_callback_success_); |
| 1279 | 1241 |
| 1280 mdm_->Disable(); | 1242 mdm_->Disable(); |
| 1281 | 1243 |
| 1282 mdm_->UnregisterDumpProvider(&mdp); | 1244 mdm_->UnregisterDumpProvider(&mdp); |
| 1283 } | 1245 } |
| 1284 | 1246 |
| 1285 } // namespace trace_event | 1247 } // namespace trace_event |
| 1286 } // namespace base | 1248 } // namespace base |
| OLD | NEW |