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

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

Issue 2820433005: memory-infra: Start disentangling tracing from memory-infra (Closed)
Patch Set: pass config in Created 3 years, 8 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
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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 978 matching lines...) Expand 10 before | Expand all | Expand 10 after
989 // Swallow all the final spurious calls until tracing gets disabled. 989 // Swallow all the final spurious calls until tracing gets disabled.
990 EXPECT_CALL(delegate, RequestGlobalMemoryDump(_, _)).Times(AnyNumber()); 990 EXPECT_CALL(delegate, RequestGlobalMemoryDump(_, _)).Times(AnyNumber());
991 991
992 EnableTracingWithTraceConfig( 992 EnableTracingWithTraceConfig(
993 TraceConfigMemoryTestUtil::GetTraceConfig_PeriodicTriggers( 993 TraceConfigMemoryTestUtil::GetTraceConfig_PeriodicTriggers(
994 kLightDumpPeriodMs, kHeavyDumpPeriodMs)); 994 kLightDumpPeriodMs, kHeavyDumpPeriodMs));
995 run_loop.Run(); 995 run_loop.Run();
996 DisableTracing(); 996 DisableTracing();
997 } 997 }
998 998
999 // Tests against race conditions that might arise when disabling tracing in the
1000 // middle of a global memory dump.
1001 // Flaky on iOS, see crbug.com/706961
1002 #if defined(OS_IOS)
1003 #define MAYBE_DisableTracingWhileDumping DISABLED_DisableTracingWhileDumping
1004 #else
1005 #define MAYBE_DisableTracingWhileDumping DisableTracingWhileDumping
1006 #endif
1007 TEST_F(MemoryDumpManagerTest, MAYBE_DisableTracingWhileDumping) {
1008 base::WaitableEvent tracing_disabled_event(
1009 WaitableEvent::ResetPolicy::AUTOMATIC,
1010 WaitableEvent::InitialState::NOT_SIGNALED);
1011 InitializeMemoryDumpManager(false /* is_coordinator */);
1012
1013 // Register a bound dump provider.
1014 std::unique_ptr<Thread> mdp_thread(new Thread("test thread"));
1015 mdp_thread->Start();
1016 MockMemoryDumpProvider mdp_with_affinity;
1017 RegisterDumpProvider(&mdp_with_affinity, mdp_thread->task_runner(),
1018 kDefaultOptions);
1019
1020 // Register also an unbound dump provider. Unbound dump providers are always
1021 // invoked after bound ones.
1022 MockMemoryDumpProvider unbound_mdp;
1023 RegisterDumpProvider(&unbound_mdp, nullptr, kDefaultOptions);
1024
1025 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory);
1026 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1);
1027 EXPECT_CALL(mdp_with_affinity, OnMemoryDump(_, _))
1028 .Times(1)
1029 .WillOnce(
1030 Invoke([&tracing_disabled_event](const MemoryDumpArgs&,
1031 ProcessMemoryDump* pmd) -> bool {
1032 tracing_disabled_event.Wait();
1033
1034 // At this point tracing has been disabled and the
1035 // MemoryDumpManager.dump_thread_ has been shut down.
1036 return true;
1037 }));
1038
1039 // |unbound_mdp| should never be invoked because the thread for unbound dump
1040 // providers has been shutdown in the meanwhile.
1041 EXPECT_CALL(unbound_mdp, OnMemoryDump(_, _)).Times(0);
1042
1043 last_callback_success_ = true;
1044 RunLoop run_loop;
1045 MemoryDumpCallback callback =
1046 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter, Unretained(this),
1047 ThreadTaskRunnerHandle::Get(), run_loop.QuitClosure());
1048 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
1049 MemoryDumpLevelOfDetail::DETAILED, callback);
1050 DisableTracing();
1051 tracing_disabled_event.Signal();
1052 run_loop.Run();
1053
1054 EXPECT_FALSE(last_callback_success_);
1055 }
1056
1057 // Tests against race conditions that can happen if tracing is disabled before 999 // Tests against race conditions that can happen if tracing is disabled before
1058 // the CreateProcessDump() call. Real-world regression: crbug.com/580295 . 1000 // the CreateProcessDump() call. Real-world regression: crbug.com/580295 .
1059 TEST_F(MemoryDumpManagerTest, DisableTracingRightBeforeStartOfDump) { 1001 TEST_F(MemoryDumpManagerTest, DisableTracingRightBeforeStartOfDump) {
1060 base::WaitableEvent tracing_disabled_event( 1002 base::WaitableEvent tracing_disabled_event(
1061 WaitableEvent::ResetPolicy::AUTOMATIC, 1003 WaitableEvent::ResetPolicy::AUTOMATIC,
1062 WaitableEvent::InitialState::NOT_SIGNALED); 1004 WaitableEvent::InitialState::NOT_SIGNALED);
1063 InitializeMemoryDumpManager(false /* is_coordinator */); 1005 InitializeMemoryDumpManager(false /* is_coordinator */);
1064 1006
1065 std::unique_ptr<Thread> mdp_thread(new Thread("test thread")); 1007 std::unique_ptr<Thread> mdp_thread(new Thread("test thread"));
1066 mdp_thread->Start(); 1008 mdp_thread->Start();
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
1280 1222
1281 Thread thread("test thread"); 1223 Thread thread("test thread");
1282 thread.Start(); 1224 thread.Start();
1283 RegisterDumpProvider(&mdp1, thread.task_runner(), kDefaultOptions, 1225 RegisterDumpProvider(&mdp1, thread.task_runner(), kDefaultOptions,
1284 "BlacklistTestDumpProvider"); 1226 "BlacklistTestDumpProvider");
1285 // Unregistering on wrong thread should not crash. 1227 // Unregistering on wrong thread should not crash.
1286 mdm_->UnregisterDumpProvider(&mdp1); 1228 mdm_->UnregisterDumpProvider(&mdp1);
1287 thread.Stop(); 1229 thread.Stop();
1288 } 1230 }
1289 1231
1232 // Tests that we can manually take a dump without enabling tracing.
1233 TEST_F(MemoryDumpManagerTest, TestManualEnable) {
Primiano Tucci (use gerrit) 2017/04/21 10:10:26 I'd s/TestManualEnable/DumpWithTracingDisabled/
hjd 2017/04/21 11:51:57 Done.
1234 InitializeMemoryDumpManager(false /* is_coordinator */);
1235 MockMemoryDumpProvider mdp;
1236 RegisterDumpProvider(&mdp, ThreadTaskRunnerHandle::Get());
1237
1238 DisableTracing();
1239
1240 const TraceConfig& trace_config =
1241 TraceConfig(TraceConfigMemoryTestUtil::GetTraceConfig_NoTriggers());
1242 const TraceConfig::MemoryDumpConfig& memory_dump_config =
1243 trace_config.memory_dump_config();
1244
1245 mdm_->Enable(memory_dump_config);
1246
1247 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(3);
1248 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(3).WillRepeatedly(Return(true));
1249 last_callback_success_ = false;
1250 for (int i = 0; i < 3; ++i)
1251 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED,
1252 MemoryDumpLevelOfDetail::DETAILED);
1253 EXPECT_TRUE(last_callback_success_);
1254
1255 mdm_->Disable();
1256
1257 mdm_->UnregisterDumpProvider(&mdp);
1258 }
1259
1290 } // namespace trace_event 1260 } // namespace trace_event
1291 } // namespace base 1261 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698