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

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

Issue 1419633004: [Tracing] Introduce HeapDumpWriter helper class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address nits Created 5 years, 1 month 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/process_memory_dump.h ('k') | base/trace_event/trace_event.gypi » ('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/process_memory_dump.h" 5 #include "base/trace_event/process_memory_dump.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/process/process_metrics.h" 9 #include "base/process/process_metrics.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 return allocator_dump ? allocator_dump 138 return allocator_dump ? allocator_dump
139 : CreateAllocatorDump( 139 : CreateAllocatorDump(
140 GetSharedGlobalAllocatorDumpName(guid), guid); 140 GetSharedGlobalAllocatorDumpName(guid), guid);
141 } 141 }
142 142
143 MemoryAllocatorDump* ProcessMemoryDump::GetSharedGlobalAllocatorDump( 143 MemoryAllocatorDump* ProcessMemoryDump::GetSharedGlobalAllocatorDump(
144 const MemoryAllocatorDumpGuid& guid) const { 144 const MemoryAllocatorDumpGuid& guid) const {
145 return GetAllocatorDump(GetSharedGlobalAllocatorDumpName(guid)); 145 return GetAllocatorDump(GetSharedGlobalAllocatorDumpName(guid));
146 } 146 }
147 147
148 void ProcessMemoryDump::AddHeapDump(const std::string& absolute_name,
149 scoped_refptr<TracedValue> heap_dump) {
150 DCHECK_EQ(0ul, heap_dumps_.count(absolute_name));
151 heap_dumps_[absolute_name] = heap_dump;
152 }
153
148 void ProcessMemoryDump::Clear() { 154 void ProcessMemoryDump::Clear() {
149 if (has_process_totals_) { 155 if (has_process_totals_) {
150 process_totals_.Clear(); 156 process_totals_.Clear();
151 has_process_totals_ = false; 157 has_process_totals_ = false;
152 } 158 }
153 159
154 if (has_process_mmaps_) { 160 if (has_process_mmaps_) {
155 process_mmaps_.Clear(); 161 process_mmaps_.Clear();
156 has_process_mmaps_ = false; 162 has_process_mmaps_ = false;
157 } 163 }
158 164
159 allocator_dumps_storage_.clear(); 165 allocator_dumps_storage_.clear();
160 allocator_dumps_.clear(); 166 allocator_dumps_.clear();
161 allocator_dumps_edges_.clear(); 167 allocator_dumps_edges_.clear();
168 heap_dumps_.clear();
162 } 169 }
163 170
164 void ProcessMemoryDump::TakeAllDumpsFrom(ProcessMemoryDump* other) { 171 void ProcessMemoryDump::TakeAllDumpsFrom(ProcessMemoryDump* other) {
165 DCHECK(!other->has_process_totals() && !other->has_process_mmaps()); 172 DCHECK(!other->has_process_totals() && !other->has_process_mmaps());
166 173
167 // Moves the ownership of all MemoryAllocatorDump(s) contained in |other| 174 // Moves the ownership of all MemoryAllocatorDump(s) contained in |other|
168 // into this ProcessMemoryDump. 175 // into this ProcessMemoryDump.
169 for (MemoryAllocatorDump* mad : other->allocator_dumps_storage_) { 176 for (MemoryAllocatorDump* mad : other->allocator_dumps_storage_) {
170 // Check that we don't merge duplicates. 177 // Check that we don't merge duplicates.
171 DCHECK_EQ(0ul, allocator_dumps_.count(mad->absolute_name())); 178 DCHECK_EQ(0ul, allocator_dumps_.count(mad->absolute_name()));
172 allocator_dumps_storage_.push_back(mad); 179 allocator_dumps_storage_.push_back(mad);
173 allocator_dumps_[mad->absolute_name()] = mad; 180 allocator_dumps_[mad->absolute_name()] = mad;
174 } 181 }
175 other->allocator_dumps_storage_.weak_clear(); 182 other->allocator_dumps_storage_.weak_clear();
176 other->allocator_dumps_.clear(); 183 other->allocator_dumps_.clear();
177 184
178 // Move all the edges. 185 // Move all the edges.
179 allocator_dumps_edges_.insert(allocator_dumps_edges_.end(), 186 allocator_dumps_edges_.insert(allocator_dumps_edges_.end(),
180 other->allocator_dumps_edges_.begin(), 187 other->allocator_dumps_edges_.begin(),
181 other->allocator_dumps_edges_.end()); 188 other->allocator_dumps_edges_.end());
182 other->allocator_dumps_edges_.clear(); 189 other->allocator_dumps_edges_.clear();
190
191 heap_dumps_.insert(other->heap_dumps_.begin(), other->heap_dumps_.end());
192 other->heap_dumps_.clear();
183 } 193 }
184 194
185 void ProcessMemoryDump::AsValueInto(TracedValue* value) const { 195 void ProcessMemoryDump::AsValueInto(TracedValue* value) const {
186 if (has_process_totals_) { 196 if (has_process_totals_) {
187 value->BeginDictionary("process_totals"); 197 value->BeginDictionary("process_totals");
188 process_totals_.AsValueInto(value); 198 process_totals_.AsValueInto(value);
189 value->EndDictionary(); 199 value->EndDictionary();
190 } 200 }
191 201
192 if (has_process_mmaps_) { 202 if (has_process_mmaps_) {
193 value->BeginDictionary("process_mmaps"); 203 value->BeginDictionary("process_mmaps");
194 process_mmaps_.AsValueInto(value); 204 process_mmaps_.AsValueInto(value);
195 value->EndDictionary(); 205 value->EndDictionary();
196 } 206 }
197 207
198 if (allocator_dumps_storage_.size() > 0) { 208 if (allocator_dumps_storage_.size() > 0) {
199 value->BeginDictionary("allocators"); 209 value->BeginDictionary("allocators");
200 for (const MemoryAllocatorDump* allocator_dump : allocator_dumps_storage_) 210 for (const MemoryAllocatorDump* allocator_dump : allocator_dumps_storage_)
201 allocator_dump->AsValueInto(value); 211 allocator_dump->AsValueInto(value);
202 value->EndDictionary(); 212 value->EndDictionary();
203 } 213 }
204 214
215 if (heap_dumps_.size() > 0) {
216 value->BeginDictionary("heaps");
217 for (const auto& name_and_dump : heap_dumps_)
218 value->SetValueWithCopiedName(name_and_dump.first, *name_and_dump.second);
219 value->EndDictionary(); // "heaps"
220 }
221
205 value->BeginArray("allocators_graph"); 222 value->BeginArray("allocators_graph");
206 for (const MemoryAllocatorDumpEdge& edge : allocator_dumps_edges_) { 223 for (const MemoryAllocatorDumpEdge& edge : allocator_dumps_edges_) {
207 value->BeginDictionary(); 224 value->BeginDictionary();
208 value->SetString("source", edge.source.ToString()); 225 value->SetString("source", edge.source.ToString());
209 value->SetString("target", edge.target.ToString()); 226 value->SetString("target", edge.target.ToString());
210 value->SetInteger("importance", edge.importance); 227 value->SetInteger("importance", edge.importance);
211 value->SetString("type", edge.type); 228 value->SetString("type", edge.type);
212 value->EndDictionary(); 229 value->EndDictionary();
213 } 230 }
214 value->EndArray(); 231 value->EndArray();
(...skipping 14 matching lines...) Expand all
229 246
230 void ProcessMemoryDump::AddSuballocation(const MemoryAllocatorDumpGuid& source, 247 void ProcessMemoryDump::AddSuballocation(const MemoryAllocatorDumpGuid& source,
231 const std::string& target_node_name) { 248 const std::string& target_node_name) {
232 std::string child_mad_name = target_node_name + "/__" + source.ToString(); 249 std::string child_mad_name = target_node_name + "/__" + source.ToString();
233 MemoryAllocatorDump* target_child_mad = CreateAllocatorDump(child_mad_name); 250 MemoryAllocatorDump* target_child_mad = CreateAllocatorDump(child_mad_name);
234 AddOwnershipEdge(source, target_child_mad->guid()); 251 AddOwnershipEdge(source, target_child_mad->guid());
235 } 252 }
236 253
237 } // namespace trace_event 254 } // namespace trace_event
238 } // namespace base 255 } // namespace base
OLDNEW
« no previous file with comments | « base/trace_event/process_memory_dump.h ('k') | base/trace_event/trace_event.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698