Chromium Code Reviews| 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 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/process/process_metrics.h" | 10 #include "base/process/process_metrics.h" |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 LOG(ERROR) << "CountResidentBytes failed. The resident size is invalid"; | 117 LOG(ERROR) << "CountResidentBytes failed. The resident size is invalid"; |
| 118 } | 118 } |
| 119 return total_resident_size; | 119 return total_resident_size; |
| 120 } | 120 } |
| 121 #endif // defined(COUNT_RESIDENT_BYTES_SUPPORTED) | 121 #endif // defined(COUNT_RESIDENT_BYTES_SUPPORTED) |
| 122 | 122 |
| 123 ProcessMemoryDump::ProcessMemoryDump( | 123 ProcessMemoryDump::ProcessMemoryDump( |
| 124 const scoped_refptr<MemoryDumpSessionState>& session_state) | 124 const scoped_refptr<MemoryDumpSessionState>& session_state) |
| 125 : has_process_totals_(false), | 125 : has_process_totals_(false), |
| 126 has_process_mmaps_(false), | 126 has_process_mmaps_(false), |
| 127 session_state_(session_state) { | 127 session_state_(session_state) {} |
| 128 } | |
| 129 | 128 |
| 130 ProcessMemoryDump::~ProcessMemoryDump() { | 129 ProcessMemoryDump::~ProcessMemoryDump() {} |
| 131 } | |
| 132 | 130 |
| 133 MemoryAllocatorDump* ProcessMemoryDump::CreateAllocatorDump( | 131 MemoryAllocatorDump* ProcessMemoryDump::CreateAllocatorDump( |
| 134 const std::string& absolute_name) { | 132 const std::string& absolute_name) { |
| 135 MemoryAllocatorDump* mad = new MemoryAllocatorDump(absolute_name, this); | 133 return AddAllocatorDumpInternal( |
| 136 AddAllocatorDumpInternal(mad); // Takes ownership of |mad|. | 134 make_scoped_ptr(new MemoryAllocatorDump(absolute_name, this))); |
| 137 return mad; | |
| 138 } | 135 } |
| 139 | 136 |
| 140 MemoryAllocatorDump* ProcessMemoryDump::CreateAllocatorDump( | 137 MemoryAllocatorDump* ProcessMemoryDump::CreateAllocatorDump( |
| 141 const std::string& absolute_name, | 138 const std::string& absolute_name, |
| 142 const MemoryAllocatorDumpGuid& guid) { | 139 const MemoryAllocatorDumpGuid& guid) { |
| 143 MemoryAllocatorDump* mad = new MemoryAllocatorDump(absolute_name, this, guid); | 140 return AddAllocatorDumpInternal( |
| 144 AddAllocatorDumpInternal(mad); // Takes ownership of |mad|. | 141 make_scoped_ptr(new MemoryAllocatorDump(absolute_name, this, guid))); |
| 145 return mad; | |
| 146 } | 142 } |
| 147 | 143 |
| 148 void ProcessMemoryDump::AddAllocatorDumpInternal(MemoryAllocatorDump* mad) { | 144 MemoryAllocatorDump* ProcessMemoryDump::AddAllocatorDumpInternal( |
| 149 DCHECK_EQ(0ul, allocator_dumps_.count(mad->absolute_name())); | 145 scoped_ptr<MemoryAllocatorDump> mad) { |
| 150 allocator_dumps_storage_.push_back(mad); | 146 auto insertion_result = allocator_dumps_.insert( |
| 151 allocator_dumps_[mad->absolute_name()] = mad; | 147 std::make_pair(mad->absolute_name(), std::move(mad))); |
|
petrcermak
2016/02/22 13:33:25
Why don't you change the signature of this method
Primiano Tucci (use gerrit)
2016/02/22 15:56:07
There doesn't seem to be any precedent for this. A
| |
| 148 DCHECK(insertion_result.second) << "Duplicate name: " << mad->absolute_name(); | |
| 149 return insertion_result.first->second.get(); | |
| 152 } | 150 } |
| 153 | 151 |
| 154 MemoryAllocatorDump* ProcessMemoryDump::GetAllocatorDump( | 152 MemoryAllocatorDump* ProcessMemoryDump::GetAllocatorDump( |
| 155 const std::string& absolute_name) const { | 153 const std::string& absolute_name) const { |
| 156 auto it = allocator_dumps_.find(absolute_name); | 154 auto it = allocator_dumps_.find(absolute_name); |
| 157 return it == allocator_dumps_.end() ? nullptr : it->second; | 155 return it == allocator_dumps_.end() ? nullptr : it->second.get(); |
| 158 } | 156 } |
| 159 | 157 |
| 160 MemoryAllocatorDump* ProcessMemoryDump::GetOrCreateAllocatorDump( | 158 MemoryAllocatorDump* ProcessMemoryDump::GetOrCreateAllocatorDump( |
| 161 const std::string& absolute_name) { | 159 const std::string& absolute_name) { |
| 162 MemoryAllocatorDump* mad = GetAllocatorDump(absolute_name); | 160 MemoryAllocatorDump* mad = GetAllocatorDump(absolute_name); |
| 163 return mad ? mad : CreateAllocatorDump(absolute_name); | 161 return mad ? mad : CreateAllocatorDump(absolute_name); |
| 164 } | 162 } |
| 165 | 163 |
| 166 MemoryAllocatorDump* ProcessMemoryDump::CreateSharedGlobalAllocatorDump( | 164 MemoryAllocatorDump* ProcessMemoryDump::CreateSharedGlobalAllocatorDump( |
| 167 const MemoryAllocatorDumpGuid& guid) { | 165 const MemoryAllocatorDumpGuid& guid) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 if (has_process_totals_) { | 200 if (has_process_totals_) { |
| 203 process_totals_.Clear(); | 201 process_totals_.Clear(); |
| 204 has_process_totals_ = false; | 202 has_process_totals_ = false; |
| 205 } | 203 } |
| 206 | 204 |
| 207 if (has_process_mmaps_) { | 205 if (has_process_mmaps_) { |
| 208 process_mmaps_.Clear(); | 206 process_mmaps_.Clear(); |
| 209 has_process_mmaps_ = false; | 207 has_process_mmaps_ = false; |
| 210 } | 208 } |
| 211 | 209 |
| 212 allocator_dumps_storage_.clear(); | |
| 213 allocator_dumps_.clear(); | 210 allocator_dumps_.clear(); |
| 214 allocator_dumps_edges_.clear(); | 211 allocator_dumps_edges_.clear(); |
| 215 heap_dumps_.clear(); | 212 heap_dumps_.clear(); |
| 216 } | 213 } |
| 217 | 214 |
| 218 void ProcessMemoryDump::TakeAllDumpsFrom(ProcessMemoryDump* other) { | 215 void ProcessMemoryDump::TakeAllDumpsFrom(ProcessMemoryDump* other) { |
| 219 DCHECK(!other->has_process_totals() && !other->has_process_mmaps()); | 216 DCHECK(!other->has_process_totals() && !other->has_process_mmaps()); |
| 220 | 217 |
| 221 // Moves the ownership of all MemoryAllocatorDump(s) contained in |other| | 218 // Moves the ownership of all MemoryAllocatorDump(s) contained in |other| |
| 222 // into this ProcessMemoryDump. | 219 // into this ProcessMemoryDump, checking for duplicates. |
| 223 for (MemoryAllocatorDump* mad : other->allocator_dumps_storage_) { | 220 for (auto& it : other->allocator_dumps_) |
| 224 // Check that we don't merge duplicates. | 221 AddAllocatorDumpInternal(std::move(it.second)); |
|
petrcermak
2016/02/22 13:33:25
Note that if you keep the std::move conversion on
Primiano Tucci (use gerrit)
2016/02/22 15:56:07
See reply above, no precedent.
Even if that should
| |
| 225 DCHECK_EQ(0ul, allocator_dumps_.count(mad->absolute_name())); | |
| 226 allocator_dumps_storage_.push_back(mad); | |
| 227 allocator_dumps_[mad->absolute_name()] = mad; | |
| 228 } | |
| 229 other->allocator_dumps_storage_.weak_clear(); | |
| 230 other->allocator_dumps_.clear(); | 222 other->allocator_dumps_.clear(); |
| 231 | 223 |
| 232 // Move all the edges. | 224 // Move all the edges. |
| 233 allocator_dumps_edges_.insert(allocator_dumps_edges_.end(), | 225 allocator_dumps_edges_.insert(allocator_dumps_edges_.end(), |
| 234 other->allocator_dumps_edges_.begin(), | 226 other->allocator_dumps_edges_.begin(), |
| 235 other->allocator_dumps_edges_.end()); | 227 other->allocator_dumps_edges_.end()); |
| 236 other->allocator_dumps_edges_.clear(); | 228 other->allocator_dumps_edges_.clear(); |
| 237 | 229 |
| 238 heap_dumps_.insert(other->heap_dumps_.begin(), other->heap_dumps_.end()); | 230 heap_dumps_.insert(other->heap_dumps_.begin(), other->heap_dumps_.end()); |
| 239 other->heap_dumps_.clear(); | 231 other->heap_dumps_.clear(); |
| 240 } | 232 } |
| 241 | 233 |
| 242 void ProcessMemoryDump::AsValueInto(TracedValue* value) const { | 234 void ProcessMemoryDump::AsValueInto(TracedValue* value) const { |
| 243 if (has_process_totals_) { | 235 if (has_process_totals_) { |
| 244 value->BeginDictionary("process_totals"); | 236 value->BeginDictionary("process_totals"); |
| 245 process_totals_.AsValueInto(value); | 237 process_totals_.AsValueInto(value); |
| 246 value->EndDictionary(); | 238 value->EndDictionary(); |
| 247 } | 239 } |
| 248 | 240 |
| 249 if (has_process_mmaps_) { | 241 if (has_process_mmaps_) { |
| 250 value->BeginDictionary("process_mmaps"); | 242 value->BeginDictionary("process_mmaps"); |
| 251 process_mmaps_.AsValueInto(value); | 243 process_mmaps_.AsValueInto(value); |
| 252 value->EndDictionary(); | 244 value->EndDictionary(); |
| 253 } | 245 } |
| 254 | 246 |
| 255 if (allocator_dumps_storage_.size() > 0) { | 247 if (allocator_dumps_.size() > 0) { |
| 256 value->BeginDictionary("allocators"); | 248 value->BeginDictionary("allocators"); |
| 257 for (const MemoryAllocatorDump* allocator_dump : allocator_dumps_storage_) | 249 for (const auto& allocator_dump_it : allocator_dumps_) |
| 258 allocator_dump->AsValueInto(value); | 250 allocator_dump_it.second->AsValueInto(value); |
| 259 value->EndDictionary(); | 251 value->EndDictionary(); |
| 260 } | 252 } |
| 261 | 253 |
| 262 if (heap_dumps_.size() > 0) { | 254 if (heap_dumps_.size() > 0) { |
| 263 value->BeginDictionary("heaps"); | 255 value->BeginDictionary("heaps"); |
| 264 for (const auto& name_and_dump : heap_dumps_) | 256 for (const auto& name_and_dump : heap_dumps_) |
| 265 value->SetValueWithCopiedName(name_and_dump.first, *name_and_dump.second); | 257 value->SetValueWithCopiedName(name_and_dump.first, *name_and_dump.second); |
| 266 value->EndDictionary(); // "heaps" | 258 value->EndDictionary(); // "heaps" |
| 267 } | 259 } |
| 268 | 260 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 293 | 285 |
| 294 void ProcessMemoryDump::AddSuballocation(const MemoryAllocatorDumpGuid& source, | 286 void ProcessMemoryDump::AddSuballocation(const MemoryAllocatorDumpGuid& source, |
| 295 const std::string& target_node_name) { | 287 const std::string& target_node_name) { |
| 296 std::string child_mad_name = target_node_name + "/__" + source.ToString(); | 288 std::string child_mad_name = target_node_name + "/__" + source.ToString(); |
| 297 MemoryAllocatorDump* target_child_mad = CreateAllocatorDump(child_mad_name); | 289 MemoryAllocatorDump* target_child_mad = CreateAllocatorDump(child_mad_name); |
| 298 AddOwnershipEdge(source, target_child_mad->guid()); | 290 AddOwnershipEdge(source, target_child_mad->guid()); |
| 299 } | 291 } |
| 300 | 292 |
| 301 } // namespace trace_event | 293 } // namespace trace_event |
| 302 } // namespace base | 294 } // namespace base |
| OLD | NEW |