Index: bin/ps/extern.h =================================================================== RCS file: /cvsroot/src/bin/ps/extern.h,v retrieving revision 1.33 diff -u -r1.33 extern.h --- bin/ps/extern.h 31 May 2010 03:18:33 -0000 1.33 +++ bin/ps/extern.h 15 Jan 2014 07:57:11 -0000 @@ -59,6 +59,7 @@ void gname(void *, VARENT *, int); void groups(void *, VARENT *, int); void groupnames(void *, VARENT *, int); +void lcputime(void *, VARENT *, int); void logname(void *, VARENT *, int); void longtname(void *, VARENT *, int); void lname(void *, VARENT *, int); Index: bin/ps/keyword.c =================================================================== RCS file: /cvsroot/src/bin/ps/keyword.c,v retrieving revision 1.53 diff -u -r1.53 keyword.c --- bin/ps/keyword.c 21 Oct 2009 21:11:57 -0000 1.53 +++ bin/ps/keyword.c 15 Jan 2014 07:57:12 -0000 @@ -149,6 +149,7 @@ VAR3("logname", "login", ALIAS), VAR6("lstart", "STARTED", LJUST, lstarted, POFF(p_ustart_sec), UINT32), VAR4("lstate", "STAT", LJUST|LWP, lstate), + VAR6("ltime", "LTIME", LWP, lcputime, 0, CPUTIME), PUVAR("majflt", "MAJFLT", 0, p_uru_majflt, UINT64, PRIu64), PUVAR("minflt", "MINFLT", 0, p_uru_minflt, UINT64, PRIu64), PUVAR("msgrcv", "MSGRCV", 0, p_uru_msgrcv, UINT64, PRIu64), Index: bin/ps/print.c =================================================================== RCS file: /cvsroot/src/bin/ps/print.c,v retrieving revision 1.120 diff -u -r1.120 print.c --- bin/ps/print.c 20 Mar 2012 18:42:28 -0000 1.120 +++ bin/ps/print.c 15 Jan 2014 07:57:12 -0000 @@ -1012,29 +1012,11 @@ intprintorsetwidth(v, l->l_cpuid, mode); } -void -cputime(void *arg, VARENT *ve, int mode) +static void +cputime1(int32_t secs, int32_t psecs, VAR *v, int mode) { - struct kinfo_proc2 *k; - VAR *v; - int32_t secs; - int32_t psecs; /* "parts" of a second. first micro, then centi */ int fmtlen; - k = arg; - v = ve->var; - - /* - * 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->p_rtime_sec; - psecs = k->p_rtime_usec; - if (sumrusage) { - secs += k->p_uctime_sec; - psecs += k->p_uctime_usec; - } /* * round and scale to 100's */ @@ -1066,6 +1048,49 @@ } } +void +cputime(void *arg, VARENT *ve, int mode) +{ + struct kinfo_proc2 *k; + VAR *v; + int32_t secs; + int32_t psecs; /* "parts" of a second. first micro, then centi */ + + k = arg; + v = ve->var; + + /* + * 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->p_rtime_sec; + psecs = k->p_rtime_usec; + if (sumrusage) { + secs += k->p_uctime_sec; + psecs += k->p_uctime_usec; + } + + cputime1(secs, psecs, v, mode); +} + +void +lcputime(void *arg, VARENT *ve, int mode) +{ + struct kinfo_lwp *l; + VAR *v; + int32_t secs; + int32_t psecs; /* "parts" of a second. first micro, then centi */ + + l = arg; + v = ve->var; + + secs = l->l_rtime_sec; + psecs = l->l_rtime_usec; + + cputime1(secs, psecs, v, mode); +} + double getpcpu(const struct kinfo_proc2 *k) { Index: bin/ps/ps.1 =================================================================== RCS file: /cvsroot/src/bin/ps/ps.1,v retrieving revision 1.101 diff -u -r1.101 ps.1 --- bin/ps/ps.1 3 Jun 2012 21:42:44 -0000 1.101 +++ bin/ps/ps.1 15 Jan 2014 07:57:12 -0000 @@ -540,6 +540,8 @@ time started .It Ar lstate symbolic LWP state +.It Ar ltime +CPU time of the LWP .It Ar majflt total page faults .It Ar minflt Index: bin/ps/ps.c =================================================================== RCS file: /cvsroot/src/bin/ps/ps.c,v retrieving revision 1.78 diff -u -r1.78 ps.c --- bin/ps/ps.c 7 May 2012 13:14:31 -0000 1.78 +++ bin/ps/ps.c 15 Jan 2014 07:57:12 -0000 @@ -136,7 +136,7 @@ char jfmt[] = "user pid ppid pgid sess jobc state tt time command"; char lfmt[] = "uid pid ppid cpu pri nice vsz rss wchan state tt time command"; char sfmt[] = "uid pid ppid cpu lid nlwp pri nice vsz rss wchan lstate tt " - "time command"; + "ltime command"; char ufmt[] = "user pid %cpu %mem vsz rss tt state start time command"; char vfmt[] = "pid state time sl re pagein vsz rss lim tsiz %cpu %mem command"; .