Chromium Code Reviews| Index: base/memory/shared_memory_tracker.cc |
| diff --git a/base/memory/shared_memory_tracker.cc b/base/memory/shared_memory_tracker.cc |
| index 8613f595336ada19357c900cf0ab9bf4d243b7f4..266a51e17e2c1baaad5fc0519756afb01d9e950f 100644 |
| --- a/base/memory/shared_memory_tracker.cc |
| +++ b/base/memory/shared_memory_tracker.cc |
| @@ -4,13 +4,29 @@ |
| #include "base/memory/shared_memory_tracker.h" |
| -#include "base/memory/shared_memory.h" |
| +#include "base/format_macros.h" |
| #include "base/strings/stringprintf.h" |
| #include "base/trace_event/memory_dump_manager.h" |
| #include "base/trace_event/process_memory_dump.h" |
| namespace base { |
| +namespace { |
| + |
| +std::string SharedMemoryUniqueIdToString(const SharedMemory::UniqueId& id) { |
| +#if defined(OS_POSIX) && (!defined(OS_MACOSX) || defined(OS_IOS)) && \ |
| + !defined(OS_NACL) |
| + return StringPrintf("shared_memory/%" PRIu64 ".%" PRIu64, |
| + static_cast<uint64_t>(id.first), |
| + static_cast<uint64_t>(id.second)); |
| +#else |
| + // TODO(hajimehoshi): Implement this for each platform. |
| + return StringPrintf("shared_memory/%d", id); |
| +#endif |
| +} |
| + |
| +} // namespace |
| + |
| SharedMemoryTracker::Usage::Usage() = default; |
| SharedMemoryTracker::Usage::Usage(const Usage& rhs) = default; |
| @@ -23,6 +39,41 @@ SharedMemoryTracker* SharedMemoryTracker::GetInstance() { |
| return instance; |
| } |
| +// static |
| +bool SharedMemoryTracker::AddOwnershipEdges( |
| + trace_event::ProcessMemoryDump* pmd, |
| + const trace_event::MemoryAllocatorDumpGuid& source, |
| + const SharedMemoryHandle& shared_memory_handle, |
| + size_t size) { |
| + return AddOwnershipEdges(pmd, source, shared_memory_handle, size, |
| + trace_event::ProcessMemoryDump::kDefaultImportance); |
| +} |
| + |
| +// static |
| +bool SharedMemoryTracker::AddOwnershipEdges( |
| + trace_event::ProcessMemoryDump* pmd, |
| + const trace_event::MemoryAllocatorDumpGuid& source, |
| + const SharedMemoryHandle& shared_memory_handle, |
| + size_t size, |
| + int importance) { |
| + SharedMemory::UniqueId id; |
| + if (!SharedMemory::GetUniqueId(shared_memory_handle, &id)) |
| + return false; |
| + |
| + std::string id_str = SharedMemoryUniqueIdToString(id); |
| + auto in_process_dump_name = |
| + StringPrintf("shared_memory_in_process/%s", id_str.c_str()); |
|
Primiano Tucci (use gerrit)
2017/03/29 17:19:50
why not just "shared_memory"?
hajimehoshi
2017/03/30 07:49:25
I thought this dump is necessary but I was wrong.
|
| + auto* in_process_dump = pmd->CreateAllocatorDump(in_process_dump_name); |
| + pmd->AddOwnershipEdge(source, in_process_dump->guid()); |
| + in_process_dump->AddScalar(trace_event::MemoryAllocatorDump::kNameSize, |
| + trace_event::MemoryAllocatorDump::kUnitsBytes, |
| + size); |
| + |
| + trace_event::MemoryAllocatorDumpGuid global_guid(id_str); |
| + pmd->AddOwnershipEdge(in_process_dump->guid(), global_guid, importance); |
| + return true; |
| +} |
| + |
| void SharedMemoryTracker::IncrementMemoryUsage( |
| const SharedMemory& shared_memory) { |
| Usage usage; |
| @@ -32,7 +83,7 @@ void SharedMemoryTracker::IncrementMemoryUsage( |
| // just after mmap and the handle must live then. See the discussion at |
| // crbug.com/604726#c30. |
| SharedMemory::UniqueId id; |
| - if (!shared_memory.GetUniqueId(&id)) |
| + if (!SharedMemory::GetUniqueId(shared_memory.handle(), &id)) |
| return; |
| usage.unique_id = id; |
| usage.size = shared_memory.mapped_size(); |
| @@ -57,9 +108,7 @@ bool SharedMemoryTracker::OnMemoryDump(const trace_event::MemoryDumpArgs& args, |
| } |
| for (auto& size : sizes) { |
| const SharedMemory::UniqueId& id = size.first; |
| - std::string dump_name = StringPrintf("%s/%lld.%lld", "shared_memory", |
| - static_cast<long long>(id.first), |
| - static_cast<long long>(id.second)); |
| + std::string dump_name = SharedMemoryUniqueIdToString(id); |
| auto guid = trace_event::MemoryAllocatorDumpGuid(dump_name); |
| trace_event::MemoryAllocatorDump* local_dump = |
| pmd->CreateAllocatorDump(dump_name); |