Index: base/trace_event/process_memory_dump.cc |
diff --git a/base/trace_event/process_memory_dump.cc b/base/trace_event/process_memory_dump.cc |
index cb8d5fa768424e1b52024c28efd532bcd49c8d1a..7acb2118a9ec870c18762a5d13916dceba8448b9 100644 |
--- a/base/trace_event/process_memory_dump.cc |
+++ b/base/trace_event/process_memory_dump.cc |
@@ -9,6 +9,7 @@ |
#include <vector> |
#include "base/memory/ptr_util.h" |
+#include "base/memory/shared_memory_tracker.h" |
#include "base/process/process_metrics.h" |
#include "base/strings/stringprintf.h" |
#include "base/trace_event/heap_profiler_heap_dump_writer.h" |
@@ -16,6 +17,7 @@ |
#include "base/trace_event/memory_infra_background_whitelist.h" |
#include "base/trace_event/process_memory_totals.h" |
#include "base/trace_event/trace_event_argument.h" |
+#include "base/unguessable_token.h" |
#include "build/build_config.h" |
#if defined(OS_IOS) |
@@ -382,6 +384,69 @@ void ProcessMemoryDump::AddOverridableOwnershipEdge( |
} |
} |
+void ProcessMemoryDump::CreateSharedMemoryOwnershipEdge( |
+ const MemoryAllocatorDumpGuid& client_local_dump_guid, |
+ const MemoryAllocatorDumpGuid& client_global_dump_guid, |
+ const UnguessableToken& shared_memory_guid, |
+ int importance) { |
+ CreateSharedMemoryOwnershipEdgeInternal( |
+ client_local_dump_guid, client_global_dump_guid, shared_memory_guid, |
+ importance, false /*is_weak*/); |
+} |
+ |
+void ProcessMemoryDump::CreateWeakSharedMemoryOwnershipEdge( |
+ const MemoryAllocatorDumpGuid& client_local_dump_guid, |
+ const MemoryAllocatorDumpGuid& client_global_dump_guid, |
+ const UnguessableToken& shared_memory_guid, |
+ int importance) { |
+ CreateSharedMemoryOwnershipEdgeInternal( |
+ client_local_dump_guid, client_global_dump_guid, shared_memory_guid, |
+ importance, true /*is_weak*/); |
+} |
+ |
+void ProcessMemoryDump::CreateSharedMemoryOwnershipEdgeInternal( |
+ const MemoryAllocatorDumpGuid& client_local_dump_guid, |
+ const MemoryAllocatorDumpGuid& client_global_dump_guid, |
+ const UnguessableToken& shared_memory_guid, |
+ int importance, |
+ bool is_weak) { |
+ if (MemoryAllocatorDumpGuid::UseSharedMemoryBasedGUIDs()) { |
+ DCHECK(!shared_memory_guid.is_empty()); |
+ // New model where the global dumps created by SharedMemoryTracker are used |
+ // for the clients. |
+ |
+ // The guid of the local dump cretaed by SharedMemoryTracker for the memory |
dcheng
2017/06/08 19:28:30
Nit: created (same typo below)
ssid
2017/06/08 19:43:16
Done.
|
+ // segment. |
+ auto local_shm_guid = |
+ SharedMemoryTracker::GetDumpGUIDForTracing(shared_memory_guid); |
+ |
+ // The dump guid of the global dump cretaed by the tracker for the memory |
+ // segment. |
+ auto global_shm_guid = |
+ SharedMemoryTracker::GetGlobalDumpGUIDForTracing(shared_memory_guid); |
+ |
+ // Create an edge between local dump of the client and the local dump of the |
+ // SharedMemoryTracker. Do not need to create the dumps here since the |
+ // tracker would create them. |
+ AddOwnershipEdge(client_local_dump_guid, local_shm_guid); |
+ |
+ // TODO(ssid): Handle the case of weak dumps here. This needs a new function |
+ // GetOrCreaetGlobalDump() in PMD since we need to change the behavior of |
+ // the created global dump. |
+ // Create an edge that overrides the edge created by SharedMemoryTracker. |
+ AddOwnershipEdge(local_shm_guid, global_shm_guid, importance); |
+ } else { |
+ // This is the old model where the clients create global dumps for |
+ // themselves. |
+ if (is_weak) |
+ CreateWeakSharedGlobalAllocatorDump(client_global_dump_guid); |
+ else |
+ CreateSharedGlobalAllocatorDump(client_global_dump_guid); |
+ AddOwnershipEdge(client_local_dump_guid, client_global_dump_guid, |
+ importance); |
+ } |
+} |
+ |
void ProcessMemoryDump::AddSuballocation(const MemoryAllocatorDumpGuid& source, |
const std::string& target_node_name) { |
// Do not create new dumps for suballocations in background mode. |