| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/atomic_sequence_num.h" | 10 #include "base/atomic_sequence_num.h" |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 // PostTask is always required for a generic SequencedTaskRunner to ensure that | 395 // PostTask is always required for a generic SequencedTaskRunner to ensure that |
| 396 // no other task is running on it concurrently. SetupNextMemoryDump() and | 396 // no other task is running on it concurrently. SetupNextMemoryDump() and |
| 397 // InvokeOnMemoryDump() are called alternatively which linearizes the dump | 397 // InvokeOnMemoryDump() are called alternatively which linearizes the dump |
| 398 // provider's OnMemoryDump invocations. | 398 // provider's OnMemoryDump invocations. |
| 399 // At most one of either SetupNextMemoryDump() or InvokeOnMemoryDump() can be | 399 // At most one of either SetupNextMemoryDump() or InvokeOnMemoryDump() can be |
| 400 // active at any time for a given PMD, regardless of status of the |lock_|. | 400 // active at any time for a given PMD, regardless of status of the |lock_|. |
| 401 // |lock_| is used in these functions purely to ensure consistency w.r.t. | 401 // |lock_| is used in these functions purely to ensure consistency w.r.t. |
| 402 // (un)registrations of |dump_providers_|. | 402 // (un)registrations of |dump_providers_|. |
| 403 void MemoryDumpManager::SetupNextMemoryDump( | 403 void MemoryDumpManager::SetupNextMemoryDump( |
| 404 std::unique_ptr<ProcessMemoryDumpAsyncState> pmd_async_state) { | 404 std::unique_ptr<ProcessMemoryDumpAsyncState> pmd_async_state) { |
| 405 SCOPED_HEAP_PROFILER_IGNORE_MALLOC_EVENT; |
| 405 // Initalizes the ThreadLocalEventBuffer to guarantee that the TRACE_EVENTs | 406 // Initalizes the ThreadLocalEventBuffer to guarantee that the TRACE_EVENTs |
| 406 // in the PostTask below don't end up registering their own dump providers | 407 // in the PostTask below don't end up registering their own dump providers |
| 407 // (for discounting trace memory overhead) while holding the |lock_|. | 408 // (for discounting trace memory overhead) while holding the |lock_|. |
| 408 TraceLog::GetInstance()->InitializeThreadLocalEventBufferIfSupported(); | 409 TraceLog::GetInstance()->InitializeThreadLocalEventBufferIfSupported(); |
| 409 | 410 |
| 410 // |dump_thread_| might be destroyed before getting this point. | 411 // |dump_thread_| might be destroyed before getting this point. |
| 411 // It means that tracing was disabled right before starting this dump. | 412 // It means that tracing was disabled right before starting this dump. |
| 412 // Anyway either tracing is stopped or this was the last hop, create a trace | 413 // Anyway either tracing is stopped or this was the last hop, create a trace |
| 413 // event, add it to the trace and finalize process dump invoking the callback. | 414 // event, add it to the trace and finalize process dump invoking the callback. |
| 414 if (!pmd_async_state->dump_thread_task_runner.get()) { | 415 if (!pmd_async_state->dump_thread_task_runner.get()) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 pmd_async_state->pending_dump_providers.pop_back(); | 468 pmd_async_state->pending_dump_providers.pop_back(); |
| 468 SetupNextMemoryDump(std::move(pmd_async_state)); | 469 SetupNextMemoryDump(std::move(pmd_async_state)); |
| 469 } | 470 } |
| 470 | 471 |
| 471 // This function is called on the right task runner for current MDP. It is | 472 // This function is called on the right task runner for current MDP. It is |
| 472 // either the task runner specified by MDP or |dump_thread_task_runner| if the | 473 // either the task runner specified by MDP or |dump_thread_task_runner| if the |
| 473 // MDP did not specify task runner. Invokes the dump provider's OnMemoryDump() | 474 // MDP did not specify task runner. Invokes the dump provider's OnMemoryDump() |
| 474 // (unless disabled). | 475 // (unless disabled). |
| 475 void MemoryDumpManager::InvokeOnMemoryDump( | 476 void MemoryDumpManager::InvokeOnMemoryDump( |
| 476 ProcessMemoryDumpAsyncState* owned_pmd_async_state) { | 477 ProcessMemoryDumpAsyncState* owned_pmd_async_state) { |
| 478 SCOPED_HEAP_PROFILER_IGNORE_MALLOC_EVENT; |
| 477 // In theory |owned_pmd_async_state| should be a scoped_ptr. The only reason | 479 // In theory |owned_pmd_async_state| should be a scoped_ptr. The only reason |
| 478 // why it isn't is because of the corner case logic of |did_post_task| | 480 // why it isn't is because of the corner case logic of |did_post_task| |
| 479 // above, which needs to take back the ownership of the |pmd_async_state| when | 481 // above, which needs to take back the ownership of the |pmd_async_state| when |
| 480 // the PostTask() fails. | 482 // the PostTask() fails. |
| 481 // Unfortunately, PostTask() destroys the scoped_ptr arguments upon failure | 483 // Unfortunately, PostTask() destroys the scoped_ptr arguments upon failure |
| 482 // to prevent accidental leaks. Using a scoped_ptr would prevent us to to | 484 // to prevent accidental leaks. Using a scoped_ptr would prevent us to to |
| 483 // skip the hop and move on. Hence the manual naked -> scoped ptr juggling. | 485 // skip the hop and move on. Hence the manual naked -> scoped ptr juggling. |
| 484 auto pmd_async_state = WrapUnique(owned_pmd_async_state); | 486 auto pmd_async_state = WrapUnique(owned_pmd_async_state); |
| 485 owned_pmd_async_state = nullptr; | 487 owned_pmd_async_state = nullptr; |
| 486 | 488 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 dump_successful ? 0 : mdpinfo->consecutive_failures + 1; | 530 dump_successful ? 0 : mdpinfo->consecutive_failures + 1; |
| 529 } | 531 } |
| 530 | 532 |
| 531 pmd_async_state->pending_dump_providers.pop_back(); | 533 pmd_async_state->pending_dump_providers.pop_back(); |
| 532 SetupNextMemoryDump(std::move(pmd_async_state)); | 534 SetupNextMemoryDump(std::move(pmd_async_state)); |
| 533 } | 535 } |
| 534 | 536 |
| 535 // static | 537 // static |
| 536 void MemoryDumpManager::FinalizeDumpAndAddToTrace( | 538 void MemoryDumpManager::FinalizeDumpAndAddToTrace( |
| 537 std::unique_ptr<ProcessMemoryDumpAsyncState> pmd_async_state) { | 539 std::unique_ptr<ProcessMemoryDumpAsyncState> pmd_async_state) { |
| 540 SCOPED_HEAP_PROFILER_IGNORE_MALLOC_EVENT; |
| 538 DCHECK(pmd_async_state->pending_dump_providers.empty()); | 541 DCHECK(pmd_async_state->pending_dump_providers.empty()); |
| 539 const uint64_t dump_guid = pmd_async_state->req_args.dump_guid; | 542 const uint64_t dump_guid = pmd_async_state->req_args.dump_guid; |
| 540 if (!pmd_async_state->callback_task_runner->BelongsToCurrentThread()) { | 543 if (!pmd_async_state->callback_task_runner->BelongsToCurrentThread()) { |
| 541 scoped_refptr<SingleThreadTaskRunner> callback_task_runner = | 544 scoped_refptr<SingleThreadTaskRunner> callback_task_runner = |
| 542 pmd_async_state->callback_task_runner; | 545 pmd_async_state->callback_task_runner; |
| 543 callback_task_runner->PostTask( | 546 callback_task_runner->PostTask( |
| 544 FROM_HERE, Bind(&MemoryDumpManager::FinalizeDumpAndAddToTrace, | 547 FROM_HERE, Bind(&MemoryDumpManager::FinalizeDumpAndAddToTrace, |
| 545 Passed(&pmd_async_state))); | 548 Passed(&pmd_async_state))); |
| 546 return; | 549 return; |
| 547 } | 550 } |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 751 if (iter == process_dumps.end()) { | 754 if (iter == process_dumps.end()) { |
| 752 std::unique_ptr<ProcessMemoryDump> new_pmd( | 755 std::unique_ptr<ProcessMemoryDump> new_pmd( |
| 753 new ProcessMemoryDump(session_state)); | 756 new ProcessMemoryDump(session_state)); |
| 754 iter = process_dumps.insert(std::make_pair(pid, std::move(new_pmd))).first; | 757 iter = process_dumps.insert(std::make_pair(pid, std::move(new_pmd))).first; |
| 755 } | 758 } |
| 756 return iter->second.get(); | 759 return iter->second.get(); |
| 757 } | 760 } |
| 758 | 761 |
| 759 } // namespace trace_event | 762 } // namespace trace_event |
| 760 } // namespace base | 763 } // namespace base |
| OLD | NEW |