libmeminfo: Add support for counting swap pages
Adds procmeminfo API to get the vector of swap_offsets
if SWAP is enabled on the device.
Bug: 114325007
Bug: 111694435
Test: libmeminfo_test 1
Change-Id: If0b52d042749a5bcb2c87aa2cb1595190d4769b1
Signed-off-by: Sandeep Patil <sspatil@google.com>
diff --git a/libmeminfo/sysmeminfo.cpp b/libmeminfo/sysmeminfo.cpp
index 50fa213..82605b6 100644
--- a/libmeminfo/sysmeminfo.cpp
+++ b/libmeminfo/sysmeminfo.cpp
@@ -37,9 +37,11 @@
namespace meminfo {
const std::vector<std::string> SysMemInfo::kDefaultSysMemInfoTags = {
- "MemTotal:", "MemFree:", "Buffers:", "Cached:", "Shmem:",
- "Slab:", "SReclaimable:", "SUnreclaim:", "SwapTotal:", "SwapFree:",
- "ZRam:", "Mapped:", "VmallocUsed:", "PageTables:", "KernelStack:",
+ SysMemInfo::kMemTotal, SysMemInfo::kMemFree, SysMemInfo::kMemBuffers,
+ SysMemInfo::kMemCached, SysMemInfo::kMemShmem, SysMemInfo::kMemSlab,
+ SysMemInfo::kMemSReclaim, SysMemInfo::kMemSUnreclaim, SysMemInfo::kMemSwapTotal,
+ SysMemInfo::kMemSwapFree, SysMemInfo::kMemZram, SysMemInfo::kMemMapped,
+ SysMemInfo::kMemVmallocUsed, SysMemInfo::kMemPageTables, SysMemInfo::kMemKernelStack,
};
bool SysMemInfo::ReadMemInfo(const std::string& path) {
@@ -99,6 +101,7 @@
buffer[len] = '\0';
char* p = buffer;
uint32_t found = 0;
+ uint32_t lineno = 0;
while (*p && found < tags.size()) {
for (auto& tag : tags) {
if (strncmp(p, tag.c_str(), tag.size()) == 0) {
@@ -107,7 +110,7 @@
char* endptr = nullptr;
mem_in_kb_[tag] = strtoull(p, &endptr, 10);
if (p == endptr) {
- PLOG(ERROR) << "Failed to parse line in file: " << path;
+ PLOG(ERROR) << "Failed to parse line:" << lineno + 1 << " in file: " << path;
return false;
}
p = endptr;
@@ -119,6 +122,7 @@
p++;
}
if (*p) p++;
+ lineno++;
}
return true;