Add method to get usage stats for a single map.
The new scudo allocator creates a huge map in 64 bit address space. Some
tests would get the usage stats of all maps, but only really cared about
a small set of maps. In this case, provide a method to only get the usage
stats for the maps you care about.
Test: Unit tests pass.
Change-Id: Ie845e47a8c789a57bf689c9f0e5878a921640e30
diff --git a/libmeminfo/libmeminfo_test.cpp b/libmeminfo/libmeminfo_test.cpp
index cf5341d..378a4cd 100644
--- a/libmeminfo/libmeminfo_test.cpp
+++ b/libmeminfo/libmeminfo_test.cpp
@@ -101,6 +101,33 @@
}
}
+TEST(ProcMemInfo, MapsUsageFillInLater) {
+ ProcMemInfo proc_mem(pid);
+ const std::vector<Vma>& maps = proc_mem.MapsWithoutUsageStats();
+ EXPECT_FALSE(maps.empty());
+ for (auto& map : maps) {
+ Vma update_map(map);
+ ASSERT_EQ(map.start, update_map.start);
+ ASSERT_EQ(map.end, update_map.end);
+ ASSERT_EQ(map.offset, update_map.offset);
+ ASSERT_EQ(map.flags, update_map.flags);
+ ASSERT_EQ(map.name, update_map.name);
+ ASSERT_EQ(0, update_map.usage.vss);
+ ASSERT_EQ(0, update_map.usage.rss);
+ ASSERT_EQ(0, update_map.usage.pss);
+ ASSERT_EQ(0, update_map.usage.uss);
+ ASSERT_EQ(0, update_map.usage.swap);
+ ASSERT_EQ(0, update_map.usage.swap_pss);
+ ASSERT_EQ(0, update_map.usage.private_clean);
+ ASSERT_EQ(0, update_map.usage.private_dirty);
+ ASSERT_EQ(0, update_map.usage.shared_clean);
+ ASSERT_EQ(0, update_map.usage.shared_dirty);
+ ASSERT_TRUE(proc_mem.FillInVmaStats(update_map));
+ // Check that at least one usage stat was updated.
+ ASSERT_NE(0, update_map.usage.vss);
+ }
+}
+
TEST(ProcMemInfo, PageMapPresent) {
static constexpr size_t kNumPages = 20;
size_t pagesize = getpagesize();