diff options
author | Ron Yorston <rmy@pobox.com> | 2024-01-05 11:17:37 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2024-01-05 11:17:37 +0000 |
commit | 49edb26faaddb81e6333e7891715ce13301aed09 (patch) | |
tree | 8f982e294e2d0ac916f28ad8ef9344611cd93f25 /miscutils | |
parent | f72312908b11605f527d002b4e8ce729bbe237a5 (diff) | |
parent | 5dc9ece3b9e87af0dcb01449821ac827391ac116 (diff) | |
download | busybox-w32-49edb26faaddb81e6333e7891715ce13301aed09.tar.gz busybox-w32-49edb26faaddb81e6333e7891715ce13301aed09.tar.bz2 busybox-w32-49edb26faaddb81e6333e7891715ce13301aed09.zip |
Merge branch 'busybox' into merge
Diffstat (limited to 'miscutils')
-rw-r--r-- | miscutils/time.c | 73 |
1 files changed, 42 insertions, 31 deletions
diff --git a/miscutils/time.c b/miscutils/time.c index 2c71382bf..1048afa7d 100644 --- a/miscutils/time.c +++ b/miscutils/time.c | |||
@@ -127,6 +127,7 @@ static void printargv(char *const *argv) | |||
127 | } while (*++argv); | 127 | } while (*++argv); |
128 | } | 128 | } |
129 | 129 | ||
130 | #ifdef UNUSED | ||
130 | /* Return the number of kilobytes corresponding to a number of pages PAGES. | 131 | /* Return the number of kilobytes corresponding to a number of pages PAGES. |
131 | (Actually, we use it to convert pages*ticks into kilobytes*ticks.) | 132 | (Actually, we use it to convert pages*ticks into kilobytes*ticks.) |
132 | 133 | ||
@@ -152,7 +153,8 @@ static unsigned long ptok(const unsigned pagesize, const unsigned long pages) | |||
152 | return tmp / 1024; /* then smaller. */ | 153 | return tmp / 1024; /* then smaller. */ |
153 | } | 154 | } |
154 | #undef pagesize | 155 | #undef pagesize |
155 | #endif | 156 | #endif /* UNUSED */ |
157 | #endif /* !ENABLE_PLATFORM_MINGW32 */ | ||
156 | 158 | ||
157 | /* summarize: Report on the system use of a command. | 159 | /* summarize: Report on the system use of a command. |
158 | 160 | ||
@@ -249,36 +251,31 @@ static void summarize(const char *fmt, char **command, resource_t *resp) | |||
249 | } | 251 | } |
250 | 252 | ||
251 | switch (*fmt) { | 253 | switch (*fmt) { |
252 | #ifdef NOT_NEEDED | ||
253 | /* Handle literal char */ | ||
254 | /* Usually we optimize for size, but there is a limit | ||
255 | * for everything. With this we do a lot of 1-byte writes */ | ||
256 | default: | ||
257 | bb_putchar(*fmt); | ||
258 | break; | ||
259 | #endif | ||
260 | |||
261 | case '%': | 254 | case '%': |
262 | switch (*++fmt) { | 255 | switch (*++fmt) { |
263 | #ifdef NOT_NEEDED_YET | 256 | #if !ENABLE_PLATFORM_MINGW32 |
264 | /* Our format strings do not have these */ | ||
265 | /* and we do not take format str from user */ | ||
266 | default: | 257 | default: |
267 | bb_putchar('%'); | 258 | /* Unknown %<char> is printed as "?<char>" */ |
259 | bb_putchar('?'); | ||
260 | if (!*fmt) { | ||
261 | /* Trailing -f '...%' prints "...?" but NOT newline */ | ||
262 | goto ret; | ||
263 | } | ||
268 | /*FALLTHROUGH*/ | 264 | /*FALLTHROUGH*/ |
269 | case '%': | 265 | case '%': |
270 | if (!*fmt) goto ret; | ||
271 | bb_putchar(*fmt); | 266 | bb_putchar(*fmt); |
272 | break; | 267 | break; |
273 | #endif | ||
274 | #if !ENABLE_PLATFORM_MINGW32 | ||
275 | case 'C': /* The command that got timed. */ | 268 | case 'C': /* The command that got timed. */ |
276 | printargv(command); | 269 | printargv(command); |
277 | break; | 270 | break; |
278 | case 'D': /* Average unshared data size. */ | 271 | case 'D': /* Average unshared data size. */ |
272 | /* (linux kernel sets ru_idrss/isrss/ixrss to 0, | ||
273 | * docs say the value is in kbytes, so ptok() is wrong) */ | ||
279 | printf("%lu", | 274 | printf("%lu", |
280 | (ptok(pagesize, (UL) resp->ru.ru_idrss) + | 275 | (/*ptok(pagesize,*/ (UL) resp->ru.ru_idrss + |
281 | ptok(pagesize, (UL) resp->ru.ru_isrss)) / cpu_ticks); | 276 | (UL) resp->ru.ru_isrss |
277 | ) / cpu_ticks | ||
278 | ); | ||
282 | break; | 279 | break; |
283 | #endif | 280 | #endif |
284 | case 'E': { /* Elapsed real (wall clock) time. */ | 281 | case 'E': { /* Elapsed real (wall clock) time. */ |
@@ -303,13 +300,17 @@ static void summarize(const char *fmt, char **command, resource_t *resp) | |||
303 | printf("%lu", resp->ru.ru_inblock); | 300 | printf("%lu", resp->ru.ru_inblock); |
304 | break; | 301 | break; |
305 | case 'K': /* Average mem usage == data+stack+text. */ | 302 | case 'K': /* Average mem usage == data+stack+text. */ |
303 | /* (linux kernel sets ru_idrss/isrss/ixrss to 0, | ||
304 | * docs say the value is in kbytes, so ptok() is wrong) */ | ||
306 | printf("%lu", | 305 | printf("%lu", |
307 | (ptok(pagesize, (UL) resp->ru.ru_idrss) + | 306 | (/*ptok(pagesize,*/ (UL) resp->ru.ru_idrss + |
308 | ptok(pagesize, (UL) resp->ru.ru_isrss) + | 307 | (UL) resp->ru.ru_isrss + |
309 | ptok(pagesize, (UL) resp->ru.ru_ixrss)) / cpu_ticks); | 308 | (UL) resp->ru.ru_ixrss |
309 | ) / cpu_ticks | ||
310 | ); | ||
310 | break; | 311 | break; |
311 | case 'M': /* Maximum resident set size. */ | 312 | case 'M': /* Maximum resident set size. */ |
312 | printf("%lu", ptok(pagesize, (UL) resp->ru.ru_maxrss)); | 313 | printf("%lu", (UL) resp->ru.ru_maxrss); |
313 | break; | 314 | break; |
314 | case 'O': /* Outputs. */ | 315 | case 'O': /* Outputs. */ |
315 | printf("%lu", resp->ru.ru_oublock); | 316 | printf("%lu", resp->ru.ru_oublock); |
@@ -364,7 +365,7 @@ static void summarize(const char *fmt, char **command, resource_t *resp) | |||
364 | printf("%lu", resp->ru.ru_nswap); | 365 | printf("%lu", resp->ru.ru_nswap); |
365 | break; | 366 | break; |
366 | case 'X': /* Average shared text size. */ | 367 | case 'X': /* Average shared text size. */ |
367 | printf("%lu", ptok(pagesize, (UL) resp->ru.ru_ixrss) / cpu_ticks); | 368 | printf("%lu", /*ptok(pagesize,*/ (UL) resp->ru.ru_ixrss / cpu_ticks); |
368 | break; | 369 | break; |
369 | case 'Z': /* Page size. */ | 370 | case 'Z': /* Page size. */ |
370 | printf("%u", pagesize); | 371 | printf("%u", pagesize); |
@@ -383,7 +384,7 @@ static void summarize(const char *fmt, char **command, resource_t *resp) | |||
383 | printf("%lu", resp->ru.ru_nsignals); | 384 | printf("%lu", resp->ru.ru_nsignals); |
384 | break; | 385 | break; |
385 | case 'p': /* Average stack segment. */ | 386 | case 'p': /* Average stack segment. */ |
386 | printf("%lu", ptok(pagesize, (UL) resp->ru.ru_isrss) / cpu_ticks); | 387 | printf("%lu", /*ptok(pagesize,*/ (UL) resp->ru.ru_isrss / cpu_ticks); |
387 | break; | 388 | break; |
388 | case 'r': /* Incoming socket messages received. */ | 389 | case 'r': /* Incoming socket messages received. */ |
389 | printf("%lu", resp->ru.ru_msgrcv); | 390 | printf("%lu", resp->ru.ru_msgrcv); |
@@ -392,7 +393,7 @@ static void summarize(const char *fmt, char **command, resource_t *resp) | |||
392 | printf("%lu", resp->ru.ru_msgsnd); | 393 | printf("%lu", resp->ru.ru_msgsnd); |
393 | break; | 394 | break; |
394 | case 't': /* Average resident set size. */ | 395 | case 't': /* Average resident set size. */ |
395 | printf("%lu", ptok(pagesize, (UL) resp->ru.ru_idrss) / cpu_ticks); | 396 | printf("%lu", /*ptok(pagesize,*/ (UL) resp->ru.ru_idrss / cpu_ticks); |
396 | break; | 397 | break; |
397 | case 'w': /* Voluntary context switches. */ | 398 | case 'w': /* Voluntary context switches. */ |
398 | printf("%lu", resp->ru.ru_nvcsw); | 399 | printf("%lu", resp->ru.ru_nvcsw); |
@@ -404,14 +405,22 @@ static void summarize(const char *fmt, char **command, resource_t *resp) | |||
404 | } | 405 | } |
405 | break; | 406 | break; |
406 | 407 | ||
407 | #ifdef NOT_NEEDED_YET | 408 | #if !ENABLE_PLATFORM_MINGW32 |
408 | case '\\': /* Format escape. */ | 409 | default: /* *fmt is '\': format escape */ |
409 | switch (*++fmt) { | 410 | switch (*++fmt) { |
410 | default: | 411 | default: |
412 | /* Unknown \<char> is printed as "?\<char>" */ | ||
413 | bb_putchar('?'); | ||
411 | bb_putchar('\\'); | 414 | bb_putchar('\\'); |
415 | if (!*fmt) { | ||
416 | /* Trailing -f '...\': GNU time 1.9 prints | ||
417 | * "...?\COMMAND" (it's probably a bug). | ||
418 | */ | ||
419 | puts(command[0]); | ||
420 | goto ret; | ||
421 | } | ||
412 | /*FALLTHROUGH*/ | 422 | /*FALLTHROUGH*/ |
413 | case '\\': | 423 | case '\\': |
414 | if (!*fmt) goto ret; | ||
415 | bb_putchar(*fmt); | 424 | bb_putchar(*fmt); |
416 | break; | 425 | break; |
417 | case 't': | 426 | case 't': |
@@ -426,8 +435,10 @@ static void summarize(const char *fmt, char **command, resource_t *resp) | |||
426 | } | 435 | } |
427 | ++fmt; | 436 | ++fmt; |
428 | } | 437 | } |
429 | /* ret: */ | ||
430 | bb_putchar('\n'); | 438 | bb_putchar('\n'); |
439 | #if !ENABLE_PLATFORM_MINGW32 | ||
440 | ret: ; | ||
441 | #endif | ||
431 | } | 442 | } |
432 | 443 | ||
433 | /* Run command CMD and return statistics on it. | 444 | /* Run command CMD and return statistics on it. |
@@ -469,7 +480,7 @@ int time_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | |||
469 | int time_main(int argc UNUSED_PARAM, char **argv) | 480 | int time_main(int argc UNUSED_PARAM, char **argv) |
470 | { | 481 | { |
471 | resource_t res; | 482 | resource_t res; |
472 | /* $TIME has lowest prio (-v,-p,-f FMT overrride it) */ | 483 | /* $TIME has lowest prio (-v,-p,-f FMT override it) */ |
473 | const char *output_format = getenv("TIME") ? : default_format; | 484 | const char *output_format = getenv("TIME") ? : default_format; |
474 | char *output_filename; | 485 | char *output_filename; |
475 | int output_fd; | 486 | int output_fd; |