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 "base/trace_event/process_memory_totals.h" | 7 #include "base/trace_event/process_memory_totals.h" |
8 #include "base/trace_event/trace_event_argument.h" | 8 #include "base/trace_event/trace_event_argument.h" |
9 | 9 |
10 namespace base { | 10 namespace base { |
(...skipping 17 matching lines...) Expand all Loading... |
28 allocator_dumps_[absolute_name] = mad; | 28 allocator_dumps_[absolute_name] = mad; |
29 return mad; | 29 return mad; |
30 } | 30 } |
31 | 31 |
32 MemoryAllocatorDump* ProcessMemoryDump::GetAllocatorDump( | 32 MemoryAllocatorDump* ProcessMemoryDump::GetAllocatorDump( |
33 const std::string& absolute_name) const { | 33 const std::string& absolute_name) const { |
34 auto it = allocator_dumps_.find(absolute_name); | 34 auto it = allocator_dumps_.find(absolute_name); |
35 return it == allocator_dumps_.end() ? nullptr : it->second; | 35 return it == allocator_dumps_.end() ? nullptr : it->second; |
36 } | 36 } |
37 | 37 |
| 38 void ProcessMemoryDump::TakeAllDumpsFrom(ProcessMemoryDump* other) { |
| 39 // We support only merging of MemoryAllocatorDumps. The special process_totals |
| 40 // and mmaps cases are not relevant, let's just prevent clients from doing it. |
| 41 DCHECK(!other->has_process_totals() && !other->has_process_mmaps()); |
| 42 |
| 43 // Moves the ownership of all MemoryAllocatorDump(s) contained in |other| |
| 44 // into this ProcessMemoryDump. |
| 45 for (MemoryAllocatorDump* mad : other->allocator_dumps_storage_) { |
| 46 // Check that we don't merge duplicates. |
| 47 DCHECK_EQ(0ul, allocator_dumps_.count(mad->absolute_name())); |
| 48 allocator_dumps_storage_.push_back(mad); |
| 49 allocator_dumps_[mad->absolute_name()] = mad; |
| 50 } |
| 51 other->allocator_dumps_storage_.weak_clear(); |
| 52 other->allocator_dumps_.clear(); |
| 53 } |
| 54 |
38 void ProcessMemoryDump::AsValueInto(TracedValue* value) const { | 55 void ProcessMemoryDump::AsValueInto(TracedValue* value) const { |
39 // Build up the [dumper name] -> [value] dictionary. | 56 // Build up the [dumper name] -> [value] dictionary. |
40 if (has_process_totals_) { | 57 if (has_process_totals_) { |
41 value->BeginDictionary("process_totals"); | 58 value->BeginDictionary("process_totals"); |
42 process_totals_.AsValueInto(value); | 59 process_totals_.AsValueInto(value); |
43 value->EndDictionary(); | 60 value->EndDictionary(); |
44 } | 61 } |
45 if (has_process_mmaps_) { | 62 if (has_process_mmaps_) { |
46 value->BeginDictionary("process_mmaps"); | 63 value->BeginDictionary("process_mmaps"); |
47 process_mmaps_.AsValueInto(value); | 64 process_mmaps_.AsValueInto(value); |
48 value->EndDictionary(); | 65 value->EndDictionary(); |
49 } | 66 } |
50 if (allocator_dumps_storage_.size() > 0) { | 67 if (allocator_dumps_storage_.size() > 0) { |
51 value->BeginDictionary("allocators"); | 68 value->BeginDictionary("allocators"); |
52 for (const MemoryAllocatorDump* allocator_dump : allocator_dumps_storage_) | 69 for (const MemoryAllocatorDump* allocator_dump : allocator_dumps_storage_) |
53 allocator_dump->AsValueInto(value); | 70 allocator_dump->AsValueInto(value); |
54 value->EndDictionary(); | 71 value->EndDictionary(); |
55 } | 72 } |
56 } | 73 } |
57 | 74 |
58 } // namespace trace_event | 75 } // namespace trace_event |
59 } // namespace base | 76 } // namespace base |
OLD | NEW |