diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-08-10 15:01:43 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-08-10 15:02:16 +0200 |
commit | 9c7c63b5c2fb35ba0fcc7d24fdc78c156204d51a (patch) | |
tree | f641311ab9b791d4794845ab6eb30414087449f4 /procps/ps.c | |
parent | 9a6f62fd5172c14adf765285d6c000691d89d58d (diff) | |
download | busybox-w32-9c7c63b5c2fb35ba0fcc7d24fdc78c156204d51a.tar.gz busybox-w32-9c7c63b5c2fb35ba0fcc7d24fdc78c156204d51a.tar.bz2 busybox-w32-9c7c63b5c2fb35ba0fcc7d24fdc78c156204d51a.zip |
ps: improve TIME column for large times: showing "14453:50" is not good
function old new delta
format_time - 110 +110
func_time 59 50 -9
func_etime 67 53 -14
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/2 up/down: 110/-23) Total: 87 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'procps/ps.c')
-rw-r--r-- | procps/ps.c | 45 |
1 files changed, 36 insertions, 9 deletions
diff --git a/procps/ps.c b/procps/ps.c index 2a53cc974..646b1144e 100644 --- a/procps/ps.c +++ b/procps/ps.c | |||
@@ -308,28 +308,55 @@ static void func_nice(char *buf, int size, const procps_status_t *ps) | |||
308 | #endif | 308 | #endif |
309 | 309 | ||
310 | #if ENABLE_FEATURE_PS_TIME | 310 | #if ENABLE_FEATURE_PS_TIME |
311 | static void format_time(char *buf, int size, unsigned long tt) | ||
312 | { | ||
313 | unsigned ff; | ||
314 | |||
315 | /* Used to show "14453:50" if tt is large. Ugly. | ||
316 | * procps-ng 3.3.10 uses "[[dd-]hh:]mm:ss" format. | ||
317 | * TODO: switch to that? | ||
318 | */ | ||
319 | |||
320 | /* Formatting for 5-char TIME column. | ||
321 | * NB: "size" is not always 5: ELAPSED is wider (7), | ||
322 | * not taking advantage of that (yet?). | ||
323 | */ | ||
324 | ff = tt % 60; | ||
325 | tt /= 60; | ||
326 | if (tt < 60) { | ||
327 | snprintf(buf, size+1, "%2u:%02u", (unsigned)tt, ff); | ||
328 | return; | ||
329 | } | ||
330 | ff = tt % 60; | ||
331 | tt /= 60; | ||
332 | if (tt < 24) { | ||
333 | snprintf(buf, size+1, "%2uh%02u", (unsigned)tt, ff); | ||
334 | return; | ||
335 | } | ||
336 | ff = tt % 24; | ||
337 | tt /= 24; | ||
338 | if (tt < 100) { | ||
339 | snprintf(buf, size+1, "%2ud%02u", (unsigned)tt, ff); | ||
340 | return; | ||
341 | } | ||
342 | snprintf(buf, size+1, "%4lud", tt); | ||
343 | } | ||
311 | static void func_etime(char *buf, int size, const procps_status_t *ps) | 344 | static void func_etime(char *buf, int size, const procps_status_t *ps) |
312 | { | 345 | { |
313 | /* elapsed time [[dd-]hh:]mm:ss; here only mm:ss */ | 346 | /* elapsed time [[dd-]hh:]mm:ss; here only mm:ss */ |
314 | unsigned long mm; | 347 | unsigned long mm; |
315 | unsigned ss; | ||
316 | 348 | ||
317 | mm = ps->start_time / get_kernel_HZ(); | 349 | mm = ps->start_time / get_kernel_HZ(); |
318 | mm = G.seconds_since_boot - mm; | 350 | mm = G.seconds_since_boot - mm; |
319 | ss = mm % 60; | 351 | format_time(buf, size, mm); |
320 | mm /= 60; | ||
321 | snprintf(buf, size+1, "%3lu:%02u", mm, ss); | ||
322 | } | 352 | } |
323 | static void func_time(char *buf, int size, const procps_status_t *ps) | 353 | static void func_time(char *buf, int size, const procps_status_t *ps) |
324 | { | 354 | { |
325 | /* cumulative time [[dd-]hh:]mm:ss; here only mm:ss */ | 355 | /* cumulative time [[dd-]hh:]mm:ss; here only mm:ss */ |
326 | unsigned long mm; | 356 | unsigned long mm; |
327 | unsigned ss; | ||
328 | 357 | ||
329 | mm = (ps->utime + ps->stime) / get_kernel_HZ(); | 358 | mm = (ps->utime + ps->stime) / get_kernel_HZ(); |
330 | ss = mm % 60; | 359 | format_time(buf, size, mm); |
331 | mm /= 60; | ||
332 | snprintf(buf, size+1, "%3lu:%02u", mm, ss); | ||
333 | } | 360 | } |
334 | #endif | 361 | #endif |
335 | 362 | ||
@@ -365,7 +392,7 @@ static const ps_out_t out_spec[] = { | |||
365 | // { 5 , "pcpu" ,"%CPU" ,func_pcpu ,PSSCAN_ }, | 392 | // { 5 , "pcpu" ,"%CPU" ,func_pcpu ,PSSCAN_ }, |
366 | #endif | 393 | #endif |
367 | #if ENABLE_FEATURE_PS_TIME | 394 | #if ENABLE_FEATURE_PS_TIME |
368 | { 6 , "time" ,"TIME" ,func_time ,PSSCAN_STIME | PSSCAN_UTIME }, | 395 | { 5 , "time" ,"TIME" ,func_time ,PSSCAN_STIME | PSSCAN_UTIME }, |
369 | #endif | 396 | #endif |
370 | { 6 , "tty" ,"TT" ,func_tty ,PSSCAN_TTY }, | 397 | { 6 , "tty" ,"TT" ,func_tty ,PSSCAN_TTY }, |
371 | { 4 , "vsz" ,"VSZ" ,func_vsz ,PSSCAN_VSZ }, | 398 | { 4 , "vsz" ,"VSZ" ,func_vsz ,PSSCAN_VSZ }, |