From 425e556ac9cfcee7074d9eae8e246690de567ea7 Mon Sep 17 00:00:00 2001 From: kib Date: Thu, 17 Mar 2011 11:25:32 +0000 Subject: Implement the usertime and systime keywords for ps, printing the corresponding times reported by getrusage(). Submitted by: Dan Nelson MFC after: 1 week --- bin/ps/print.c | 69 +++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 51 insertions(+), 18 deletions(-) (limited to 'bin/ps/print.c') diff --git a/bin/ps/print.c b/bin/ps/print.c index 46b979b..253793a 100644 --- a/bin/ps/print.c +++ b/bin/ps/print.c @@ -550,12 +550,11 @@ vsize(KINFO *k, VARENT *ve) (void)printf("%*lu", v->width, (u_long)(k->ki_p->ki_size / 1024)); } -void -cputime(KINFO *k, VARENT *ve) +static void +printtime(KINFO *k, VARENT *ve, long secs, long psecs) +/* psecs is "parts" of a second. first micro, then centi */ { VAR *v; - long secs; - long psecs; /* "parts" of a second. first micro, then centi */ char obuff[128]; static char decimal_point; @@ -566,20 +565,7 @@ cputime(KINFO *k, VARENT *ve) secs = 0; psecs = 0; } else { - /* - * This counts time spent handling interrupts. We could - * fix this, but it is not 100% trivial (and interrupt - * time fractions only work on the sparc anyway). XXX - */ - secs = k->ki_p->ki_runtime / 1000000; - psecs = k->ki_p->ki_runtime % 1000000; - if (sumrusage) { - secs += k->ki_p->ki_childtime.tv_sec; - psecs += k->ki_p->ki_childtime.tv_usec; - } - /* - * round and scale to 100's - */ + /* round and scale to 100's */ psecs = (psecs + 5000) / 10000; secs += psecs / 100; psecs = psecs % 100; @@ -590,6 +576,53 @@ cputime(KINFO *k, VARENT *ve) } void +cputime(KINFO *k, VARENT *ve) +{ + long secs, psecs; + + /* + * This counts time spent handling interrupts. We could + * fix this, but it is not 100% trivial (and interrupt + * time fractions only work on the sparc anyway). XXX + */ + secs = k->ki_p->ki_runtime / 1000000; + psecs = k->ki_p->ki_runtime % 1000000; + if (sumrusage) { + secs += k->ki_p->ki_childtime.tv_sec; + psecs += k->ki_p->ki_childtime.tv_usec; + } + printtime(k, ve, secs, psecs); +} + +void +systime(KINFO *k, VARENT *ve) +{ + long secs, psecs; + + secs = k->ki_p->ki_rusage.ru_stime.tv_sec; + psecs = k->ki_p->ki_rusage.ru_stime.tv_usec; + if (sumrusage) { + secs += k->ki_p->ki_childstime.tv_sec; + psecs += k->ki_p->ki_childstime.tv_usec; + } + printtime(k, ve, secs, psecs); +} + +void +usertime(KINFO *k, VARENT *ve) +{ + long secs, psecs; + + secs = k->ki_p->ki_rusage.ru_utime.tv_sec; + psecs = k->ki_p->ki_rusage.ru_utime.tv_usec; + if (sumrusage) { + secs += k->ki_p->ki_childutime.tv_sec; + psecs += k->ki_p->ki_childutime.tv_usec; + } + printtime(k, ve, secs, psecs); +} + +void elapsed(KINFO *k, VARENT *ve) { VAR *v; -- cgit v1.1