diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-09-08 16:51:19 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-09-08 16:51:19 +0000 |
commit | ff6e8e2974433aeabaaefaf9d8b6a35e9641b9ac (patch) | |
tree | 83de779a734d2a1e6d877718841188e630629265 /libbb | |
parent | 9382b3809b3f6bea8dec6483ff66d7c2b21abd94 (diff) | |
download | busybox-w32-ff6e8e2974433aeabaaefaf9d8b6a35e9641b9ac.tar.gz busybox-w32-ff6e8e2974433aeabaaefaf9d8b6a35e9641b9ac.tar.bz2 busybox-w32-ff6e8e2974433aeabaaefaf9d8b6a35e9641b9ac.zip |
top: TOPMEM feature - 's(how sizes)' command. +2.5k when enabled,
+80 bytes when disabled (mainly because of text wrapping fixes
in display_process_list).
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/procps.c | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/libbb/procps.c b/libbb/procps.c index 8d3aea332..3a31eeff3 100644 --- a/libbb/procps.c +++ b/libbb/procps.c | |||
@@ -115,6 +115,28 @@ void free_procps_scan(procps_status_t* sp) | |||
115 | free(sp); | 115 | free(sp); |
116 | } | 116 | } |
117 | 117 | ||
118 | #if ENABLE_FEATURE_TOPMEM | ||
119 | static unsigned long fast_strtoul_16(char **endptr) | ||
120 | { | ||
121 | unsigned char c; | ||
122 | char *str = *endptr; | ||
123 | unsigned long n = 0; | ||
124 | |||
125 | while ((c = *str++) != ' ') { | ||
126 | c = ((c|0x20) - '0'); | ||
127 | if (c > 9) | ||
128 | // c = c + '0' - 'a' + 10: | ||
129 | c = c - ('a' - '0' - 10); | ||
130 | n = n*16 + c; | ||
131 | } | ||
132 | *endptr = str; /* We skip trailing space! */ | ||
133 | return n; | ||
134 | } | ||
135 | /* TOPMEM uses fast_strtoul_10, so... */ | ||
136 | #undef ENABLE_FEATURE_FAST_TOP | ||
137 | #define ENABLE_FEATURE_FAST_TOP 1 | ||
138 | #endif | ||
139 | |||
118 | #if ENABLE_FEATURE_FAST_TOP | 140 | #if ENABLE_FEATURE_FAST_TOP |
119 | /* We cut a lot of corners here for speed */ | 141 | /* We cut a lot of corners here for speed */ |
120 | static unsigned long fast_strtoul_10(char **endptr) | 142 | static unsigned long fast_strtoul_10(char **endptr) |
@@ -278,6 +300,57 @@ procps_status_t *procps_scan(procps_status_t* sp, int flags) | |||
278 | 300 | ||
279 | } | 301 | } |
280 | 302 | ||
303 | #if ENABLE_FEATURE_TOPMEM | ||
304 | if (flags & (PSSCAN_SMAPS)) { | ||
305 | FILE *file; | ||
306 | |||
307 | strcpy(filename_tail, "/smaps"); | ||
308 | file = fopen(filename, "r"); | ||
309 | if (!file) | ||
310 | break; | ||
311 | while (fgets(buf, sizeof(buf), file)) { | ||
312 | unsigned long sz; | ||
313 | char *tp; | ||
314 | char w; | ||
315 | #define SCAN(str, name) \ | ||
316 | if (strncmp(buf, str, sizeof(str)-1) == 0) { \ | ||
317 | tp = skip_whitespace(buf + sizeof(str)-1); \ | ||
318 | sp->name += fast_strtoul_10(&tp); \ | ||
319 | continue; \ | ||
320 | } | ||
321 | SCAN("Shared_Clean:" , shared_clean ); | ||
322 | SCAN("Shared_Dirty:" , shared_dirty ); | ||
323 | SCAN("Private_Clean:", private_clean); | ||
324 | SCAN("Private_Dirty:", private_dirty); | ||
325 | #undef SCAN | ||
326 | // f7d29000-f7d39000 rw-s ADR M:m OFS FILE | ||
327 | tp = strchr(buf, '-'); | ||
328 | if (tp) { | ||
329 | *tp = ' '; | ||
330 | tp = buf; | ||
331 | sz = fast_strtoul_16(&tp); /* start */ | ||
332 | sz = (fast_strtoul_16(&tp) - sz) >> 10; /* end - start */ | ||
333 | // tp -> "rw-s" string | ||
334 | w = tp[1]; | ||
335 | // skipping "rw-s ADR M:m OFS " | ||
336 | tp = skip_whitespace(skip_fields(tp, 4)); | ||
337 | // filter out /dev/something (something != zero) | ||
338 | if (strncmp(tp, "/dev/", 5) != 0 || strcmp(tp, "/dev/zero\n") == 0) { | ||
339 | if (w == 'w') { | ||
340 | sp->mapped_rw += sz; | ||
341 | } else if (w == '-') { | ||
342 | sp->mapped_ro += sz; | ||
343 | } | ||
344 | } | ||
345 | //else printf("DROPPING %s (%s)\n", buf, tp); | ||
346 | if (strcmp(tp, "[stack]\n") == 0) | ||
347 | sp->stack += sz; | ||
348 | } | ||
349 | } | ||
350 | fclose(file); | ||
351 | } | ||
352 | #endif /* TOPMEM */ | ||
353 | |||
281 | #if 0 /* PSSCAN_CMD is not used */ | 354 | #if 0 /* PSSCAN_CMD is not used */ |
282 | if (flags & (PSSCAN_CMD|PSSCAN_ARGV0)) { | 355 | if (flags & (PSSCAN_CMD|PSSCAN_ARGV0)) { |
283 | if (sp->argv0) { | 356 | if (sp->argv0) { |