Skip to content

Commit a5aa8f9

Browse files
committed
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
1 parent 6d7b862 commit a5aa8f9

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

showmap/showmap.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ struct mapinfo {
2525
char name[1];
2626
};
2727

28+
static bool verbose = false;
29+
static bool terse = false;
30+
static bool addresses = false;
31+
static bool quiet = false;
32+
2833
static int is_library(const char *name) {
2934
int len = strlen(name);
3035
return len >= 4 && name[0] == '/'
@@ -173,7 +178,7 @@ static mapinfo *load_maps(int pid, int sort_by_address, int coalesce_by_name)
173178
snprintf(fn, sizeof(fn), "/proc/%d/smaps", pid);
174179
fp = fopen(fn, "r");
175180
if (fp == 0) {
176-
fprintf(stderr, "cannot open /proc/%d/smaps: %s\n", pid, strerror(errno));
181+
if (!quiet) fprintf(stderr, "cannot open /proc/%d/smaps: %s\n", pid, strerror(errno));
177182
return NULL;
178183
}
179184

@@ -202,17 +207,13 @@ static mapinfo *load_maps(int pid, int sort_by_address, int coalesce_by_name)
202207
fclose(fp);
203208

204209
if (!head) {
205-
fprintf(stderr, "could not read /proc/%d/smaps\n", pid);
210+
if (!quiet) fprintf(stderr, "could not read /proc/%d/smaps\n", pid);
206211
return NULL;
207212
}
208213

209214
return head;
210215
}
211216

212-
static bool verbose = false;
213-
static bool terse = false;
214-
static bool addresses = false;
215-
216217
static void print_header()
217218
{
218219
const char *addr1 = addresses ? " start end " : "";
@@ -264,7 +265,7 @@ static int show_map(int pid)
264265

265266
mapinfo *milist = load_maps(pid, addresses, !verbose && !addresses);
266267
if (milist == NULL) {
267-
return 1;
268+
return quiet ? 0 : 1;
268269
}
269270

270271
print_header();
@@ -282,7 +283,7 @@ static int show_map(int pid)
282283
total.pss += mi->pss;
283284
total.size += mi->size;
284285
total.count += mi->count;
285-
286+
286287
if (terse && !mi->private_dirty) {
287288
goto out;
288289
}
@@ -328,6 +329,10 @@ int main(int argc, char *argv[])
328329
addresses = true;
329330
continue;
330331
}
332+
if (!strcmp(arg,"-q")) {
333+
quiet = true;
334+
continue;
335+
}
331336
if (argc != 1) {
332337
fprintf(stderr, "too many arguments\n");
333338
break;
@@ -346,10 +351,11 @@ int main(int argc, char *argv[])
346351

347352
if (usage) {
348353
fprintf(stderr,
349-
"showmap [-t] [-v] [-c] <pid>\n"
354+
"showmap [-t] [-v] [-c] [-q] <pid>\n"
350355
" -t = terse (show only items with private pages)\n"
351356
" -v = verbose (don't coalesce maps with the same name)\n"
352357
" -a = addresses (show virtual memory map)\n"
358+
" -q = quiet (don't show error if map could not be read)\n"
353359
);
354360
result = 1;
355361
}

0 commit comments

Comments
 (0)