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

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

Issue 2845633002: memory-infra: Remove is_enabled_ from MDM (Closed)
Patch Set: address comments Created 3 years, 7 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 1012 matching lines...) Expand 10 before | Expand all | Expand 10 after
1023 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)) 1023 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _))
1024 .Times(AnyNumber()); 1024 .Times(AnyNumber());
1025 1025
1026 EnableTracingWithTraceConfig( 1026 EnableTracingWithTraceConfig(
1027 TraceConfigMemoryTestUtil::GetTraceConfig_PeriodicTriggers( 1027 TraceConfigMemoryTestUtil::GetTraceConfig_PeriodicTriggers(
1028 kLightDumpPeriodMs, kHeavyDumpPeriodMs)); 1028 kLightDumpPeriodMs, kHeavyDumpPeriodMs));
1029 run_loop.Run(); 1029 run_loop.Run();
1030 DisableTracing(); 1030 DisableTracing();
1031 } 1031 }
1032 1032
1033 // Tests against race conditions that can happen if tracing is disabled before
1034 // the CreateProcessDump() call. Real-world regression: crbug.com/580295 .
1035 TEST_F(MemoryDumpManagerTest, DisableTracingRightBeforeStartOfDump) {
1036 base::WaitableEvent tracing_disabled_event(
1037 WaitableEvent::ResetPolicy::AUTOMATIC,
1038 WaitableEvent::InitialState::NOT_SIGNALED);
1039 InitializeMemoryDumpManager(false /* is_coordinator */);
1040
1041 std::unique_ptr<Thread> mdp_thread(new Thread("test thread"));
1042 mdp_thread->Start();
1043
1044 // Create both same-thread MDP and another MDP with dedicated thread
1045 MockMemoryDumpProvider mdp1;
1046 RegisterDumpProvider(&mdp1, nullptr);
1047 MockMemoryDumpProvider mdp2;
1048 RegisterDumpProvider(&mdp2, mdp_thread->task_runner(), kDefaultOptions);
1049 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory);
1050
1051 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _))
1052 .WillOnce(Invoke([this](const MemoryDumpRequestArgs& args,
1053 const GlobalMemoryDumpCallback& callback) {
1054 DisableTracing();
1055 ProcessMemoryDumpCallback process_callback =
1056 Bind(&ProcessDumpCallbackAdapter, callback);
1057 mdm_->CreateProcessDump(args, process_callback);
1058 }));
1059
1060 // If tracing is disabled for current session CreateProcessDump() should NOT
1061 // request dumps from providers. Real-world regression: crbug.com/600570 .
1062 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(0);
1063 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).Times(0);
1064
1065 last_callback_success_ = true;
1066 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED,
1067 MemoryDumpLevelOfDetail::DETAILED);
1068 EXPECT_FALSE(last_callback_success_);
1069 }
1070
1071 TEST_F(MemoryDumpManagerTest, DumpOnBehalfOfOtherProcess) { 1033 TEST_F(MemoryDumpManagerTest, DumpOnBehalfOfOtherProcess) {
1072 using trace_analyzer::Query; 1034 using trace_analyzer::Query;
1073 1035
1074 InitializeMemoryDumpManager(false /* is_coordinator */); 1036 InitializeMemoryDumpManager(false /* is_coordinator */);
1075 1037
1076 // Standard provider with default options (create dump for current process). 1038 // Standard provider with default options (create dump for current process).
1077 MemoryDumpProvider::Options options; 1039 MemoryDumpProvider::Options options;
1078 MockMemoryDumpProvider mdp1; 1040 MockMemoryDumpProvider mdp1;
1079 RegisterDumpProvider(&mdp1, nullptr, options); 1041 RegisterDumpProvider(&mdp1, nullptr, options);
1080 1042
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
1296 // successful we also managed to add the dump to the trace. 1258 // successful we also managed to add the dump to the trace.
1297 EXPECT_FALSE(last_callback_success_); 1259 EXPECT_FALSE(last_callback_success_);
1298 1260
1299 mdm_->Disable(); 1261 mdm_->Disable();
1300 1262
1301 mdm_->UnregisterDumpProvider(&mdp); 1263 mdm_->UnregisterDumpProvider(&mdp);
1302 } 1264 }
1303 1265
1304 } // namespace trace_event 1266 } // namespace trace_event
1305 } // namespace base 1267 } // namespace base
OLDNEW
« base/trace_event/memory_dump_manager.cc ('K') | « base/trace_event/memory_dump_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698