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/allocator/features.h" | 10 #include "base/allocator/features.h" |
| 11 #include "base/atomic_sequence_num.h" | 11 #include "base/atomic_sequence_num.h" |
| 12 #include "base/base_switches.h" | 12 #include "base/base_switches.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/debug/alias.h" | 15 #include "base/debug/alias.h" |
| 16 #include "base/debug/debugging_flags.h" | 16 #include "base/debug/debugging_flags.h" |
| 17 #include "base/debug/stack_trace.h" | 17 #include "base/debug/stack_trace.h" |
| 18 #include "base/debug/thread_heap_usage_tracker.h" | 18 #include "base/debug/thread_heap_usage_tracker.h" |
| 19 #include "base/memory/ptr_util.h" | 19 #include "base/memory/ptr_util.h" |
| 20 #include "base/strings/pattern.h" | |
| 21 #include "base/strings/string_piece.h" | |
| 20 #include "base/threading/thread.h" | 22 #include "base/threading/thread.h" |
| 21 #include "base/threading/thread_task_runner_handle.h" | 23 #include "base/threading/thread_task_runner_handle.h" |
| 22 #include "base/trace_event/heap_profiler.h" | 24 #include "base/trace_event/heap_profiler.h" |
| 23 #include "base/trace_event/heap_profiler_allocation_context_tracker.h" | 25 #include "base/trace_event/heap_profiler_allocation_context_tracker.h" |
| 24 #include "base/trace_event/heap_profiler_event_filter.h" | 26 #include "base/trace_event/heap_profiler_event_filter.h" |
| 25 #include "base/trace_event/heap_profiler_stack_frame_deduplicator.h" | 27 #include "base/trace_event/heap_profiler_stack_frame_deduplicator.h" |
| 26 #include "base/trace_event/heap_profiler_type_name_deduplicator.h" | 28 #include "base/trace_event/heap_profiler_type_name_deduplicator.h" |
| 27 #include "base/trace_event/malloc_dump_provider.h" | 29 #include "base/trace_event/malloc_dump_provider.h" |
| 28 #include "base/trace_event/memory_dump_provider.h" | 30 #include "base/trace_event/memory_dump_provider.h" |
| 29 #include "base/trace_event/memory_dump_scheduler.h" | 31 #include "base/trace_event/memory_dump_scheduler.h" |
| (...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 712 // disabled (unregistered). This is to avoid taking lock while polling. | 714 // disabled (unregistered). This is to avoid taking lock while polling. |
| 713 for (const auto& mdpinfo : dump_providers_for_polling_) { | 715 for (const auto& mdpinfo : dump_providers_for_polling_) { |
| 714 uint64_t value = 0; | 716 uint64_t value = 0; |
| 715 mdpinfo->dump_provider->PollFastMemoryTotal(&value); | 717 mdpinfo->dump_provider->PollFastMemoryTotal(&value); |
| 716 *memory_total += value; | 718 *memory_total += value; |
| 717 } | 719 } |
| 718 return true; | 720 return true; |
| 719 } | 721 } |
| 720 | 722 |
| 721 // static | 723 // static |
| 724 uint32_t MemoryDumpManager::GetDumpsSumKb(const std::string& pattern, | |
| 725 const ProcessMemoryDump* pmd) { | |
| 726 uint64_t sum = 0; | |
| 727 for (const auto& kv : pmd->allocator_dumps()) { | |
| 728 auto name = StringPiece(kv.first); | |
| 729 if (MatchPattern(name, pattern)) | |
| 730 sum += kv.second->GetSize(); | |
| 731 } | |
| 732 return sum / 1024; | |
| 733 } | |
| 734 | |
| 735 // static | |
| 722 void MemoryDumpManager::FinalizeDumpAndAddToTrace( | 736 void MemoryDumpManager::FinalizeDumpAndAddToTrace( |
| 723 std::unique_ptr<ProcessMemoryDumpAsyncState> pmd_async_state) { | 737 std::unique_ptr<ProcessMemoryDumpAsyncState> pmd_async_state) { |
| 724 HEAP_PROFILER_SCOPED_IGNORE; | 738 HEAP_PROFILER_SCOPED_IGNORE; |
| 725 DCHECK(pmd_async_state->pending_dump_providers.empty()); | 739 DCHECK(pmd_async_state->pending_dump_providers.empty()); |
| 726 const uint64_t dump_guid = pmd_async_state->req_args.dump_guid; | 740 const uint64_t dump_guid = pmd_async_state->req_args.dump_guid; |
| 727 if (!pmd_async_state->callback_task_runner->BelongsToCurrentThread()) { | 741 if (!pmd_async_state->callback_task_runner->BelongsToCurrentThread()) { |
| 728 scoped_refptr<SingleThreadTaskRunner> callback_task_runner = | 742 scoped_refptr<SingleThreadTaskRunner> callback_task_runner = |
| 729 pmd_async_state->callback_task_runner; | 743 pmd_async_state->callback_task_runner; |
| 730 callback_task_runner->PostTask( | 744 callback_task_runner->PostTask( |
| 731 FROM_HERE, Bind(&MemoryDumpManager::FinalizeDumpAndAddToTrace, | 745 FROM_HERE, Bind(&MemoryDumpManager::FinalizeDumpAndAddToTrace, |
| 732 Passed(&pmd_async_state))); | 746 Passed(&pmd_async_state))); |
| 733 return; | 747 return; |
| 734 } | 748 } |
| 735 | 749 |
| 736 TRACE_EVENT_WITH_FLOW0(kTraceCategory, | 750 TRACE_EVENT_WITH_FLOW0(kTraceCategory, |
| 737 "MemoryDumpManager::FinalizeDumpAndAddToTrace", | 751 "MemoryDumpManager::FinalizeDumpAndAddToTrace", |
| 738 TRACE_ID_MANGLE(dump_guid), TRACE_EVENT_FLAG_FLOW_IN); | 752 TRACE_ID_MANGLE(dump_guid), TRACE_EVENT_FLAG_FLOW_IN); |
| 739 | 753 |
| 754 // The results struct to fill. | |
| 755 // TODO(hjd): Transitional until we send the full PMD. See crbug.com/704203 | |
| 756 MemoryDumpCallbackResult result; | |
| 757 | |
| 740 for (const auto& kv : pmd_async_state->process_dumps) { | 758 for (const auto& kv : pmd_async_state->process_dumps) { |
| 741 ProcessId pid = kv.first; // kNullProcessId for the current process. | 759 ProcessId pid = kv.first; // kNullProcessId for the current process. |
| 742 ProcessMemoryDump* process_memory_dump = kv.second.get(); | 760 ProcessMemoryDump* process_memory_dump = kv.second.get(); |
| 743 std::unique_ptr<TracedValue> traced_value(new TracedValue); | 761 std::unique_ptr<TracedValue> traced_value(new TracedValue); |
| 744 process_memory_dump->AsValueInto(traced_value.get()); | 762 process_memory_dump->AsValueInto(traced_value.get()); |
| 745 traced_value->SetString("level_of_detail", | 763 traced_value->SetString("level_of_detail", |
| 746 MemoryDumpLevelOfDetailToString( | 764 MemoryDumpLevelOfDetailToString( |
| 747 pmd_async_state->req_args.level_of_detail)); | 765 pmd_async_state->req_args.level_of_detail)); |
| 748 const char* const event_name = | 766 const char* const event_name = |
| 749 MemoryDumpTypeToString(pmd_async_state->req_args.dump_type); | 767 MemoryDumpTypeToString(pmd_async_state->req_args.dump_type); |
| 750 | 768 |
| 751 std::unique_ptr<ConvertableToTraceFormat> event_value( | 769 std::unique_ptr<ConvertableToTraceFormat> event_value( |
| 752 std::move(traced_value)); | 770 std::move(traced_value)); |
| 753 TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_PROCESS_ID( | 771 TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_PROCESS_ID( |
| 754 TRACE_EVENT_PHASE_MEMORY_DUMP, | 772 TRACE_EVENT_PHASE_MEMORY_DUMP, |
| 755 TraceLog::GetCategoryGroupEnabled(kTraceCategory), event_name, | 773 TraceLog::GetCategoryGroupEnabled(kTraceCategory), event_name, |
| 756 trace_event_internal::kGlobalScope, dump_guid, pid, | 774 trace_event_internal::kGlobalScope, dump_guid, pid, |
| 757 kTraceEventNumArgs, kTraceEventArgNames, | 775 kTraceEventNumArgs, kTraceEventArgNames, |
| 758 kTraceEventArgTypes, nullptr /* arg_values */, &event_value, | 776 kTraceEventArgTypes, nullptr /* arg_values */, &event_value, |
| 759 TRACE_EVENT_FLAG_HAS_ID); | 777 TRACE_EVENT_FLAG_HAS_ID); |
| 778 | |
| 779 // TODO(hjd): Transitional until we send the full PMD. See crbug.com/704203 | |
| 780 if (pid == kNullProcessId) { | |
|
ssid
2017/03/23 18:32:34
This should still not work for detailed mode. I th
Primiano Tucci (use gerrit)
2017/03/23 19:01:25
Aaaand you are right (unless we make it so that th
hjd
2017/03/24 11:28:36
Done.
| |
| 781 result.chrome_dump.malloc_total_kb = | |
| 782 GetDumpsSumKb("malloc", process_memory_dump); | |
| 783 result.chrome_dump.v8_total_kb = | |
| 784 GetDumpsSumKb("v8/*", process_memory_dump); | |
| 785 | |
| 786 // partition_alloc reports sizes for both allocated_objects and | |
| 787 // partitions. The memory allocated_objects uses is a subset of | |
| 788 // the partitions memory so to avoid double counting we only | |
| 789 // count partitions memory. | |
| 790 result.chrome_dump.partition_alloc_total_kb = | |
| 791 GetDumpsSumKb("partition_alloc/partitions/*", process_memory_dump); | |
| 792 result.chrome_dump.blink_gc_total_kb = | |
| 793 GetDumpsSumKb("blink_gc", process_memory_dump); | |
| 794 } | |
| 760 } | 795 } |
| 761 | 796 |
| 762 bool tracing_still_enabled; | 797 bool tracing_still_enabled; |
| 763 TRACE_EVENT_CATEGORY_GROUP_ENABLED(kTraceCategory, &tracing_still_enabled); | 798 TRACE_EVENT_CATEGORY_GROUP_ENABLED(kTraceCategory, &tracing_still_enabled); |
| 764 if (!tracing_still_enabled) { | 799 if (!tracing_still_enabled) { |
| 765 pmd_async_state->dump_successful = false; | 800 pmd_async_state->dump_successful = false; |
| 766 VLOG(1) << kLogPrefix << " failed because tracing was disabled before" | 801 VLOG(1) << kLogPrefix << " failed because tracing was disabled before" |
| 767 << " the dump was completed"; | 802 << " the dump was completed"; |
| 768 } | 803 } |
| 769 | 804 |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 961 if (iter == process_dumps.end()) { | 996 if (iter == process_dumps.end()) { |
| 962 std::unique_ptr<ProcessMemoryDump> new_pmd( | 997 std::unique_ptr<ProcessMemoryDump> new_pmd( |
| 963 new ProcessMemoryDump(session_state, dump_args)); | 998 new ProcessMemoryDump(session_state, dump_args)); |
| 964 iter = process_dumps.insert(std::make_pair(pid, std::move(new_pmd))).first; | 999 iter = process_dumps.insert(std::make_pair(pid, std::move(new_pmd))).first; |
| 965 } | 1000 } |
| 966 return iter->second.get(); | 1001 return iter->second.get(); |
| 967 } | 1002 } |
| 968 | 1003 |
| 969 } // namespace trace_event | 1004 } // namespace trace_event |
| 970 } // namespace base | 1005 } // namespace base |
| OLD | NEW |