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

Unified Diff: base/trace_event/process_memory_dump_unittest.cc

Issue 2923123004: [memory-infra] Add API to ProcessMemoryDump to create ownership edges for base::SharedMemory (Closed)
Patch Set: fix typo. Created 3 years, 6 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/trace_event/process_memory_dump.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/trace_event/process_memory_dump_unittest.cc
diff --git a/base/trace_event/process_memory_dump_unittest.cc b/base/trace_event/process_memory_dump_unittest.cc
index 4bddb6103995c56257c0f1c173cf27d956f4bae7..3f3e88a74c118d7ba9c38c7f1057528637518422 100644
--- a/base/trace_event/process_memory_dump_unittest.cc
+++ b/base/trace_event/process_memory_dump_unittest.cc
@@ -8,10 +8,12 @@
#include "base/memory/aligned_memory.h"
#include "base/memory/ptr_util.h"
+#include "base/memory/shared_memory_tracker.h"
#include "base/process/process_metrics.h"
#include "base/trace_event/memory_allocator_dump_guid.h"
#include "base/trace_event/memory_infra_background_whitelist.h"
#include "base/trace_event/trace_event_argument.h"
+#include "base/unguessable_token.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace base {
@@ -300,6 +302,66 @@ TEST(ProcessMemoryDumpTest, GlobalAllocatorDumpTest) {
ASSERT_EQ(MemoryAllocatorDump::Flags::DEFAULT, shared_mad1->flags());
}
+TEST(ProcessMemoryDumpTest, OldSharedMemoryOwnershipTest) {
+ std::unique_ptr<ProcessMemoryDump> pmd(
+ new ProcessMemoryDump(nullptr, kDetailedDumpArgs));
+ const ProcessMemoryDump::AllocatorDumpEdgesMap& edges =
+ pmd->allocator_dumps_edges_for_testing();
+
+ auto* shm_dump1 = pmd->CreateAllocatorDump("shared_mem/seg1");
+
+ auto* client_dump1 = pmd->CreateAllocatorDump("discardable/segment1");
+ MemoryAllocatorDumpGuid client_global_guid1(1);
+ auto shm_token1 = UnguessableToken::Create();
+ MemoryAllocatorDumpGuid shm_global_guid1 =
+ SharedMemoryTracker::GetGlobalDumpGUIDForTracing(shm_token1);
+ pmd->AddOverridableOwnershipEdge(shm_dump1->guid(), shm_global_guid1,
+ 0 /* importance */);
+
+ pmd->CreateSharedMemoryOwnershipEdge(client_dump1->guid(),
+ client_global_guid1, shm_token1,
+ 1 /* importance */);
+
+ EXPECT_EQ(2u, edges.size());
+ EXPECT_EQ(shm_global_guid1, edges.find(shm_dump1->guid())->second.target);
+ EXPECT_EQ(0, edges.find(shm_dump1->guid())->second.importance);
+ EXPECT_TRUE(edges.find(shm_dump1->guid())->second.overridable);
+ EXPECT_EQ(client_global_guid1,
+ edges.find(client_dump1->guid())->second.target);
+ EXPECT_EQ(1, edges.find(client_dump1->guid())->second.importance);
+ EXPECT_FALSE(edges.find(client_dump1->guid())->second.overridable);
+}
+
+TEST(ProcessMemoryDumpTest, NewSharedMemoryOwnershipTest) {
+ std::unique_ptr<ProcessMemoryDump> pmd(
+ new ProcessMemoryDump(nullptr, kDetailedDumpArgs));
+ const ProcessMemoryDump::AllocatorDumpEdgesMap& edges =
+ pmd->allocator_dumps_edges_for_testing();
+ MemoryAllocatorDumpGuid::SetUseSharedMemoryBasedGUIDsForTesting();
+
+ auto* client_dump2 = pmd->CreateAllocatorDump("discardable/segment2");
+ MemoryAllocatorDumpGuid client_global_guid2(2);
+ auto shm_token2 = UnguessableToken::Create();
+ MemoryAllocatorDumpGuid shm_local_guid2 =
+ SharedMemoryTracker::GetDumpGUIDForTracing(shm_token2);
+ MemoryAllocatorDumpGuid shm_global_guid2 =
+ SharedMemoryTracker::GetGlobalDumpGUIDForTracing(shm_token2);
+ pmd->AddOverridableOwnershipEdge(shm_local_guid2, shm_global_guid2,
+ 0 /* importance */);
+
+ pmd->CreateSharedMemoryOwnershipEdge(client_dump2->guid(),
+ client_global_guid2, shm_token2,
+ 1 /* importance */);
+ EXPECT_EQ(2u, edges.size());
+
+ EXPECT_EQ(shm_global_guid2, edges.find(shm_local_guid2)->second.target);
+ EXPECT_EQ(1, edges.find(shm_local_guid2)->second.importance);
+ EXPECT_FALSE(edges.find(shm_local_guid2)->second.overridable);
+ EXPECT_EQ(shm_local_guid2, edges.find(client_dump2->guid())->second.target);
+ EXPECT_EQ(0, edges.find(client_dump2->guid())->second.importance);
+ EXPECT_FALSE(edges.find(client_dump2->guid())->second.overridable);
+}
+
TEST(ProcessMemoryDumpTest, BackgroundModeTest) {
MemoryDumpArgs background_args = {MemoryDumpLevelOfDetail::BACKGROUND};
std::unique_ptr<ProcessMemoryDump> pmd(
« no previous file with comments | « base/trace_event/process_memory_dump.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698