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..740dc6dedb2da30367fb77efbd1b1f107e51eb3d 100644 |
| --- a/base/memory/shared_memory_tracker.cc |
| +++ b/base/memory/shared_memory_tracker.cc |
| @@ -5,18 +5,11 @@ |
| #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 { |
| -SharedMemoryTracker::Usage::Usage() = default; |
| - |
| -SharedMemoryTracker::Usage::Usage(const Usage& rhs) = default; |
| - |
| -SharedMemoryTracker::Usage::~Usage() = default; |
| - |
| // static |
| SharedMemoryTracker* SharedMemoryTracker::GetInstance() { |
| static SharedMemoryTracker* instance = new SharedMemoryTracker; |
| @@ -25,19 +18,8 @@ SharedMemoryTracker* SharedMemoryTracker::GetInstance() { |
| void SharedMemoryTracker::IncrementMemoryUsage( |
| const SharedMemory& shared_memory) { |
| - Usage usage; |
| - // |shared_memory|'s unique ID must be generated here and it'd be too late at |
| - // OnMemoryDump. An ID is generated with a SharedMemoryHandle, but the handle |
| - // might already be closed at that time. Now IncrementMemoryUsage is called |
| - // 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)) |
| - return; |
| - usage.unique_id = id; |
| - usage.size = shared_memory.mapped_size(); |
| AutoLock hold(usages_lock_); |
| - usages_[&shared_memory] = usage; |
| + usages_[&shared_memory] = shared_memory.mapped_size(); |
| } |
| void SharedMemoryTracker::DecrementMemoryUsage( |
| @@ -48,31 +30,36 @@ void SharedMemoryTracker::DecrementMemoryUsage( |
| bool SharedMemoryTracker::OnMemoryDump(const trace_event::MemoryDumpArgs& args, |
| trace_event::ProcessMemoryDump* pmd) { |
| - std::unordered_map<SharedMemory::UniqueId, size_t, SharedMemory::UniqueIdHash> |
| - sizes; |
| + std::vector<std::tuple<base::UnguessableToken, size_t>> usages; |
| { |
| AutoLock hold(usages_lock_); |
| - for (const auto& usage : usages_) |
| - sizes[usage.second.unique_id] += usage.second.size; |
| + usages.reserve(usages_.size()); |
| + for (auto& usage : usages_) |
|
erikchen
2017/05/11 21:54:40
The C++ style guide says to only use auto "to avoi
hajimehoshi
2017/05/12 09:27:31
Done. I think auto for map iterators is encouraged
|
| + usages.emplace_back(usage.first->handle().GetGUID(), usage.second); |
| } |
| - 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)); |
| - auto guid = trace_event::MemoryAllocatorDumpGuid(dump_name); |
| + for (auto& usage : usages) { |
| + auto guid = std::get<0>(usage); |
|
Primiano Tucci (use gerrit)
2017/05/11 15:10:43
const auto&?
hajimehoshi
2017/05/12 09:27:31
Done.
|
| + auto size = std::get<1>(usage); |
| + // TODO(hajimehoshi): As passing ID across mojo is not implemented yet |
| + // (crbug/713763), ID can be empty. |
| + if (guid.is_empty()) |
|
Primiano Tucci (use gerrit)
2017/05/11 15:10:43
see my previous comment, copy-pasting
----
However
hajimehoshi
2017/05/12 09:27:31
Ah sorry I missed that comment. As all shared memo
|
| + continue; |
| + std::string dump_name = "shared_memory/" + guid.ToString(); |
| + auto dump_guid = trace_event::MemoryAllocatorDumpGuid(dump_name); |
| + // The dump might already be created on single-process mode. |
| trace_event::MemoryAllocatorDump* local_dump = |
| - pmd->CreateAllocatorDump(dump_name); |
| + pmd->GetAllocatorDump(dump_name); |
| + if (local_dump) |
|
erikchen
2017/05/11 21:54:40
This logic looks new? In general, we shouldn't nee
hajimehoshi
2017/05/12 09:27:31
Ah, in theory this conflict can happen even before
hajimehoshi
2017/05/17 10:13:35
ping primiano@
|
| + continue; |
| + local_dump = pmd->GetOrCreateAllocatorDump(dump_name); |
| // TODO(hajimehoshi): The size is not resident size but virtual size so far. |
| // Fix this to record resident size. |
| local_dump->AddScalar(trace_event::MemoryAllocatorDump::kNameSize, |
| - trace_event::MemoryAllocatorDump::kUnitsBytes, |
| - size.second); |
| + trace_event::MemoryAllocatorDump::kUnitsBytes, size); |
| trace_event::MemoryAllocatorDump* global_dump = |
| - pmd->CreateSharedGlobalAllocatorDump(guid); |
| + pmd->CreateSharedGlobalAllocatorDump(dump_guid); |
| global_dump->AddScalar(trace_event::MemoryAllocatorDump::kNameSize, |
| - trace_event::MemoryAllocatorDump::kUnitsBytes, |
| - size.second); |
| + trace_event::MemoryAllocatorDump::kUnitsBytes, size); |
| // TOOD(hajimehoshi): Detect which the shared memory comes from browser, |
| // renderer or GPU process. |
| // TODO(hajimehoshi): Shared memory reported by GPU and discardable is |