| 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 // This mocks the RequestGlobalDumpFunction which is typically handled by |
| 132 // requests locally to the MemoryDumpManager instead of performing IPC dances. | 132 // process_local_dump_manager_impl.cc, by short-circuiting dump requests locally |
| 133 class MemoryDumpManagerDelegateForTesting : public MemoryDumpManagerDelegate { | 133 // to the MemoryDumpManager without an actual service. |
| 134 class GlobalMemoryDumpHandler { |
| 134 public: | 135 public: |
| 135 MemoryDumpManagerDelegateForTesting(bool is_coordinator) | 136 MOCK_METHOD2(RequestGlobalMemoryDump, |
| 136 : is_coordinator_(is_coordinator) { | 137 void(const MemoryDumpRequestArgs& args, |
| 138 const GlobalMemoryDumpCallback& callback)); |
| 139 |
| 140 GlobalMemoryDumpHandler() { |
| 137 ON_CALL(*this, RequestGlobalMemoryDump(_, _)) | 141 ON_CALL(*this, RequestGlobalMemoryDump(_, _)) |
| 138 .WillByDefault(Invoke([this](const MemoryDumpRequestArgs& args, | 142 .WillByDefault(Invoke([this](const MemoryDumpRequestArgs& args, |
| 139 const GlobalMemoryDumpCallback& callback) { | 143 const GlobalMemoryDumpCallback& callback) { |
| 140 ProcessMemoryDumpCallback process_callback = | 144 ProcessMemoryDumpCallback process_callback = |
| 141 Bind(&ProcessDumpCallbackAdapter, callback); | 145 Bind(&ProcessDumpCallbackAdapter, callback); |
| 142 CreateProcessDump(args, process_callback); | 146 MemoryDumpManager::GetInstance()->CreateProcessDump(args, |
| 147 process_callback); |
| 143 })); | 148 })); |
| 144 } | 149 } |
| 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 }; | 150 }; |
| 158 | 151 |
| 159 class MockMemoryDumpProvider : public MemoryDumpProvider { | 152 class MockMemoryDumpProvider : public MemoryDumpProvider { |
| 160 public: | 153 public: |
| 161 MOCK_METHOD0(Destructor, void()); | 154 MOCK_METHOD0(Destructor, void()); |
| 162 MOCK_METHOD2(OnMemoryDump, | 155 MOCK_METHOD2(OnMemoryDump, |
| 163 bool(const MemoryDumpArgs& args, ProcessMemoryDump* pmd)); | 156 bool(const MemoryDumpArgs& args, ProcessMemoryDump* pmd)); |
| 164 MOCK_METHOD1(PollFastMemoryTotal, void(uint64_t* memory_total)); | 157 MOCK_METHOD1(PollFastMemoryTotal, void(uint64_t* memory_total)); |
| 165 MOCK_METHOD0(SuspendFastMemoryPolling, void()); | 158 MOCK_METHOD0(SuspendFastMemoryPolling, void()); |
| 166 | 159 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 void SetUp() override { | 230 void SetUp() override { |
| 238 last_callback_success_ = false; | 231 last_callback_success_ = false; |
| 239 message_loop_.reset(new MessageLoop()); | 232 message_loop_.reset(new MessageLoop()); |
| 240 mdm_.reset(new MemoryDumpManager()); | 233 mdm_.reset(new MemoryDumpManager()); |
| 241 MemoryDumpManager::SetInstanceForTesting(mdm_.get()); | 234 MemoryDumpManager::SetInstanceForTesting(mdm_.get()); |
| 242 ASSERT_EQ(mdm_.get(), MemoryDumpManager::GetInstance()); | 235 ASSERT_EQ(mdm_.get(), MemoryDumpManager::GetInstance()); |
| 243 } | 236 } |
| 244 | 237 |
| 245 void TearDown() override { | 238 void TearDown() override { |
| 246 MemoryDumpManager::SetInstanceForTesting(nullptr); | 239 MemoryDumpManager::SetInstanceForTesting(nullptr); |
| 247 delegate_ = nullptr; | |
| 248 mdm_.reset(); | 240 mdm_.reset(); |
| 249 message_loop_.reset(); | 241 message_loop_.reset(); |
| 250 TraceLog::DeleteForTesting(); | 242 TraceLog::DeleteForTesting(); |
| 251 } | 243 } |
| 252 | 244 |
| 253 // Turns a Closure into a GlobalMemoryDumpCallback, keeping track of the | 245 // Turns a Closure into a GlobalMemoryDumpCallback, keeping track of the |
| 254 // callback result and taking care of posting the closure on the correct task | 246 // callback result and taking care of posting the closure on the correct task |
| 255 // runner. | 247 // runner. |
| 256 void GlobalDumpCallbackAdapter( | 248 void GlobalDumpCallbackAdapter( |
| 257 scoped_refptr<SingleThreadTaskRunner> task_runner, | 249 scoped_refptr<SingleThreadTaskRunner> task_runner, |
| 258 Closure closure, | 250 Closure closure, |
| 259 uint64_t dump_guid, | 251 uint64_t dump_guid, |
| 260 bool success) { | 252 bool success) { |
| 261 last_callback_success_ = success; | 253 last_callback_success_ = success; |
| 262 task_runner->PostTask(FROM_HERE, closure); | 254 task_runner->PostTask(FROM_HERE, closure); |
| 263 } | 255 } |
| 264 | 256 |
| 265 protected: | 257 protected: |
| 266 void InitializeMemoryDumpManager(bool is_coordinator) { | 258 void InitializeMemoryDumpManager(bool is_coordinator) { |
| 267 mdm_->set_dumper_registrations_ignored_for_testing(true); | 259 mdm_->set_dumper_registrations_ignored_for_testing(true); |
| 268 delegate_ = new MemoryDumpManagerDelegateForTesting(is_coordinator); | 260 mdm_->Initialize( |
| 269 mdm_->Initialize(base::WrapUnique(delegate_)); | 261 BindRepeating(&GlobalMemoryDumpHandler::RequestGlobalMemoryDump, |
| 262 Unretained(&global_dump_handler_)), |
| 263 is_coordinator); |
| 270 } | 264 } |
| 271 | 265 |
| 272 void RequestGlobalDumpAndWait(MemoryDumpType dump_type, | 266 void RequestGlobalDumpAndWait(MemoryDumpType dump_type, |
| 273 MemoryDumpLevelOfDetail level_of_detail) { | 267 MemoryDumpLevelOfDetail level_of_detail) { |
| 274 RunLoop run_loop; | 268 RunLoop run_loop; |
| 275 GlobalMemoryDumpCallback callback = Bind( | 269 GlobalMemoryDumpCallback callback = Bind( |
| 276 &MemoryDumpManagerTest::GlobalDumpCallbackAdapter, Unretained(this), | 270 &MemoryDumpManagerTest::GlobalDumpCallbackAdapter, Unretained(this), |
| 277 ThreadTaskRunnerHandle::Get(), run_loop.QuitClosure()); | 271 ThreadTaskRunnerHandle::Get(), run_loop.QuitClosure()); |
| 278 mdm_->RequestGlobalDump(dump_type, level_of_detail, callback); | 272 mdm_->RequestGlobalDump(dump_type, level_of_detail, callback); |
| 279 run_loop.Run(); | 273 run_loop.Run(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 294 bool IsPeriodicDumpingEnabled() const { | 288 bool IsPeriodicDumpingEnabled() const { |
| 295 return MemoryDumpScheduler::GetInstance()->is_enabled_for_testing(); | 289 return MemoryDumpScheduler::GetInstance()->is_enabled_for_testing(); |
| 296 } | 290 } |
| 297 | 291 |
| 298 int GetMaxConsecutiveFailuresCount() const { | 292 int GetMaxConsecutiveFailuresCount() const { |
| 299 return MemoryDumpManager::kMaxConsecutiveFailuresCount; | 293 return MemoryDumpManager::kMaxConsecutiveFailuresCount; |
| 300 } | 294 } |
| 301 | 295 |
| 302 const MemoryDumpProvider::Options kDefaultOptions; | 296 const MemoryDumpProvider::Options kDefaultOptions; |
| 303 std::unique_ptr<MemoryDumpManager> mdm_; | 297 std::unique_ptr<MemoryDumpManager> mdm_; |
| 304 MemoryDumpManagerDelegateForTesting* delegate_; | 298 GlobalMemoryDumpHandler global_dump_handler_; |
| 305 bool last_callback_success_; | 299 bool last_callback_success_; |
| 306 | 300 |
| 307 private: | 301 private: |
| 308 std::unique_ptr<MessageLoop> message_loop_; | 302 std::unique_ptr<MessageLoop> message_loop_; |
| 309 | 303 |
| 310 // We want our singleton torn down after each test. | 304 // We want our singleton torn down after each test. |
| 311 ShadowingAtExitManager at_exit_manager_; | 305 ShadowingAtExitManager at_exit_manager_; |
| 312 }; | 306 }; |
| 313 | 307 |
| 314 // Basic sanity checks. Registers a memory dump provider and checks that it is | 308 // Basic sanity checks. Registers a memory dump provider and checks that it is |
| 315 // called, but only when memory-infra is enabled. | 309 // called, but only when memory-infra is enabled. |
| 316 TEST_F(MemoryDumpManagerTest, SingleDumper) { | 310 TEST_F(MemoryDumpManagerTest, SingleDumper) { |
| 317 InitializeMemoryDumpManager(false /* is_coordinator */); | 311 InitializeMemoryDumpManager(false /* is_coordinator */); |
| 318 MockMemoryDumpProvider mdp; | 312 MockMemoryDumpProvider mdp; |
| 319 RegisterDumpProvider(&mdp, ThreadTaskRunnerHandle::Get()); | 313 RegisterDumpProvider(&mdp, ThreadTaskRunnerHandle::Get()); |
| 320 | 314 |
| 321 // Check that the dumper is not called if the memory category is not enabled. | 315 // Check that the dumper is not called if the memory category is not enabled. |
| 322 EnableTracingWithLegacyCategories("foobar-but-not-memory"); | 316 EnableTracingWithLegacyCategories("foobar-but-not-memory"); |
| 323 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(0); | 317 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(0); |
| 324 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); | 318 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); |
| 325 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 319 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 326 MemoryDumpLevelOfDetail::DETAILED); | 320 MemoryDumpLevelOfDetail::DETAILED); |
| 327 DisableTracing(); | 321 DisableTracing(); |
| 328 | 322 |
| 329 // Now repeat enabling the memory category and check that the dumper is | 323 // Now repeat enabling the memory category and check that the dumper is |
| 330 // invoked this time. | 324 // invoked this time. |
| 331 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 325 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
| 332 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(3); | 326 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(3); |
| 333 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(3).WillRepeatedly(Return(true)); | 327 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(3).WillRepeatedly(Return(true)); |
| 334 for (int i = 0; i < 3; ++i) { | 328 for (int i = 0; i < 3; ++i) { |
| 335 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 329 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 336 MemoryDumpLevelOfDetail::DETAILED); | 330 MemoryDumpLevelOfDetail::DETAILED); |
| 337 } | 331 } |
| 338 DisableTracing(); | 332 DisableTracing(); |
| 339 | 333 |
| 340 mdm_->UnregisterDumpProvider(&mdp); | 334 mdm_->UnregisterDumpProvider(&mdp); |
| 341 | 335 |
| 342 // Finally check the unregister logic: the delegate will be invoked but not | 336 // Finally check the unregister logic: the global dump handler will be invoked |
| 343 // the dump provider, as it has been unregistered. | 337 // but not the dump provider, as it has been unregistered. |
| 344 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 338 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
| 345 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(3); | 339 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(3); |
| 346 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); | 340 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); |
| 347 | 341 |
| 348 for (int i = 0; i < 3; ++i) { | 342 for (int i = 0; i < 3; ++i) { |
| 349 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 343 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 350 MemoryDumpLevelOfDetail::DETAILED); | 344 MemoryDumpLevelOfDetail::DETAILED); |
| 351 } | 345 } |
| 352 DisableTracing(); | 346 DisableTracing(); |
| 353 } | 347 } |
| 354 | 348 |
| 355 // Checks that requesting dumps with high level of detail actually propagates | 349 // Checks that requesting dumps with high level of detail actually propagates |
| 356 // the level of the detail properly to OnMemoryDump() call on dump providers. | 350 // the level of the detail properly to OnMemoryDump() call on dump providers. |
| 357 TEST_F(MemoryDumpManagerTest, CheckMemoryDumpArgs) { | 351 TEST_F(MemoryDumpManagerTest, CheckMemoryDumpArgs) { |
| 358 InitializeMemoryDumpManager(false /* is_coordinator */); | 352 InitializeMemoryDumpManager(false /* is_coordinator */); |
| 359 MockMemoryDumpProvider mdp; | 353 MockMemoryDumpProvider mdp; |
| 360 | 354 |
| 361 RegisterDumpProvider(&mdp, ThreadTaskRunnerHandle::Get()); | 355 RegisterDumpProvider(&mdp, ThreadTaskRunnerHandle::Get()); |
| 362 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 356 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
| 363 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 357 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(1); |
| 364 EXPECT_CALL(mdp, OnMemoryDump(IsDetailedDump(), _)).WillOnce(Return(true)); | 358 EXPECT_CALL(mdp, OnMemoryDump(IsDetailedDump(), _)).WillOnce(Return(true)); |
| 365 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 359 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 366 MemoryDumpLevelOfDetail::DETAILED); | 360 MemoryDumpLevelOfDetail::DETAILED); |
| 367 DisableTracing(); | 361 DisableTracing(); |
| 368 mdm_->UnregisterDumpProvider(&mdp); | 362 mdm_->UnregisterDumpProvider(&mdp); |
| 369 | 363 |
| 370 // Check that requesting dumps with low level of detail actually propagates to | 364 // Check that requesting dumps with low level of detail actually propagates to |
| 371 // OnMemoryDump() call on dump providers. | 365 // OnMemoryDump() call on dump providers. |
| 372 RegisterDumpProvider(&mdp, ThreadTaskRunnerHandle::Get()); | 366 RegisterDumpProvider(&mdp, ThreadTaskRunnerHandle::Get()); |
| 373 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 367 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
| 374 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 368 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(1); |
| 375 EXPECT_CALL(mdp, OnMemoryDump(IsLightDump(), _)).WillOnce(Return(true)); | 369 EXPECT_CALL(mdp, OnMemoryDump(IsLightDump(), _)).WillOnce(Return(true)); |
| 376 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 370 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 377 MemoryDumpLevelOfDetail::LIGHT); | 371 MemoryDumpLevelOfDetail::LIGHT); |
| 378 DisableTracing(); | 372 DisableTracing(); |
| 379 mdm_->UnregisterDumpProvider(&mdp); | 373 mdm_->UnregisterDumpProvider(&mdp); |
| 380 } | 374 } |
| 381 | 375 |
| 382 // Checks that the SharedSessionState object is acqually shared over time. | 376 // Checks that the SharedSessionState object is acqually shared over time. |
| 383 TEST_F(MemoryDumpManagerTest, SharedSessionState) { | 377 TEST_F(MemoryDumpManagerTest, SharedSessionState) { |
| 384 InitializeMemoryDumpManager(false /* is_coordinator */); | 378 InitializeMemoryDumpManager(false /* is_coordinator */); |
| 385 MockMemoryDumpProvider mdp1; | 379 MockMemoryDumpProvider mdp1; |
| 386 MockMemoryDumpProvider mdp2; | 380 MockMemoryDumpProvider mdp2; |
| 387 RegisterDumpProvider(&mdp1, nullptr); | 381 RegisterDumpProvider(&mdp1, nullptr); |
| 388 RegisterDumpProvider(&mdp2, nullptr); | 382 RegisterDumpProvider(&mdp2, nullptr); |
| 389 | 383 |
| 390 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 384 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
| 391 const MemoryDumpSessionState* session_state = | 385 const MemoryDumpSessionState* session_state = |
| 392 mdm_->session_state_for_testing().get(); | 386 mdm_->session_state_for_testing().get(); |
| 393 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(2); | 387 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(2); |
| 394 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) | 388 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) |
| 395 .Times(2) | 389 .Times(2) |
| 396 .WillRepeatedly(Invoke([session_state](const MemoryDumpArgs&, | 390 .WillRepeatedly(Invoke([session_state](const MemoryDumpArgs&, |
| 397 ProcessMemoryDump* pmd) -> bool { | 391 ProcessMemoryDump* pmd) -> bool { |
| 398 EXPECT_EQ(session_state, pmd->session_state().get()); | 392 EXPECT_EQ(session_state, pmd->session_state().get()); |
| 399 return true; | 393 return true; |
| 400 })); | 394 })); |
| 401 EXPECT_CALL(mdp2, OnMemoryDump(_, _)) | 395 EXPECT_CALL(mdp2, OnMemoryDump(_, _)) |
| 402 .Times(2) | 396 .Times(2) |
| 403 .WillRepeatedly(Invoke([session_state](const MemoryDumpArgs&, | 397 .WillRepeatedly(Invoke([session_state](const MemoryDumpArgs&, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 416 | 410 |
| 417 // Checks that the (Un)RegisterDumpProvider logic behaves sanely. | 411 // Checks that the (Un)RegisterDumpProvider logic behaves sanely. |
| 418 TEST_F(MemoryDumpManagerTest, MultipleDumpers) { | 412 TEST_F(MemoryDumpManagerTest, MultipleDumpers) { |
| 419 InitializeMemoryDumpManager(false /* is_coordinator */); | 413 InitializeMemoryDumpManager(false /* is_coordinator */); |
| 420 MockMemoryDumpProvider mdp1; | 414 MockMemoryDumpProvider mdp1; |
| 421 MockMemoryDumpProvider mdp2; | 415 MockMemoryDumpProvider mdp2; |
| 422 | 416 |
| 423 // Enable only mdp1. | 417 // Enable only mdp1. |
| 424 RegisterDumpProvider(&mdp1, ThreadTaskRunnerHandle::Get()); | 418 RegisterDumpProvider(&mdp1, ThreadTaskRunnerHandle::Get()); |
| 425 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 419 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
| 426 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 420 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(1); |
| 427 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).WillOnce(Return(true)); | 421 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).WillOnce(Return(true)); |
| 428 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).Times(0); | 422 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).Times(0); |
| 429 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 423 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 430 MemoryDumpLevelOfDetail::DETAILED); | 424 MemoryDumpLevelOfDetail::DETAILED); |
| 431 DisableTracing(); | 425 DisableTracing(); |
| 432 | 426 |
| 433 // Invert: enable mdp1 and disable mdp2. | 427 // Invert: enable mdp1 and disable mdp2. |
| 434 mdm_->UnregisterDumpProvider(&mdp1); | 428 mdm_->UnregisterDumpProvider(&mdp1); |
| 435 RegisterDumpProvider(&mdp2, nullptr); | 429 RegisterDumpProvider(&mdp2, nullptr); |
| 436 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 430 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
| 437 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 431 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(1); |
| 438 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(0); | 432 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(0); |
| 439 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).WillOnce(Return(true)); | 433 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).WillOnce(Return(true)); |
| 440 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 434 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 441 MemoryDumpLevelOfDetail::DETAILED); | 435 MemoryDumpLevelOfDetail::DETAILED); |
| 442 DisableTracing(); | 436 DisableTracing(); |
| 443 | 437 |
| 444 // Enable both mdp1 and mdp2. | 438 // Enable both mdp1 and mdp2. |
| 445 RegisterDumpProvider(&mdp1, nullptr); | 439 RegisterDumpProvider(&mdp1, nullptr); |
| 446 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 440 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
| 447 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 441 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(1); |
| 448 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).WillOnce(Return(true)); | 442 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).WillOnce(Return(true)); |
| 449 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).WillOnce(Return(true)); | 443 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).WillOnce(Return(true)); |
| 450 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 444 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 451 MemoryDumpLevelOfDetail::DETAILED); | 445 MemoryDumpLevelOfDetail::DETAILED); |
| 452 DisableTracing(); | 446 DisableTracing(); |
| 453 } | 447 } |
| 454 | 448 |
| 455 // Checks that the dump provider invocations depend only on the current | 449 // Checks that the dump provider invocations depend only on the current |
| 456 // registration state and not on previous registrations and dumps. | 450 // registration state and not on previous registrations and dumps. |
| 457 // Flaky on iOS, see crbug.com/706874 | 451 // Flaky on iOS, see crbug.com/706874 |
| 458 #if defined(OS_IOS) | 452 #if defined(OS_IOS) |
| 459 #define MAYBE_RegistrationConsistency DISABLED_RegistrationConsistency | 453 #define MAYBE_RegistrationConsistency DISABLED_RegistrationConsistency |
| 460 #else | 454 #else |
| 461 #define MAYBE_RegistrationConsistency RegistrationConsistency | 455 #define MAYBE_RegistrationConsistency RegistrationConsistency |
| 462 #endif | 456 #endif |
| 463 TEST_F(MemoryDumpManagerTest, MAYBE_RegistrationConsistency) { | 457 TEST_F(MemoryDumpManagerTest, MAYBE_RegistrationConsistency) { |
| 464 InitializeMemoryDumpManager(false /* is_coordinator */); | 458 InitializeMemoryDumpManager(false /* is_coordinator */); |
| 465 MockMemoryDumpProvider mdp; | 459 MockMemoryDumpProvider mdp; |
| 466 | 460 |
| 467 RegisterDumpProvider(&mdp, ThreadTaskRunnerHandle::Get()); | 461 RegisterDumpProvider(&mdp, ThreadTaskRunnerHandle::Get()); |
| 468 | 462 |
| 469 { | 463 { |
| 470 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 464 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(1); |
| 471 EXPECT_CALL(mdp, OnMemoryDump(_, _)).WillOnce(Return(true)); | 465 EXPECT_CALL(mdp, OnMemoryDump(_, _)).WillOnce(Return(true)); |
| 472 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 466 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
| 473 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 467 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 474 MemoryDumpLevelOfDetail::DETAILED); | 468 MemoryDumpLevelOfDetail::DETAILED); |
| 475 DisableTracing(); | 469 DisableTracing(); |
| 476 } | 470 } |
| 477 | 471 |
| 478 mdm_->UnregisterDumpProvider(&mdp); | 472 mdm_->UnregisterDumpProvider(&mdp); |
| 479 | 473 |
| 480 { | 474 { |
| 481 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 475 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(1); |
| 482 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); | 476 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); |
| 483 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 477 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
| 484 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 478 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 485 MemoryDumpLevelOfDetail::DETAILED); | 479 MemoryDumpLevelOfDetail::DETAILED); |
| 486 DisableTracing(); | 480 DisableTracing(); |
| 487 } | 481 } |
| 488 | 482 |
| 489 RegisterDumpProvider(&mdp, ThreadTaskRunnerHandle::Get()); | 483 RegisterDumpProvider(&mdp, ThreadTaskRunnerHandle::Get()); |
| 490 mdm_->UnregisterDumpProvider(&mdp); | 484 mdm_->UnregisterDumpProvider(&mdp); |
| 491 | 485 |
| 492 { | 486 { |
| 493 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 487 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(1); |
| 494 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); | 488 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); |
| 495 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 489 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
| 496 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 490 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 497 MemoryDumpLevelOfDetail::DETAILED); | 491 MemoryDumpLevelOfDetail::DETAILED); |
| 498 DisableTracing(); | 492 DisableTracing(); |
| 499 } | 493 } |
| 500 | 494 |
| 501 RegisterDumpProvider(&mdp, ThreadTaskRunnerHandle::Get()); | 495 RegisterDumpProvider(&mdp, ThreadTaskRunnerHandle::Get()); |
| 502 mdm_->UnregisterDumpProvider(&mdp); | 496 mdm_->UnregisterDumpProvider(&mdp); |
| 503 RegisterDumpProvider(&mdp, ThreadTaskRunnerHandle::Get()); | 497 RegisterDumpProvider(&mdp, ThreadTaskRunnerHandle::Get()); |
| 504 | 498 |
| 505 { | 499 { |
| 506 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 500 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(1); |
| 507 EXPECT_CALL(mdp, OnMemoryDump(_, _)).WillOnce(Return(true)); | 501 EXPECT_CALL(mdp, OnMemoryDump(_, _)).WillOnce(Return(true)); |
| 508 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 502 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
| 509 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 503 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 510 MemoryDumpLevelOfDetail::DETAILED); | 504 MemoryDumpLevelOfDetail::DETAILED); |
| 511 DisableTracing(); | 505 DisableTracing(); |
| 512 } | 506 } |
| 513 } | 507 } |
| 514 | 508 |
| 515 // Checks that the MemoryDumpManager respects the thread affinity when a | 509 // Checks that the MemoryDumpManager respects the thread affinity when a |
| 516 // MemoryDumpProvider specifies a task_runner(). The test starts creating 8 | 510 // MemoryDumpProvider specifies a task_runner(). The test starts creating 8 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 539 .WillRepeatedly(Invoke( | 533 .WillRepeatedly(Invoke( |
| 540 [task_runner](const MemoryDumpArgs&, ProcessMemoryDump*) -> bool { | 534 [task_runner](const MemoryDumpArgs&, ProcessMemoryDump*) -> bool { |
| 541 EXPECT_TRUE(task_runner->RunsTasksOnCurrentThread()); | 535 EXPECT_TRUE(task_runner->RunsTasksOnCurrentThread()); |
| 542 return true; | 536 return true; |
| 543 })); | 537 })); |
| 544 } | 538 } |
| 545 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 539 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
| 546 | 540 |
| 547 while (!threads.empty()) { | 541 while (!threads.empty()) { |
| 548 last_callback_success_ = false; | 542 last_callback_success_ = false; |
| 549 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 543 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(1); |
| 550 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 544 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 551 MemoryDumpLevelOfDetail::DETAILED); | 545 MemoryDumpLevelOfDetail::DETAILED); |
| 552 EXPECT_TRUE(last_callback_success_); | 546 EXPECT_TRUE(last_callback_success_); |
| 553 | 547 |
| 554 // Unregister a MDP and destroy one thread at each iteration to check the | 548 // 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 | 549 // live unregistration logic. The unregistration needs to happen on the same |
| 556 // thread the MDP belongs to. | 550 // thread the MDP belongs to. |
| 557 { | 551 { |
| 558 RunLoop run_loop; | 552 RunLoop run_loop; |
| 559 Closure unregistration = | 553 Closure unregistration = |
| (...skipping 24 matching lines...) Expand all Loading... |
| 584 RegisterDumpProviderWithSequencedTaskRunner(&mdps[0], task_runner1, | 578 RegisterDumpProviderWithSequencedTaskRunner(&mdps[0], task_runner1, |
| 585 kDefaultOptions); | 579 kDefaultOptions); |
| 586 RegisterDumpProviderWithSequencedTaskRunner(&mdps[1], task_runner2, | 580 RegisterDumpProviderWithSequencedTaskRunner(&mdps[1], task_runner2, |
| 587 kDefaultOptions); | 581 kDefaultOptions); |
| 588 RegisterDumpProviderWithSequencedTaskRunner(&mdps[2], task_runner2, | 582 RegisterDumpProviderWithSequencedTaskRunner(&mdps[2], task_runner2, |
| 589 kDefaultOptions); | 583 kDefaultOptions); |
| 590 // |mdps[0]| should be disabled permanently after first dump. | 584 // |mdps[0]| should be disabled permanently after first dump. |
| 591 EXPECT_CALL(mdps[0], OnMemoryDump(_, _)).Times(0); | 585 EXPECT_CALL(mdps[0], OnMemoryDump(_, _)).Times(0); |
| 592 EXPECT_CALL(mdps[1], OnMemoryDump(_, _)).Times(2); | 586 EXPECT_CALL(mdps[1], OnMemoryDump(_, _)).Times(2); |
| 593 EXPECT_CALL(mdps[2], OnMemoryDump(_, _)).Times(2); | 587 EXPECT_CALL(mdps[2], OnMemoryDump(_, _)).Times(2); |
| 594 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(2); | 588 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(2); |
| 595 | 589 |
| 596 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 590 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
| 597 | 591 |
| 598 task_runner1->set_enabled(false); | 592 task_runner1->set_enabled(false); |
| 599 last_callback_success_ = false; | 593 last_callback_success_ = false; |
| 600 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 594 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 601 MemoryDumpLevelOfDetail::DETAILED); | 595 MemoryDumpLevelOfDetail::DETAILED); |
| 602 // Tasks should be individually posted even if |mdps[1]| and |mdps[2]| belong | 596 // Tasks should be individually posted even if |mdps[1]| and |mdps[2]| belong |
| 603 // to same task runner. | 597 // to same task runner. |
| 604 EXPECT_EQ(1u, task_runner1->no_of_post_tasks()); | 598 EXPECT_EQ(1u, task_runner1->no_of_post_tasks()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 620 TEST_F(MemoryDumpManagerTest, DisableFailingDumpers) { | 614 TEST_F(MemoryDumpManagerTest, DisableFailingDumpers) { |
| 621 InitializeMemoryDumpManager(false /* is_coordinator */); | 615 InitializeMemoryDumpManager(false /* is_coordinator */); |
| 622 MockMemoryDumpProvider mdp1; | 616 MockMemoryDumpProvider mdp1; |
| 623 MockMemoryDumpProvider mdp2; | 617 MockMemoryDumpProvider mdp2; |
| 624 | 618 |
| 625 RegisterDumpProvider(&mdp1, nullptr); | 619 RegisterDumpProvider(&mdp1, nullptr); |
| 626 RegisterDumpProvider(&mdp2, nullptr); | 620 RegisterDumpProvider(&mdp2, nullptr); |
| 627 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 621 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
| 628 | 622 |
| 629 const int kNumDumps = 2 * GetMaxConsecutiveFailuresCount(); | 623 const int kNumDumps = 2 * GetMaxConsecutiveFailuresCount(); |
| 630 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(kNumDumps); | 624 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)) |
| 625 .Times(kNumDumps); |
| 631 | 626 |
| 632 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) | 627 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) |
| 633 .Times(GetMaxConsecutiveFailuresCount()) | 628 .Times(GetMaxConsecutiveFailuresCount()) |
| 634 .WillRepeatedly(Return(false)); | 629 .WillRepeatedly(Return(false)); |
| 635 | 630 |
| 636 EXPECT_CALL(mdp2, OnMemoryDump(_, _)) | 631 EXPECT_CALL(mdp2, OnMemoryDump(_, _)) |
| 637 .WillOnce(Return(false)) | 632 .WillOnce(Return(false)) |
| 638 .WillOnce(Return(true)) | 633 .WillOnce(Return(true)) |
| 639 .WillOnce(Return(false)) | 634 .WillOnce(Return(false)) |
| 640 .WillOnce(Return(false)) | 635 .WillOnce(Return(false)) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 652 // Sneakily registers an extra memory dump provider while an existing one is | 647 // 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. | 648 // dumping and expect it to take part in the already active tracing session. |
| 654 TEST_F(MemoryDumpManagerTest, RegisterDumperWhileDumping) { | 649 TEST_F(MemoryDumpManagerTest, RegisterDumperWhileDumping) { |
| 655 InitializeMemoryDumpManager(false /* is_coordinator */); | 650 InitializeMemoryDumpManager(false /* is_coordinator */); |
| 656 MockMemoryDumpProvider mdp1; | 651 MockMemoryDumpProvider mdp1; |
| 657 MockMemoryDumpProvider mdp2; | 652 MockMemoryDumpProvider mdp2; |
| 658 | 653 |
| 659 RegisterDumpProvider(&mdp1, nullptr); | 654 RegisterDumpProvider(&mdp1, nullptr); |
| 660 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 655 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
| 661 | 656 |
| 662 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(4); | 657 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(4); |
| 663 | 658 |
| 664 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) | 659 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) |
| 665 .Times(4) | 660 .Times(4) |
| 666 .WillOnce(Return(true)) | 661 .WillOnce(Return(true)) |
| 667 .WillOnce( | 662 .WillOnce( |
| 668 Invoke([&mdp2](const MemoryDumpArgs&, ProcessMemoryDump*) -> bool { | 663 Invoke([&mdp2](const MemoryDumpArgs&, ProcessMemoryDump*) -> bool { |
| 669 RegisterDumpProvider(&mdp2, nullptr); | 664 RegisterDumpProvider(&mdp2, nullptr); |
| 670 return true; | 665 return true; |
| 671 })) | 666 })) |
| 672 .WillRepeatedly(Return(true)); | 667 .WillRepeatedly(Return(true)); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 688 // Like RegisterDumperWhileDumping, but unregister the dump provider instead. | 683 // Like RegisterDumperWhileDumping, but unregister the dump provider instead. |
| 689 TEST_F(MemoryDumpManagerTest, UnregisterDumperWhileDumping) { | 684 TEST_F(MemoryDumpManagerTest, UnregisterDumperWhileDumping) { |
| 690 InitializeMemoryDumpManager(false /* is_coordinator */); | 685 InitializeMemoryDumpManager(false /* is_coordinator */); |
| 691 MockMemoryDumpProvider mdp1; | 686 MockMemoryDumpProvider mdp1; |
| 692 MockMemoryDumpProvider mdp2; | 687 MockMemoryDumpProvider mdp2; |
| 693 | 688 |
| 694 RegisterDumpProvider(&mdp1, ThreadTaskRunnerHandle::Get(), kDefaultOptions); | 689 RegisterDumpProvider(&mdp1, ThreadTaskRunnerHandle::Get(), kDefaultOptions); |
| 695 RegisterDumpProvider(&mdp2, ThreadTaskRunnerHandle::Get(), kDefaultOptions); | 690 RegisterDumpProvider(&mdp2, ThreadTaskRunnerHandle::Get(), kDefaultOptions); |
| 696 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 691 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
| 697 | 692 |
| 698 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(4); | 693 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(4); |
| 699 | 694 |
| 700 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) | 695 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) |
| 701 .Times(4) | 696 .Times(4) |
| 702 .WillOnce(Return(true)) | 697 .WillOnce(Return(true)) |
| 703 .WillOnce( | 698 .WillOnce( |
| 704 Invoke([&mdp2](const MemoryDumpArgs&, ProcessMemoryDump*) -> bool { | 699 Invoke([&mdp2](const MemoryDumpArgs&, ProcessMemoryDump*) -> bool { |
| 705 MemoryDumpManager::GetInstance()->UnregisterDumpProvider(&mdp2); | 700 MemoryDumpManager::GetInstance()->UnregisterDumpProvider(&mdp2); |
| 706 return true; | 701 return true; |
| 707 })) | 702 })) |
| 708 .WillRepeatedly(Return(true)); | 703 .WillRepeatedly(Return(true)); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 758 | 753 |
| 759 // OnMemoryDump is called once for the provider that dumps first, and zero | 754 // OnMemoryDump is called once for the provider that dumps first, and zero |
| 760 // times for the other provider. | 755 // times for the other provider. |
| 761 EXPECT_CALL(*mdp, OnMemoryDump(_, _)) | 756 EXPECT_CALL(*mdp, OnMemoryDump(_, _)) |
| 762 .Times(AtMost(1)) | 757 .Times(AtMost(1)) |
| 763 .WillOnce(Invoke(on_dump)); | 758 .WillOnce(Invoke(on_dump)); |
| 764 } | 759 } |
| 765 | 760 |
| 766 last_callback_success_ = false; | 761 last_callback_success_ = false; |
| 767 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 762 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
| 768 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 763 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(1); |
| 769 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 764 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 770 MemoryDumpLevelOfDetail::DETAILED); | 765 MemoryDumpLevelOfDetail::DETAILED); |
| 771 ASSERT_EQ(1, on_memory_dump_call_count); | 766 ASSERT_EQ(1, on_memory_dump_call_count); |
| 772 ASSERT_TRUE(last_callback_success_); | 767 ASSERT_TRUE(last_callback_success_); |
| 773 | 768 |
| 774 DisableTracing(); | 769 DisableTracing(); |
| 775 } | 770 } |
| 776 | 771 |
| 777 TEST_F(MemoryDumpManagerTest, TestPollingOnDumpThread) { | 772 TEST_F(MemoryDumpManagerTest, TestPollingOnDumpThread) { |
| 778 InitializeMemoryDumpManager(false /* is_coordinator */); | 773 InitializeMemoryDumpManager(false /* is_coordinator */); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 860 | 855 |
| 861 // OnMemoryDump is called once for the provider that dumps first, and zero | 856 // OnMemoryDump is called once for the provider that dumps first, and zero |
| 862 // times for the other provider. | 857 // times for the other provider. |
| 863 EXPECT_CALL(*mdp, OnMemoryDump(_, _)) | 858 EXPECT_CALL(*mdp, OnMemoryDump(_, _)) |
| 864 .Times(AtMost(1)) | 859 .Times(AtMost(1)) |
| 865 .WillOnce(Invoke(on_dump)); | 860 .WillOnce(Invoke(on_dump)); |
| 866 } | 861 } |
| 867 | 862 |
| 868 last_callback_success_ = false; | 863 last_callback_success_ = false; |
| 869 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 864 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
| 870 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 865 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(1); |
| 871 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 866 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 872 MemoryDumpLevelOfDetail::DETAILED); | 867 MemoryDumpLevelOfDetail::DETAILED); |
| 873 ASSERT_EQ(1, on_memory_dump_call_count); | 868 ASSERT_EQ(1, on_memory_dump_call_count); |
| 874 ASSERT_TRUE(last_callback_success_); | 869 ASSERT_TRUE(last_callback_success_); |
| 875 | 870 |
| 876 DisableTracing(); | 871 DisableTracing(); |
| 877 } | 872 } |
| 878 | 873 |
| 879 // Checks that a NACK callback is invoked if RequestGlobalDump() is called when | 874 // Checks that a NACK callback is invoked if RequestGlobalDump() is called when |
| 880 // tracing is not enabled. | 875 // tracing is not enabled. |
| 881 TEST_F(MemoryDumpManagerTest, CallbackCalledOnFailure) { | 876 TEST_F(MemoryDumpManagerTest, CallbackCalledOnFailure) { |
| 882 InitializeMemoryDumpManager(false /* is_coordinator */); | 877 InitializeMemoryDumpManager(false /* is_coordinator */); |
| 883 MockMemoryDumpProvider mdp1; | 878 MockMemoryDumpProvider mdp1; |
| 884 RegisterDumpProvider(&mdp1, nullptr); | 879 RegisterDumpProvider(&mdp1, nullptr); |
| 885 | 880 |
| 886 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(0); | 881 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(0); |
| 887 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(0); | 882 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(0); |
| 888 | 883 |
| 889 last_callback_success_ = true; | 884 last_callback_success_ = true; |
| 890 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 885 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 891 MemoryDumpLevelOfDetail::DETAILED); | 886 MemoryDumpLevelOfDetail::DETAILED); |
| 892 EXPECT_FALSE(last_callback_success_); | 887 EXPECT_FALSE(last_callback_success_); |
| 893 } | 888 } |
| 894 | 889 |
| 895 // Checks that is the MemoryDumpManager is initialized after tracing already | 890 // Checks that is the MemoryDumpManager is initialized after tracing already |
| 896 // began, it will still late-join the party (real use case: startup tracing). | 891 // began, it will still late-join the party (real use case: startup tracing). |
| 897 TEST_F(MemoryDumpManagerTest, InitializedAfterStartOfTracing) { | 892 TEST_F(MemoryDumpManagerTest, InitializedAfterStartOfTracing) { |
| 898 MockMemoryDumpProvider mdp; | 893 MockMemoryDumpProvider mdp; |
| 899 RegisterDumpProvider(&mdp, nullptr); | 894 RegisterDumpProvider(&mdp, nullptr); |
| 900 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 895 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
| 901 | 896 |
| 902 // First check that a RequestGlobalDump() issued before the MemoryDumpManager | 897 // First check that a RequestGlobalDump() issued before the MemoryDumpManager |
| 903 // initialization gets NACK-ed cleanly. | 898 // initialization gets NACK-ed cleanly. |
| 904 { | 899 { |
| 905 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); | 900 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); |
| 906 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 901 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 907 MemoryDumpLevelOfDetail::DETAILED); | 902 MemoryDumpLevelOfDetail::DETAILED); |
| 908 EXPECT_FALSE(last_callback_success_); | 903 EXPECT_FALSE(last_callback_success_); |
| 909 } | 904 } |
| 910 | 905 |
| 911 // Now late-initialize the MemoryDumpManager and check that the | 906 // Now late-initialize the MemoryDumpManager and check that the |
| 912 // RequestGlobalDump completes successfully. | 907 // RequestGlobalDump completes successfully. |
| 913 { | 908 { |
| 914 InitializeMemoryDumpManager(false /* is_coordinator */); | 909 InitializeMemoryDumpManager(false /* is_coordinator */); |
| 915 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(1); | 910 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(1); |
| 916 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 911 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(1); |
| 917 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 912 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 918 MemoryDumpLevelOfDetail::DETAILED); | 913 MemoryDumpLevelOfDetail::DETAILED); |
| 919 EXPECT_TRUE(last_callback_success_); | 914 EXPECT_TRUE(last_callback_success_); |
| 920 } | 915 } |
| 921 DisableTracing(); | 916 DisableTracing(); |
| 922 } | 917 } |
| 923 | 918 |
| 924 // This test (and the MemoryDumpManagerTestCoordinator below) crystallizes the | 919 // This test (and the MemoryDumpManagerTestCoordinator below) crystallizes the |
| 925 // expectations of the chrome://tracing UI and chrome telemetry w.r.t. periodic | 920 // 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 | 921 // dumps in memory-infra, handling gracefully the transition between the legacy |
| 927 // and the new-style (JSON-based) TraceConfig. | 922 // and the new-style (JSON-based) TraceConfig. |
| 928 TEST_F(MemoryDumpManagerTest, TraceConfigExpectations) { | 923 TEST_F(MemoryDumpManagerTest, TraceConfigExpectations) { |
| 929 InitializeMemoryDumpManager(false /* is_coordinator */); | 924 InitializeMemoryDumpManager(false /* is_coordinator */); |
| 930 MemoryDumpManagerDelegateForTesting& delegate = *delegate_; | |
| 931 | 925 |
| 932 // Don't trigger the default behavior of the mock delegate in this test, | 926 // 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 | 927 // which would short-circuit the dump request to the actual |
| 934 // CreateProcessDump(). | 928 // CreateProcessDump(). |
| 935 // We don't want to create any dump in this test, only check whether the dumps | 929 // We don't want to create any dump in this test, only check whether the dumps |
| 936 // are requested or not. | 930 // are requested or not. |
| 937 ON_CALL(delegate, RequestGlobalMemoryDump(_, _)).WillByDefault(Return()); | 931 ON_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)) |
| 932 .WillByDefault(Return()); |
| 938 | 933 |
| 939 // Enabling memory-infra in a non-coordinator process should not trigger any | 934 // Enabling memory-infra in a non-coordinator process should not trigger any |
| 940 // periodic dumps. | 935 // periodic dumps. |
| 941 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 936 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
| 942 EXPECT_FALSE(IsPeriodicDumpingEnabled()); | 937 EXPECT_FALSE(IsPeriodicDumpingEnabled()); |
| 943 DisableTracing(); | 938 DisableTracing(); |
| 944 | 939 |
| 945 // Enabling memory-infra with the new (JSON) TraceConfig in a non-coordinator | 940 // 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 | 941 // process with a fully defined trigger config should NOT enable any periodic |
| 947 // dumps. | 942 // dumps. |
| 948 EnableTracingWithTraceConfig( | 943 EnableTracingWithTraceConfig( |
| 949 TraceConfigMemoryTestUtil::GetTraceConfig_PeriodicTriggers(1, 5)); | 944 TraceConfigMemoryTestUtil::GetTraceConfig_PeriodicTriggers(1, 5)); |
| 950 EXPECT_FALSE(IsPeriodicDumpingEnabled()); | 945 EXPECT_FALSE(IsPeriodicDumpingEnabled()); |
| 951 DisableTracing(); | 946 DisableTracing(); |
| 952 } | 947 } |
| 953 | 948 |
| 954 TEST_F(MemoryDumpManagerTest, TraceConfigExpectationsWhenIsCoordinator) { | 949 TEST_F(MemoryDumpManagerTest, TraceConfigExpectationsWhenIsCoordinator) { |
| 955 InitializeMemoryDumpManager(true /* is_coordinator */); | 950 InitializeMemoryDumpManager(true /* is_coordinator */); |
| 956 MemoryDumpManagerDelegateForTesting& delegate = *delegate_; | 951 ON_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)) |
| 957 ON_CALL(delegate, RequestGlobalMemoryDump(_, _)).WillByDefault(Return()); | 952 .WillByDefault(Return()); |
| 958 | 953 |
| 959 // Enabling memory-infra with the legacy TraceConfig (category filter) in | 954 // Enabling memory-infra with the legacy TraceConfig (category filter) in |
| 960 // a coordinator process should enable periodic dumps. | 955 // a coordinator process should enable periodic dumps. |
| 961 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 956 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
| 962 EXPECT_TRUE(IsPeriodicDumpingEnabled()); | 957 EXPECT_TRUE(IsPeriodicDumpingEnabled()); |
| 963 DisableTracing(); | 958 DisableTracing(); |
| 964 | 959 |
| 965 // Enabling memory-infra with the new (JSON) TraceConfig in a coordinator | 960 // Enabling memory-infra with the new (JSON) TraceConfig in a coordinator |
| 966 // process without specifying any "memory_dump_config" section should enable | 961 // process without specifying any "memory_dump_config" section should enable |
| 967 // periodic dumps. This is to preserve the behavior chrome://tracing UI, that | 962 // 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. | 980 // be performed in the correct order. |
| 986 RunLoop run_loop; | 981 RunLoop run_loop; |
| 987 auto test_task_runner = ThreadTaskRunnerHandle::Get(); | 982 auto test_task_runner = ThreadTaskRunnerHandle::Get(); |
| 988 auto quit_closure = run_loop.QuitClosure(); | 983 auto quit_closure = run_loop.QuitClosure(); |
| 989 | 984 |
| 990 const int kHeavyDumpRate = 5; | 985 const int kHeavyDumpRate = 5; |
| 991 const int kLightDumpPeriodMs = 1; | 986 const int kLightDumpPeriodMs = 1; |
| 992 const int kHeavyDumpPeriodMs = kHeavyDumpRate * kLightDumpPeriodMs; | 987 const int kHeavyDumpPeriodMs = kHeavyDumpRate * kLightDumpPeriodMs; |
| 993 // The expected sequence with light=1ms, heavy=5ms is H,L,L,L,L,H,... | 988 // The expected sequence with light=1ms, heavy=5ms is H,L,L,L,L,H,... |
| 994 testing::InSequence sequence; | 989 testing::InSequence sequence; |
| 995 EXPECT_CALL(delegate, RequestGlobalMemoryDump(IsDetailedDump(), _)); | 990 EXPECT_CALL(global_dump_handler_, |
| 996 EXPECT_CALL(delegate, RequestGlobalMemoryDump(IsLightDump(), _)) | 991 RequestGlobalMemoryDump(IsDetailedDump(), _)); |
| 992 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(IsLightDump(), _)) |
| 997 .Times(kHeavyDumpRate - 1); | 993 .Times(kHeavyDumpRate - 1); |
| 998 EXPECT_CALL(delegate, RequestGlobalMemoryDump(IsDetailedDump(), _)); | 994 EXPECT_CALL(global_dump_handler_, |
| 999 EXPECT_CALL(delegate, RequestGlobalMemoryDump(IsLightDump(), _)) | 995 RequestGlobalMemoryDump(IsDetailedDump(), _)); |
| 996 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(IsLightDump(), _)) |
| 1000 .Times(kHeavyDumpRate - 2); | 997 .Times(kHeavyDumpRate - 2); |
| 1001 EXPECT_CALL(delegate, RequestGlobalMemoryDump(IsLightDump(), _)) | 998 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(IsLightDump(), _)) |
| 1002 .WillOnce(Invoke([test_task_runner, quit_closure]( | 999 .WillOnce(Invoke([test_task_runner, quit_closure]( |
| 1003 const MemoryDumpRequestArgs& args, | 1000 const MemoryDumpRequestArgs& args, |
| 1004 const GlobalMemoryDumpCallback& callback) { | 1001 const GlobalMemoryDumpCallback& callback) { |
| 1005 test_task_runner->PostTask(FROM_HERE, quit_closure); | 1002 test_task_runner->PostTask(FROM_HERE, quit_closure); |
| 1006 })); | 1003 })); |
| 1007 | 1004 |
| 1008 // Swallow all the final spurious calls until tracing gets disabled. | 1005 // Swallow all the final spurious calls until tracing gets disabled. |
| 1009 EXPECT_CALL(delegate, RequestGlobalMemoryDump(_, _)).Times(AnyNumber()); | 1006 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)) |
| 1007 .Times(AnyNumber()); |
| 1010 | 1008 |
| 1011 EnableTracingWithTraceConfig( | 1009 EnableTracingWithTraceConfig( |
| 1012 TraceConfigMemoryTestUtil::GetTraceConfig_PeriodicTriggers( | 1010 TraceConfigMemoryTestUtil::GetTraceConfig_PeriodicTriggers( |
| 1013 kLightDumpPeriodMs, kHeavyDumpPeriodMs)); | 1011 kLightDumpPeriodMs, kHeavyDumpPeriodMs)); |
| 1014 run_loop.Run(); | 1012 run_loop.Run(); |
| 1015 DisableTracing(); | 1013 DisableTracing(); |
| 1016 } | 1014 } |
| 1017 | 1015 |
| 1018 // Tests against race conditions that can happen if tracing is disabled before | 1016 // Tests against race conditions that can happen if tracing is disabled before |
| 1019 // the CreateProcessDump() call. Real-world regression: crbug.com/580295 . | 1017 // the CreateProcessDump() call. Real-world regression: crbug.com/580295 . |
| 1020 TEST_F(MemoryDumpManagerTest, DisableTracingRightBeforeStartOfDump) { | 1018 TEST_F(MemoryDumpManagerTest, DisableTracingRightBeforeStartOfDump) { |
| 1021 base::WaitableEvent tracing_disabled_event( | 1019 base::WaitableEvent tracing_disabled_event( |
| 1022 WaitableEvent::ResetPolicy::AUTOMATIC, | 1020 WaitableEvent::ResetPolicy::AUTOMATIC, |
| 1023 WaitableEvent::InitialState::NOT_SIGNALED); | 1021 WaitableEvent::InitialState::NOT_SIGNALED); |
| 1024 InitializeMemoryDumpManager(false /* is_coordinator */); | 1022 InitializeMemoryDumpManager(false /* is_coordinator */); |
| 1025 | 1023 |
| 1026 std::unique_ptr<Thread> mdp_thread(new Thread("test thread")); | 1024 std::unique_ptr<Thread> mdp_thread(new Thread("test thread")); |
| 1027 mdp_thread->Start(); | 1025 mdp_thread->Start(); |
| 1028 | 1026 |
| 1029 // Create both same-thread MDP and another MDP with dedicated thread | 1027 // Create both same-thread MDP and another MDP with dedicated thread |
| 1030 MockMemoryDumpProvider mdp1; | 1028 MockMemoryDumpProvider mdp1; |
| 1031 RegisterDumpProvider(&mdp1, nullptr); | 1029 RegisterDumpProvider(&mdp1, nullptr); |
| 1032 MockMemoryDumpProvider mdp2; | 1030 MockMemoryDumpProvider mdp2; |
| 1033 RegisterDumpProvider(&mdp2, mdp_thread->task_runner(), kDefaultOptions); | 1031 RegisterDumpProvider(&mdp2, mdp_thread->task_runner(), kDefaultOptions); |
| 1034 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 1032 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
| 1035 | 1033 |
| 1036 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)) | 1034 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)) |
| 1037 .WillOnce(Invoke([this](const MemoryDumpRequestArgs& args, | 1035 .WillOnce(Invoke([this](const MemoryDumpRequestArgs& args, |
| 1038 const GlobalMemoryDumpCallback& callback) { | 1036 const GlobalMemoryDumpCallback& callback) { |
| 1039 DisableTracing(); | 1037 DisableTracing(); |
| 1040 ProcessMemoryDumpCallback process_callback = | 1038 ProcessMemoryDumpCallback process_callback = |
| 1041 Bind(&ProcessDumpCallbackAdapter, callback); | 1039 Bind(&ProcessDumpCallbackAdapter, callback); |
| 1042 delegate_->CreateProcessDump(args, process_callback); | 1040 mdm_->CreateProcessDump(args, process_callback); |
| 1043 })); | 1041 })); |
| 1044 | 1042 |
| 1045 // If tracing is disabled for current session CreateProcessDump() should NOT | 1043 // If tracing is disabled for current session CreateProcessDump() should NOT |
| 1046 // request dumps from providers. Real-world regression: crbug.com/600570 . | 1044 // request dumps from providers. Real-world regression: crbug.com/600570 . |
| 1047 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(0); | 1045 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(0); |
| 1048 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).Times(0); | 1046 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).Times(0); |
| 1049 | 1047 |
| 1050 last_callback_success_ = true; | 1048 last_callback_success_ = true; |
| 1051 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 1049 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 1052 MemoryDumpLevelOfDetail::DETAILED); | 1050 MemoryDumpLevelOfDetail::DETAILED); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1067 MockMemoryDumpProvider mdp2; | 1065 MockMemoryDumpProvider mdp2; |
| 1068 options.target_pid = 123; | 1066 options.target_pid = 123; |
| 1069 RegisterDumpProvider(&mdp2, nullptr, options); | 1067 RegisterDumpProvider(&mdp2, nullptr, options); |
| 1070 | 1068 |
| 1071 // Another provider with out-of-process dumping. | 1069 // Another provider with out-of-process dumping. |
| 1072 MockMemoryDumpProvider mdp3; | 1070 MockMemoryDumpProvider mdp3; |
| 1073 options.target_pid = 456; | 1071 options.target_pid = 456; |
| 1074 RegisterDumpProvider(&mdp3, nullptr, options); | 1072 RegisterDumpProvider(&mdp3, nullptr, options); |
| 1075 | 1073 |
| 1076 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 1074 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
| 1077 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 1075 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(1); |
| 1078 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(1).WillRepeatedly(Return(true)); | 1076 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(1).WillRepeatedly(Return(true)); |
| 1079 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).Times(1).WillRepeatedly(Return(true)); | 1077 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).Times(1).WillRepeatedly(Return(true)); |
| 1080 EXPECT_CALL(mdp3, OnMemoryDump(_, _)).Times(1).WillRepeatedly(Return(true)); | 1078 EXPECT_CALL(mdp3, OnMemoryDump(_, _)).Times(1).WillRepeatedly(Return(true)); |
| 1081 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 1079 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 1082 MemoryDumpLevelOfDetail::DETAILED); | 1080 MemoryDumpLevelOfDetail::DETAILED); |
| 1083 DisableTracing(); | 1081 DisableTracing(); |
| 1084 | 1082 |
| 1085 // Flush the trace into JSON. | 1083 // Flush the trace into JSON. |
| 1086 trace_event::TraceResultBuffer buffer; | 1084 trace_event::TraceResultBuffer buffer; |
| 1087 TraceResultBuffer::SimpleOutput trace_output; | 1085 TraceResultBuffer::SimpleOutput trace_output; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1161 EXPECT_CALL(*mdp, OnMemoryDump(_, _)) | 1159 EXPECT_CALL(*mdp, OnMemoryDump(_, _)) |
| 1162 .Times(1) | 1160 .Times(1) |
| 1163 .WillOnce(Invoke(self_unregister_from_another_thread)); | 1161 .WillOnce(Invoke(self_unregister_from_another_thread)); |
| 1164 EXPECT_CALL(*mdp, Destructor()) | 1162 EXPECT_CALL(*mdp, Destructor()) |
| 1165 .Times(1) | 1163 .Times(1) |
| 1166 .WillOnce(Invoke([&thread_ref]() { | 1164 .WillOnce(Invoke([&thread_ref]() { |
| 1167 EXPECT_EQ(thread_ref, PlatformThread::CurrentRef()); | 1165 EXPECT_EQ(thread_ref, PlatformThread::CurrentRef()); |
| 1168 })); | 1166 })); |
| 1169 | 1167 |
| 1170 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 1168 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
| 1171 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(2); | 1169 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(2); |
| 1172 for (int i = 0; i < 2; ++i) { | 1170 for (int i = 0; i < 2; ++i) { |
| 1173 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 1171 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 1174 MemoryDumpLevelOfDetail::DETAILED); | 1172 MemoryDumpLevelOfDetail::DETAILED); |
| 1175 } | 1173 } |
| 1176 DisableTracing(); | 1174 DisableTracing(); |
| 1177 } | 1175 } |
| 1178 | 1176 |
| 1179 TEST_F(MemoryDumpManagerTest, TestWhitelistingMDP) { | 1177 TEST_F(MemoryDumpManagerTest, TestWhitelistingMDP) { |
| 1180 InitializeMemoryDumpManager(false /* is_coordinator */); | 1178 InitializeMemoryDumpManager(false /* is_coordinator */); |
| 1181 SetDumpProviderWhitelistForTesting(kTestMDPWhitelist); | 1179 SetDumpProviderWhitelistForTesting(kTestMDPWhitelist); |
| 1182 std::unique_ptr<MockMemoryDumpProvider> mdp1(new MockMemoryDumpProvider); | 1180 std::unique_ptr<MockMemoryDumpProvider> mdp1(new MockMemoryDumpProvider); |
| 1183 RegisterDumpProvider(mdp1.get(), nullptr); | 1181 RegisterDumpProvider(mdp1.get(), nullptr); |
| 1184 std::unique_ptr<MockMemoryDumpProvider> mdp2(new MockMemoryDumpProvider); | 1182 std::unique_ptr<MockMemoryDumpProvider> mdp2(new MockMemoryDumpProvider); |
| 1185 RegisterDumpProvider(mdp2.get(), nullptr, kDefaultOptions, | 1183 RegisterDumpProvider(mdp2.get(), nullptr, kDefaultOptions, |
| 1186 kWhitelistedMDPName); | 1184 kWhitelistedMDPName); |
| 1187 | 1185 |
| 1188 EXPECT_CALL(*mdp1, OnMemoryDump(_, _)).Times(0); | 1186 EXPECT_CALL(*mdp1, OnMemoryDump(_, _)).Times(0); |
| 1189 EXPECT_CALL(*mdp2, OnMemoryDump(_, _)).Times(1).WillOnce(Return(true)); | 1187 EXPECT_CALL(*mdp2, OnMemoryDump(_, _)).Times(1).WillOnce(Return(true)); |
| 1190 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 1188 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(1); |
| 1191 | 1189 |
| 1192 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 1190 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
| 1193 EXPECT_FALSE(IsPeriodicDumpingEnabled()); | 1191 EXPECT_FALSE(IsPeriodicDumpingEnabled()); |
| 1194 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 1192 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 1195 MemoryDumpLevelOfDetail::BACKGROUND); | 1193 MemoryDumpLevelOfDetail::BACKGROUND); |
| 1196 DisableTracing(); | 1194 DisableTracing(); |
| 1197 } | 1195 } |
| 1198 | 1196 |
| 1199 TEST_F(MemoryDumpManagerTest, TestBackgroundTracingSetup) { | 1197 TEST_F(MemoryDumpManagerTest, TestBackgroundTracingSetup) { |
| 1200 InitializeMemoryDumpManager(true /* is_coordinator */); | 1198 InitializeMemoryDumpManager(true /* is_coordinator */); |
| 1201 | 1199 |
| 1202 RunLoop run_loop; | 1200 RunLoop run_loop; |
| 1203 auto test_task_runner = ThreadTaskRunnerHandle::Get(); | 1201 auto test_task_runner = ThreadTaskRunnerHandle::Get(); |
| 1204 auto quit_closure = run_loop.QuitClosure(); | 1202 auto quit_closure = run_loop.QuitClosure(); |
| 1205 | 1203 |
| 1206 testing::InSequence sequence; | 1204 testing::InSequence sequence; |
| 1207 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(IsBackgroundDump(), _)) | 1205 EXPECT_CALL(global_dump_handler_, |
| 1206 RequestGlobalMemoryDump(IsBackgroundDump(), _)) |
| 1208 .Times(5); | 1207 .Times(5); |
| 1209 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(IsBackgroundDump(), _)) | 1208 EXPECT_CALL(global_dump_handler_, |
| 1209 RequestGlobalMemoryDump(IsBackgroundDump(), _)) |
| 1210 .WillOnce(Invoke([test_task_runner, quit_closure]( | 1210 .WillOnce(Invoke([test_task_runner, quit_closure]( |
| 1211 const MemoryDumpRequestArgs& args, | 1211 const MemoryDumpRequestArgs& args, |
| 1212 const GlobalMemoryDumpCallback& callback) { | 1212 const GlobalMemoryDumpCallback& callback) { |
| 1213 test_task_runner->PostTask(FROM_HERE, quit_closure); | 1213 test_task_runner->PostTask(FROM_HERE, quit_closure); |
| 1214 })); | 1214 })); |
| 1215 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(AnyNumber()); | 1215 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)) |
| 1216 .Times(AnyNumber()); |
| 1216 | 1217 |
| 1217 EnableTracingWithTraceConfig( | 1218 EnableTracingWithTraceConfig( |
| 1218 TraceConfigMemoryTestUtil::GetTraceConfig_BackgroundTrigger( | 1219 TraceConfigMemoryTestUtil::GetTraceConfig_BackgroundTrigger( |
| 1219 1 /* period_ms */)); | 1220 1 /* period_ms */)); |
| 1220 | 1221 |
| 1221 // Only background mode dumps should be allowed with the trace config. | 1222 // Only background mode dumps should be allowed with the trace config. |
| 1222 last_callback_success_ = false; | 1223 last_callback_success_ = false; |
| 1223 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 1224 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 1224 MemoryDumpLevelOfDetail::LIGHT); | 1225 MemoryDumpLevelOfDetail::LIGHT); |
| 1225 EXPECT_FALSE(last_callback_success_); | 1226 EXPECT_FALSE(last_callback_success_); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1258 | 1259 |
| 1259 DisableTracing(); | 1260 DisableTracing(); |
| 1260 | 1261 |
| 1261 const TraceConfig& trace_config = | 1262 const TraceConfig& trace_config = |
| 1262 TraceConfig(TraceConfigMemoryTestUtil::GetTraceConfig_NoTriggers()); | 1263 TraceConfig(TraceConfigMemoryTestUtil::GetTraceConfig_NoTriggers()); |
| 1263 const TraceConfig::MemoryDumpConfig& memory_dump_config = | 1264 const TraceConfig::MemoryDumpConfig& memory_dump_config = |
| 1264 trace_config.memory_dump_config(); | 1265 trace_config.memory_dump_config(); |
| 1265 | 1266 |
| 1266 mdm_->Enable(memory_dump_config); | 1267 mdm_->Enable(memory_dump_config); |
| 1267 | 1268 |
| 1268 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(3); | 1269 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(3); |
| 1269 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(3).WillRepeatedly(Return(true)); | 1270 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(3).WillRepeatedly(Return(true)); |
| 1270 last_callback_success_ = true; | 1271 last_callback_success_ = true; |
| 1271 for (int i = 0; i < 3; ++i) | 1272 for (int i = 0; i < 3; ++i) |
| 1272 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 1273 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 1273 MemoryDumpLevelOfDetail::DETAILED); | 1274 MemoryDumpLevelOfDetail::DETAILED); |
| 1274 // The callback result should actually be false since (for the moment at | 1275 // The callback result should actually be false since (for the moment at |
| 1275 // least) a true result means that as well as the dump generally being | 1276 // least) a true result means that as well as the dump generally being |
| 1276 // successful we also managed to add the dump to the trace. | 1277 // successful we also managed to add the dump to the trace. |
| 1277 EXPECT_FALSE(last_callback_success_); | 1278 EXPECT_FALSE(last_callback_success_); |
| 1278 | 1279 |
| 1279 mdm_->Disable(); | 1280 mdm_->Disable(); |
| 1280 | 1281 |
| 1281 mdm_->UnregisterDumpProvider(&mdp); | 1282 mdm_->UnregisterDumpProvider(&mdp); |
| 1282 } | 1283 } |
| 1283 | 1284 |
| 1284 } // namespace trace_event | 1285 } // namespace trace_event |
| 1285 } // namespace base | 1286 } // namespace base |
| OLD | NEW |