| 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..823e8c8dc6764f824efc9c949135551a8d7d4448 100644
|
| --- a/base/memory/shared_memory_tracker.cc
|
| +++ b/base/memory/shared_memory_tracker.cc
|
| @@ -4,13 +4,26 @@
|
|
|
| #include "base/memory/shared_memory_tracker.h"
|
|
|
| -#include "base/memory/shared_memory.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))
|
| + return StringPrintf("%s/%lld.%lld", "shared_memory",
|
| + static_cast<long long>(id.first),
|
| + static_cast<long long>(id.second));
|
| +#else
|
| + // TODO(hajimehoshi): Implement this.
|
| + return "";
|
| +#endif
|
| +}
|
| +}
|
| +
|
| SharedMemoryTracker::Usage::Usage() = default;
|
|
|
| SharedMemoryTracker::Usage::Usage(const Usage& rhs) = default;
|
| @@ -23,6 +36,31 @@ 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 mapped_size) {
|
| + SharedMemory::UniqueId id;
|
| + if (!SharedMemory::GetUniqueId(shared_memory_handle, &id))
|
| + return false;
|
| +
|
| + // TODO: Fix the dump name
|
| + std::string id_str = SharedMemoryUniqueIdToString(id);
|
| + auto in_process_dump_name =
|
| + StringPrintf("shared_memory_in_process/%s", id_str.c_str());
|
| + 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,
|
| + mapped_size);
|
| +
|
| + trace_event::MemoryAllocatorDumpGuid global_guid(id_str);
|
| + pmd->AddOwnershipEdge(in_process_dump->guid(), global_guid);
|
| + return true;
|
| +}
|
| +
|
| void SharedMemoryTracker::IncrementMemoryUsage(
|
| const SharedMemory& shared_memory) {
|
| Usage usage;
|
| @@ -32,7 +70,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 +95,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);
|
|
|