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/string_piece.h" | |
| 20 #include "base/threading/thread.h" | 21 #include "base/threading/thread.h" |
| 21 #include "base/threading/thread_task_runner_handle.h" | 22 #include "base/threading/thread_task_runner_handle.h" |
| 22 #include "base/trace_event/heap_profiler.h" | 23 #include "base/trace_event/heap_profiler.h" |
| 23 #include "base/trace_event/heap_profiler_allocation_context_tracker.h" | 24 #include "base/trace_event/heap_profiler_allocation_context_tracker.h" |
| 24 #include "base/trace_event/heap_profiler_event_filter.h" | 25 #include "base/trace_event/heap_profiler_event_filter.h" |
| 25 #include "base/trace_event/heap_profiler_stack_frame_deduplicator.h" | 26 #include "base/trace_event/heap_profiler_stack_frame_deduplicator.h" |
| 26 #include "base/trace_event/heap_profiler_type_name_deduplicator.h" | 27 #include "base/trace_event/heap_profiler_type_name_deduplicator.h" |
| 27 #include "base/trace_event/malloc_dump_provider.h" | 28 #include "base/trace_event/malloc_dump_provider.h" |
| 28 #include "base/trace_event/memory_dump_provider.h" | 29 #include "base/trace_event/memory_dump_provider.h" |
| 29 #include "base/trace_event/memory_dump_scheduler.h" | 30 #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. | 713 // disabled (unregistered). This is to avoid taking lock while polling. |
| 713 for (const auto& mdpinfo : dump_providers_for_polling_) { | 714 for (const auto& mdpinfo : dump_providers_for_polling_) { |
| 714 uint64_t value = 0; | 715 uint64_t value = 0; |
| 715 mdpinfo->dump_provider->PollFastMemoryTotal(&value); | 716 mdpinfo->dump_provider->PollFastMemoryTotal(&value); |
| 716 *memory_total += value; | 717 *memory_total += value; |
| 717 } | 718 } |
| 718 return true; | 719 return true; |
| 719 } | 720 } |
| 720 | 721 |
| 721 // static | 722 // static |
| 723 uint32_t MemoryDumpManager::GetDumpsSumKb(const std::string& prefix, | |
| 724 const ProcessMemoryDump* pmd) { | |
| 725 uint64_t sum = 0; | |
| 726 for (const auto& kv : pmd->allocator_dumps()) { | |
| 727 auto name = StringPiece(kv.first); | |
| 728 if (name.starts_with(prefix)) { | |
| 729 sum += kv.second->GetSize(); | |
| 730 } | |
| 731 // We shouldn't be summing things with suballocations. | |
| 732 DCHECK(name.find("/__") == name.npos); | |
|
ssid
2017/03/23 03:11:38
So, this is supposed to work only for BACKGROUND m
hjd
2017/03/23 14:50:31
I removed this now that it should work in all mode
| |
| 733 } | |
| 734 return sum / 1024; | |
| 735 } | |
| 736 | |
| 737 // static | |
| 722 void MemoryDumpManager::FinalizeDumpAndAddToTrace( | 738 void MemoryDumpManager::FinalizeDumpAndAddToTrace( |
| 723 std::unique_ptr<ProcessMemoryDumpAsyncState> pmd_async_state) { | 739 std::unique_ptr<ProcessMemoryDumpAsyncState> pmd_async_state) { |
| 724 HEAP_PROFILER_SCOPED_IGNORE; | 740 HEAP_PROFILER_SCOPED_IGNORE; |
| 725 DCHECK(pmd_async_state->pending_dump_providers.empty()); | 741 DCHECK(pmd_async_state->pending_dump_providers.empty()); |
| 726 const uint64_t dump_guid = pmd_async_state->req_args.dump_guid; | 742 const uint64_t dump_guid = pmd_async_state->req_args.dump_guid; |
| 727 if (!pmd_async_state->callback_task_runner->BelongsToCurrentThread()) { | 743 if (!pmd_async_state->callback_task_runner->BelongsToCurrentThread()) { |
| 728 scoped_refptr<SingleThreadTaskRunner> callback_task_runner = | 744 scoped_refptr<SingleThreadTaskRunner> callback_task_runner = |
| 729 pmd_async_state->callback_task_runner; | 745 pmd_async_state->callback_task_runner; |
| 730 callback_task_runner->PostTask( | 746 callback_task_runner->PostTask( |
| 731 FROM_HERE, Bind(&MemoryDumpManager::FinalizeDumpAndAddToTrace, | 747 FROM_HERE, Bind(&MemoryDumpManager::FinalizeDumpAndAddToTrace, |
| 732 Passed(&pmd_async_state))); | 748 Passed(&pmd_async_state))); |
| 733 return; | 749 return; |
| 734 } | 750 } |
| 735 | 751 |
| 736 TRACE_EVENT_WITH_FLOW0(kTraceCategory, | 752 TRACE_EVENT_WITH_FLOW0(kTraceCategory, |
| 737 "MemoryDumpManager::FinalizeDumpAndAddToTrace", | 753 "MemoryDumpManager::FinalizeDumpAndAddToTrace", |
| 738 TRACE_ID_MANGLE(dump_guid), TRACE_EVENT_FLAG_FLOW_IN); | 754 TRACE_ID_MANGLE(dump_guid), TRACE_EVENT_FLAG_FLOW_IN); |
| 739 | 755 |
| 756 // The results struct to fill. | |
| 757 // TODO(hjd): Transitional until we send the full PMD. See crbug.com/704203 | |
| 758 MemoryDumpCallbackResult result; | |
| 759 | |
| 740 for (const auto& kv : pmd_async_state->process_dumps) { | 760 for (const auto& kv : pmd_async_state->process_dumps) { |
| 741 ProcessId pid = kv.first; // kNullProcessId for the current process. | 761 ProcessId pid = kv.first; // kNullProcessId for the current process. |
| 742 ProcessMemoryDump* process_memory_dump = kv.second.get(); | 762 ProcessMemoryDump* process_memory_dump = kv.second.get(); |
| 743 std::unique_ptr<TracedValue> traced_value(new TracedValue); | 763 std::unique_ptr<TracedValue> traced_value(new TracedValue); |
| 744 process_memory_dump->AsValueInto(traced_value.get()); | 764 process_memory_dump->AsValueInto(traced_value.get()); |
| 745 traced_value->SetString("level_of_detail", | 765 traced_value->SetString("level_of_detail", |
| 746 MemoryDumpLevelOfDetailToString( | 766 MemoryDumpLevelOfDetailToString( |
| 747 pmd_async_state->req_args.level_of_detail)); | 767 pmd_async_state->req_args.level_of_detail)); |
| 748 const char* const event_name = | 768 const char* const event_name = |
| 749 MemoryDumpTypeToString(pmd_async_state->req_args.dump_type); | 769 MemoryDumpTypeToString(pmd_async_state->req_args.dump_type); |
| 750 | 770 |
| 751 std::unique_ptr<ConvertableToTraceFormat> event_value( | 771 std::unique_ptr<ConvertableToTraceFormat> event_value( |
| 752 std::move(traced_value)); | 772 std::move(traced_value)); |
| 753 TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_PROCESS_ID( | 773 TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_PROCESS_ID( |
| 754 TRACE_EVENT_PHASE_MEMORY_DUMP, | 774 TRACE_EVENT_PHASE_MEMORY_DUMP, |
| 755 TraceLog::GetCategoryGroupEnabled(kTraceCategory), event_name, | 775 TraceLog::GetCategoryGroupEnabled(kTraceCategory), event_name, |
| 756 trace_event_internal::kGlobalScope, dump_guid, pid, | 776 trace_event_internal::kGlobalScope, dump_guid, pid, |
| 757 kTraceEventNumArgs, kTraceEventArgNames, | 777 kTraceEventNumArgs, kTraceEventArgNames, |
| 758 kTraceEventArgTypes, nullptr /* arg_values */, &event_value, | 778 kTraceEventArgTypes, nullptr /* arg_values */, &event_value, |
| 759 TRACE_EVENT_FLAG_HAS_ID); | 779 TRACE_EVENT_FLAG_HAS_ID); |
| 780 | |
| 781 // TODO(hjd): Transitional until we send the full PMD. See crbug.com/704203 | |
| 782 if (pmd_async_state->req_args.level_of_detail == | |
| 783 MemoryDumpLevelOfDetail::BACKGROUND) { | |
| 784 if (pid == kNullProcessId) { | |
| 785 result.chrome_dump.malloc_total_kb = | |
| 786 GetDumpsSumKb("malloc/", process_memory_dump); | |
|
ssid
2017/03/23 03:11:38
This seems very fragile. the double counting depen
Primiano Tucci (use gerrit)
2017/03/23 12:27:58
In this case I'd just count "malloc" (without any
hjd
2017/03/23 14:50:30
Done.
| |
| 787 result.chrome_dump.v8_total_kb = | |
| 788 GetDumpsSumKb("v8/", process_memory_dump); | |
| 789 // partition_alloc reports sizes for both allocated_objects and | |
| 790 // partitions. The memory allocated_objects uses is a subset of | |
| 791 // the partitions memory so to avoid double counting we only | |
| 792 // count partitions memory. | |
| 793 result.chrome_dump.partition_alloc_total_kb = | |
| 794 GetDumpsSumKb("partition_alloc/partitions", process_memory_dump); | |
| 795 result.chrome_dump.blink_gc_total_kb = | |
| 796 GetDumpsSumKb("blink_gc/", process_memory_dump); | |
|
ssid
2017/03/23 03:11:38
So, in this case we would be counting the "allocat
Primiano Tucci (use gerrit)
2017/03/23 12:27:58
We don't for blink_gc.
Since we have an explicit t
hjd
2017/03/23 14:50:31
Done.
| |
| 797 } | |
| 798 } | |
| 760 } | 799 } |
| 761 | 800 |
| 762 bool tracing_still_enabled; | 801 bool tracing_still_enabled; |
| 763 TRACE_EVENT_CATEGORY_GROUP_ENABLED(kTraceCategory, &tracing_still_enabled); | 802 TRACE_EVENT_CATEGORY_GROUP_ENABLED(kTraceCategory, &tracing_still_enabled); |
| 764 if (!tracing_still_enabled) { | 803 if (!tracing_still_enabled) { |
| 765 pmd_async_state->dump_successful = false; | 804 pmd_async_state->dump_successful = false; |
| 766 VLOG(1) << kLogPrefix << " failed because tracing was disabled before" | 805 VLOG(1) << kLogPrefix << " failed because tracing was disabled before" |
| 767 << " the dump was completed"; | 806 << " the dump was completed"; |
| 768 } | 807 } |
| 769 | 808 |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 961 if (iter == process_dumps.end()) { | 1000 if (iter == process_dumps.end()) { |
| 962 std::unique_ptr<ProcessMemoryDump> new_pmd( | 1001 std::unique_ptr<ProcessMemoryDump> new_pmd( |
| 963 new ProcessMemoryDump(session_state, dump_args)); | 1002 new ProcessMemoryDump(session_state, dump_args)); |
| 964 iter = process_dumps.insert(std::make_pair(pid, std::move(new_pmd))).first; | 1003 iter = process_dumps.insert(std::make_pair(pid, std::move(new_pmd))).first; |
| 965 } | 1004 } |
| 966 return iter->second.get(); | 1005 return iter->second.get(); |
| 967 } | 1006 } |
| 968 | 1007 |
| 969 } // namespace trace_event | 1008 } // namespace trace_event |
| 970 } // namespace base | 1009 } // namespace base |
| OLD | NEW |