Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Unified Diff: base/memory/shared_memory_tracker.cc

Issue 2535213002: [WIP] Add SharedMemoryTracker to dump base::SharedMemory usage
Patch Set: (rebase) Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/memory/shared_memory_tracker.h ('k') | cc/raster/staging_buffer_pool.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..7d38ada032aafe39edfad21b04b64610c3c3459a 100644
--- a/base/memory/shared_memory_tracker.cc
+++ b/base/memory/shared_memory_tracker.cc
@@ -4,40 +4,36 @@
#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 {
-SharedMemoryTracker::Usage::Usage() = default;
-
-SharedMemoryTracker::Usage::Usage(const Usage& rhs) = default;
-
-SharedMemoryTracker::Usage::~Usage() = default;
-
// static
SharedMemoryTracker* SharedMemoryTracker::GetInstance() {
static SharedMemoryTracker* instance = new SharedMemoryTracker;
return instance;
}
+// static
+bool SharedMemoryTracker::AddOwnershipEdges(
+ trace_event::ProcessMemoryDump* pmd,
+ const trace_event::MemoryAllocatorDumpGuid& source,
+ const SharedMemory& shared_memory) {
+ std::string id_str = shared_memory.handle().GetGUIDNameForTracing();
+ // The same dump name might be already created on single-process mode.
+ trace_event::MemoryAllocatorDump* dump =
+ pmd->GetOrCreateAllocatorDump(id_str);
+ pmd->AddOwnershipEdge(source, dump->guid());
+ return true;
+}
+
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,36 +44,30 @@ 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;
- {
- AutoLock hold(usages_lock_);
- for (const auto& usage : usages_)
- sizes[usage.second.unique_id] += usage.second.size;
- }
- 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_) {
+ const SharedMemory* shared_memory = usage.first;
+ std::string dump_name = shared_memory->handle().GetGUIDNameForTracing();
+ if (dump_name.empty())
+ continue;
trace_event::MemoryAllocatorDump* local_dump =
- pmd->CreateAllocatorDump(dump_name);
+ 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);
+ usage.second);
+ auto guid = trace_event::MemoryAllocatorDumpGuid(dump_name);
trace_event::MemoryAllocatorDump* global_dump =
pmd->CreateSharedGlobalAllocatorDump(guid);
global_dump->AddScalar(trace_event::MemoryAllocatorDump::kNameSize,
trace_event::MemoryAllocatorDump::kUnitsBytes,
- size.second);
+ usage.second);
// TOOD(hajimehoshi): Detect which the shared memory comes from browser,
// renderer or GPU process.
// TODO(hajimehoshi): Shared memory reported by GPU and discardable is
// currently double-counted. Add ownership edges to avoid this.
- pmd->AddOwnershipEdge(local_dump->guid(), global_dump->guid());
+ pmd->AddOwnershipEdge(local_dump->guid(), global_dump->guid(),
+ shared_memory->importance());
}
return true;
}
« no previous file with comments | « base/memory/shared_memory_tracker.h ('k') | cc/raster/staging_buffer_pool.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698