No functional changes. Cleanup time printing code so it can be used
elsewhere in the tree.
This commit is contained in:
parent
dd27ab284c
commit
271dc0c3c3
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: extern.h,v 1.17 2005/06/26 19:10:48 christos Exp $ */
|
||||
/* $NetBSD: extern.h,v 1.18 2007/02/24 21:29:13 matt Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993
|
||||
|
@ -288,11 +288,10 @@ void plist(struct varent *);
|
|||
*/
|
||||
void donice(Char **, struct command *);
|
||||
void dotime(Char **, struct command *);
|
||||
void prusage(struct rusage *, struct rusage *, struct timeval *,
|
||||
void prusage(FILE *, struct rusage *, struct rusage *, struct timeval *,
|
||||
struct timeval *);
|
||||
void ruadd(struct rusage *, struct rusage *);
|
||||
void settimes(void);
|
||||
void pcsecs(long);
|
||||
void psecs(long);
|
||||
|
||||
/*
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: proc.c,v 1.29 2005/06/26 19:10:48 christos Exp $ */
|
||||
/* $NetBSD: proc.c,v 1.30 2007/02/24 21:29:13 matt Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1980, 1991, 1993
|
||||
|
@ -34,7 +34,7 @@
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)proc.c 8.1 (Berkeley) 5/31/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: proc.c,v 1.29 2005/06/26 19:10:48 christos Exp $");
|
||||
__RCSID("$NetBSD: proc.c,v 1.30 2007/02/24 21:29:13 matt Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
|
@ -769,7 +769,7 @@ prcomd:
|
|||
if (pp->p_flags & PPTIME && !(status & (PSTOPPED | PRUNNING))) {
|
||||
if (!hadnl)
|
||||
(void)fprintf(cshout, "\n\t");
|
||||
prusage(&zru, &pp->p_rusage, &pp->p_etime,
|
||||
prusage(cshout, &zru, &pp->p_rusage, &pp->p_etime,
|
||||
&pp->p_btime);
|
||||
hadnl = 1;
|
||||
}
|
||||
|
@ -814,7 +814,7 @@ ptprint(struct process *tp)
|
|||
if (timercmp(&diff, &tetime, >))
|
||||
tetime = diff;
|
||||
} while ((pp = pp->p_friends) != tp);
|
||||
prusage(&zru, &ru, &tetime, &ztime);
|
||||
prusage(cshout, &zru, &ru, &tetime, &ztime);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: time.c,v 1.15 2005/06/26 19:10:48 christos Exp $ */
|
||||
/* $NetBSD: time.c,v 1.16 2007/02/24 21:29:13 matt Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1980, 1991, 1993
|
||||
|
@ -34,23 +34,25 @@
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)time.c 8.1 (Berkeley) 5/31/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: time.c,v 1.15 2005/06/26 19:10:48 christos Exp $");
|
||||
__RCSID("$NetBSD: time.c,v 1.16 2007/02/24 21:29:13 matt Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef NOT_CSH
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "csh.h"
|
||||
#include "extern.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* C Shell - routines handling process timing and niceing
|
||||
*/
|
||||
static void pdeltat(struct timeval *, struct timeval *);
|
||||
extern char *strpct(u_long num, u_long denom, u_int digits);
|
||||
static void pdeltat(FILE *, struct timeval *, struct timeval *);
|
||||
static void pcsecs(FILE *, long);
|
||||
extern char *strpct(u_long, u_long, u_int);
|
||||
|
||||
#ifndef NOT_CSH
|
||||
void
|
||||
settimes(void)
|
||||
{
|
||||
|
@ -77,7 +79,7 @@ dotime(Char **v, struct command *t)
|
|||
(void)getrusage(RUSAGE_CHILDREN, &ruch);
|
||||
ruadd(&ru1, &ruch);
|
||||
(void)gettimeofday(&timedol, NULL);
|
||||
prusage(&ru0, &ru1, &timedol, &time0);
|
||||
prusage(cshout, &ru0, &ru1, &timedol, &time0);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -122,12 +124,15 @@ ruadd(struct rusage *ru, struct rusage *ru2)
|
|||
ru->ru_nvcsw += ru2->ru_nvcsw;
|
||||
ru->ru_nivcsw += ru2->ru_nivcsw;
|
||||
}
|
||||
#endif /* NOT_CSH */
|
||||
|
||||
void
|
||||
prusage(struct rusage *r0, struct rusage *r1, struct timeval *e,
|
||||
prusage(FILE *fp, struct rusage *r0, struct rusage *r1, struct timeval *e,
|
||||
struct timeval *b)
|
||||
{
|
||||
#ifndef NOT_CSH
|
||||
struct varent *vp;
|
||||
#endif
|
||||
const char *cp;
|
||||
long i;
|
||||
time_t t;
|
||||
|
@ -139,97 +144,100 @@ prusage(struct rusage *r0, struct rusage *r1, struct timeval *e,
|
|||
(r1->ru_utime.tv_usec - r0->ru_utime.tv_usec) / 10000 +
|
||||
(r1->ru_stime.tv_sec - r0->ru_stime.tv_sec) * 100 +
|
||||
(r1->ru_stime.tv_usec - r0->ru_stime.tv_usec) / 10000;
|
||||
#ifndef NOT_CSH
|
||||
vp = adrof(STRtime);
|
||||
|
||||
if (vp && vp->vec[0] && vp->vec[1])
|
||||
cp = short2str(vp->vec[1]);
|
||||
#endif
|
||||
|
||||
for (; *cp; cp++)
|
||||
if (*cp != '%')
|
||||
(void) fputc(*cp, cshout);
|
||||
(void) fputc(*cp, fp);
|
||||
else if (cp[1])
|
||||
switch (*++cp) {
|
||||
case 'D': /* (average) unshared data size */
|
||||
(void)fprintf(cshout, "%ld", t == 0 ? 0L :
|
||||
(void)fprintf(fp, "%ld", t == 0 ? 0L :
|
||||
(r1->ru_idrss + r1->ru_isrss -
|
||||
(r0->ru_idrss + r0->ru_isrss)) / t);
|
||||
break;
|
||||
case 'E': /* elapsed (wall-clock) time */
|
||||
pcsecs((long) ms);
|
||||
pcsecs(fp, (long) ms);
|
||||
break;
|
||||
case 'F': /* page faults */
|
||||
(void)fprintf(cshout, "%ld", r1->ru_majflt - r0->ru_majflt);
|
||||
(void)fprintf(fp, "%ld", r1->ru_majflt - r0->ru_majflt);
|
||||
break;
|
||||
case 'I': /* FS blocks in */
|
||||
(void)fprintf(cshout, "%ld", r1->ru_inblock - r0->ru_inblock);
|
||||
(void)fprintf(fp, "%ld", r1->ru_inblock - r0->ru_inblock);
|
||||
break;
|
||||
case 'K': /* (average) total data memory used */
|
||||
(void)fprintf(cshout, "%ld", t == 0 ? 0L :
|
||||
(void)fprintf(fp, "%ld", t == 0 ? 0L :
|
||||
((r1->ru_ixrss + r1->ru_isrss + r1->ru_idrss) -
|
||||
(r0->ru_ixrss + r0->ru_idrss + r0->ru_isrss)) / t);
|
||||
break;
|
||||
case 'M': /* max. Resident Set Size */
|
||||
(void)fprintf(cshout, "%ld", r1->ru_maxrss / 2L);
|
||||
(void)fprintf(fp, "%ld", r1->ru_maxrss / 2L);
|
||||
break;
|
||||
case 'O': /* FS blocks out */
|
||||
(void)fprintf(cshout, "%ld", r1->ru_oublock - r0->ru_oublock);
|
||||
(void)fprintf(fp, "%ld", r1->ru_oublock - r0->ru_oublock);
|
||||
break;
|
||||
case 'P': /* percent time spent running */
|
||||
/* check if it did not run at all */
|
||||
if (ms == 0) {
|
||||
(void)fputs("0.0%", cshout);
|
||||
(void)fputs("0.0%", fp);
|
||||
} else {
|
||||
(void)fputs(strpct((ulong)t, (ulong)ms, 1), cshout);
|
||||
(void)fputs(strpct((ulong)t, (ulong)ms, 1), fp);
|
||||
}
|
||||
break;
|
||||
case 'R': /* page reclaims */
|
||||
(void)fprintf(cshout, "%ld", r1->ru_minflt - r0->ru_minflt);
|
||||
(void)fprintf(fp, "%ld", r1->ru_minflt - r0->ru_minflt);
|
||||
break;
|
||||
case 'S': /* system CPU time used */
|
||||
pdeltat(&r1->ru_stime, &r0->ru_stime);
|
||||
pdeltat(fp, &r1->ru_stime, &r0->ru_stime);
|
||||
break;
|
||||
case 'U': /* user CPU time used */
|
||||
pdeltat(&r1->ru_utime, &r0->ru_utime);
|
||||
pdeltat(fp, &r1->ru_utime, &r0->ru_utime);
|
||||
break;
|
||||
case 'W': /* number of swaps */
|
||||
i = r1->ru_nswap - r0->ru_nswap;
|
||||
(void)fprintf(cshout, "%ld", i);
|
||||
(void)fprintf(fp, "%ld", i);
|
||||
break;
|
||||
case 'X': /* (average) shared text size */
|
||||
(void)fprintf(cshout, "%ld", t == 0 ? 0L :
|
||||
(void)fprintf(fp, "%ld", t == 0 ? 0L :
|
||||
(r1->ru_ixrss - r0->ru_ixrss) / t);
|
||||
break;
|
||||
case 'c': /* num. involuntary context switches */
|
||||
(void)fprintf(cshout, "%ld", r1->ru_nivcsw - r0->ru_nivcsw);
|
||||
(void)fprintf(fp, "%ld", r1->ru_nivcsw - r0->ru_nivcsw);
|
||||
break;
|
||||
case 'k': /* number of signals received */
|
||||
(void)fprintf(cshout, "%ld", r1->ru_nsignals-r0->ru_nsignals);
|
||||
(void)fprintf(fp, "%ld", r1->ru_nsignals-r0->ru_nsignals);
|
||||
break;
|
||||
case 'r': /* socket messages received */
|
||||
(void)fprintf(cshout, "%ld", r1->ru_msgrcv - r0->ru_msgrcv);
|
||||
(void)fprintf(fp, "%ld", r1->ru_msgrcv - r0->ru_msgrcv);
|
||||
break;
|
||||
case 's': /* socket messages sent */
|
||||
(void)fprintf(cshout, "%ld", r1->ru_msgsnd - r0->ru_msgsnd);
|
||||
(void)fprintf(fp, "%ld", r1->ru_msgsnd - r0->ru_msgsnd);
|
||||
break;
|
||||
case 'w': /* num. voluntary context switches (waits) */
|
||||
(void)fprintf(cshout, "%ld", r1->ru_nvcsw - r0->ru_nvcsw);
|
||||
(void)fprintf(fp, "%ld", r1->ru_nvcsw - r0->ru_nvcsw);
|
||||
break;
|
||||
}
|
||||
(void)fputc('\n', cshout);
|
||||
(void)fputc('\n', fp);
|
||||
}
|
||||
|
||||
static void
|
||||
pdeltat(struct timeval *t1, struct timeval *t0)
|
||||
pdeltat(FILE *fp, struct timeval *t1, struct timeval *t0)
|
||||
{
|
||||
struct timeval td;
|
||||
|
||||
timersub(t1, t0, &td);
|
||||
(void)fprintf(cshout, "%ld.%01ld", (long)td.tv_sec,
|
||||
(void)fprintf(fp, "%ld.%01ld", (long)td.tv_sec,
|
||||
(long)(td.tv_usec / 100000));
|
||||
}
|
||||
|
||||
#define P2DIG(i) (void)fprintf(cshout, "%d%d", (i) / 10, (i) % 10)
|
||||
#define P2DIG(fp, i) (void)fprintf(fp, "%d%d", (i) / 10, (i) % 10)
|
||||
|
||||
#ifndef NOT_CSH
|
||||
void
|
||||
psecs(long l)
|
||||
{
|
||||
|
@ -239,7 +247,7 @@ psecs(long l)
|
|||
if (i) {
|
||||
(void)fprintf(cshout, "%d:", i);
|
||||
i = l % 3600;
|
||||
P2DIG(i / 60);
|
||||
P2DIG(cshout, i / 60);
|
||||
goto minsec;
|
||||
}
|
||||
i = l;
|
||||
|
@ -247,27 +255,28 @@ psecs(long l)
|
|||
minsec:
|
||||
i %= 60;
|
||||
(void)fputc(':', cshout);
|
||||
P2DIG(i);
|
||||
P2DIG(cshout, i);
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
pcsecs(long l) /* PWP: print mm:ss.dd, l is in sec*100 */
|
||||
static void
|
||||
pcsecs(FILE *fp, long l) /* PWP: print mm:ss.dd, l is in sec*100 */
|
||||
{
|
||||
int i;
|
||||
|
||||
i = l / 360000;
|
||||
if (i) {
|
||||
(void)fprintf(cshout, "%d:", i);
|
||||
(void)fprintf(fp, "%d:", i);
|
||||
i = (l % 360000) / 100;
|
||||
P2DIG(i / 60);
|
||||
P2DIG(fp, i / 60);
|
||||
goto minsec;
|
||||
}
|
||||
i = l / 100;
|
||||
(void)fprintf(cshout, "%d", i / 60);
|
||||
(void)fprintf(fp, "%d", i / 60);
|
||||
minsec:
|
||||
i %= 60;
|
||||
(void)fputc(':', cshout);
|
||||
P2DIG(i);
|
||||
(void)fputc('.', cshout);
|
||||
P2DIG((int) (l % 100));
|
||||
(void)fputc(':', fp);
|
||||
P2DIG(fp, i);
|
||||
(void)fputc('.', fp);
|
||||
P2DIG(fp, (int) (l % 100));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue