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
3 // found in the LICENSE file.
5 #include "base/trace_event/memory_dump_manager.h"
7 #include "base/bind_helpers.h"
8 #include "base/memory/scoped_vector.h"
9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h"
11 #include "base/test/test_io_thread.h"
12 #include "base/thread_task_runner_handle.h"
13 #include "base/threading/thread.h"
14 #include "base/trace_event/memory_dump_provider.h"
15 #include "base/trace_event/process_memory_dump.h"
16 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h"
20 using testing::AtMost
;
21 using testing::Between
;
22 using testing::Invoke
;
23 using testing::Return
;
26 namespace trace_event
{
28 MemoryDumpArgs g_high_detail_args
= {MemoryDumpArgs::LevelOfDetail::HIGH
};
29 MemoryDumpArgs g_low_detail_args
= {MemoryDumpArgs::LevelOfDetail::LOW
};
32 // Testing MemoryDumpManagerDelegate which short-circuits dump requests locally
33 // instead of performing IPC dances.
34 class MemoryDumpManagerDelegateForTesting
: public MemoryDumpManagerDelegate
{
36 void RequestGlobalMemoryDump(const MemoryDumpRequestArgs
& args
,
37 const MemoryDumpCallback
& callback
) override
{
38 CreateProcessDump(args
, callback
);
41 bool IsCoordinatorProcess() const override
{ return false; }
42 uint64
GetTracingProcessId() const override
{
43 return MemoryDumpManager::kInvalidTracingProcessId
;
47 class MemoryDumpManagerDelegateForPeriodicDumpTest
48 : public MemoryDumpManagerDelegateForTesting
{
50 MOCK_METHOD2(RequestGlobalMemoryDump
,
51 void(const MemoryDumpRequestArgs
& args
,
52 const MemoryDumpCallback
& callback
));
54 bool IsCoordinatorProcess() const override
{ return true; }
57 class MemoryDumpManagerTest
: public testing::Test
{
59 void SetUp() override
{
60 last_callback_success_
= false;
61 message_loop_
.reset(new MessageLoop());
62 mdm_
.reset(new MemoryDumpManager());
63 MemoryDumpManager::SetInstanceForTesting(mdm_
.get());
64 ASSERT_EQ(mdm_
, MemoryDumpManager::GetInstance());
65 MemoryDumpManager::GetInstance()->Initialize();
68 void TearDown() override
{
69 MemoryDumpManager::SetInstanceForTesting(nullptr);
71 message_loop_
.reset();
72 TraceLog::DeleteForTesting();
75 void DumpCallbackAdapter(scoped_refptr
<SingleThreadTaskRunner
> task_runner
,
79 last_callback_success_
= success
;
80 task_runner
->PostTask(FROM_HERE
, closure
);
84 void SetDelegate(scoped_ptr
<MemoryDumpManagerDelegateForTesting
> delegate
) {
85 delegate_
= delegate
.Pass();
86 MemoryDumpManager::GetInstance()->SetDelegate(delegate_
.get());
89 // This enalbes tracing using the legacy category filter string.
90 void EnableTracing(const char* category
) {
92 delegate_
.reset(new MemoryDumpManagerDelegateForTesting());
93 MemoryDumpManager::GetInstance()->SetDelegate(delegate_
.get());
95 TraceLog::GetInstance()->SetEnabled(
96 TraceConfig(category
, ""), TraceLog::RECORDING_MODE
);
99 void EnableTracingWithTraceConfig(const char* trace_config
) {
101 TraceConfig
tc(trace_config
);
102 TraceLog::GetInstance()->SetEnabled(tc
, TraceLog::RECORDING_MODE
);
105 void DisableTracing() { TraceLog::GetInstance()->SetDisabled(); }
107 scoped_ptr
<MemoryDumpManager
> mdm_
;
108 bool last_callback_success_
;
109 scoped_ptr
<MemoryDumpManagerDelegateForTesting
> delegate_
;
112 scoped_ptr
<MessageLoop
> message_loop_
;
114 // We want our singleton torn down after each test.
115 ShadowingAtExitManager at_exit_manager_
;
118 class MockDumpProvider
: public MemoryDumpProvider
{
121 : dump_provider_to_register_or_unregister(nullptr),
122 last_session_state_(nullptr),
123 level_of_detail_(MemoryDumpArgs::LevelOfDetail::HIGH
) {}
125 // Ctor used by the RespectTaskRunnerAffinity test.
126 explicit MockDumpProvider(
127 const scoped_refptr
<SingleThreadTaskRunner
>& task_runner
)
128 : last_session_state_(nullptr),
129 task_runner_(task_runner
),
130 level_of_detail_(MemoryDumpArgs::LevelOfDetail::HIGH
) {}
132 // Ctor used by CheckMemoryDumpArgs test.
133 explicit MockDumpProvider(const MemoryDumpArgs::LevelOfDetail level_of_detail
)
134 : last_session_state_(nullptr), level_of_detail_(level_of_detail
) {}
136 virtual ~MockDumpProvider() {}
138 MOCK_METHOD2(OnMemoryDump
,
139 bool(const MemoryDumpArgs
& args
, ProcessMemoryDump
* pmd
));
141 // OnMemoryDump() override for the RespectTaskRunnerAffinity test.
142 bool OnMemoryDump_CheckTaskRunner(const MemoryDumpArgs
& args
,
143 ProcessMemoryDump
* pmd
) {
144 EXPECT_TRUE(task_runner_
->RunsTasksOnCurrentThread());
148 // OnMemoryDump() override for the SharedSessionState test.
149 bool OnMemoryDump_CheckSessionState(const MemoryDumpArgs
& args
,
150 ProcessMemoryDump
* pmd
) {
151 MemoryDumpSessionState
* cur_session_state
= pmd
->session_state().get();
152 if (last_session_state_
)
153 EXPECT_EQ(last_session_state_
, cur_session_state
);
154 last_session_state_
= cur_session_state
;
158 // OnMemoryDump() override for the RegisterDumperWhileDumping test.
159 bool OnMemoryDump_RegisterExtraDumpProvider(const MemoryDumpArgs
& args
,
160 ProcessMemoryDump
* pmd
) {
161 MemoryDumpManager::GetInstance()->RegisterDumpProvider(
162 dump_provider_to_register_or_unregister
);
166 // OnMemoryDump() override for the UnegisterDumperWhileDumping test.
167 bool OnMemoryDump_UnregisterDumpProvider(const MemoryDumpArgs
& args
,
168 ProcessMemoryDump
* pmd
) {
169 MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
170 dump_provider_to_register_or_unregister
);
174 // OnMemoryDump() override for the CheckMemoryDumpArgs test.
175 bool OnMemoryDump_CheckMemoryDumpArgs(const MemoryDumpArgs
& args
,
176 ProcessMemoryDump
* pmd
) {
177 EXPECT_EQ(level_of_detail_
, args
.level_of_detail
);
181 // Used by OnMemoryDump_(Un)RegisterExtraDumpProvider.
182 MemoryDumpProvider
* dump_provider_to_register_or_unregister
;
185 MemoryDumpSessionState
* last_session_state_
;
186 scoped_refptr
<SingleThreadTaskRunner
> task_runner_
;
187 const MemoryDumpArgs::LevelOfDetail level_of_detail_
;
190 TEST_F(MemoryDumpManagerTest
, SingleDumper
) {
191 MockDumpProvider mdp
;
192 mdm_
->RegisterDumpProvider(&mdp
);
194 // Check that the dumper is not called if the memory category is not enabled.
195 EnableTracing("foo-and-bar-but-not-memory");
196 EXPECT_CALL(mdp
, OnMemoryDump(_
, _
)).Times(0);
197 mdm_
->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED
,
201 // Now repeat enabling the memory category and check that the dumper is
202 // invoked this time.
203 EnableTracing(MemoryDumpManager::kTraceCategory
);
204 EXPECT_CALL(mdp
, OnMemoryDump(_
, _
)).Times(3).WillRepeatedly(Return(true));
205 for (int i
= 0; i
< 3; ++i
)
206 mdm_
->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED
,
210 mdm_
->UnregisterDumpProvider(&mdp
);
212 // Finally check the unregister logic (no calls to the mdp after unregister).
213 EnableTracing(MemoryDumpManager::kTraceCategory
);
214 EXPECT_CALL(mdp
, OnMemoryDump(_
, _
)).Times(0);
215 mdm_
->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED
,
217 TraceLog::GetInstance()->SetDisabled();
220 TEST_F(MemoryDumpManagerTest
, CheckMemoryDumpArgs
) {
221 // Check that requesting dumps with high level of detail actually propagates
222 // to OnMemoryDump() call on dump providers.
223 MockDumpProvider
mdp_high_detail(MemoryDumpArgs::LevelOfDetail::HIGH
);
224 mdm_
->RegisterDumpProvider(&mdp_high_detail
);
226 EnableTracing(MemoryDumpManager::kTraceCategory
);
227 EXPECT_CALL(mdp_high_detail
, OnMemoryDump(_
, _
))
230 Invoke(&mdp_high_detail
,
231 &MockDumpProvider::OnMemoryDump_CheckMemoryDumpArgs
));
232 mdm_
->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED
,
235 mdm_
->UnregisterDumpProvider(&mdp_high_detail
);
237 // Check that requesting dumps with low level of detail actually propagates to
238 // OnMemoryDump() call on dump providers.
239 MockDumpProvider
mdp_low_detail(MemoryDumpArgs::LevelOfDetail::LOW
);
240 mdm_
->RegisterDumpProvider(&mdp_low_detail
);
242 EnableTracing(MemoryDumpManager::kTraceCategory
);
243 EXPECT_CALL(mdp_low_detail
, OnMemoryDump(_
, _
))
246 Invoke(&mdp_low_detail
,
247 &MockDumpProvider::OnMemoryDump_CheckMemoryDumpArgs
));
248 mdm_
->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED
,
251 mdm_
->UnregisterDumpProvider(&mdp_low_detail
);
254 TEST_F(MemoryDumpManagerTest
, SharedSessionState
) {
255 MockDumpProvider mdp1
;
256 MockDumpProvider mdp2
;
257 mdm_
->RegisterDumpProvider(&mdp1
);
258 mdm_
->RegisterDumpProvider(&mdp2
);
260 EnableTracing(MemoryDumpManager::kTraceCategory
);
261 EXPECT_CALL(mdp1
, OnMemoryDump(_
, _
))
264 Invoke(&mdp1
, &MockDumpProvider::OnMemoryDump_CheckSessionState
));
265 EXPECT_CALL(mdp2
, OnMemoryDump(_
, _
))
268 Invoke(&mdp2
, &MockDumpProvider::OnMemoryDump_CheckSessionState
));
270 for (int i
= 0; i
< 2; ++i
)
271 mdm_
->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED
,
277 TEST_F(MemoryDumpManagerTest
, MultipleDumpers
) {
278 MockDumpProvider mdp1
;
279 MockDumpProvider mdp2
;
282 mdm_
->RegisterDumpProvider(&mdp1
);
283 EnableTracing(MemoryDumpManager::kTraceCategory
);
284 EXPECT_CALL(mdp1
, OnMemoryDump(_
, _
)).Times(1).WillRepeatedly(Return(true));
285 EXPECT_CALL(mdp2
, OnMemoryDump(_
, _
)).Times(0);
286 mdm_
->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED
,
290 // Invert: enable mdp1 and disable mdp2.
291 mdm_
->UnregisterDumpProvider(&mdp1
);
292 mdm_
->RegisterDumpProvider(&mdp2
);
293 EnableTracing(MemoryDumpManager::kTraceCategory
);
294 EXPECT_CALL(mdp1
, OnMemoryDump(_
, _
)).Times(0);
295 EXPECT_CALL(mdp2
, OnMemoryDump(_
, _
)).Times(1).WillRepeatedly(Return(true));
296 mdm_
->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED
,
300 // Enable both mdp1 and mdp2.
301 mdm_
->RegisterDumpProvider(&mdp1
);
302 EnableTracing(MemoryDumpManager::kTraceCategory
);
303 EXPECT_CALL(mdp1
, OnMemoryDump(_
, _
)).Times(1).WillRepeatedly(Return(true));
304 EXPECT_CALL(mdp2
, OnMemoryDump(_
, _
)).Times(1).WillRepeatedly(Return(true));
305 mdm_
->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED
,
310 // Verify that whether OnMemoryDump is called depends only on the current
311 // registration state and not on previous registrations and dumps.
312 TEST_F(MemoryDumpManagerTest
, RegistrationConsistency
) {
313 MockDumpProvider mdp
;
315 mdm_
->RegisterDumpProvider(&mdp
);
318 EXPECT_CALL(mdp
, OnMemoryDump(_
, _
)).Times(1);
319 EnableTracing(MemoryDumpManager::kTraceCategory
);
320 mdm_
->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED
,
325 mdm_
->UnregisterDumpProvider(&mdp
);
328 EXPECT_CALL(mdp
, OnMemoryDump(_
, _
)).Times(0);
329 EnableTracing(MemoryDumpManager::kTraceCategory
);
330 mdm_
->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED
,
335 mdm_
->RegisterDumpProvider(&mdp
);
336 mdm_
->UnregisterDumpProvider(&mdp
);
339 EXPECT_CALL(mdp
, OnMemoryDump(_
, _
)).Times(0);
340 EnableTracing(MemoryDumpManager::kTraceCategory
);
341 mdm_
->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED
,
346 mdm_
->RegisterDumpProvider(&mdp
);
347 mdm_
->UnregisterDumpProvider(&mdp
);
348 mdm_
->RegisterDumpProvider(&mdp
);
351 EXPECT_CALL(mdp
, OnMemoryDump(_
, _
)).Times(1);
352 EnableTracing(MemoryDumpManager::kTraceCategory
);
353 mdm_
->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED
,
359 // Checks that the MemoryDumpManager respects the thread affinity when a
360 // MemoryDumpProvider specifies a task_runner(). The test starts creating 8
361 // threads and registering a MemoryDumpProvider on each of them. At each
362 // iteration, one thread is removed, to check the live unregistration logic.
363 TEST_F(MemoryDumpManagerTest
, RespectTaskRunnerAffinity
) {
364 const uint32 kNumInitialThreads
= 8;
366 ScopedVector
<Thread
> threads
;
367 ScopedVector
<MockDumpProvider
> mdps
;
369 // Create the threads and setup the expectations. Given that at each iteration
370 // we will pop out one thread/MemoryDumpProvider, each MDP is supposed to be
371 // invoked a number of times equal to its index.
372 for (uint32 i
= kNumInitialThreads
; i
> 0; --i
) {
373 threads
.push_back(new Thread("test thread"));
374 threads
.back()->Start();
375 mdps
.push_back(new MockDumpProvider(threads
.back()->task_runner()));
376 MockDumpProvider
* mdp
= mdps
.back();
377 mdm_
->RegisterDumpProvider(mdp
, threads
.back()->task_runner());
378 EXPECT_CALL(*mdp
, OnMemoryDump(_
, _
))
381 Invoke(mdp
, &MockDumpProvider::OnMemoryDump_CheckTaskRunner
));
384 EnableTracing(MemoryDumpManager::kTraceCategory
);
386 while (!threads
.empty()) {
387 last_callback_success_
= false;
390 MemoryDumpCallback callback
=
391 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter
, Unretained(this),
392 MessageLoop::current()->task_runner(), run_loop
.QuitClosure());
393 mdm_
->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED
,
394 g_high_detail_args
, callback
);
395 // This nested message loop (|run_loop|) will be quit if and only if
396 // the RequestGlobalDump callback is invoked.
399 EXPECT_TRUE(last_callback_success_
);
401 // Unregister a MDP and destroy one thread at each iteration to check the
402 // live unregistration logic. The unregistration needs to happen on the same
403 // thread the MDP belongs to.
406 Closure unregistration
=
407 Bind(&MemoryDumpManager::UnregisterDumpProvider
,
408 Unretained(mdm_
.get()), Unretained(mdps
.back()));
409 threads
.back()->task_runner()->PostTaskAndReply(FROM_HERE
, unregistration
,
410 run_loop
.QuitClosure());
414 threads
.back()->Stop();
421 // Enable both dump providers, make sure that mdp gets disabled after 3 failures
422 // and not disabled after 1.
423 TEST_F(MemoryDumpManagerTest
, DisableFailingDumpers
) {
424 MockDumpProvider mdp1
;
425 MockDumpProvider mdp2
;
427 mdm_
->RegisterDumpProvider(&mdp1
);
428 mdm_
->RegisterDumpProvider(&mdp2
);
429 EnableTracing(MemoryDumpManager::kTraceCategory
);
431 EXPECT_CALL(mdp1
, OnMemoryDump(_
, _
))
432 .Times(MemoryDumpManager::kMaxConsecutiveFailuresCount
)
433 .WillRepeatedly(Return(false));
435 EXPECT_CALL(mdp2
, OnMemoryDump(_
, _
))
436 .Times(1 + MemoryDumpManager::kMaxConsecutiveFailuresCount
)
437 .WillOnce(Return(false))
438 .WillRepeatedly(Return(true));
439 for (int i
= 0; i
< 1 + MemoryDumpManager::kMaxConsecutiveFailuresCount
;
441 mdm_
->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED
,
448 // Sneakily register an extra memory dump provider while an existing one is
449 // dumping and expect it to take part in the already active tracing session.
450 TEST_F(MemoryDumpManagerTest
, RegisterDumperWhileDumping
) {
451 MockDumpProvider mdp1
;
452 MockDumpProvider mdp2
;
454 mdp1
.dump_provider_to_register_or_unregister
= &mdp2
;
455 mdm_
->RegisterDumpProvider(&mdp1
);
456 EnableTracing(MemoryDumpManager::kTraceCategory
);
458 EXPECT_CALL(mdp1
, OnMemoryDump(_
, _
))
460 .WillOnce(Return(true))
462 &mdp1
, &MockDumpProvider::OnMemoryDump_RegisterExtraDumpProvider
))
463 .WillRepeatedly(Return(true));
465 // Depending on the insertion order (before or after mdp1), mdp2 might be
466 // called also immediately after it gets registered.
467 EXPECT_CALL(mdp2
, OnMemoryDump(_
, _
))
468 .Times(Between(2, 3))
469 .WillRepeatedly(Return(true));
471 for (int i
= 0; i
< 4; i
++) {
472 mdm_
->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED
,
479 // Like the above, but suddenly unregister the dump provider.
480 TEST_F(MemoryDumpManagerTest
, UnregisterDumperWhileDumping
) {
481 MockDumpProvider mdp1
;
482 MockDumpProvider mdp2
;
484 mdm_
->RegisterDumpProvider(&mdp1
, ThreadTaskRunnerHandle::Get());
485 mdm_
->RegisterDumpProvider(&mdp2
, ThreadTaskRunnerHandle::Get());
486 mdp1
.dump_provider_to_register_or_unregister
= &mdp2
;
487 EnableTracing(MemoryDumpManager::kTraceCategory
);
489 EXPECT_CALL(mdp1
, OnMemoryDump(_
, _
))
491 .WillOnce(Return(true))
493 Invoke(&mdp1
, &MockDumpProvider::OnMemoryDump_UnregisterDumpProvider
))
494 .WillRepeatedly(Return(true));
496 // Depending on the insertion order (before or after mdp1), mdp2 might have
497 // been already called when OnMemoryDump_UnregisterDumpProvider happens.
498 EXPECT_CALL(mdp2
, OnMemoryDump(_
, _
))
499 .Times(Between(1, 2))
500 .WillRepeatedly(Return(true));
502 for (int i
= 0; i
< 4; i
++) {
503 mdm_
->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED
,
510 // Verify that the dump does not abort when unregistering a provider while
511 // dumping from a different thread than the dumping thread.
512 TEST_F(MemoryDumpManagerTest
, UnregisterDumperFromThreadWhileDumping
) {
513 ScopedVector
<TestIOThread
> threads
;
514 ScopedVector
<MockDumpProvider
> mdps
;
516 for (int i
= 0; i
< 2; i
++) {
517 threads
.push_back(new TestIOThread(TestIOThread::kAutoStart
));
518 mdps
.push_back(new MockDumpProvider(threads
.back()->task_runner()));
519 mdm_
->RegisterDumpProvider(mdps
.back(), threads
.back()->task_runner());
522 int on_memory_dump_call_count
= 0;
525 // When OnMemoryDump is called on either of the dump providers, it will
526 // unregister the other one.
527 for (MockDumpProvider
* mdp
: mdps
) {
528 int other_idx
= (mdps
.front() == mdp
);
529 TestIOThread
* other_thread
= threads
[other_idx
];
530 MockDumpProvider
* other_mdp
= mdps
[other_idx
];
531 auto on_dump
= [this, other_thread
, other_mdp
, &on_memory_dump_call_count
](
532 const MemoryDumpArgs
& args
, ProcessMemoryDump
* pmd
) {
533 other_thread
->PostTaskAndWait(
534 FROM_HERE
, base::Bind(&MemoryDumpManager::UnregisterDumpProvider
,
535 base::Unretained(&*mdm_
), other_mdp
));
536 on_memory_dump_call_count
++;
540 // OnMemoryDump is called once for the provider that dumps first, and zero
541 // times for the other provider.
542 EXPECT_CALL(*mdp
, OnMemoryDump(_
, _
))
544 .WillOnce(Invoke(on_dump
));
547 last_callback_success_
= false;
548 MemoryDumpCallback callback
=
549 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter
, Unretained(this),
550 MessageLoop::current()->task_runner(), run_loop
.QuitClosure());
552 EnableTracing(MemoryDumpManager::kTraceCategory
);
553 MemoryDumpRequestArgs request_args
= {0, MemoryDumpType::EXPLICITLY_TRIGGERED
,
555 mdm_
->CreateProcessDump(request_args
, callback
);
559 ASSERT_EQ(1, on_memory_dump_call_count
);
560 ASSERT_EQ(true, last_callback_success_
);
565 // Ensures that a NACK callback is invoked if RequestGlobalDump is called when
566 // tracing is not enabled.
567 TEST_F(MemoryDumpManagerTest
, CallbackCalledOnFailure
) {
568 MockDumpProvider mdp1
;
570 mdm_
->RegisterDumpProvider(&mdp1
);
571 EXPECT_CALL(mdp1
, OnMemoryDump(_
, _
)).Times(0);
573 last_callback_success_
= true;
576 MemoryDumpCallback callback
=
577 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter
, Unretained(this),
578 MessageLoop::current()->task_runner(), run_loop
.QuitClosure());
579 mdm_
->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED
,
580 g_high_detail_args
, callback
);
583 EXPECT_FALSE(last_callback_success_
);
586 MATCHER(IsHighDetail
, "") {
587 return arg
.dump_args
.level_of_detail
== MemoryDumpArgs::LevelOfDetail::HIGH
;
590 MATCHER(IsLowDetail
, "") {
591 return arg
.dump_args
.level_of_detail
== MemoryDumpArgs::LevelOfDetail::LOW
;
594 TEST_F(MemoryDumpManagerTest
, SchedulePeriodicDumpsFromTraceConfig
) {
595 const char kMemoryDumpTraceConfigString
[] =
597 "\"included_categories\":["
598 "\"disabled-by-default-memory-infra\""
600 "\"memory_dump_config\":{"
603 "\"mode\":\"light\","
604 "\"periodic_interval_ms\":1"
607 "\"mode\":\"detailed\","
608 "\"periodic_interval_ms\":3"
615 scoped_ptr
<MemoryDumpManagerDelegateForPeriodicDumpTest
> delegate(
616 new MemoryDumpManagerDelegateForPeriodicDumpTest());
618 auto quit_closure
= run_loop
.QuitClosure();
619 testing::InSequence sequence
;
620 EXPECT_CALL(*delegate
.get(), RequestGlobalMemoryDump(IsHighDetail(), _
))
622 EXPECT_CALL(*delegate
.get(), RequestGlobalMemoryDump(IsLowDetail(), _
))
624 EXPECT_CALL(*delegate
.get(), RequestGlobalMemoryDump(IsHighDetail(), _
))
626 EXPECT_CALL(*delegate
.get(), RequestGlobalMemoryDump(IsLowDetail(), _
))
628 .WillOnce(Invoke([quit_closure
](const MemoryDumpRequestArgs
& args
,
629 const MemoryDumpCallback
& callback
) {
630 TraceLog::GetInstance()->SetDisabled();
631 ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE
, quit_closure
);
634 SetDelegate(delegate
.Pass());
635 EnableTracingWithTraceConfig(kMemoryDumpTraceConfigString
);
640 } // namespace trace_event