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

Unified Diff: base/memory/shared_memory_tracker.cc

Issue 2775423003: Add ownership edges between HostSharedBitmap and shared memory
Patch Set: Fix comments Created 3 years, 9 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') | base/trace_event/process_memory_dump.h » ('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..90780e4e3a3f5bfe8276823d32388ae0368067d7 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,31 @@ SharedMemoryTracker* SharedMemoryTracker::GetInstance() {
return instance;
}
+// static
+bool SharedMemoryTracker::AddOwnershipEdges(
+ trace_event::ProcessMemoryDump* pmd,
+ const trace_event::MemoryAllocatorDumpGuid& source,
+ const SharedMemoryHandle& shared_memory_handle) {
+ return AddOwnershipEdges(pmd, source, shared_memory_handle,
+ trace_event::ProcessMemoryDump::kDefaultImportance);
+}
+
+// static
+bool SharedMemoryTracker::AddOwnershipEdges(
+ trace_event::ProcessMemoryDump* pmd,
+ const trace_event::MemoryAllocatorDumpGuid& source,
+ const SharedMemoryHandle& shared_memory_handle,
+ int importance) {
+ SharedMemory::UniqueId id;
+ if (!SharedMemory::GetUniqueId(shared_memory_handle, &id))
+ return false;
+
+ std::string id_str = SharedMemoryUniqueIdToString(id);
+ trace_event::MemoryAllocatorDump* dump = pmd->GetAllocatorDump(id_str);
+ pmd->AddOwnershipEdge(source, dump->guid(), importance);
+ return true;
+}
+
void SharedMemoryTracker::IncrementMemoryUsage(
const SharedMemory& shared_memory) {
Usage usage;
@@ -32,7 +73,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 +98,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);
« no previous file with comments | « base/memory/shared_memory_tracker.h ('k') | base/trace_event/process_memory_dump.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698