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 <inttypes.h> | 7 #include <inttypes.h> |
| 8 #include <stdio.h> | 8 #include <stdio.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 #include "base/memory/ptr_util.h" | 22 #include "base/memory/ptr_util.h" |
| 23 #include "base/optional.h" | 23 #include "base/optional.h" |
| 24 #include "base/sequenced_task_runner.h" | 24 #include "base/sequenced_task_runner.h" |
| 25 #include "base/strings/pattern.h" | 25 #include "base/strings/pattern.h" |
| 26 #include "base/strings/string_piece.h" | 26 #include "base/strings/string_piece.h" |
| 27 #include "base/threading/thread.h" | 27 #include "base/threading/thread.h" |
| 28 #include "base/threading/thread_task_runner_handle.h" | 28 #include "base/threading/thread_task_runner_handle.h" |
| 29 #include "base/trace_event/heap_profiler.h" | 29 #include "base/trace_event/heap_profiler.h" |
| 30 #include "base/trace_event/heap_profiler_allocation_context_tracker.h" | 30 #include "base/trace_event/heap_profiler_allocation_context_tracker.h" |
| 31 #include "base/trace_event/heap_profiler_event_filter.h" | 31 #include "base/trace_event/heap_profiler_event_filter.h" |
| 32 #include "base/trace_event/heap_profiler_serialization_state.h" | 32 #include "base/trace_event/heap_profiler_event_writer.h" |
| 33 #include "base/trace_event/heap_profiler_stack_frame_deduplicator.h" | |
| 34 #include "base/trace_event/heap_profiler_type_name_deduplicator.h" | |
| 35 #include "base/trace_event/malloc_dump_provider.h" | 33 #include "base/trace_event/malloc_dump_provider.h" |
| 36 #include "base/trace_event/memory_dump_provider.h" | 34 #include "base/trace_event/memory_dump_provider.h" |
| 37 #include "base/trace_event/memory_dump_scheduler.h" | 35 #include "base/trace_event/memory_dump_scheduler.h" |
| 38 #include "base/trace_event/memory_infra_background_whitelist.h" | 36 #include "base/trace_event/memory_infra_background_whitelist.h" |
| 39 #include "base/trace_event/memory_peak_detector.h" | 37 #include "base/trace_event/memory_peak_detector.h" |
| 40 #include "base/trace_event/memory_tracing_observer.h" | 38 #include "base/trace_event/memory_tracing_observer.h" |
| 41 #include "base/trace_event/process_memory_dump.h" | 39 #include "base/trace_event/process_memory_dump.h" |
| 42 #include "base/trace_event/trace_event.h" | 40 #include "base/trace_event/trace_event.h" |
| 43 #include "base/trace_event/trace_event_argument.h" | 41 #include "base/trace_event/trace_event_argument.h" |
| 44 #include "build/build_config.h" | 42 #include "build/build_config.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 void FillOsDumpFromProcessMemoryDump( | 74 void FillOsDumpFromProcessMemoryDump( |
| 77 const ProcessMemoryDump* pmd, | 75 const ProcessMemoryDump* pmd, |
| 78 MemoryDumpCallbackResult::OSMemDump* osDump) { | 76 MemoryDumpCallbackResult::OSMemDump* osDump) { |
| 79 if (pmd->has_process_totals()) { | 77 if (pmd->has_process_totals()) { |
| 80 const ProcessMemoryTotals* totals = pmd->process_totals(); | 78 const ProcessMemoryTotals* totals = pmd->process_totals(); |
| 81 osDump->resident_set_kb = totals->resident_set_bytes() / 1024; | 79 osDump->resident_set_kb = totals->resident_set_bytes() / 1024; |
| 82 osDump->platform_private_footprint = totals->GetPlatformPrivateFootprint(); | 80 osDump->platform_private_footprint = totals->GetPlatformPrivateFootprint(); |
| 83 } | 81 } |
| 84 } | 82 } |
| 85 | 83 |
| 86 // Proxy class which wraps a ConvertableToTraceFormat owned by the | |
| 87 // |heap_profiler_serialization_state| into a proxy object that can be added to | |
| 88 // the trace event log. This is to solve the problem that the | |
| 89 // HeapProfilerSerializationState is refcounted but the tracing subsystem wants | |
| 90 // a std::unique_ptr<ConvertableToTraceFormat>. | |
| 91 template <typename T> | |
| 92 struct SessionStateConvertableProxy : public ConvertableToTraceFormat { | |
| 93 using GetterFunctPtr = T* (HeapProfilerSerializationState::*)() const; | |
| 94 | |
| 95 SessionStateConvertableProxy(scoped_refptr<HeapProfilerSerializationState> | |
| 96 heap_profiler_serialization_state, | |
| 97 GetterFunctPtr getter_function) | |
| 98 : heap_profiler_serialization_state(heap_profiler_serialization_state), | |
| 99 getter_function(getter_function) {} | |
| 100 | |
| 101 void AppendAsTraceFormat(std::string* out) const override { | |
| 102 return (heap_profiler_serialization_state.get()->*getter_function)() | |
| 103 ->AppendAsTraceFormat(out); | |
| 104 } | |
| 105 | |
| 106 void EstimateTraceMemoryOverhead( | |
| 107 TraceEventMemoryOverhead* overhead) override { | |
| 108 return (heap_profiler_serialization_state.get()->*getter_function)() | |
| 109 ->EstimateTraceMemoryOverhead(overhead); | |
| 110 } | |
| 111 | |
| 112 scoped_refptr<HeapProfilerSerializationState> | |
| 113 heap_profiler_serialization_state; | |
| 114 GetterFunctPtr const getter_function; | |
| 115 }; | |
| 116 | |
| 117 void OnPeakDetected(MemoryDumpLevelOfDetail level_of_detail) { | 84 void OnPeakDetected(MemoryDumpLevelOfDetail level_of_detail) { |
| 118 MemoryDumpManager::GetInstance()->RequestGlobalDump( | 85 MemoryDumpManager::GetInstance()->RequestGlobalDump( |
| 119 MemoryDumpType::PEAK_MEMORY_USAGE, level_of_detail); | 86 MemoryDumpType::PEAK_MEMORY_USAGE, level_of_detail); |
| 120 } | 87 } |
| 121 | 88 |
| 122 void OnPeriodicSchedulerTick(MemoryDumpLevelOfDetail level_of_detail) { | 89 void OnPeriodicSchedulerTick(MemoryDumpLevelOfDetail level_of_detail) { |
| 123 MemoryDumpManager::GetInstance()->RequestGlobalDump( | 90 MemoryDumpManager::GetInstance()->RequestGlobalDump( |
| 124 MemoryDumpType::PERIODIC_INTERVAL, level_of_detail); | 91 MemoryDumpType::PERIODIC_INTERVAL, level_of_detail); |
| 125 } | 92 } |
| 126 | 93 |
| (...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 773 GetDumpsSumKb("partition_alloc/partitions/*", process_memory_dump); | 740 GetDumpsSumKb("partition_alloc/partitions/*", process_memory_dump); |
| 774 result->chrome_dump.blink_gc_total_kb = | 741 result->chrome_dump.blink_gc_total_kb = |
| 775 GetDumpsSumKb("blink_gc", process_memory_dump); | 742 GetDumpsSumKb("blink_gc", process_memory_dump); |
| 776 FillOsDumpFromProcessMemoryDump(process_memory_dump, &result->os_dump); | 743 FillOsDumpFromProcessMemoryDump(process_memory_dump, &result->os_dump); |
| 777 } else { | 744 } else { |
| 778 auto& os_dump = result->extra_processes_dump[pid]; | 745 auto& os_dump = result->extra_processes_dump[pid]; |
| 779 FillOsDumpFromProcessMemoryDump(process_memory_dump, &os_dump); | 746 FillOsDumpFromProcessMemoryDump(process_memory_dump, &os_dump); |
| 780 } | 747 } |
| 781 } | 748 } |
| 782 | 749 |
| 750 bool tracing_still_enabled; | |
|
Primiano Tucci (use gerrit)
2017/05/30 18:50:53
I think this is a rebase leftover. we don't want t
DmitrySkiba
2017/06/05 00:50:18
Nice catch! Done.
| |
| 751 TRACE_EVENT_CATEGORY_GROUP_ENABLED(kTraceCategory, &tracing_still_enabled); | |
| 752 if (!tracing_still_enabled) { | |
| 753 pmd_async_state->dump_successful = false; | |
| 754 VLOG(1) << kLogPrefix << " failed because tracing was disabled before" | |
| 755 << " the dump was completed"; | |
| 756 } | |
| 757 | |
| 783 if (!pmd_async_state->callback.is_null()) { | 758 if (!pmd_async_state->callback.is_null()) { |
| 784 pmd_async_state->callback.Run(dump_guid, dump_successful, result); | 759 pmd_async_state->callback.Run(dump_guid, dump_successful, result); |
| 785 pmd_async_state->callback.Reset(); | 760 pmd_async_state->callback.Reset(); |
| 786 } | 761 } |
| 787 | 762 |
| 788 TRACE_EVENT_NESTABLE_ASYNC_END0(kTraceCategory, "ProcessMemoryDump", | 763 TRACE_EVENT_NESTABLE_ASYNC_END0(kTraceCategory, "ProcessMemoryDump", |
| 789 TRACE_ID_LOCAL(dump_guid)); | 764 TRACE_ID_LOCAL(dump_guid)); |
| 790 } | 765 } |
| 791 | 766 |
| 792 void MemoryDumpManager::SetupForTracing( | 767 void MemoryDumpManager::SetupForTracing( |
| 793 const TraceConfig::MemoryDumpConfig& memory_dump_config) { | 768 const TraceConfig::MemoryDumpConfig& memory_dump_config) { |
| 794 scoped_refptr<HeapProfilerSerializationState> | 769 scoped_refptr<HeapProfilerSerializationState> |
| 795 heap_profiler_serialization_state = new HeapProfilerSerializationState; | 770 heap_profiler_serialization_state = new HeapProfilerSerializationState; |
| 796 heap_profiler_serialization_state | 771 heap_profiler_serialization_state |
| 797 ->set_heap_profiler_breakdown_threshold_bytes( | 772 ->set_heap_profiler_breakdown_threshold_bytes( |
| 798 memory_dump_config.heap_profiler_options.breakdown_threshold_bytes); | 773 memory_dump_config.heap_profiler_options.breakdown_threshold_bytes); |
| 799 if (heap_profiling_enabled_) { | 774 if (heap_profiling_enabled_) { |
| 800 // If heap profiling is enabled, the stack frame deduplicator and type name | 775 heap_profiler_serialization_state->CreateDeduplicators(); |
| 801 // deduplicator will be in use. Add a metadata events to write the frames | 776 const TraceConfig& trace_config = |
| 802 // and type IDs. | 777 TraceLog::GetInstance()->GetCurrentTraceConfig(); |
| 803 heap_profiler_serialization_state->SetStackFrameDeduplicator( | 778 // TODO(dskiba): support continuous mode (crbug.com/701052) |
| 804 WrapUnique(new StackFrameDeduplicator)); | 779 LOG_IF(ERROR, trace_config.GetTraceRecordMode() != RECORD_CONTINUOUSLY) |
|
Primiano Tucci (use gerrit)
2017/05/30 18:50:53
FATAL (which causes a crash) or D/VLOG. any other
DmitrySkiba
2017/06/05 00:50:18
I think it was your idea to use LOG_IF :)
"
Primi
| |
| 805 | 780 << "Heap profile format is incremental and doesn't yet fully support " |
| 806 heap_profiler_serialization_state->SetTypeNameDeduplicator( | 781 << "continuous mode."; |
| 807 WrapUnique(new TypeNameDeduplicator)); | |
| 808 | |
| 809 TRACE_EVENT_API_ADD_METADATA_EVENT( | |
| 810 TraceLog::GetCategoryGroupEnabled("__metadata"), "stackFrames", | |
| 811 "stackFrames", | |
| 812 MakeUnique<SessionStateConvertableProxy<StackFrameDeduplicator>>( | |
| 813 heap_profiler_serialization_state, | |
| 814 &HeapProfilerSerializationState::stack_frame_deduplicator)); | |
| 815 | |
| 816 TRACE_EVENT_API_ADD_METADATA_EVENT( | |
| 817 TraceLog::GetCategoryGroupEnabled("__metadata"), "typeNames", | |
| 818 "typeNames", | |
| 819 MakeUnique<SessionStateConvertableProxy<TypeNameDeduplicator>>( | |
| 820 heap_profiler_serialization_state, | |
| 821 &HeapProfilerSerializationState::type_name_deduplicator)); | |
| 822 } | 782 } |
| 823 | 783 |
| 824 AutoLock lock(lock_); | 784 AutoLock lock(lock_); |
| 825 | 785 |
| 826 // At this point we must have the ability to request global dumps. | 786 // At this point we must have the ability to request global dumps. |
| 827 DCHECK(!request_dump_function_.is_null()); | 787 DCHECK(!request_dump_function_.is_null()); |
| 828 heap_profiler_serialization_state_ = heap_profiler_serialization_state; | 788 heap_profiler_serialization_state_ = heap_profiler_serialization_state; |
| 829 | 789 |
| 830 MemoryDumpScheduler::Config periodic_config; | 790 MemoryDumpScheduler::Config periodic_config; |
| 831 bool peak_detector_configured = false; | 791 bool peak_detector_configured = false; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 908 if (iter == process_dumps.end()) { | 868 if (iter == process_dumps.end()) { |
| 909 std::unique_ptr<ProcessMemoryDump> new_pmd( | 869 std::unique_ptr<ProcessMemoryDump> new_pmd( |
| 910 new ProcessMemoryDump(heap_profiler_serialization_state, dump_args)); | 870 new ProcessMemoryDump(heap_profiler_serialization_state, dump_args)); |
| 911 iter = process_dumps.insert(std::make_pair(pid, std::move(new_pmd))).first; | 871 iter = process_dumps.insert(std::make_pair(pid, std::move(new_pmd))).first; |
| 912 } | 872 } |
| 913 return iter->second.get(); | 873 return iter->second.get(); |
| 914 } | 874 } |
| 915 | 875 |
| 916 } // namespace trace_event | 876 } // namespace trace_event |
| 917 } // namespace base | 877 } // namespace base |
| OLD | NEW |