Chromium Code Reviews| 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 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 // Initalizes the ThreadLocalEventBuffer to guarantee that the TRACE_EVENTs | 405 // Initalizes the ThreadLocalEventBuffer to guarantee that the TRACE_EVENTs |
| 406 // in the PostTask below don't end up registering their own dump providers | 406 // in the PostTask below don't end up registering their own dump providers |
| 407 // (for discounting trace memory overhead) while holding the |lock_|. | 407 // (for discounting trace memory overhead) while holding the |lock_|. |
| 408 TraceLog::GetInstance()->InitializeThreadLocalEventBufferIfSupported(); | 408 TraceLog::GetInstance()->InitializeThreadLocalEventBufferIfSupported(); |
| 409 | 409 |
| 410 // If this was the last hop, create a trace event, add it to the trace and | 410 // |dump_thread_| might be destroyed before getting this point. |
| 411 // finalize process dump (invoke callback). | 411 // It means that tracing was disabled a moment ago. |
|
Primiano Tucci (use gerrit)
2016/04/13 20:19:16
s/a moment ago/right before starting this dump/
| |
| 412 // 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 (invoke callback). | |
|
Primiano Tucci (use gerrit)
2016/04/13 20:19:16
s/(invoke callback)/, invoking the callback/
| |
| 414 if (!pmd_async_state->dump_thread_task_runner.get()) { | |
| 415 pmd_async_state->dump_successful = false; | |
| 416 pmd_async_state->pending_dump_providers.clear(); | |
| 417 } | |
| 412 if (pmd_async_state->pending_dump_providers.empty()) | 418 if (pmd_async_state->pending_dump_providers.empty()) |
| 413 return FinalizeDumpAndAddToTrace(std::move(pmd_async_state)); | 419 return FinalizeDumpAndAddToTrace(std::move(pmd_async_state)); |
| 414 | 420 |
| 415 // Read MemoryDumpProviderInfo thread safety considerations in | 421 // Read MemoryDumpProviderInfo thread safety considerations in |
| 416 // memory_dump_manager.h when accessing |mdpinfo| fields. | 422 // memory_dump_manager.h when accessing |mdpinfo| fields. |
| 417 MemoryDumpProviderInfo* mdpinfo = | 423 MemoryDumpProviderInfo* mdpinfo = |
| 418 pmd_async_state->pending_dump_providers.back().get(); | 424 pmd_async_state->pending_dump_providers.back().get(); |
| 419 | 425 |
| 420 // If the dump provider did not specify a task runner affinity, dump on | 426 // If the dump provider did not specify a task runner affinity, dump on |
| 421 // |dump_thread_|. Note that |dump_thread_| might have been destroyed | 427 // |dump_thread_| which is already checked above for presence. |
| 422 // meanwhile. | |
| 423 SequencedTaskRunner* task_runner = mdpinfo->task_runner.get(); | 428 SequencedTaskRunner* task_runner = mdpinfo->task_runner.get(); |
| 424 if (!task_runner) { | 429 if (!task_runner) { |
| 425 DCHECK(mdpinfo->options.dumps_on_single_thread_task_runner); | 430 DCHECK(mdpinfo->options.dumps_on_single_thread_task_runner); |
| 426 task_runner = pmd_async_state->dump_thread_task_runner.get(); | 431 task_runner = pmd_async_state->dump_thread_task_runner.get(); |
|
bashi
2016/04/13 23:39:01
DCHECK(task_runner) ?
| |
| 427 if (!task_runner) { | |
| 428 // If tracing was disabled before reaching CreateProcessDump() the | |
| 429 // dump_thread_ would have been already torn down. Nack current dump and | |
| 430 // continue. | |
| 431 pmd_async_state->dump_successful = false; | |
| 432 pmd_async_state->pending_dump_providers.pop_back(); | |
| 433 return SetupNextMemoryDump(std::move(pmd_async_state)); | |
| 434 } | |
| 435 } | 432 } |
| 436 | 433 |
| 437 if (mdpinfo->options.dumps_on_single_thread_task_runner && | 434 if (mdpinfo->options.dumps_on_single_thread_task_runner && |
| 438 task_runner->RunsTasksOnCurrentThread()) { | 435 task_runner->RunsTasksOnCurrentThread()) { |
| 439 // If |dumps_on_single_thread_task_runner| is true then no PostTask is | 436 // If |dumps_on_single_thread_task_runner| is true then no PostTask is |
| 440 // required if we are on the right thread. | 437 // required if we are on the right thread. |
| 441 return InvokeOnMemoryDump(pmd_async_state.release()); | 438 return InvokeOnMemoryDump(pmd_async_state.release()); |
| 442 } | 439 } |
| 443 | 440 |
| 444 bool did_post_task = task_runner->PostTask( | 441 bool did_post_task = task_runner->PostTask( |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 753 if (iter == process_dumps.end()) { | 750 if (iter == process_dumps.end()) { |
| 754 std::unique_ptr<ProcessMemoryDump> new_pmd( | 751 std::unique_ptr<ProcessMemoryDump> new_pmd( |
| 755 new ProcessMemoryDump(session_state)); | 752 new ProcessMemoryDump(session_state)); |
| 756 iter = process_dumps.insert(std::make_pair(pid, std::move(new_pmd))).first; | 753 iter = process_dumps.insert(std::make_pair(pid, std::move(new_pmd))).first; |
| 757 } | 754 } |
| 758 return iter->second.get(); | 755 return iter->second.get(); |
| 759 } | 756 } |
| 760 | 757 |
| 761 } // namespace trace_event | 758 } // namespace trace_event |
| 762 } // namespace base | 759 } // namespace base |
| OLD | NEW |