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/process_memory_dump.h" | 5 #include "base/trace_event/process_memory_dump.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
279 void ProcessMemoryDump::TakeAllDumpsFrom(ProcessMemoryDump* other) { | 279 void ProcessMemoryDump::TakeAllDumpsFrom(ProcessMemoryDump* other) { |
280 DCHECK(!other->has_process_totals() && !other->has_process_mmaps()); | 280 DCHECK(!other->has_process_totals() && !other->has_process_mmaps()); |
281 | 281 |
282 // Moves the ownership of all MemoryAllocatorDump(s) contained in |other| | 282 // Moves the ownership of all MemoryAllocatorDump(s) contained in |other| |
283 // into this ProcessMemoryDump, checking for duplicates. | 283 // into this ProcessMemoryDump, checking for duplicates. |
284 for (auto& it : other->allocator_dumps_) | 284 for (auto& it : other->allocator_dumps_) |
285 AddAllocatorDumpInternal(std::move(it.second)); | 285 AddAllocatorDumpInternal(std::move(it.second)); |
286 other->allocator_dumps_.clear(); | 286 other->allocator_dumps_.clear(); |
287 | 287 |
288 // Move all the edges. | 288 // Move all the edges. |
289 allocator_dumps_edges_.insert(allocator_dumps_edges_.end(), | 289 allocator_dumps_edges_.insert(other->allocator_dumps_edges_.begin(), |
290 other->allocator_dumps_edges_.begin(), | |
291 other->allocator_dumps_edges_.end()); | 290 other->allocator_dumps_edges_.end()); |
292 other->allocator_dumps_edges_.clear(); | 291 other->allocator_dumps_edges_.clear(); |
293 | 292 |
294 for (auto& it : other->heap_dumps_) { | 293 for (auto& it : other->heap_dumps_) { |
295 DCHECK_EQ(0ul, heap_dumps_.count(it.first)); | 294 DCHECK_EQ(0ul, heap_dumps_.count(it.first)); |
296 heap_dumps_.insert(std::make_pair(it.first, std::move(it.second))); | 295 heap_dumps_.insert(std::make_pair(it.first, std::move(it.second))); |
297 } | 296 } |
298 other->heap_dumps_.clear(); | 297 other->heap_dumps_.clear(); |
299 } | 298 } |
300 | 299 |
(...skipping 18 matching lines...) Expand all Loading... | |
319 } | 318 } |
320 | 319 |
321 if (heap_dumps_.size() > 0) { | 320 if (heap_dumps_.size() > 0) { |
322 value->BeginDictionary("heaps"); | 321 value->BeginDictionary("heaps"); |
323 for (const auto& name_and_dump : heap_dumps_) | 322 for (const auto& name_and_dump : heap_dumps_) |
324 value->SetValueWithCopiedName(name_and_dump.first, *name_and_dump.second); | 323 value->SetValueWithCopiedName(name_and_dump.first, *name_and_dump.second); |
325 value->EndDictionary(); // "heaps" | 324 value->EndDictionary(); // "heaps" |
326 } | 325 } |
327 | 326 |
328 value->BeginArray("allocators_graph"); | 327 value->BeginArray("allocators_graph"); |
329 for (const MemoryAllocatorDumpEdge& edge : allocator_dumps_edges_) { | 328 for (const auto& edge : allocator_dumps_edges_) { |
330 value->BeginDictionary(); | 329 value->BeginDictionary(); |
331 value->SetString("source", edge.source.ToString()); | 330 value->SetString("source", edge.first.ToString()); |
Primiano Tucci (use gerrit)
2017/06/05 15:23:39
since the edge has still the |source| I think this
ssid
2017/06/05 17:03:29
Fixed.
| |
332 value->SetString("target", edge.target.ToString()); | 331 value->SetString("target", edge.second.target.ToString()); |
333 value->SetInteger("importance", edge.importance); | 332 value->SetInteger("importance", edge.second.importance); |
334 value->SetString("type", edge.type); | 333 value->SetString("type", edge.second.type); |
335 value->EndDictionary(); | 334 value->EndDictionary(); |
336 } | 335 } |
337 value->EndArray(); | 336 value->EndArray(); |
338 } | 337 } |
339 | 338 |
340 void ProcessMemoryDump::AddOwnershipEdge(const MemoryAllocatorDumpGuid& source, | 339 void ProcessMemoryDump::AddOwnershipEdge(const MemoryAllocatorDumpGuid& source, |
341 const MemoryAllocatorDumpGuid& target, | 340 const MemoryAllocatorDumpGuid& target, |
342 int importance) { | 341 int importance) { |
343 allocator_dumps_edges_.push_back( | 342 DCHECK(allocator_dumps_edges_.find(source) == allocator_dumps_edges_.end() || |
Primiano Tucci (use gerrit)
2017/06/05 15:23:39
allocator_dump_edges.count(source) == 0 is more co
ssid
2017/06/05 17:03:29
Done.
| |
344 {source, target, importance, kEdgeTypeOwnership}); | 343 allocator_dumps_edges_[source].overridable) |
344 << "Cannot add multiple ownership edges between same allocator dumps"; | |
345 allocator_dumps_edges_[source] = {target, importance, kEdgeTypeOwnership, | |
346 false /* overridable */}; | |
345 } | 347 } |
346 | 348 |
347 void ProcessMemoryDump::AddOwnershipEdge( | 349 void ProcessMemoryDump::AddOwnershipEdge( |
348 const MemoryAllocatorDumpGuid& source, | 350 const MemoryAllocatorDumpGuid& source, |
349 const MemoryAllocatorDumpGuid& target) { | 351 const MemoryAllocatorDumpGuid& target) { |
350 AddOwnershipEdge(source, target, 0 /* importance */); | 352 AddOwnershipEdge(source, target, 0 /* importance */); |
351 } | 353 } |
352 | 354 |
355 void ProcessMemoryDump::AddOverridableOwnershipEdge( | |
356 const MemoryAllocatorDumpGuid& source, | |
357 const MemoryAllocatorDumpGuid& target, | |
358 int importance) { | |
359 if (allocator_dumps_edges_.find(source) == allocator_dumps_edges_.end()) { | |
360 allocator_dumps_edges_[source] = {target, importance, kEdgeTypeOwnership, | |
361 true /* overridable */}; | |
362 } else { | |
363 DCHECK(!allocator_dumps_edges_[source].overridable); | |
Primiano Tucci (use gerrit)
2017/06/05 15:23:39
isn't this branch forgetting to actually override
ssid
2017/06/05 17:03:29
Actually I went for the model where we specify the
| |
364 } | |
365 } | |
366 | |
353 void ProcessMemoryDump::AddSuballocation(const MemoryAllocatorDumpGuid& source, | 367 void ProcessMemoryDump::AddSuballocation(const MemoryAllocatorDumpGuid& source, |
354 const std::string& target_node_name) { | 368 const std::string& target_node_name) { |
355 // Do not create new dumps for suballocations in background mode. | 369 // Do not create new dumps for suballocations in background mode. |
356 if (dump_args_.level_of_detail == MemoryDumpLevelOfDetail::BACKGROUND) | 370 if (dump_args_.level_of_detail == MemoryDumpLevelOfDetail::BACKGROUND) |
357 return; | 371 return; |
358 | 372 |
359 std::string child_mad_name = target_node_name + "/__" + source.ToString(); | 373 std::string child_mad_name = target_node_name + "/__" + source.ToString(); |
360 MemoryAllocatorDump* target_child_mad = CreateAllocatorDump(child_mad_name); | 374 MemoryAllocatorDump* target_child_mad = CreateAllocatorDump(child_mad_name); |
361 AddOwnershipEdge(source, target_child_mad->guid()); | 375 AddOwnershipEdge(source, target_child_mad->guid()); |
362 } | 376 } |
363 | 377 |
364 MemoryAllocatorDump* ProcessMemoryDump::GetBlackHoleMad() { | 378 MemoryAllocatorDump* ProcessMemoryDump::GetBlackHoleMad() { |
365 DCHECK(is_black_hole_non_fatal_for_testing_); | 379 DCHECK(is_black_hole_non_fatal_for_testing_); |
366 if (!black_hole_mad_) | 380 if (!black_hole_mad_) |
367 black_hole_mad_.reset(new MemoryAllocatorDump("discarded", this)); | 381 black_hole_mad_.reset(new MemoryAllocatorDump("discarded", this)); |
368 return black_hole_mad_.get(); | 382 return black_hole_mad_.get(); |
369 } | 383 } |
370 | 384 |
371 } // namespace trace_event | 385 } // namespace trace_event |
372 } // namespace base | 386 } // namespace base |
OLD | NEW |