@@ -25,6 +25,11 @@ struct mapinfo {
25
25
char name[1 ];
26
26
};
27
27
28
+ static bool verbose = false ;
29
+ static bool terse = false ;
30
+ static bool addresses = false ;
31
+ static bool quiet = false ;
32
+
28
33
static int is_library (const char *name) {
29
34
int len = strlen (name);
30
35
return len >= 4 && name[0 ] == ' /'
@@ -173,7 +178,7 @@ static mapinfo *load_maps(int pid, int sort_by_address, int coalesce_by_name)
173
178
snprintf (fn, sizeof (fn), " /proc/%d/smaps" , pid);
174
179
fp = fopen (fn, " r" );
175
180
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));
177
182
return NULL ;
178
183
}
179
184
@@ -202,17 +207,13 @@ static mapinfo *load_maps(int pid, int sort_by_address, int coalesce_by_name)
202
207
fclose (fp);
203
208
204
209
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);
206
211
return NULL ;
207
212
}
208
213
209
214
return head;
210
215
}
211
216
212
- static bool verbose = false ;
213
- static bool terse = false ;
214
- static bool addresses = false ;
215
-
216
217
static void print_header ()
217
218
{
218
219
const char *addr1 = addresses ? " start end " : " " ;
@@ -264,7 +265,7 @@ static int show_map(int pid)
264
265
265
266
mapinfo *milist = load_maps (pid, addresses, !verbose && !addresses);
266
267
if (milist == NULL ) {
267
- return 1 ;
268
+ return quiet ? 0 : 1 ;
268
269
}
269
270
270
271
print_header ();
@@ -282,7 +283,7 @@ static int show_map(int pid)
282
283
total.pss += mi->pss ;
283
284
total.size += mi->size ;
284
285
total.count += mi->count ;
285
-
286
+
286
287
if (terse && !mi->private_dirty ) {
287
288
goto out;
288
289
}
@@ -328,6 +329,10 @@ int main(int argc, char *argv[])
328
329
addresses = true ;
329
330
continue ;
330
331
}
332
+ if (!strcmp (arg," -q" )) {
333
+ quiet = true ;
334
+ continue ;
335
+ }
331
336
if (argc != 1 ) {
332
337
fprintf (stderr, " too many arguments\n " );
333
338
break ;
@@ -346,10 +351,11 @@ int main(int argc, char *argv[])
346
351
347
352
if (usage) {
348
353
fprintf (stderr,
349
- " showmap [-t] [-v] [-c] <pid>\n "
354
+ " showmap [-t] [-v] [-c] [-q] <pid>\n "
350
355
" -t = terse (show only items with private pages)\n "
351
356
" -v = verbose (don't coalesce maps with the same name)\n "
352
357
" -a = addresses (show virtual memory map)\n "
358
+ " -q = quiet (don't show error if map could not be read)\n "
353
359
);
354
360
result = 1 ;
355
361
}
0 commit comments