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

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

Issue 2650863003: [tracing] Switch to new heap dump format. (Closed)
Patch Set: Rebase Created 3 years, 6 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 669 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 } 763 }
797 764
798 void MemoryDumpManager::SetupForTracing( 765 void MemoryDumpManager::SetupForTracing(
799 const TraceConfig::MemoryDumpConfig& memory_dump_config) { 766 const TraceConfig::MemoryDumpConfig& memory_dump_config) {
800 scoped_refptr<HeapProfilerSerializationState> 767 scoped_refptr<HeapProfilerSerializationState>
801 heap_profiler_serialization_state = new HeapProfilerSerializationState; 768 heap_profiler_serialization_state = new HeapProfilerSerializationState;
802 heap_profiler_serialization_state 769 heap_profiler_serialization_state
803 ->set_heap_profiler_breakdown_threshold_bytes( 770 ->set_heap_profiler_breakdown_threshold_bytes(
804 memory_dump_config.heap_profiler_options.breakdown_threshold_bytes); 771 memory_dump_config.heap_profiler_options.breakdown_threshold_bytes);
805 if (heap_profiling_enabled_) { 772 if (heap_profiling_enabled_) {
806 // If heap profiling is enabled, the stack frame deduplicator and type name 773 heap_profiler_serialization_state->CreateDeduplicators();
807 // deduplicator will be in use. Add a metadata events to write the frames 774 // TODO(dskiba): support continuous mode (crbug.com/701052)
808 // and type IDs. 775 DLOG_IF(
809 heap_profiler_serialization_state->SetStackFrameDeduplicator( 776 ERROR,
810 WrapUnique(new StackFrameDeduplicator)); 777 TraceLog::GetInstance()->GetCurrentTraceConfig().GetTraceRecordMode() ==
811 778 RECORD_CONTINUOUSLY)
812 heap_profiler_serialization_state->SetTypeNameDeduplicator( 779 << "Heap profile format is incremental and doesn't yet fully support "
813 WrapUnique(new TypeNameDeduplicator)); 780 << "continuous mode.";
814
815 TRACE_EVENT_API_ADD_METADATA_EVENT(
816 TraceLog::GetCategoryGroupEnabled("__metadata"), "stackFrames",
817 "stackFrames",
818 MakeUnique<SessionStateConvertableProxy<StackFrameDeduplicator>>(
819 heap_profiler_serialization_state,
820 &HeapProfilerSerializationState::stack_frame_deduplicator));
821
822 TRACE_EVENT_API_ADD_METADATA_EVENT(
823 TraceLog::GetCategoryGroupEnabled("__metadata"), "typeNames",
824 "typeNames",
825 MakeUnique<SessionStateConvertableProxy<TypeNameDeduplicator>>(
826 heap_profiler_serialization_state,
827 &HeapProfilerSerializationState::type_name_deduplicator));
828 } 781 }
829 782
830 AutoLock lock(lock_); 783 AutoLock lock(lock_);
831 784
832 // At this point we must have the ability to request global dumps. 785 // At this point we must have the ability to request global dumps.
833 DCHECK(!request_dump_function_.is_null()); 786 DCHECK(!request_dump_function_.is_null());
834 heap_profiler_serialization_state_ = heap_profiler_serialization_state; 787 heap_profiler_serialization_state_ = heap_profiler_serialization_state;
835 788
836 MemoryDumpScheduler::Config periodic_config; 789 MemoryDumpScheduler::Config periodic_config;
837 bool peak_detector_configured = false; 790 bool peak_detector_configured = false;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 if (iter == process_dumps.end()) { 867 if (iter == process_dumps.end()) {
915 std::unique_ptr<ProcessMemoryDump> new_pmd( 868 std::unique_ptr<ProcessMemoryDump> new_pmd(
916 new ProcessMemoryDump(heap_profiler_serialization_state, dump_args)); 869 new ProcessMemoryDump(heap_profiler_serialization_state, dump_args));
917 iter = process_dumps.insert(std::make_pair(pid, std::move(new_pmd))).first; 870 iter = process_dumps.insert(std::make_pair(pid, std::move(new_pmd))).first;
918 } 871 }
919 return iter->second.get(); 872 return iter->second.get();
920 } 873 }
921 874
922 } // namespace trace_event 875 } // namespace trace_event
923 } // namespace base 876 } // 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