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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
121 // TODO (fmeawad): we should keep the results for verification, but currently | 121 // TODO (fmeawad): we should keep the results for verification, but currently |
122 // all results are empty. | 122 // all results are empty. |
123 void ProcessDumpCallbackAdapter( | 123 void ProcessDumpCallbackAdapter( |
124 GlobalMemoryDumpCallback callback, | 124 GlobalMemoryDumpCallback callback, |
125 uint64_t dump_guid, | 125 uint64_t dump_guid, |
126 bool success, | 126 bool success, |
127 const base::Optional<base::trace_event::MemoryDumpCallbackResult>&) { | 127 const base::Optional<base::trace_event::MemoryDumpCallbackResult>&) { |
128 callback.Run(dump_guid, success); | 128 callback.Run(dump_guid, success); |
129 } | 129 } |
130 | 130 |
131 // Testing MemoryDumpManagerDelegate which, by default, short-circuits dump | 131 class GlobalMemoryDumpHandler { |
Primiano Tucci (use gerrit)
2017/04/19 15:44:34
I'd keep a comment saing: this mocks the ReqGlobal
ssid
2017/04/20 01:18:21
Done.
| |
132 // requests locally to the MemoryDumpManager instead of performing IPC dances. | |
133 class MemoryDumpManagerDelegateForTesting : public MemoryDumpManagerDelegate { | |
134 public: | 132 public: |
135 MemoryDumpManagerDelegateForTesting(bool is_coordinator) | 133 MOCK_METHOD2(RequestGlobalMemoryDump, |
136 : is_coordinator_(is_coordinator) { | 134 void(const MemoryDumpRequestArgs& args, |
135 const GlobalMemoryDumpCallback& callback)); | |
136 | |
137 GlobalMemoryDumpHandler() { | |
137 ON_CALL(*this, RequestGlobalMemoryDump(_, _)) | 138 ON_CALL(*this, RequestGlobalMemoryDump(_, _)) |
138 .WillByDefault(Invoke([this](const MemoryDumpRequestArgs& args, | 139 .WillByDefault(Invoke([this](const MemoryDumpRequestArgs& args, |
139 const GlobalMemoryDumpCallback& callback) { | 140 const GlobalMemoryDumpCallback& callback) { |
140 ProcessMemoryDumpCallback process_callback = | 141 ProcessMemoryDumpCallback process_callback = |
141 Bind(&ProcessDumpCallbackAdapter, callback); | 142 Bind(&ProcessDumpCallbackAdapter, callback); |
142 CreateProcessDump(args, process_callback); | 143 MemoryDumpManager::GetInstance()->CreateProcessDump(args, |
144 process_callback); | |
143 })); | 145 })); |
144 } | 146 } |
145 | |
146 MOCK_METHOD2(RequestGlobalMemoryDump, | |
147 void(const MemoryDumpRequestArgs& args, | |
148 const GlobalMemoryDumpCallback& callback)); | |
149 | |
150 bool IsCoordinator() const override { return is_coordinator_; } | |
151 | |
152 // Promote the CreateProcessDump to public so it can be used by test fixtures. | |
153 using MemoryDumpManagerDelegate::CreateProcessDump; | |
154 | |
155 private: | |
156 bool is_coordinator_; | |
157 }; | 147 }; |
158 | 148 |
159 class MockMemoryDumpProvider : public MemoryDumpProvider { | 149 class MockMemoryDumpProvider : public MemoryDumpProvider { |
160 public: | 150 public: |
161 MOCK_METHOD0(Destructor, void()); | 151 MOCK_METHOD0(Destructor, void()); |
162 MOCK_METHOD2(OnMemoryDump, | 152 MOCK_METHOD2(OnMemoryDump, |
163 bool(const MemoryDumpArgs& args, ProcessMemoryDump* pmd)); | 153 bool(const MemoryDumpArgs& args, ProcessMemoryDump* pmd)); |
164 MOCK_METHOD1(PollFastMemoryTotal, void(uint64_t* memory_total)); | 154 MOCK_METHOD1(PollFastMemoryTotal, void(uint64_t* memory_total)); |
165 MOCK_METHOD0(SuspendFastMemoryPolling, void()); | 155 MOCK_METHOD0(SuspendFastMemoryPolling, void()); |
166 | 156 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
237 void SetUp() override { | 227 void SetUp() override { |
238 last_callback_success_ = false; | 228 last_callback_success_ = false; |
239 message_loop_.reset(new MessageLoop()); | 229 message_loop_.reset(new MessageLoop()); |
240 mdm_.reset(new MemoryDumpManager()); | 230 mdm_.reset(new MemoryDumpManager()); |
241 MemoryDumpManager::SetInstanceForTesting(mdm_.get()); | 231 MemoryDumpManager::SetInstanceForTesting(mdm_.get()); |
242 ASSERT_EQ(mdm_.get(), MemoryDumpManager::GetInstance()); | 232 ASSERT_EQ(mdm_.get(), MemoryDumpManager::GetInstance()); |
243 } | 233 } |
244 | 234 |
245 void TearDown() override { | 235 void TearDown() override { |
246 MemoryDumpManager::SetInstanceForTesting(nullptr); | 236 MemoryDumpManager::SetInstanceForTesting(nullptr); |
247 delegate_ = nullptr; | |
248 mdm_.reset(); | 237 mdm_.reset(); |
249 message_loop_.reset(); | 238 message_loop_.reset(); |
250 TraceLog::DeleteForTesting(); | 239 TraceLog::DeleteForTesting(); |
251 } | 240 } |
252 | 241 |
253 // Turns a Closure into a GlobalMemoryDumpCallback, keeping track of the | 242 // Turns a Closure into a GlobalMemoryDumpCallback, keeping track of the |
254 // callback result and taking care of posting the closure on the correct task | 243 // callback result and taking care of posting the closure on the correct task |
255 // runner. | 244 // runner. |
256 void GlobalDumpCallbackAdapter( | 245 void GlobalDumpCallbackAdapter( |
257 scoped_refptr<SingleThreadTaskRunner> task_runner, | 246 scoped_refptr<SingleThreadTaskRunner> task_runner, |
258 Closure closure, | 247 Closure closure, |
259 uint64_t dump_guid, | 248 uint64_t dump_guid, |
260 bool success) { | 249 bool success) { |
261 last_callback_success_ = success; | 250 last_callback_success_ = success; |
262 task_runner->PostTask(FROM_HERE, closure); | 251 task_runner->PostTask(FROM_HERE, closure); |
263 } | 252 } |
264 | 253 |
265 protected: | 254 protected: |
266 void InitializeMemoryDumpManager(bool is_coordinator) { | 255 void InitializeMemoryDumpManager(bool is_coordinator) { |
267 mdm_->set_dumper_registrations_ignored_for_testing(true); | 256 mdm_->set_dumper_registrations_ignored_for_testing(true); |
268 delegate_ = new MemoryDumpManagerDelegateForTesting(is_coordinator); | 257 mdm_->Initialize( |
269 mdm_->Initialize(base::WrapUnique(delegate_)); | 258 BindRepeating(&GlobalMemoryDumpHandler::RequestGlobalMemoryDump, |
259 Unretained(&global_dump_handler_)), | |
260 is_coordinator); | |
270 } | 261 } |
271 | 262 |
272 void RequestGlobalDumpAndWait(MemoryDumpType dump_type, | 263 void RequestGlobalDumpAndWait(MemoryDumpType dump_type, |
273 MemoryDumpLevelOfDetail level_of_detail) { | 264 MemoryDumpLevelOfDetail level_of_detail) { |
274 RunLoop run_loop; | 265 RunLoop run_loop; |
275 GlobalMemoryDumpCallback callback = Bind( | 266 GlobalMemoryDumpCallback callback = Bind( |
276 &MemoryDumpManagerTest::GlobalDumpCallbackAdapter, Unretained(this), | 267 &MemoryDumpManagerTest::GlobalDumpCallbackAdapter, Unretained(this), |
277 ThreadTaskRunnerHandle::Get(), run_loop.QuitClosure()); | 268 ThreadTaskRunnerHandle::Get(), run_loop.QuitClosure()); |
278 mdm_->RequestGlobalDump(dump_type, level_of_detail, callback); | 269 mdm_->RequestGlobalDump(dump_type, level_of_detail, callback); |
279 run_loop.Run(); | 270 run_loop.Run(); |
(...skipping 14 matching lines...) Expand all Loading... | |
294 bool IsPeriodicDumpingEnabled() const { | 285 bool IsPeriodicDumpingEnabled() const { |
295 return MemoryDumpScheduler::GetInstance()->is_enabled_for_testing(); | 286 return MemoryDumpScheduler::GetInstance()->is_enabled_for_testing(); |
296 } | 287 } |
297 | 288 |
298 int GetMaxConsecutiveFailuresCount() const { | 289 int GetMaxConsecutiveFailuresCount() const { |
299 return MemoryDumpManager::kMaxConsecutiveFailuresCount; | 290 return MemoryDumpManager::kMaxConsecutiveFailuresCount; |
300 } | 291 } |
301 | 292 |
302 const MemoryDumpProvider::Options kDefaultOptions; | 293 const MemoryDumpProvider::Options kDefaultOptions; |
303 std::unique_ptr<MemoryDumpManager> mdm_; | 294 std::unique_ptr<MemoryDumpManager> mdm_; |
304 MemoryDumpManagerDelegateForTesting* delegate_; | 295 GlobalMemoryDumpHandler global_dump_handler_; |
305 bool last_callback_success_; | 296 bool last_callback_success_; |
306 | 297 |
307 private: | 298 private: |
308 std::unique_ptr<MessageLoop> message_loop_; | 299 std::unique_ptr<MessageLoop> message_loop_; |
309 | 300 |
310 // We want our singleton torn down after each test. | 301 // We want our singleton torn down after each test. |
311 ShadowingAtExitManager at_exit_manager_; | 302 ShadowingAtExitManager at_exit_manager_; |
312 }; | 303 }; |
313 | 304 |
314 // Basic sanity checks. Registers a memory dump provider and checks that it is | 305 // Basic sanity checks. Registers a memory dump provider and checks that it is |
315 // called, but only when memory-infra is enabled. | 306 // called, but only when memory-infra is enabled. |
316 TEST_F(MemoryDumpManagerTest, SingleDumper) { | 307 TEST_F(MemoryDumpManagerTest, SingleDumper) { |
317 InitializeMemoryDumpManager(false /* is_coordinator */); | 308 InitializeMemoryDumpManager(false /* is_coordinator */); |
318 MockMemoryDumpProvider mdp; | 309 MockMemoryDumpProvider mdp; |
319 RegisterDumpProvider(&mdp, ThreadTaskRunnerHandle::Get()); | 310 RegisterDumpProvider(&mdp, ThreadTaskRunnerHandle::Get()); |
320 | 311 |
321 // Check that the dumper is not called if the memory category is not enabled. | 312 // Check that the dumper is not called if the memory category is not enabled. |
322 EnableTracingWithLegacyCategories("foobar-but-not-memory"); | 313 EnableTracingWithLegacyCategories("foobar-but-not-memory"); |
323 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(0); | 314 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(0); |
324 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); | 315 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); |
325 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 316 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
326 MemoryDumpLevelOfDetail::DETAILED); | 317 MemoryDumpLevelOfDetail::DETAILED); |
327 DisableTracing(); | 318 DisableTracing(); |
328 | 319 |
329 // Now repeat enabling the memory category and check that the dumper is | 320 // Now repeat enabling the memory category and check that the dumper is |
330 // invoked this time. | 321 // invoked this time. |
331 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 322 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
332 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(3); | 323 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(3); |
333 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(3).WillRepeatedly(Return(true)); | 324 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(3).WillRepeatedly(Return(true)); |
334 for (int i = 0; i < 3; ++i) { | 325 for (int i = 0; i < 3; ++i) { |
335 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 326 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
336 MemoryDumpLevelOfDetail::DETAILED); | 327 MemoryDumpLevelOfDetail::DETAILED); |
337 } | 328 } |
338 DisableTracing(); | 329 DisableTracing(); |
339 | 330 |
340 mdm_->UnregisterDumpProvider(&mdp); | 331 mdm_->UnregisterDumpProvider(&mdp); |
341 | 332 |
342 // Finally check the unregister logic: the delegate will be invoked but not | 333 // Finally check the unregister logic: the global dump handler will be invoked |
343 // the dump provider, as it has been unregistered. | 334 // but not the dump provider, as it has been unregistered. |
344 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 335 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
345 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(3); | 336 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(3); |
346 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); | 337 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); |
347 | 338 |
348 for (int i = 0; i < 3; ++i) { | 339 for (int i = 0; i < 3; ++i) { |
349 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 340 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
350 MemoryDumpLevelOfDetail::DETAILED); | 341 MemoryDumpLevelOfDetail::DETAILED); |
351 } | 342 } |
352 DisableTracing(); | 343 DisableTracing(); |
353 } | 344 } |
354 | 345 |
355 // Checks that requesting dumps with high level of detail actually propagates | 346 // Checks that requesting dumps with high level of detail actually propagates |
356 // the level of the detail properly to OnMemoryDump() call on dump providers. | 347 // the level of the detail properly to OnMemoryDump() call on dump providers. |
357 TEST_F(MemoryDumpManagerTest, CheckMemoryDumpArgs) { | 348 TEST_F(MemoryDumpManagerTest, CheckMemoryDumpArgs) { |
358 InitializeMemoryDumpManager(false /* is_coordinator */); | 349 InitializeMemoryDumpManager(false /* is_coordinator */); |
359 MockMemoryDumpProvider mdp; | 350 MockMemoryDumpProvider mdp; |
360 | 351 |
361 RegisterDumpProvider(&mdp, ThreadTaskRunnerHandle::Get()); | 352 RegisterDumpProvider(&mdp, ThreadTaskRunnerHandle::Get()); |
362 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 353 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
363 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 354 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(1); |
364 EXPECT_CALL(mdp, OnMemoryDump(IsDetailedDump(), _)).WillOnce(Return(true)); | 355 EXPECT_CALL(mdp, OnMemoryDump(IsDetailedDump(), _)).WillOnce(Return(true)); |
365 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 356 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
366 MemoryDumpLevelOfDetail::DETAILED); | 357 MemoryDumpLevelOfDetail::DETAILED); |
367 DisableTracing(); | 358 DisableTracing(); |
368 mdm_->UnregisterDumpProvider(&mdp); | 359 mdm_->UnregisterDumpProvider(&mdp); |
369 | 360 |
370 // Check that requesting dumps with low level of detail actually propagates to | 361 // Check that requesting dumps with low level of detail actually propagates to |
371 // OnMemoryDump() call on dump providers. | 362 // OnMemoryDump() call on dump providers. |
372 RegisterDumpProvider(&mdp, ThreadTaskRunnerHandle::Get()); | 363 RegisterDumpProvider(&mdp, ThreadTaskRunnerHandle::Get()); |
373 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 364 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
374 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 365 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(1); |
375 EXPECT_CALL(mdp, OnMemoryDump(IsLightDump(), _)).WillOnce(Return(true)); | 366 EXPECT_CALL(mdp, OnMemoryDump(IsLightDump(), _)).WillOnce(Return(true)); |
376 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 367 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
377 MemoryDumpLevelOfDetail::LIGHT); | 368 MemoryDumpLevelOfDetail::LIGHT); |
378 DisableTracing(); | 369 DisableTracing(); |
379 mdm_->UnregisterDumpProvider(&mdp); | 370 mdm_->UnregisterDumpProvider(&mdp); |
380 } | 371 } |
381 | 372 |
382 // Checks that the SharedSessionState object is acqually shared over time. | 373 // Checks that the SharedSessionState object is acqually shared over time. |
383 TEST_F(MemoryDumpManagerTest, SharedSessionState) { | 374 TEST_F(MemoryDumpManagerTest, SharedSessionState) { |
384 InitializeMemoryDumpManager(false /* is_coordinator */); | 375 InitializeMemoryDumpManager(false /* is_coordinator */); |
385 MockMemoryDumpProvider mdp1; | 376 MockMemoryDumpProvider mdp1; |
386 MockMemoryDumpProvider mdp2; | 377 MockMemoryDumpProvider mdp2; |
387 RegisterDumpProvider(&mdp1, nullptr); | 378 RegisterDumpProvider(&mdp1, nullptr); |
388 RegisterDumpProvider(&mdp2, nullptr); | 379 RegisterDumpProvider(&mdp2, nullptr); |
389 | 380 |
390 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 381 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
391 const MemoryDumpSessionState* session_state = | 382 const MemoryDumpSessionState* session_state = |
392 mdm_->session_state_for_testing().get(); | 383 mdm_->session_state_for_testing().get(); |
393 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(2); | 384 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(2); |
394 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) | 385 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) |
395 .Times(2) | 386 .Times(2) |
396 .WillRepeatedly(Invoke([session_state](const MemoryDumpArgs&, | 387 .WillRepeatedly(Invoke([session_state](const MemoryDumpArgs&, |
397 ProcessMemoryDump* pmd) -> bool { | 388 ProcessMemoryDump* pmd) -> bool { |
398 EXPECT_EQ(session_state, pmd->session_state().get()); | 389 EXPECT_EQ(session_state, pmd->session_state().get()); |
399 return true; | 390 return true; |
400 })); | 391 })); |
401 EXPECT_CALL(mdp2, OnMemoryDump(_, _)) | 392 EXPECT_CALL(mdp2, OnMemoryDump(_, _)) |
402 .Times(2) | 393 .Times(2) |
403 .WillRepeatedly(Invoke([session_state](const MemoryDumpArgs&, | 394 .WillRepeatedly(Invoke([session_state](const MemoryDumpArgs&, |
(...skipping 12 matching lines...) Expand all Loading... | |
416 | 407 |
417 // Checks that the (Un)RegisterDumpProvider logic behaves sanely. | 408 // Checks that the (Un)RegisterDumpProvider logic behaves sanely. |
418 TEST_F(MemoryDumpManagerTest, MultipleDumpers) { | 409 TEST_F(MemoryDumpManagerTest, MultipleDumpers) { |
419 InitializeMemoryDumpManager(false /* is_coordinator */); | 410 InitializeMemoryDumpManager(false /* is_coordinator */); |
420 MockMemoryDumpProvider mdp1; | 411 MockMemoryDumpProvider mdp1; |
421 MockMemoryDumpProvider mdp2; | 412 MockMemoryDumpProvider mdp2; |
422 | 413 |
423 // Enable only mdp1. | 414 // Enable only mdp1. |
424 RegisterDumpProvider(&mdp1, ThreadTaskRunnerHandle::Get()); | 415 RegisterDumpProvider(&mdp1, ThreadTaskRunnerHandle::Get()); |
425 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 416 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
426 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 417 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(1); |
427 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).WillOnce(Return(true)); | 418 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).WillOnce(Return(true)); |
428 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).Times(0); | 419 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).Times(0); |
429 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 420 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
430 MemoryDumpLevelOfDetail::DETAILED); | 421 MemoryDumpLevelOfDetail::DETAILED); |
431 DisableTracing(); | 422 DisableTracing(); |
432 | 423 |
433 // Invert: enable mdp1 and disable mdp2. | 424 // Invert: enable mdp1 and disable mdp2. |
434 mdm_->UnregisterDumpProvider(&mdp1); | 425 mdm_->UnregisterDumpProvider(&mdp1); |
435 RegisterDumpProvider(&mdp2, nullptr); | 426 RegisterDumpProvider(&mdp2, nullptr); |
436 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 427 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
437 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 428 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(1); |
438 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(0); | 429 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(0); |
439 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).WillOnce(Return(true)); | 430 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).WillOnce(Return(true)); |
440 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 431 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
441 MemoryDumpLevelOfDetail::DETAILED); | 432 MemoryDumpLevelOfDetail::DETAILED); |
442 DisableTracing(); | 433 DisableTracing(); |
443 | 434 |
444 // Enable both mdp1 and mdp2. | 435 // Enable both mdp1 and mdp2. |
445 RegisterDumpProvider(&mdp1, nullptr); | 436 RegisterDumpProvider(&mdp1, nullptr); |
446 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 437 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
447 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 438 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(1); |
448 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).WillOnce(Return(true)); | 439 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).WillOnce(Return(true)); |
449 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).WillOnce(Return(true)); | 440 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).WillOnce(Return(true)); |
450 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 441 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
451 MemoryDumpLevelOfDetail::DETAILED); | 442 MemoryDumpLevelOfDetail::DETAILED); |
452 DisableTracing(); | 443 DisableTracing(); |
453 } | 444 } |
454 | 445 |
455 // Checks that the dump provider invocations depend only on the current | 446 // Checks that the dump provider invocations depend only on the current |
456 // registration state and not on previous registrations and dumps. | 447 // registration state and not on previous registrations and dumps. |
457 // Flaky on iOS, see crbug.com/706874 | 448 // Flaky on iOS, see crbug.com/706874 |
458 #if defined(OS_IOS) | 449 #if defined(OS_IOS) |
459 #define MAYBE_RegistrationConsistency DISABLED_RegistrationConsistency | 450 #define MAYBE_RegistrationConsistency DISABLED_RegistrationConsistency |
460 #else | 451 #else |
461 #define MAYBE_RegistrationConsistency RegistrationConsistency | 452 #define MAYBE_RegistrationConsistency RegistrationConsistency |
462 #endif | 453 #endif |
463 TEST_F(MemoryDumpManagerTest, MAYBE_RegistrationConsistency) { | 454 TEST_F(MemoryDumpManagerTest, MAYBE_RegistrationConsistency) { |
464 InitializeMemoryDumpManager(false /* is_coordinator */); | 455 InitializeMemoryDumpManager(false /* is_coordinator */); |
465 MockMemoryDumpProvider mdp; | 456 MockMemoryDumpProvider mdp; |
466 | 457 |
467 RegisterDumpProvider(&mdp, ThreadTaskRunnerHandle::Get()); | 458 RegisterDumpProvider(&mdp, ThreadTaskRunnerHandle::Get()); |
468 | 459 |
469 { | 460 { |
470 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 461 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(1); |
471 EXPECT_CALL(mdp, OnMemoryDump(_, _)).WillOnce(Return(true)); | 462 EXPECT_CALL(mdp, OnMemoryDump(_, _)).WillOnce(Return(true)); |
472 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 463 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
473 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 464 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
474 MemoryDumpLevelOfDetail::DETAILED); | 465 MemoryDumpLevelOfDetail::DETAILED); |
475 DisableTracing(); | 466 DisableTracing(); |
476 } | 467 } |
477 | 468 |
478 mdm_->UnregisterDumpProvider(&mdp); | 469 mdm_->UnregisterDumpProvider(&mdp); |
479 | 470 |
480 { | 471 { |
481 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 472 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(1); |
482 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); | 473 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); |
483 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 474 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
484 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 475 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
485 MemoryDumpLevelOfDetail::DETAILED); | 476 MemoryDumpLevelOfDetail::DETAILED); |
486 DisableTracing(); | 477 DisableTracing(); |
487 } | 478 } |
488 | 479 |
489 RegisterDumpProvider(&mdp, ThreadTaskRunnerHandle::Get()); | 480 RegisterDumpProvider(&mdp, ThreadTaskRunnerHandle::Get()); |
490 mdm_->UnregisterDumpProvider(&mdp); | 481 mdm_->UnregisterDumpProvider(&mdp); |
491 | 482 |
492 { | 483 { |
493 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 484 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(1); |
494 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); | 485 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); |
495 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 486 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
496 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 487 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
497 MemoryDumpLevelOfDetail::DETAILED); | 488 MemoryDumpLevelOfDetail::DETAILED); |
498 DisableTracing(); | 489 DisableTracing(); |
499 } | 490 } |
500 | 491 |
501 RegisterDumpProvider(&mdp, ThreadTaskRunnerHandle::Get()); | 492 RegisterDumpProvider(&mdp, ThreadTaskRunnerHandle::Get()); |
502 mdm_->UnregisterDumpProvider(&mdp); | 493 mdm_->UnregisterDumpProvider(&mdp); |
503 RegisterDumpProvider(&mdp, ThreadTaskRunnerHandle::Get()); | 494 RegisterDumpProvider(&mdp, ThreadTaskRunnerHandle::Get()); |
504 | 495 |
505 { | 496 { |
506 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 497 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(1); |
507 EXPECT_CALL(mdp, OnMemoryDump(_, _)).WillOnce(Return(true)); | 498 EXPECT_CALL(mdp, OnMemoryDump(_, _)).WillOnce(Return(true)); |
508 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 499 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
509 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 500 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
510 MemoryDumpLevelOfDetail::DETAILED); | 501 MemoryDumpLevelOfDetail::DETAILED); |
511 DisableTracing(); | 502 DisableTracing(); |
512 } | 503 } |
513 } | 504 } |
514 | 505 |
515 // Checks that the MemoryDumpManager respects the thread affinity when a | 506 // Checks that the MemoryDumpManager respects the thread affinity when a |
516 // MemoryDumpProvider specifies a task_runner(). The test starts creating 8 | 507 // MemoryDumpProvider specifies a task_runner(). The test starts creating 8 |
(...skipping 22 matching lines...) Expand all Loading... | |
539 .WillRepeatedly(Invoke( | 530 .WillRepeatedly(Invoke( |
540 [task_runner](const MemoryDumpArgs&, ProcessMemoryDump*) -> bool { | 531 [task_runner](const MemoryDumpArgs&, ProcessMemoryDump*) -> bool { |
541 EXPECT_TRUE(task_runner->RunsTasksOnCurrentThread()); | 532 EXPECT_TRUE(task_runner->RunsTasksOnCurrentThread()); |
542 return true; | 533 return true; |
543 })); | 534 })); |
544 } | 535 } |
545 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 536 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
546 | 537 |
547 while (!threads.empty()) { | 538 while (!threads.empty()) { |
548 last_callback_success_ = false; | 539 last_callback_success_ = false; |
549 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 540 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(1); |
550 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 541 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
551 MemoryDumpLevelOfDetail::DETAILED); | 542 MemoryDumpLevelOfDetail::DETAILED); |
552 EXPECT_TRUE(last_callback_success_); | 543 EXPECT_TRUE(last_callback_success_); |
553 | 544 |
554 // Unregister a MDP and destroy one thread at each iteration to check the | 545 // Unregister a MDP and destroy one thread at each iteration to check the |
555 // live unregistration logic. The unregistration needs to happen on the same | 546 // live unregistration logic. The unregistration needs to happen on the same |
556 // thread the MDP belongs to. | 547 // thread the MDP belongs to. |
557 { | 548 { |
558 RunLoop run_loop; | 549 RunLoop run_loop; |
559 Closure unregistration = | 550 Closure unregistration = |
(...skipping 24 matching lines...) Expand all Loading... | |
584 RegisterDumpProviderWithSequencedTaskRunner(&mdps[0], task_runner1, | 575 RegisterDumpProviderWithSequencedTaskRunner(&mdps[0], task_runner1, |
585 kDefaultOptions); | 576 kDefaultOptions); |
586 RegisterDumpProviderWithSequencedTaskRunner(&mdps[1], task_runner2, | 577 RegisterDumpProviderWithSequencedTaskRunner(&mdps[1], task_runner2, |
587 kDefaultOptions); | 578 kDefaultOptions); |
588 RegisterDumpProviderWithSequencedTaskRunner(&mdps[2], task_runner2, | 579 RegisterDumpProviderWithSequencedTaskRunner(&mdps[2], task_runner2, |
589 kDefaultOptions); | 580 kDefaultOptions); |
590 // |mdps[0]| should be disabled permanently after first dump. | 581 // |mdps[0]| should be disabled permanently after first dump. |
591 EXPECT_CALL(mdps[0], OnMemoryDump(_, _)).Times(0); | 582 EXPECT_CALL(mdps[0], OnMemoryDump(_, _)).Times(0); |
592 EXPECT_CALL(mdps[1], OnMemoryDump(_, _)).Times(2); | 583 EXPECT_CALL(mdps[1], OnMemoryDump(_, _)).Times(2); |
593 EXPECT_CALL(mdps[2], OnMemoryDump(_, _)).Times(2); | 584 EXPECT_CALL(mdps[2], OnMemoryDump(_, _)).Times(2); |
594 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(2); | 585 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(2); |
595 | 586 |
596 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 587 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
597 | 588 |
598 task_runner1->set_enabled(false); | 589 task_runner1->set_enabled(false); |
599 last_callback_success_ = false; | 590 last_callback_success_ = false; |
600 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 591 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
601 MemoryDumpLevelOfDetail::DETAILED); | 592 MemoryDumpLevelOfDetail::DETAILED); |
602 // Tasks should be individually posted even if |mdps[1]| and |mdps[2]| belong | 593 // Tasks should be individually posted even if |mdps[1]| and |mdps[2]| belong |
603 // to same task runner. | 594 // to same task runner. |
604 EXPECT_EQ(1u, task_runner1->no_of_post_tasks()); | 595 EXPECT_EQ(1u, task_runner1->no_of_post_tasks()); |
(...skipping 15 matching lines...) Expand all Loading... | |
620 TEST_F(MemoryDumpManagerTest, DisableFailingDumpers) { | 611 TEST_F(MemoryDumpManagerTest, DisableFailingDumpers) { |
621 InitializeMemoryDumpManager(false /* is_coordinator */); | 612 InitializeMemoryDumpManager(false /* is_coordinator */); |
622 MockMemoryDumpProvider mdp1; | 613 MockMemoryDumpProvider mdp1; |
623 MockMemoryDumpProvider mdp2; | 614 MockMemoryDumpProvider mdp2; |
624 | 615 |
625 RegisterDumpProvider(&mdp1, nullptr); | 616 RegisterDumpProvider(&mdp1, nullptr); |
626 RegisterDumpProvider(&mdp2, nullptr); | 617 RegisterDumpProvider(&mdp2, nullptr); |
627 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 618 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
628 | 619 |
629 const int kNumDumps = 2 * GetMaxConsecutiveFailuresCount(); | 620 const int kNumDumps = 2 * GetMaxConsecutiveFailuresCount(); |
630 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(kNumDumps); | 621 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)) |
622 .Times(kNumDumps); | |
631 | 623 |
632 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) | 624 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) |
633 .Times(GetMaxConsecutiveFailuresCount()) | 625 .Times(GetMaxConsecutiveFailuresCount()) |
634 .WillRepeatedly(Return(false)); | 626 .WillRepeatedly(Return(false)); |
635 | 627 |
636 EXPECT_CALL(mdp2, OnMemoryDump(_, _)) | 628 EXPECT_CALL(mdp2, OnMemoryDump(_, _)) |
637 .WillOnce(Return(false)) | 629 .WillOnce(Return(false)) |
638 .WillOnce(Return(true)) | 630 .WillOnce(Return(true)) |
639 .WillOnce(Return(false)) | 631 .WillOnce(Return(false)) |
640 .WillOnce(Return(false)) | 632 .WillOnce(Return(false)) |
(...skipping 11 matching lines...) Expand all Loading... | |
652 // Sneakily registers an extra memory dump provider while an existing one is | 644 // Sneakily registers an extra memory dump provider while an existing one is |
653 // dumping and expect it to take part in the already active tracing session. | 645 // dumping and expect it to take part in the already active tracing session. |
654 TEST_F(MemoryDumpManagerTest, RegisterDumperWhileDumping) { | 646 TEST_F(MemoryDumpManagerTest, RegisterDumperWhileDumping) { |
655 InitializeMemoryDumpManager(false /* is_coordinator */); | 647 InitializeMemoryDumpManager(false /* is_coordinator */); |
656 MockMemoryDumpProvider mdp1; | 648 MockMemoryDumpProvider mdp1; |
657 MockMemoryDumpProvider mdp2; | 649 MockMemoryDumpProvider mdp2; |
658 | 650 |
659 RegisterDumpProvider(&mdp1, nullptr); | 651 RegisterDumpProvider(&mdp1, nullptr); |
660 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 652 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
661 | 653 |
662 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(4); | 654 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(4); |
663 | 655 |
664 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) | 656 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) |
665 .Times(4) | 657 .Times(4) |
666 .WillOnce(Return(true)) | 658 .WillOnce(Return(true)) |
667 .WillOnce( | 659 .WillOnce( |
668 Invoke([&mdp2](const MemoryDumpArgs&, ProcessMemoryDump*) -> bool { | 660 Invoke([&mdp2](const MemoryDumpArgs&, ProcessMemoryDump*) -> bool { |
669 RegisterDumpProvider(&mdp2, nullptr); | 661 RegisterDumpProvider(&mdp2, nullptr); |
670 return true; | 662 return true; |
671 })) | 663 })) |
672 .WillRepeatedly(Return(true)); | 664 .WillRepeatedly(Return(true)); |
(...skipping 15 matching lines...) Expand all Loading... | |
688 // Like RegisterDumperWhileDumping, but unregister the dump provider instead. | 680 // Like RegisterDumperWhileDumping, but unregister the dump provider instead. |
689 TEST_F(MemoryDumpManagerTest, UnregisterDumperWhileDumping) { | 681 TEST_F(MemoryDumpManagerTest, UnregisterDumperWhileDumping) { |
690 InitializeMemoryDumpManager(false /* is_coordinator */); | 682 InitializeMemoryDumpManager(false /* is_coordinator */); |
691 MockMemoryDumpProvider mdp1; | 683 MockMemoryDumpProvider mdp1; |
692 MockMemoryDumpProvider mdp2; | 684 MockMemoryDumpProvider mdp2; |
693 | 685 |
694 RegisterDumpProvider(&mdp1, ThreadTaskRunnerHandle::Get(), kDefaultOptions); | 686 RegisterDumpProvider(&mdp1, ThreadTaskRunnerHandle::Get(), kDefaultOptions); |
695 RegisterDumpProvider(&mdp2, ThreadTaskRunnerHandle::Get(), kDefaultOptions); | 687 RegisterDumpProvider(&mdp2, ThreadTaskRunnerHandle::Get(), kDefaultOptions); |
696 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 688 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
697 | 689 |
698 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(4); | 690 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(4); |
699 | 691 |
700 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) | 692 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) |
701 .Times(4) | 693 .Times(4) |
702 .WillOnce(Return(true)) | 694 .WillOnce(Return(true)) |
703 .WillOnce( | 695 .WillOnce( |
704 Invoke([&mdp2](const MemoryDumpArgs&, ProcessMemoryDump*) -> bool { | 696 Invoke([&mdp2](const MemoryDumpArgs&, ProcessMemoryDump*) -> bool { |
705 MemoryDumpManager::GetInstance()->UnregisterDumpProvider(&mdp2); | 697 MemoryDumpManager::GetInstance()->UnregisterDumpProvider(&mdp2); |
706 return true; | 698 return true; |
707 })) | 699 })) |
708 .WillRepeatedly(Return(true)); | 700 .WillRepeatedly(Return(true)); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
758 | 750 |
759 // OnMemoryDump is called once for the provider that dumps first, and zero | 751 // OnMemoryDump is called once for the provider that dumps first, and zero |
760 // times for the other provider. | 752 // times for the other provider. |
761 EXPECT_CALL(*mdp, OnMemoryDump(_, _)) | 753 EXPECT_CALL(*mdp, OnMemoryDump(_, _)) |
762 .Times(AtMost(1)) | 754 .Times(AtMost(1)) |
763 .WillOnce(Invoke(on_dump)); | 755 .WillOnce(Invoke(on_dump)); |
764 } | 756 } |
765 | 757 |
766 last_callback_success_ = false; | 758 last_callback_success_ = false; |
767 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 759 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
768 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 760 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(1); |
769 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 761 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
770 MemoryDumpLevelOfDetail::DETAILED); | 762 MemoryDumpLevelOfDetail::DETAILED); |
771 ASSERT_EQ(1, on_memory_dump_call_count); | 763 ASSERT_EQ(1, on_memory_dump_call_count); |
772 ASSERT_TRUE(last_callback_success_); | 764 ASSERT_TRUE(last_callback_success_); |
773 | 765 |
774 DisableTracing(); | 766 DisableTracing(); |
775 } | 767 } |
776 | 768 |
777 TEST_F(MemoryDumpManagerTest, TestPollingOnDumpThread) { | 769 TEST_F(MemoryDumpManagerTest, TestPollingOnDumpThread) { |
778 InitializeMemoryDumpManager(false /* is_coordinator */); | 770 InitializeMemoryDumpManager(false /* is_coordinator */); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
860 | 852 |
861 // OnMemoryDump is called once for the provider that dumps first, and zero | 853 // OnMemoryDump is called once for the provider that dumps first, and zero |
862 // times for the other provider. | 854 // times for the other provider. |
863 EXPECT_CALL(*mdp, OnMemoryDump(_, _)) | 855 EXPECT_CALL(*mdp, OnMemoryDump(_, _)) |
864 .Times(AtMost(1)) | 856 .Times(AtMost(1)) |
865 .WillOnce(Invoke(on_dump)); | 857 .WillOnce(Invoke(on_dump)); |
866 } | 858 } |
867 | 859 |
868 last_callback_success_ = false; | 860 last_callback_success_ = false; |
869 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 861 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
870 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 862 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(1); |
871 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 863 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
872 MemoryDumpLevelOfDetail::DETAILED); | 864 MemoryDumpLevelOfDetail::DETAILED); |
873 ASSERT_EQ(1, on_memory_dump_call_count); | 865 ASSERT_EQ(1, on_memory_dump_call_count); |
874 ASSERT_TRUE(last_callback_success_); | 866 ASSERT_TRUE(last_callback_success_); |
875 | 867 |
876 DisableTracing(); | 868 DisableTracing(); |
877 } | 869 } |
878 | 870 |
879 // Checks that a NACK callback is invoked if RequestGlobalDump() is called when | 871 // Checks that a NACK callback is invoked if RequestGlobalDump() is called when |
880 // tracing is not enabled. | 872 // tracing is not enabled. |
881 TEST_F(MemoryDumpManagerTest, CallbackCalledOnFailure) { | 873 TEST_F(MemoryDumpManagerTest, CallbackCalledOnFailure) { |
882 InitializeMemoryDumpManager(false /* is_coordinator */); | 874 InitializeMemoryDumpManager(false /* is_coordinator */); |
883 MockMemoryDumpProvider mdp1; | 875 MockMemoryDumpProvider mdp1; |
884 RegisterDumpProvider(&mdp1, nullptr); | 876 RegisterDumpProvider(&mdp1, nullptr); |
885 | 877 |
886 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(0); | 878 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(0); |
887 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(0); | 879 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(0); |
888 | 880 |
889 last_callback_success_ = true; | 881 last_callback_success_ = true; |
890 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 882 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
891 MemoryDumpLevelOfDetail::DETAILED); | 883 MemoryDumpLevelOfDetail::DETAILED); |
892 EXPECT_FALSE(last_callback_success_); | 884 EXPECT_FALSE(last_callback_success_); |
893 } | 885 } |
894 | 886 |
895 // Checks that is the MemoryDumpManager is initialized after tracing already | 887 // Checks that is the MemoryDumpManager is initialized after tracing already |
896 // began, it will still late-join the party (real use case: startup tracing). | 888 // began, it will still late-join the party (real use case: startup tracing). |
897 TEST_F(MemoryDumpManagerTest, InitializedAfterStartOfTracing) { | 889 TEST_F(MemoryDumpManagerTest, InitializedAfterStartOfTracing) { |
898 MockMemoryDumpProvider mdp; | 890 MockMemoryDumpProvider mdp; |
899 RegisterDumpProvider(&mdp, nullptr); | 891 RegisterDumpProvider(&mdp, nullptr); |
900 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 892 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
901 | 893 |
902 // First check that a RequestGlobalDump() issued before the MemoryDumpManager | 894 // First check that a RequestGlobalDump() issued before the MemoryDumpManager |
903 // initialization gets NACK-ed cleanly. | 895 // initialization gets NACK-ed cleanly. |
904 { | 896 { |
905 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); | 897 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); |
906 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 898 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
907 MemoryDumpLevelOfDetail::DETAILED); | 899 MemoryDumpLevelOfDetail::DETAILED); |
908 EXPECT_FALSE(last_callback_success_); | 900 EXPECT_FALSE(last_callback_success_); |
909 } | 901 } |
910 | 902 |
911 // Now late-initialize the MemoryDumpManager and check that the | 903 // Now late-initialize the MemoryDumpManager and check that the |
912 // RequestGlobalDump completes successfully. | 904 // RequestGlobalDump completes successfully. |
913 { | 905 { |
914 InitializeMemoryDumpManager(false /* is_coordinator */); | 906 InitializeMemoryDumpManager(false /* is_coordinator */); |
915 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(1); | 907 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(1); |
916 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 908 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(1); |
917 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 909 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
918 MemoryDumpLevelOfDetail::DETAILED); | 910 MemoryDumpLevelOfDetail::DETAILED); |
919 EXPECT_TRUE(last_callback_success_); | 911 EXPECT_TRUE(last_callback_success_); |
920 } | 912 } |
921 DisableTracing(); | 913 DisableTracing(); |
922 } | 914 } |
923 | 915 |
924 // This test (and the MemoryDumpManagerTestCoordinator below) crystallizes the | 916 // This test (and the MemoryDumpManagerTestCoordinator below) crystallizes the |
925 // expectations of the chrome://tracing UI and chrome telemetry w.r.t. periodic | 917 // expectations of the chrome://tracing UI and chrome telemetry w.r.t. periodic |
926 // dumps in memory-infra, handling gracefully the transition between the legacy | 918 // dumps in memory-infra, handling gracefully the transition between the legacy |
927 // and the new-style (JSON-based) TraceConfig. | 919 // and the new-style (JSON-based) TraceConfig. |
928 TEST_F(MemoryDumpManagerTest, TraceConfigExpectations) { | 920 TEST_F(MemoryDumpManagerTest, TraceConfigExpectations) { |
929 InitializeMemoryDumpManager(false /* is_coordinator */); | 921 InitializeMemoryDumpManager(false /* is_coordinator */); |
930 MemoryDumpManagerDelegateForTesting& delegate = *delegate_; | |
931 | 922 |
932 // Don't trigger the default behavior of the mock delegate in this test, | 923 // Don't trigger the default behavior of the global dump handler in this test, |
933 // which would short-circuit the dump request to the actual | 924 // which would short-circuit the dump request to the actual |
934 // CreateProcessDump(). | 925 // CreateProcessDump(). |
935 // We don't want to create any dump in this test, only check whether the dumps | 926 // We don't want to create any dump in this test, only check whether the dumps |
936 // are requested or not. | 927 // are requested or not. |
937 ON_CALL(delegate, RequestGlobalMemoryDump(_, _)).WillByDefault(Return()); | 928 ON_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)) |
929 .WillByDefault(Return()); | |
938 | 930 |
939 // Enabling memory-infra in a non-coordinator process should not trigger any | 931 // Enabling memory-infra in a non-coordinator process should not trigger any |
940 // periodic dumps. | 932 // periodic dumps. |
941 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 933 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
942 EXPECT_FALSE(IsPeriodicDumpingEnabled()); | 934 EXPECT_FALSE(IsPeriodicDumpingEnabled()); |
943 DisableTracing(); | 935 DisableTracing(); |
944 | 936 |
945 // Enabling memory-infra with the new (JSON) TraceConfig in a non-coordinator | 937 // Enabling memory-infra with the new (JSON) TraceConfig in a non-coordinator |
946 // process with a fully defined trigger config should NOT enable any periodic | 938 // process with a fully defined trigger config should NOT enable any periodic |
947 // dumps. | 939 // dumps. |
948 EnableTracingWithTraceConfig( | 940 EnableTracingWithTraceConfig( |
949 TraceConfigMemoryTestUtil::GetTraceConfig_PeriodicTriggers(1, 5)); | 941 TraceConfigMemoryTestUtil::GetTraceConfig_PeriodicTriggers(1, 5)); |
950 EXPECT_FALSE(IsPeriodicDumpingEnabled()); | 942 EXPECT_FALSE(IsPeriodicDumpingEnabled()); |
951 DisableTracing(); | 943 DisableTracing(); |
952 } | 944 } |
953 | 945 |
954 TEST_F(MemoryDumpManagerTest, TraceConfigExpectationsWhenIsCoordinator) { | 946 TEST_F(MemoryDumpManagerTest, TraceConfigExpectationsWhenIsCoordinator) { |
955 InitializeMemoryDumpManager(true /* is_coordinator */); | 947 InitializeMemoryDumpManager(true /* is_coordinator */); |
956 MemoryDumpManagerDelegateForTesting& delegate = *delegate_; | 948 ON_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)) |
957 ON_CALL(delegate, RequestGlobalMemoryDump(_, _)).WillByDefault(Return()); | 949 .WillByDefault(Return()); |
958 | 950 |
959 // Enabling memory-infra with the legacy TraceConfig (category filter) in | 951 // Enabling memory-infra with the legacy TraceConfig (category filter) in |
960 // a coordinator process should enable periodic dumps. | 952 // a coordinator process should enable periodic dumps. |
961 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 953 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
962 EXPECT_TRUE(IsPeriodicDumpingEnabled()); | 954 EXPECT_TRUE(IsPeriodicDumpingEnabled()); |
963 DisableTracing(); | 955 DisableTracing(); |
964 | 956 |
965 // Enabling memory-infra with the new (JSON) TraceConfig in a coordinator | 957 // Enabling memory-infra with the new (JSON) TraceConfig in a coordinator |
966 // process without specifying any "memory_dump_config" section should enable | 958 // process without specifying any "memory_dump_config" section should enable |
967 // periodic dumps. This is to preserve the behavior chrome://tracing UI, that | 959 // periodic dumps. This is to preserve the behavior chrome://tracing UI, that |
(...skipping 17 matching lines...) Expand all Loading... | |
985 // be performed in the correct order. | 977 // be performed in the correct order. |
986 RunLoop run_loop; | 978 RunLoop run_loop; |
987 auto test_task_runner = ThreadTaskRunnerHandle::Get(); | 979 auto test_task_runner = ThreadTaskRunnerHandle::Get(); |
988 auto quit_closure = run_loop.QuitClosure(); | 980 auto quit_closure = run_loop.QuitClosure(); |
989 | 981 |
990 const int kHeavyDumpRate = 5; | 982 const int kHeavyDumpRate = 5; |
991 const int kLightDumpPeriodMs = 1; | 983 const int kLightDumpPeriodMs = 1; |
992 const int kHeavyDumpPeriodMs = kHeavyDumpRate * kLightDumpPeriodMs; | 984 const int kHeavyDumpPeriodMs = kHeavyDumpRate * kLightDumpPeriodMs; |
993 // The expected sequence with light=1ms, heavy=5ms is H,L,L,L,L,H,... | 985 // The expected sequence with light=1ms, heavy=5ms is H,L,L,L,L,H,... |
994 testing::InSequence sequence; | 986 testing::InSequence sequence; |
995 EXPECT_CALL(delegate, RequestGlobalMemoryDump(IsDetailedDump(), _)); | 987 EXPECT_CALL(global_dump_handler_, |
996 EXPECT_CALL(delegate, RequestGlobalMemoryDump(IsLightDump(), _)) | 988 RequestGlobalMemoryDump(IsDetailedDump(), _)); |
989 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(IsLightDump(), _)) | |
997 .Times(kHeavyDumpRate - 1); | 990 .Times(kHeavyDumpRate - 1); |
998 EXPECT_CALL(delegate, RequestGlobalMemoryDump(IsDetailedDump(), _)); | 991 EXPECT_CALL(global_dump_handler_, |
999 EXPECT_CALL(delegate, RequestGlobalMemoryDump(IsLightDump(), _)) | 992 RequestGlobalMemoryDump(IsDetailedDump(), _)); |
993 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(IsLightDump(), _)) | |
1000 .Times(kHeavyDumpRate - 2); | 994 .Times(kHeavyDumpRate - 2); |
1001 EXPECT_CALL(delegate, RequestGlobalMemoryDump(IsLightDump(), _)) | 995 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(IsLightDump(), _)) |
1002 .WillOnce(Invoke([test_task_runner, quit_closure]( | 996 .WillOnce(Invoke([test_task_runner, quit_closure]( |
1003 const MemoryDumpRequestArgs& args, | 997 const MemoryDumpRequestArgs& args, |
1004 const GlobalMemoryDumpCallback& callback) { | 998 const GlobalMemoryDumpCallback& callback) { |
1005 test_task_runner->PostTask(FROM_HERE, quit_closure); | 999 test_task_runner->PostTask(FROM_HERE, quit_closure); |
1006 })); | 1000 })); |
1007 | 1001 |
1008 // Swallow all the final spurious calls until tracing gets disabled. | 1002 // Swallow all the final spurious calls until tracing gets disabled. |
1009 EXPECT_CALL(delegate, RequestGlobalMemoryDump(_, _)).Times(AnyNumber()); | 1003 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)) |
1004 .Times(AnyNumber()); | |
1010 | 1005 |
1011 EnableTracingWithTraceConfig( | 1006 EnableTracingWithTraceConfig( |
1012 TraceConfigMemoryTestUtil::GetTraceConfig_PeriodicTriggers( | 1007 TraceConfigMemoryTestUtil::GetTraceConfig_PeriodicTriggers( |
1013 kLightDumpPeriodMs, kHeavyDumpPeriodMs)); | 1008 kLightDumpPeriodMs, kHeavyDumpPeriodMs)); |
1014 run_loop.Run(); | 1009 run_loop.Run(); |
1015 DisableTracing(); | 1010 DisableTracing(); |
1016 } | 1011 } |
1017 | 1012 |
1018 // Tests against race conditions that might arise when disabling tracing in the | 1013 // Tests against race conditions that might arise when disabling tracing in the |
1019 // middle of a global memory dump. | 1014 // middle of a global memory dump. |
(...skipping 15 matching lines...) Expand all Loading... | |
1035 MockMemoryDumpProvider mdp_with_affinity; | 1030 MockMemoryDumpProvider mdp_with_affinity; |
1036 RegisterDumpProvider(&mdp_with_affinity, mdp_thread->task_runner(), | 1031 RegisterDumpProvider(&mdp_with_affinity, mdp_thread->task_runner(), |
1037 kDefaultOptions); | 1032 kDefaultOptions); |
1038 | 1033 |
1039 // Register also an unbound dump provider. Unbound dump providers are always | 1034 // Register also an unbound dump provider. Unbound dump providers are always |
1040 // invoked after bound ones. | 1035 // invoked after bound ones. |
1041 MockMemoryDumpProvider unbound_mdp; | 1036 MockMemoryDumpProvider unbound_mdp; |
1042 RegisterDumpProvider(&unbound_mdp, nullptr, kDefaultOptions); | 1037 RegisterDumpProvider(&unbound_mdp, nullptr, kDefaultOptions); |
1043 | 1038 |
1044 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 1039 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
1045 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 1040 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(1); |
1046 EXPECT_CALL(mdp_with_affinity, OnMemoryDump(_, _)) | 1041 EXPECT_CALL(mdp_with_affinity, OnMemoryDump(_, _)) |
1047 .Times(1) | 1042 .Times(1) |
1048 .WillOnce( | 1043 .WillOnce( |
1049 Invoke([&tracing_disabled_event](const MemoryDumpArgs&, | 1044 Invoke([&tracing_disabled_event](const MemoryDumpArgs&, |
1050 ProcessMemoryDump* pmd) -> bool { | 1045 ProcessMemoryDump* pmd) -> bool { |
1051 tracing_disabled_event.Wait(); | 1046 tracing_disabled_event.Wait(); |
1052 | 1047 |
1053 // At this point tracing has been disabled and the | 1048 // At this point tracing has been disabled and the |
1054 // MemoryDumpManager.dump_thread_ has been shut down. | 1049 // MemoryDumpManager.dump_thread_ has been shut down. |
1055 return true; | 1050 return true; |
(...skipping 28 matching lines...) Expand all Loading... | |
1084 std::unique_ptr<Thread> mdp_thread(new Thread("test thread")); | 1079 std::unique_ptr<Thread> mdp_thread(new Thread("test thread")); |
1085 mdp_thread->Start(); | 1080 mdp_thread->Start(); |
1086 | 1081 |
1087 // Create both same-thread MDP and another MDP with dedicated thread | 1082 // Create both same-thread MDP and another MDP with dedicated thread |
1088 MockMemoryDumpProvider mdp1; | 1083 MockMemoryDumpProvider mdp1; |
1089 RegisterDumpProvider(&mdp1, nullptr); | 1084 RegisterDumpProvider(&mdp1, nullptr); |
1090 MockMemoryDumpProvider mdp2; | 1085 MockMemoryDumpProvider mdp2; |
1091 RegisterDumpProvider(&mdp2, mdp_thread->task_runner(), kDefaultOptions); | 1086 RegisterDumpProvider(&mdp2, mdp_thread->task_runner(), kDefaultOptions); |
1092 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 1087 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
1093 | 1088 |
1094 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)) | 1089 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)) |
1095 .WillOnce(Invoke([this](const MemoryDumpRequestArgs& args, | 1090 .WillOnce(Invoke([this](const MemoryDumpRequestArgs& args, |
1096 const GlobalMemoryDumpCallback& callback) { | 1091 const GlobalMemoryDumpCallback& callback) { |
1097 DisableTracing(); | 1092 DisableTracing(); |
1098 ProcessMemoryDumpCallback process_callback = | 1093 ProcessMemoryDumpCallback process_callback = |
1099 Bind(&ProcessDumpCallbackAdapter, callback); | 1094 Bind(&ProcessDumpCallbackAdapter, callback); |
1100 delegate_->CreateProcessDump(args, process_callback); | 1095 mdm_->CreateProcessDump(args, process_callback); |
1101 })); | 1096 })); |
1102 | 1097 |
1103 // If tracing is disabled for current session CreateProcessDump() should NOT | 1098 // If tracing is disabled for current session CreateProcessDump() should NOT |
1104 // request dumps from providers. Real-world regression: crbug.com/600570 . | 1099 // request dumps from providers. Real-world regression: crbug.com/600570 . |
1105 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(0); | 1100 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(0); |
1106 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).Times(0); | 1101 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).Times(0); |
1107 | 1102 |
1108 last_callback_success_ = true; | 1103 last_callback_success_ = true; |
1109 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 1104 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
1110 MemoryDumpLevelOfDetail::DETAILED); | 1105 MemoryDumpLevelOfDetail::DETAILED); |
(...skipping 14 matching lines...) Expand all Loading... | |
1125 MockMemoryDumpProvider mdp2; | 1120 MockMemoryDumpProvider mdp2; |
1126 options.target_pid = 123; | 1121 options.target_pid = 123; |
1127 RegisterDumpProvider(&mdp2, nullptr, options); | 1122 RegisterDumpProvider(&mdp2, nullptr, options); |
1128 | 1123 |
1129 // Another provider with out-of-process dumping. | 1124 // Another provider with out-of-process dumping. |
1130 MockMemoryDumpProvider mdp3; | 1125 MockMemoryDumpProvider mdp3; |
1131 options.target_pid = 456; | 1126 options.target_pid = 456; |
1132 RegisterDumpProvider(&mdp3, nullptr, options); | 1127 RegisterDumpProvider(&mdp3, nullptr, options); |
1133 | 1128 |
1134 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 1129 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
1135 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 1130 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(1); |
1136 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(1).WillRepeatedly(Return(true)); | 1131 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(1).WillRepeatedly(Return(true)); |
1137 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).Times(1).WillRepeatedly(Return(true)); | 1132 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).Times(1).WillRepeatedly(Return(true)); |
1138 EXPECT_CALL(mdp3, OnMemoryDump(_, _)).Times(1).WillRepeatedly(Return(true)); | 1133 EXPECT_CALL(mdp3, OnMemoryDump(_, _)).Times(1).WillRepeatedly(Return(true)); |
1139 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 1134 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
1140 MemoryDumpLevelOfDetail::DETAILED); | 1135 MemoryDumpLevelOfDetail::DETAILED); |
1141 DisableTracing(); | 1136 DisableTracing(); |
1142 | 1137 |
1143 // Flush the trace into JSON. | 1138 // Flush the trace into JSON. |
1144 trace_event::TraceResultBuffer buffer; | 1139 trace_event::TraceResultBuffer buffer; |
1145 TraceResultBuffer::SimpleOutput trace_output; | 1140 TraceResultBuffer::SimpleOutput trace_output; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1219 EXPECT_CALL(*mdp, OnMemoryDump(_, _)) | 1214 EXPECT_CALL(*mdp, OnMemoryDump(_, _)) |
1220 .Times(1) | 1215 .Times(1) |
1221 .WillOnce(Invoke(self_unregister_from_another_thread)); | 1216 .WillOnce(Invoke(self_unregister_from_another_thread)); |
1222 EXPECT_CALL(*mdp, Destructor()) | 1217 EXPECT_CALL(*mdp, Destructor()) |
1223 .Times(1) | 1218 .Times(1) |
1224 .WillOnce(Invoke([&thread_ref]() { | 1219 .WillOnce(Invoke([&thread_ref]() { |
1225 EXPECT_EQ(thread_ref, PlatformThread::CurrentRef()); | 1220 EXPECT_EQ(thread_ref, PlatformThread::CurrentRef()); |
1226 })); | 1221 })); |
1227 | 1222 |
1228 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 1223 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
1229 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(2); | 1224 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(2); |
1230 for (int i = 0; i < 2; ++i) { | 1225 for (int i = 0; i < 2; ++i) { |
1231 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 1226 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
1232 MemoryDumpLevelOfDetail::DETAILED); | 1227 MemoryDumpLevelOfDetail::DETAILED); |
1233 } | 1228 } |
1234 DisableTracing(); | 1229 DisableTracing(); |
1235 } | 1230 } |
1236 | 1231 |
1237 TEST_F(MemoryDumpManagerTest, TestWhitelistingMDP) { | 1232 TEST_F(MemoryDumpManagerTest, TestWhitelistingMDP) { |
1238 InitializeMemoryDumpManager(false /* is_coordinator */); | 1233 InitializeMemoryDumpManager(false /* is_coordinator */); |
1239 SetDumpProviderWhitelistForTesting(kTestMDPWhitelist); | 1234 SetDumpProviderWhitelistForTesting(kTestMDPWhitelist); |
1240 std::unique_ptr<MockMemoryDumpProvider> mdp1(new MockMemoryDumpProvider); | 1235 std::unique_ptr<MockMemoryDumpProvider> mdp1(new MockMemoryDumpProvider); |
1241 RegisterDumpProvider(mdp1.get(), nullptr); | 1236 RegisterDumpProvider(mdp1.get(), nullptr); |
1242 std::unique_ptr<MockMemoryDumpProvider> mdp2(new MockMemoryDumpProvider); | 1237 std::unique_ptr<MockMemoryDumpProvider> mdp2(new MockMemoryDumpProvider); |
1243 RegisterDumpProvider(mdp2.get(), nullptr, kDefaultOptions, | 1238 RegisterDumpProvider(mdp2.get(), nullptr, kDefaultOptions, |
1244 kWhitelistedMDPName); | 1239 kWhitelistedMDPName); |
1245 | 1240 |
1246 EXPECT_CALL(*mdp1, OnMemoryDump(_, _)).Times(0); | 1241 EXPECT_CALL(*mdp1, OnMemoryDump(_, _)).Times(0); |
1247 EXPECT_CALL(*mdp2, OnMemoryDump(_, _)).Times(1).WillOnce(Return(true)); | 1242 EXPECT_CALL(*mdp2, OnMemoryDump(_, _)).Times(1).WillOnce(Return(true)); |
1248 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 1243 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(1); |
1249 | 1244 |
1250 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 1245 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
1251 EXPECT_FALSE(IsPeriodicDumpingEnabled()); | 1246 EXPECT_FALSE(IsPeriodicDumpingEnabled()); |
1252 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 1247 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
1253 MemoryDumpLevelOfDetail::BACKGROUND); | 1248 MemoryDumpLevelOfDetail::BACKGROUND); |
1254 DisableTracing(); | 1249 DisableTracing(); |
1255 } | 1250 } |
1256 | 1251 |
1257 TEST_F(MemoryDumpManagerTest, TestBackgroundTracingSetup) { | 1252 TEST_F(MemoryDumpManagerTest, TestBackgroundTracingSetup) { |
1258 InitializeMemoryDumpManager(true /* is_coordinator */); | 1253 InitializeMemoryDumpManager(true /* is_coordinator */); |
1259 | 1254 |
1260 RunLoop run_loop; | 1255 RunLoop run_loop; |
1261 auto test_task_runner = ThreadTaskRunnerHandle::Get(); | 1256 auto test_task_runner = ThreadTaskRunnerHandle::Get(); |
1262 auto quit_closure = run_loop.QuitClosure(); | 1257 auto quit_closure = run_loop.QuitClosure(); |
1263 | 1258 |
1264 testing::InSequence sequence; | 1259 testing::InSequence sequence; |
1265 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(IsBackgroundDump(), _)) | 1260 EXPECT_CALL(global_dump_handler_, |
1261 RequestGlobalMemoryDump(IsBackgroundDump(), _)) | |
1266 .Times(5); | 1262 .Times(5); |
1267 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(IsBackgroundDump(), _)) | 1263 EXPECT_CALL(global_dump_handler_, |
1264 RequestGlobalMemoryDump(IsBackgroundDump(), _)) | |
1268 .WillOnce(Invoke([test_task_runner, quit_closure]( | 1265 .WillOnce(Invoke([test_task_runner, quit_closure]( |
1269 const MemoryDumpRequestArgs& args, | 1266 const MemoryDumpRequestArgs& args, |
1270 const GlobalMemoryDumpCallback& callback) { | 1267 const GlobalMemoryDumpCallback& callback) { |
1271 test_task_runner->PostTask(FROM_HERE, quit_closure); | 1268 test_task_runner->PostTask(FROM_HERE, quit_closure); |
1272 })); | 1269 })); |
1273 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(AnyNumber()); | 1270 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)) |
1271 .Times(AnyNumber()); | |
1274 | 1272 |
1275 EnableTracingWithTraceConfig( | 1273 EnableTracingWithTraceConfig( |
1276 TraceConfigMemoryTestUtil::GetTraceConfig_BackgroundTrigger( | 1274 TraceConfigMemoryTestUtil::GetTraceConfig_BackgroundTrigger( |
1277 1 /* period_ms */)); | 1275 1 /* period_ms */)); |
1278 | 1276 |
1279 // Only background mode dumps should be allowed with the trace config. | 1277 // Only background mode dumps should be allowed with the trace config. |
1280 last_callback_success_ = false; | 1278 last_callback_success_ = false; |
1281 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 1279 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
1282 MemoryDumpLevelOfDetail::LIGHT); | 1280 MemoryDumpLevelOfDetail::LIGHT); |
1283 EXPECT_FALSE(last_callback_success_); | 1281 EXPECT_FALSE(last_callback_success_); |
(...skipping 19 matching lines...) Expand all Loading... | |
1303 thread.Start(); | 1301 thread.Start(); |
1304 RegisterDumpProvider(&mdp1, thread.task_runner(), kDefaultOptions, | 1302 RegisterDumpProvider(&mdp1, thread.task_runner(), kDefaultOptions, |
1305 "BlacklistTestDumpProvider"); | 1303 "BlacklistTestDumpProvider"); |
1306 // Unregistering on wrong thread should not crash. | 1304 // Unregistering on wrong thread should not crash. |
1307 mdm_->UnregisterDumpProvider(&mdp1); | 1305 mdm_->UnregisterDumpProvider(&mdp1); |
1308 thread.Stop(); | 1306 thread.Stop(); |
1309 } | 1307 } |
1310 | 1308 |
1311 } // namespace trace_event | 1309 } // namespace trace_event |
1312 } // namespace base | 1310 } // namespace base |
OLD | NEW |