diff options
author | Ron Yorston <rmy@pobox.com> | 2024-01-05 12:39:30 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2024-01-05 12:39:30 +0000 |
commit | 5f2527702577d4ddcc5f059ba007e827b8ab779c (patch) | |
tree | 5385a04e3aeb4c008e3d7cfdc35699d5e2da3542 | |
parent | 49edb26faaddb81e6333e7891715ce13301aed09 (diff) | |
download | busybox-w32-5f2527702577d4ddcc5f059ba007e827b8ab779c.tar.gz busybox-w32-5f2527702577d4ddcc5f059ba007e827b8ab779c.tar.bz2 busybox-w32-5f2527702577d4ddcc5f059ba007e827b8ab779c.zip |
time: enable '-f' option
The '-f' option allows the user to specify a format string to
control which data is reported.
Adds 224-240 bytes.
-rw-r--r-- | miscutils/time.c | 23 |
1 files changed, 6 insertions, 17 deletions
diff --git a/miscutils/time.c b/miscutils/time.c index 1048afa7d..e24221341 100644 --- a/miscutils/time.c +++ b/miscutils/time.c | |||
@@ -26,7 +26,7 @@ | |||
26 | //usage: "[-vpa] [-o FILE] PROG ARGS" | 26 | //usage: "[-vpa] [-o FILE] PROG ARGS" |
27 | //usage: ) | 27 | //usage: ) |
28 | //usage: IF_PLATFORM_MINGW32( | 28 | //usage: IF_PLATFORM_MINGW32( |
29 | //usage: "[-pa] [-o FILE] PROG ARGS" | 29 | //usage: "[-pa] [-f FMT] [-o FILE] PROG ARGS" |
30 | //usage: ) | 30 | //usage: ) |
31 | //usage:#define time_full_usage "\n\n" | 31 | //usage:#define time_full_usage "\n\n" |
32 | //usage: "Run PROG, display resource usage when it exits\n" | 32 | //usage: "Run PROG, display resource usage when it exits\n" |
@@ -34,9 +34,7 @@ | |||
34 | //usage: "\n -v Verbose" | 34 | //usage: "\n -v Verbose" |
35 | //usage: ) | 35 | //usage: ) |
36 | //usage: "\n -p POSIX output format" | 36 | //usage: "\n -p POSIX output format" |
37 | //usage: IF_NOT_PLATFORM_MINGW32( | ||
38 | //usage: "\n -f FMT Custom format" | 37 | //usage: "\n -f FMT Custom format" |
39 | //usage: ) | ||
40 | //usage: "\n -o FILE Write result to FILE" | 38 | //usage: "\n -o FILE Write result to FILE" |
41 | //usage: "\n -a Append (else overwrite)" | 39 | //usage: "\n -a Append (else overwrite)" |
42 | 40 | ||
@@ -117,7 +115,6 @@ static void resuse_end(pid_t pid, resource_t *resp) | |||
117 | resp->elapsed_ms = monotonic_ms() - resp->elapsed_ms; | 115 | resp->elapsed_ms = monotonic_ms() - resp->elapsed_ms; |
118 | } | 116 | } |
119 | 117 | ||
120 | #if !ENABLE_PLATFORM_MINGW32 | ||
121 | static void printargv(char *const *argv) | 118 | static void printargv(char *const *argv) |
122 | { | 119 | { |
123 | const char *fmt = " %s" + 1; | 120 | const char *fmt = " %s" + 1; |
@@ -154,7 +151,6 @@ static unsigned long ptok(const unsigned pagesize, const unsigned long pages) | |||
154 | } | 151 | } |
155 | #undef pagesize | 152 | #undef pagesize |
156 | #endif /* UNUSED */ | 153 | #endif /* UNUSED */ |
157 | #endif /* !ENABLE_PLATFORM_MINGW32 */ | ||
158 | 154 | ||
159 | /* summarize: Report on the system use of a command. | 155 | /* summarize: Report on the system use of a command. |
160 | 156 | ||
@@ -204,10 +200,6 @@ static unsigned long ptok(const unsigned pagesize, const unsigned long pages) | |||
204 | #define TICKS_PER_SEC 100 | 200 | #define TICKS_PER_SEC 100 |
205 | #endif | 201 | #endif |
206 | 202 | ||
207 | #if ENABLE_PLATFORM_MINGW32 | ||
208 | #define summarize(f, c, r) summarize(f, r) | ||
209 | #endif | ||
210 | |||
211 | static void summarize(const char *fmt, char **command, resource_t *resp) | 203 | static void summarize(const char *fmt, char **command, resource_t *resp) |
212 | { | 204 | { |
213 | #if !ENABLE_PLATFORM_MINGW32 | 205 | #if !ENABLE_PLATFORM_MINGW32 |
@@ -253,7 +245,6 @@ static void summarize(const char *fmt, char **command, resource_t *resp) | |||
253 | switch (*fmt) { | 245 | switch (*fmt) { |
254 | case '%': | 246 | case '%': |
255 | switch (*++fmt) { | 247 | switch (*++fmt) { |
256 | #if !ENABLE_PLATFORM_MINGW32 | ||
257 | default: | 248 | default: |
258 | /* Unknown %<char> is printed as "?<char>" */ | 249 | /* Unknown %<char> is printed as "?<char>" */ |
259 | bb_putchar('?'); | 250 | bb_putchar('?'); |
@@ -268,6 +259,7 @@ static void summarize(const char *fmt, char **command, resource_t *resp) | |||
268 | case 'C': /* The command that got timed. */ | 259 | case 'C': /* The command that got timed. */ |
269 | printargv(command); | 260 | printargv(command); |
270 | break; | 261 | break; |
262 | #if !ENABLE_PLATFORM_MINGW32 | ||
271 | case 'D': /* Average unshared data size. */ | 263 | case 'D': /* Average unshared data size. */ |
272 | /* (linux kernel sets ru_idrss/isrss/ixrss to 0, | 264 | /* (linux kernel sets ru_idrss/isrss/ixrss to 0, |
273 | * docs say the value is in kbytes, so ptok() is wrong) */ | 265 | * docs say the value is in kbytes, so ptok() is wrong) */ |
@@ -398,14 +390,13 @@ static void summarize(const char *fmt, char **command, resource_t *resp) | |||
398 | case 'w': /* Voluntary context switches. */ | 390 | case 'w': /* Voluntary context switches. */ |
399 | printf("%lu", resp->ru.ru_nvcsw); | 391 | printf("%lu", resp->ru.ru_nvcsw); |
400 | break; | 392 | break; |
393 | #endif | ||
401 | case 'x': /* Exit status. */ | 394 | case 'x': /* Exit status. */ |
402 | printf("%u", WEXITSTATUS(resp->waitstatus)); | 395 | printf("%u", WEXITSTATUS(resp->waitstatus)); |
403 | break; | 396 | break; |
404 | #endif | ||
405 | } | 397 | } |
406 | break; | 398 | break; |
407 | 399 | ||
408 | #if !ENABLE_PLATFORM_MINGW32 | ||
409 | default: /* *fmt is '\': format escape */ | 400 | default: /* *fmt is '\': format escape */ |
410 | switch (*++fmt) { | 401 | switch (*++fmt) { |
411 | default: | 402 | default: |
@@ -431,14 +422,11 @@ static void summarize(const char *fmt, char **command, resource_t *resp) | |||
431 | break; | 422 | break; |
432 | } | 423 | } |
433 | break; | 424 | break; |
434 | #endif | ||
435 | } | 425 | } |
436 | ++fmt; | 426 | ++fmt; |
437 | } | 427 | } |
438 | bb_putchar('\n'); | 428 | bb_putchar('\n'); |
439 | #if !ENABLE_PLATFORM_MINGW32 | ||
440 | ret: ; | 429 | ret: ; |
441 | #endif | ||
442 | } | 430 | } |
443 | 431 | ||
444 | /* Run command CMD and return statistics on it. | 432 | /* Run command CMD and return statistics on it. |
@@ -497,6 +485,7 @@ int time_main(int argc UNUSED_PARAM, char **argv) | |||
497 | OPT_p = (1 << 0), | 485 | OPT_p = (1 << 0), |
498 | OPT_a = (1 << 1), | 486 | OPT_a = (1 << 1), |
499 | OPT_o = (1 << 2), | 487 | OPT_o = (1 << 2), |
488 | OPT_f = (1 << 3), | ||
500 | #endif | 489 | #endif |
501 | }; | 490 | }; |
502 | 491 | ||
@@ -506,8 +495,8 @@ int time_main(int argc UNUSED_PARAM, char **argv) | |||
506 | &output_filename, &output_format | 495 | &output_filename, &output_format |
507 | ); | 496 | ); |
508 | #else | 497 | #else |
509 | opt = getopt32(argv, "^+" "pao:" "\0" "-1"/*at least one arg*/, | 498 | opt = getopt32(argv, "^+" "pao:f:" "\0" "-1"/*at least one arg*/, |
510 | &output_filename | 499 | &output_filename, &output_format |
511 | ); | 500 | ); |
512 | #endif | 501 | #endif |
513 | argv += optind; | 502 | argv += optind; |