libmeminfo: Report VMA flags in procmem report
Add VMA flags into procmem report so that we can distinguish different
sections of an executable or a library.
Bug: 138148041
Test: procmem -h <PID>
Change-Id: I062464aa1f1c508bcc8ef05a6d9cfad9a4318d95
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
diff --git a/libmeminfo/tools/procmem.cpp b/libmeminfo/tools/procmem.cpp
index 47881ed..b245f2a 100644
--- a/libmeminfo/tools/procmem.cpp
+++ b/libmeminfo/tools/procmem.cpp
@@ -17,6 +17,7 @@
#include <errno.h>
#include <inttypes.h>
#include <stdlib.h>
+#include <sys/mman.h>
#include <unistd.h>
#include <iostream>
@@ -59,25 +60,25 @@
static void print_separator(std::stringstream& ss) {
if (show_wss) {
- ss << ::android::base::StringPrintf("%7s %7s %7s %7s %7s %7s %7s %s\n", "-------",
+ ss << ::android::base::StringPrintf("%7s %7s %7s %7s %7s %7s %7s %7s %s\n",
"-------", "-------", "-------", "-------", "-------",
- "-------", "");
+ "-------", "-------", "-------", "");
return;
}
- ss << ::android::base::StringPrintf("%7s %7s %7s %7s %7s %7s %7s %7s %s\n", "-------",
+ ss << ::android::base::StringPrintf("%7s %7s %7s %7s %7s %7s %7s %7s %7s %s\n",
"-------", "-------", "-------", "-------", "-------",
- "-------", "-------", "");
+ "-------", "-------", "-------", "-------", "");
}
static void print_header(std::stringstream& ss) {
if (show_wss) {
- ss << ::android::base::StringPrintf("%7s %7s %7s %7s %7s %7s %7s %s\n", "WRss",
+ ss << ::android::base::StringPrintf("%7s %7s %7s %7s %7s %7s %7s %7s %s\n", "WRss",
"WPss", "WUss", "WShCl", "WShDi", "WPrCl", "WPrDi",
- "Name");
+ "Flags", "Name");
} else {
- ss << ::android::base::StringPrintf("%7s %7s %7s %7s %7s %7s %7s %7s %s\n", "Vss",
- "Rss", "Pss", "Uss", "ShCl", "ShDi", "PrCl", "PrDi",
- "Name");
+ ss << ::android::base::StringPrintf("%7s %7s %7s %7s %7s %7s %7s %7s %7s %s\n",
+ "Vss", "Rss", "Pss", "Uss", "ShCl", "ShDi", "PrCl",
+ "PrDi", "Flags", "Name");
}
print_separator(ss);
}
@@ -103,7 +104,15 @@
continue;
}
print_stats(ss, vma_stats);
- ss << vma.name << std::endl;
+
+ // TODO: b/141711064 fix libprocinfo to record (p)rivate or (s)hared flag
+ // for now always report as private
+ std::string flags_str("---p");
+ if (vma.flags & PROT_READ) flags_str[0] = 'r';
+ if (vma.flags & PROT_WRITE) flags_str[1] = 'w';
+ if (vma.flags & PROT_EXEC) flags_str[2] = 'x';
+
+ ss << ::android::base::StringPrintf("%7s ", flags_str.c_str()) << vma.name << std::endl;
}
print_separator(ss);
print_stats(ss, proc_stats);