Implement the usertime and systime keywords for ps, printing the
corresponding times reported by getrusage(). Submitted by: Dan Nelson <dnelson allantgroup com> MFC after: 1 week
This commit is contained in:
parent
ffda66c299
commit
a870bf2c31
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=219713
@ -81,12 +81,14 @@ int s_uname(KINFO *);
|
|||||||
void showkey(void);
|
void showkey(void);
|
||||||
void started(KINFO *, VARENT *);
|
void started(KINFO *, VARENT *);
|
||||||
void state(KINFO *, VARENT *);
|
void state(KINFO *, VARENT *);
|
||||||
|
void systime(KINFO *, VARENT *);
|
||||||
void tdev(KINFO *, VARENT *);
|
void tdev(KINFO *, VARENT *);
|
||||||
void tdnam(KINFO *, VARENT *);
|
void tdnam(KINFO *, VARENT *);
|
||||||
void tname(KINFO *, VARENT *);
|
void tname(KINFO *, VARENT *);
|
||||||
void ucomm(KINFO *, VARENT *);
|
void ucomm(KINFO *, VARENT *);
|
||||||
void uname(KINFO *, VARENT *);
|
void uname(KINFO *, VARENT *);
|
||||||
void upr(KINFO *, VARENT *);
|
void upr(KINFO *, VARENT *);
|
||||||
|
void usertime(KINFO *, VARENT *);
|
||||||
void vsize(KINFO *, VARENT *);
|
void vsize(KINFO *, VARENT *);
|
||||||
void wchan(KINFO *, VARENT *);
|
void wchan(KINFO *, VARENT *);
|
||||||
__END_DECLS
|
__END_DECLS
|
||||||
|
@ -189,6 +189,7 @@ static VAR var[] = {
|
|||||||
UINT, UIDFMT, 0},
|
UINT, UIDFMT, 0},
|
||||||
{"svuid", "SVUID", NULL, 0, kvar, NULL, UIDLEN, KOFF(ki_svuid),
|
{"svuid", "SVUID", NULL, 0, kvar, NULL, UIDLEN, KOFF(ki_svuid),
|
||||||
UINT, UIDFMT, 0},
|
UINT, UIDFMT, 0},
|
||||||
|
{"systime", "SYSTIME", NULL, USER, systime, NULL, 9, 0, CHAR, NULL, 0},
|
||||||
{"tdaddr", "TDADDR", NULL, 0, kvar, NULL, sizeof(void *) * 2,
|
{"tdaddr", "TDADDR", NULL, 0, kvar, NULL, sizeof(void *) * 2,
|
||||||
KOFF(ki_tdaddr), KPTR, "lx", 0},
|
KOFF(ki_tdaddr), KPTR, "lx", 0},
|
||||||
{"tdev", "TDEV", NULL, 0, tdev, NULL, 5, 0, CHAR, NULL, 0},
|
{"tdev", "TDEV", NULL, 0, tdev, NULL, 5, 0, CHAR, NULL, 0},
|
||||||
@ -210,6 +211,8 @@ static VAR var[] = {
|
|||||||
KOFF(ki_paddr), KPTR, "lx", 0},
|
KOFF(ki_paddr), KPTR, "lx", 0},
|
||||||
{"user", "USER", NULL, LJUST|DSIZ, uname, s_uname, USERLEN, 0, CHAR,
|
{"user", "USER", NULL, LJUST|DSIZ, uname, s_uname, USERLEN, 0, CHAR,
|
||||||
NULL, 0},
|
NULL, 0},
|
||||||
|
{"usertime", "USERTIME", NULL, USER, usertime, NULL, 9, 0, CHAR, NULL,
|
||||||
|
0},
|
||||||
{"usrpri", "", "upr", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
|
{"usrpri", "", "upr", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
|
||||||
{"vsize", "", "vsz", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
|
{"vsize", "", "vsz", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
|
||||||
{"vsz", "VSZ", NULL, 0, vsize, NULL, 6, 0, CHAR, NULL, 0},
|
{"vsz", "VSZ", NULL, 0, vsize, NULL, 6, 0, CHAR, NULL, 0},
|
||||||
|
@ -550,12 +550,11 @@ vsize(KINFO *k, VARENT *ve)
|
|||||||
(void)printf("%*lu", v->width, (u_long)(k->ki_p->ki_size / 1024));
|
(void)printf("%*lu", v->width, (u_long)(k->ki_p->ki_size / 1024));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
cputime(KINFO *k, VARENT *ve)
|
printtime(KINFO *k, VARENT *ve, long secs, long psecs)
|
||||||
|
/* psecs is "parts" of a second. first micro, then centi */
|
||||||
{
|
{
|
||||||
VAR *v;
|
VAR *v;
|
||||||
long secs;
|
|
||||||
long psecs; /* "parts" of a second. first micro, then centi */
|
|
||||||
char obuff[128];
|
char obuff[128];
|
||||||
static char decimal_point;
|
static char decimal_point;
|
||||||
|
|
||||||
@ -566,20 +565,7 @@ cputime(KINFO *k, VARENT *ve)
|
|||||||
secs = 0;
|
secs = 0;
|
||||||
psecs = 0;
|
psecs = 0;
|
||||||
} else {
|
} else {
|
||||||
/*
|
/* round and scale to 100's */
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
psecs = (psecs + 5000) / 10000;
|
psecs = (psecs + 5000) / 10000;
|
||||||
secs += psecs / 100;
|
secs += psecs / 100;
|
||||||
psecs = psecs % 100;
|
psecs = psecs % 100;
|
||||||
@ -589,6 +575,53 @@ cputime(KINFO *k, VARENT *ve)
|
|||||||
(void)printf("%*s", v->width, obuff);
|
(void)printf("%*s", v->width, obuff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
void
|
||||||
elapsed(KINFO *k, VARENT *ve)
|
elapsed(KINFO *k, VARENT *ve)
|
||||||
{
|
{
|
||||||
|
10
bin/ps/ps.1
10
bin/ps/ps.1
@ -29,7 +29,7 @@
|
|||||||
.\" @(#)ps.1 8.3 (Berkeley) 4/18/94
|
.\" @(#)ps.1 8.3 (Berkeley) 4/18/94
|
||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd March 5, 2011
|
.Dd March 16, 2011
|
||||||
.Dt PS 1
|
.Dt PS 1
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@ -205,8 +205,8 @@ Display information about processes which match the specified process IDs.
|
|||||||
Sort by current CPU usage, instead of the combination of controlling
|
Sort by current CPU usage, instead of the combination of controlling
|
||||||
terminal and process ID.
|
terminal and process ID.
|
||||||
.It Fl S
|
.It Fl S
|
||||||
Change the way the process time is calculated by summing all exited
|
Change the way the process times, namely cputime, systime, and usertime,
|
||||||
children to their parent process.
|
are calculated by summing all exited children to their parent process.
|
||||||
.It Fl T
|
.It Fl T
|
||||||
Display information about processes attached to the device associated
|
Display information about processes attached to the device associated
|
||||||
with the standard input.
|
with the standard input.
|
||||||
@ -596,6 +596,8 @@ symbolic process state (alias
|
|||||||
saved gid from a setgid executable
|
saved gid from a setgid executable
|
||||||
.It Cm svuid
|
.It Cm svuid
|
||||||
saved UID from a setuid executable
|
saved UID from a setuid executable
|
||||||
|
.It Cm systime
|
||||||
|
accumulated system CPU time
|
||||||
.It Cm tdaddr
|
.It Cm tdaddr
|
||||||
thread address
|
thread address
|
||||||
.It Cm tdev
|
.It Cm tdev
|
||||||
@ -626,6 +628,8 @@ scheduling priority on return from system call (alias
|
|||||||
.Cm usrpri )
|
.Cm usrpri )
|
||||||
.It Cm user
|
.It Cm user
|
||||||
user name (from UID)
|
user name (from UID)
|
||||||
|
.It Cm usertime
|
||||||
|
accumulated user CPU time
|
||||||
.It Cm vsz
|
.It Cm vsz
|
||||||
virtual size in Kbytes (alias
|
virtual size in Kbytes (alias
|
||||||
.Cm vsize )
|
.Cm vsize )
|
||||||
|
Loading…
Reference in New Issue
Block a user