Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(400)

Side by Side Diff: base/trace_event/memory_dump_manager.cc

Issue 2650863003: [tracing] Switch to new heap dump format. (Closed)
Patch Set: Fix rebase damage Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/trace_event/malloc_dump_provider.cc ('k') | base/trace_event/process_memory_dump.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 642 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 GetDumpsSumKb("partition_alloc/partitions/*", process_memory_dump); 736 GetDumpsSumKb("partition_alloc/partitions/*", process_memory_dump);
770 result->chrome_dump.blink_gc_total_kb = 737 result->chrome_dump.blink_gc_total_kb =
771 GetDumpsSumKb("blink_gc", process_memory_dump); 738 GetDumpsSumKb("blink_gc", process_memory_dump);
772 FillOsDumpFromProcessMemoryDump(process_memory_dump, &result->os_dump); 739 FillOsDumpFromProcessMemoryDump(process_memory_dump, &result->os_dump);
773 } else { 740 } else {
774 auto& os_dump = result->extra_processes_dump[pid]; 741 auto& os_dump = result->extra_processes_dump[pid];
775 FillOsDumpFromProcessMemoryDump(process_memory_dump, &os_dump); 742 FillOsDumpFromProcessMemoryDump(process_memory_dump, &os_dump);
776 } 743 }
777 } 744 }
778 745
746 bool tracing_still_enabled;
747 TRACE_EVENT_CATEGORY_GROUP_ENABLED(kTraceCategory, &tracing_still_enabled);
748 if (!tracing_still_enabled) {
749 pmd_async_state->dump_successful = false;
750 VLOG(1) << kLogPrefix << " failed because tracing was disabled before"
751 << " the dump was completed";
752 }
753
779 if (!pmd_async_state->callback.is_null()) { 754 if (!pmd_async_state->callback.is_null()) {
780 pmd_async_state->callback.Run(dump_guid, dump_successful, result); 755 pmd_async_state->callback.Run(dump_guid, dump_successful, result);
781 pmd_async_state->callback.Reset(); 756 pmd_async_state->callback.Reset();
782 } 757 }
783 758
784 TRACE_EVENT_NESTABLE_ASYNC_END0(kTraceCategory, "ProcessMemoryDump", 759 TRACE_EVENT_NESTABLE_ASYNC_END0(kTraceCategory, "ProcessMemoryDump",
785 TRACE_ID_LOCAL(dump_guid)); 760 TRACE_ID_LOCAL(dump_guid));
786 } 761 }
787 762
788 void MemoryDumpManager::SetupForTracing( 763 void MemoryDumpManager::SetupForTracing(
789 const TraceConfig::MemoryDumpConfig& memory_dump_config) { 764 const TraceConfig::MemoryDumpConfig& memory_dump_config) {
790 scoped_refptr<HeapProfilerSerializationState> 765 scoped_refptr<HeapProfilerSerializationState>
791 heap_profiler_serialization_state = new HeapProfilerSerializationState; 766 heap_profiler_serialization_state = new HeapProfilerSerializationState;
792 heap_profiler_serialization_state 767 heap_profiler_serialization_state
793 ->set_heap_profiler_breakdown_threshold_bytes( 768 ->set_heap_profiler_breakdown_threshold_bytes(
794 memory_dump_config.heap_profiler_options.breakdown_threshold_bytes); 769 memory_dump_config.heap_profiler_options.breakdown_threshold_bytes);
795 if (heap_profiling_enabled_) { 770 if (heap_profiling_enabled_) {
796 // If heap profiling is enabled, the stack frame deduplicator and type name 771 heap_profiler_serialization_state->CreateDeduplicators();
797 // deduplicator will be in use. Add a metadata events to write the frames 772 const TraceConfig& trace_config =
798 // and type IDs. 773 TraceLog::GetInstance()->GetCurrentTraceConfig();
799 heap_profiler_serialization_state->SetStackFrameDeduplicator( 774 // TODO(dskiba): support continuous mode (crbug.com/701052)
800 WrapUnique(new StackFrameDeduplicator)); 775 LOG_IF(ERROR, trace_config.GetTraceRecordMode() != RECORD_CONTINUOUSLY)
801 776 << "Heap profile format is incremental and doesn't yet fully support "
802 heap_profiler_serialization_state->SetTypeNameDeduplicator( 777 << "continuous mode.";
803 WrapUnique(new TypeNameDeduplicator));
804
805 TRACE_EVENT_API_ADD_METADATA_EVENT(
806 TraceLog::GetCategoryGroupEnabled("__metadata"), "stackFrames",
807 "stackFrames",
808 MakeUnique<SessionStateConvertableProxy<StackFrameDeduplicator>>(
809 heap_profiler_serialization_state,
810 &HeapProfilerSerializationState::stack_frame_deduplicator));
811
812 TRACE_EVENT_API_ADD_METADATA_EVENT(
813 TraceLog::GetCategoryGroupEnabled("__metadata"), "typeNames",
814 "typeNames",
815 MakeUnique<SessionStateConvertableProxy<TypeNameDeduplicator>>(
816 heap_profiler_serialization_state,
817 &HeapProfilerSerializationState::type_name_deduplicator));
818 } 778 }
819 779
820 AutoLock lock(lock_); 780 AutoLock lock(lock_);
821 781
822 // At this point we must have the ability to request global dumps. 782 // At this point we must have the ability to request global dumps.
823 DCHECK(!request_dump_function_.is_null()); 783 DCHECK(!request_dump_function_.is_null());
824 heap_profiler_serialization_state_ = heap_profiler_serialization_state; 784 heap_profiler_serialization_state_ = heap_profiler_serialization_state;
825 785
826 MemoryDumpScheduler::Config periodic_config; 786 MemoryDumpScheduler::Config periodic_config;
827 bool peak_detector_configured = false; 787 bool peak_detector_configured = false;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 if (iter == process_dumps.end()) { 864 if (iter == process_dumps.end()) {
905 std::unique_ptr<ProcessMemoryDump> new_pmd( 865 std::unique_ptr<ProcessMemoryDump> new_pmd(
906 new ProcessMemoryDump(heap_profiler_serialization_state, dump_args)); 866 new ProcessMemoryDump(heap_profiler_serialization_state, dump_args));
907 iter = process_dumps.insert(std::make_pair(pid, std::move(new_pmd))).first; 867 iter = process_dumps.insert(std::make_pair(pid, std::move(new_pmd))).first;
908 } 868 }
909 return iter->second.get(); 869 return iter->second.get();
910 } 870 }
911 871
912 } // namespace trace_event 872 } // namespace trace_event
913 } // namespace base 873 } // namespace base
OLDNEW
« no previous file with comments | « base/trace_event/malloc_dump_provider.cc ('k') | base/trace_event/process_memory_dump.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698