summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Leme <felipeal@google.com>2016-03-17 14:56:34 -0700
committerFelipe Leme <felipeal@google.com>2016-03-17 14:56:34 -0700
commita5aa8f9583aec9fcfba38161cb31b6ae2b588313 (patch)
treebbc5f05491514fd7612a37971ee3329430bbb28c
parent6d7b862b59743b64500b9b079c90cc50d556ecdf (diff)
downloadextras-a5aa8f9583aec9fcfba38161cb31b6ae2b588313.tar.gz
Added -q flag to ignore errors.
dumpstate calls showmap for each pid, and since most of them are empty, it ends up polluting logcat with entries like: 03-17 14:49:05.974 12160 12160 E dumpstate: command '/system/xbin/su root showmap -q 9867' failed: No such file or directory BUG: 26906985 Change-Id: I18d86adefe3f4b248f672732460d1145103e5828
-rw-r--r--showmap/showmap.cpp24
1 files changed, 15 insertions, 9 deletions
diff --git a/showmap/showmap.cpp b/showmap/showmap.cpp
index d7d41b66..6efe2607 100644
--- a/showmap/showmap.cpp
+++ b/showmap/showmap.cpp
@@ -25,6 +25,11 @@ struct mapinfo {
char name[1];
};
+static bool verbose = false;
+static bool terse = false;
+static bool addresses = false;
+static bool quiet = false;
+
static int is_library(const char *name) {
int len = strlen(name);
return len >= 4 && name[0] == '/'
@@ -173,7 +178,7 @@ static mapinfo *load_maps(int pid, int sort_by_address, int coalesce_by_name)
snprintf(fn, sizeof(fn), "/proc/%d/smaps", pid);
fp = fopen(fn, "r");
if (fp == 0) {
- fprintf(stderr, "cannot open /proc/%d/smaps: %s\n", pid, strerror(errno));
+ if (!quiet) fprintf(stderr, "cannot open /proc/%d/smaps: %s\n", pid, strerror(errno));
return NULL;
}
@@ -202,17 +207,13 @@ static mapinfo *load_maps(int pid, int sort_by_address, int coalesce_by_name)
fclose(fp);
if (!head) {
- fprintf(stderr, "could not read /proc/%d/smaps\n", pid);
+ if (!quiet) fprintf(stderr, "could not read /proc/%d/smaps\n", pid);
return NULL;
}
return head;
}
-static bool verbose = false;
-static bool terse = false;
-static bool addresses = false;
-
static void print_header()
{
const char *addr1 = addresses ? " start end " : "";
@@ -264,7 +265,7 @@ static int show_map(int pid)
mapinfo *milist = load_maps(pid, addresses, !verbose && !addresses);
if (milist == NULL) {
- return 1;
+ return quiet ? 0 : 1;
}
print_header();
@@ -282,7 +283,7 @@ static int show_map(int pid)
total.pss += mi->pss;
total.size += mi->size;
total.count += mi->count;
-
+
if (terse && !mi->private_dirty) {
goto out;
}
@@ -328,6 +329,10 @@ int main(int argc, char *argv[])
addresses = true;
continue;
}
+ if (!strcmp(arg,"-q")) {
+ quiet = true;
+ continue;
+ }
if (argc != 1) {
fprintf(stderr, "too many arguments\n");
break;
@@ -346,10 +351,11 @@ int main(int argc, char *argv[])
if (usage) {
fprintf(stderr,
- "showmap [-t] [-v] [-c] <pid>\n"
+ "showmap [-t] [-v] [-c] [-q] <pid>\n"
" -t = terse (show only items with private pages)\n"
" -v = verbose (don't coalesce maps with the same name)\n"
" -a = addresses (show virtual memory map)\n"
+ " -q = quiet (don't show error if map could not be read)\n"
);
result = 1;
}