Implement a SUSv3-ignorant but "time"-similar format for "etime", elapsed
run time (NOT cpu time). cputime() and elapsed() both need to honour SUSv3 now.
This commit is contained in:
parent
4049699b95
commit
76e1a9fe48
@ -49,6 +49,7 @@ void arguments(KINFO *, VARENT *);
|
||||
void command(KINFO *, VARENT *);
|
||||
void cputime(KINFO *, VARENT *);
|
||||
int donlist(void);
|
||||
void elapsed(KINFO *, VARENT *);
|
||||
const char *fmt_argv(char **, char *, size_t);
|
||||
double getpcpu(const KINFO *);
|
||||
void kvar(KINFO *, VARENT *);
|
||||
|
@ -96,6 +96,7 @@ static VAR var[] = {
|
||||
{"cpu", "CPU", NULL, 0, kvar, NULL, 3, KOFF(ki_estcpu), UINT, "d",
|
||||
0},
|
||||
{"cputime", "", "time", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
|
||||
{"etime", "ELAPSED", NULL, USER, elapsed, NULL, 9, 0, CHAR, NULL, 0},
|
||||
{"f", "F", NULL, 0, kvar, NULL, 7, KOFF(ki_flag), INT, "x", 0},
|
||||
{"flags", "", "f", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
|
||||
{"ignored", "", "sigignore", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
|
||||
|
@ -535,6 +535,23 @@ cputime(KINFO *k, VARENT *ve)
|
||||
(void)printf("%*s", v->width, obuff);
|
||||
}
|
||||
|
||||
void
|
||||
elapsed(KINFO *k, VARENT *ve)
|
||||
{
|
||||
VAR *v;
|
||||
time_t secs;
|
||||
char obuff[128];
|
||||
static time_t now;
|
||||
|
||||
v = ve->var;
|
||||
|
||||
if (!now)
|
||||
time(&now);
|
||||
secs = now - k->ki_p->ki_start.tv_sec;
|
||||
(void)snprintf(obuff, sizeof(obuff), "%3ld:%02ld", secs/60, secs%60);
|
||||
(void)printf("%*s", v->width, obuff);
|
||||
}
|
||||
|
||||
double
|
||||
getpcpu(const KINFO *k)
|
||||
{
|
||||
|
@ -378,6 +378,8 @@ command
|
||||
command and arguments
|
||||
.It cpu
|
||||
short-term cpu usage factor (for scheduling)
|
||||
.It etime
|
||||
elapsed running time
|
||||
.It flags
|
||||
the process flags, in hexadecimal (alias f)
|
||||
.It inblk
|
||||
|
Loading…
x
Reference in New Issue
Block a user