From e94d4d2ed6a442604885618a239373e8df23c269 Mon Sep 17 00:00:00 2001 From: trasz Date: Thu, 24 Mar 2011 20:15:42 +0000 Subject: Add proper width calculation for time fields (time, cputime and usertime). This fixes the ugly overflow in "ps aux" output for "[idle]". --- bin/ps/print.c | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'bin/ps/print.c') diff --git a/bin/ps/print.c b/bin/ps/print.c index 0c97030..432cffa 100644 --- a/bin/ps/print.c +++ b/bin/ps/print.c @@ -570,11 +570,20 @@ printtime(KINFO *k, VARENT *ve, long secs, long psecs) secs += psecs / 100; psecs = psecs % 100; } - (void)snprintf(obuff, sizeof(obuff), "%3ld:%02ld%c%02ld", + (void)snprintf(obuff, sizeof(obuff), "%ld:%02ld%c%02ld", secs / 60, secs % 60, decimal_point, psecs); (void)printf("%*s", v->width, obuff); } +static int +sizetime(long secs) +{ + + if (secs < 60) + return (7); + return (log10(secs / 60) + 7); +} + void cputime(KINFO *k, VARENT *ve) { @@ -930,6 +939,17 @@ s_comm(KINFO *k) } int +s_cputime(KINFO *k) +{ + long secs; + + secs = k->ki_p->ki_runtime / 1000000; + if (sumrusage) + secs += k->ki_p->ki_childtime.tv_sec; + return (sizetime(secs)); +} + +int s_label(KINFO *k) { char *string = NULL; @@ -975,3 +995,25 @@ s_logname(KINFO *k) return (strlen(s)); } + +int +s_systime(KINFO *k) +{ + long secs; + + secs = k->ki_p->ki_rusage.ru_stime.tv_sec; + if (sumrusage) + secs += k->ki_p->ki_childstime.tv_sec; + return (sizetime(secs)); +} + +int +s_usertime(KINFO *k) +{ + long secs; + + secs = k->ki_p->ki_rusage.ru_utime.tv_sec; + if (sumrusage) + secs += k->ki_p->ki_childutime.tv_sec; + return (sizetime(secs)); +} -- cgit v1.1