summaryrefslogtreecommitdiff
path: root/libpagemap
diff options
context:
space:
mode:
authorSandeep Patil <sspatil@google.com>2018-08-16 13:00:01 -0700
committerSandeep Patil <sspatil@google.com>2018-08-22 16:59:20 -0700
commit533cee50270b864276d1750914471ba7f6cf9ae7 (patch)
tree036cbc3a5cb5483de85d178c5488c01511e19567 /libpagemap
parent0f595cb6ca9dcebe372786724636eb99ebeba0a4 (diff)
downloadextras-533cee50270b864276d1750914471ba7f6cf9ae7.tar.gz
libpagemap: procmem: Add option to sort by USS.
In same case, especially working set, USS may be much more actionable for a process than PSS. Add option to sort by USS in all cases for the same. Bug: 111694435 Test: procmem -h -u 1 Test: procmem -h -i -u -w 1 Change-Id: Ifb9c4bd2ff18bb73d82c492cb1862a065ed630b4 Signed-off-by: Sandeep Patil <sspatil@google.com>
Diffstat (limited to 'libpagemap')
-rw-r--r--libpagemap/procmem.cpp21
1 files changed, 20 insertions, 1 deletions
diff --git a/libpagemap/procmem.cpp b/libpagemap/procmem.cpp
index 9728d066..e8eb4eda 100644
--- a/libpagemap/procmem.cpp
+++ b/libpagemap/procmem.cpp
@@ -39,6 +39,9 @@ static void usage(const char *cmd);
/* qsort compare function to compare maps by PSS */
int comp_pss(const void *a, const void *b);
+/* qsort compare function to compare maps by USS */
+int comp_uss(const void* a, const void* b);
+
int main(int argc, char *argv[]) {
pid_t pid;
@@ -96,6 +99,10 @@ int main(int argc, char *argv[]) {
}
if (!strcmp(argv[i], "-m")) { compfn = NULL; continue; }
if (!strcmp(argv[i], "-p")) { compfn = &comp_pss; continue; }
+ if (!strcmp(argv[i], "-u")) {
+ compfn = &comp_uss;
+ continue;
+ }
if (!strcmp(argv[i], "-h")) { hide_zeros = 1; continue; }
fprintf(stderr, "Invalid argument \"%s\".\n", argv[i]);
usage(argv[0]);
@@ -331,13 +338,14 @@ int main(int argc, char *argv[]) {
return 0;
}
-static void usage(const char *cmd) {
+static void usage(const char* cmd) {
fprintf(stderr,
"Usage: %s [-i] [ -w | -W ] [ -p | -m ] [ -h ] pid\n"
" -i Uses idle page tracking for working set statistics.\n"
" -w Displays statistics for the working set only.\n"
" -W Resets the working set of the process.\n"
" -p Sort by PSS.\n"
+ " -u Sort by USS.\n"
" -m Sort by mapping order (as read from /proc).\n"
" -h Hide maps with no RSS.\n",
cmd);
@@ -353,3 +361,14 @@ int comp_pss(const void *a, const void *b) {
if (mb->usage.pss > ma->usage.pss) return 1;
return 0;
}
+
+int comp_uss(const void* a, const void* b) {
+ struct map_info *ma, *mb;
+
+ ma = *((struct map_info**)a);
+ mb = *((struct map_info**)b);
+
+ if (mb->usage.uss < ma->usage.uss) return -1;
+ if (mb->usage.uss > ma->usage.uss) return 1;
+ return 0;
+}