Exemplo n.º 1
0
void
prusage(struct rusage *r0, struct rusage *r1, struct timespec *e,
    struct timespec *b)
{
    time_t t =
    (r1->ru_utime.tv_sec - r0->ru_utime.tv_sec) * 100 +
    (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;
    char *cp;
    long i;
    struct varent *vp = adrof(STRtime);

    int     ms =
    (e->tv_sec - b->tv_sec) * 100 + (e->tv_nsec - b->tv_nsec) / 10000000;

    cp = "%Uu %Ss %E %P %X+%Dk %I+%Oio %Fpf+%Ww";

    if (vp && vp->vec[0] && vp->vec[1])
	cp = short2str(vp->vec[1]);

    for (; *cp; cp++)
	if (*cp != '%')
	    (void) fputc(*cp, cshout);
	else if (cp[1])
	    switch (*++cp) {

	    case 'U':		/* user CPU time used */
		pdeltat(&r1->ru_utime, &r0->ru_utime);
		break;

	    case 'S':		/* system CPU time used */
		pdeltat(&r1->ru_stime, &r0->ru_stime);
		break;

	    case 'E':		/* elapsed (wall-clock) time */
		pcsecs((long) ms);
		break;

	    case 'P':		/* percent time spent running */
		/* check if it did not run at all */
		i = (ms == 0) ? 0 : ((long long)t * 1000 / ms);
		/* nn.n% */
		(void) fprintf(cshout, "%ld.%01ld%%", i / 10, i % 10);
		break;

	    case 'W':		/* number of swaps */
		i = r1->ru_nswap - r0->ru_nswap;
		(void) fprintf(cshout, "%ld", i);
		break;

	    case 'X':		/* (average) shared text size */
		(void) fprintf(cshout, "%ld", t == 0 ? 0L :
			       (long)((r1->ru_ixrss - r0->ru_ixrss) / t));
		break;

	    case 'D':		/* (average) unshared data size */
		(void) fprintf(cshout, "%ld", t == 0 ? 0L :
			(long)((r1->ru_idrss + r1->ru_isrss -
			       (r0->ru_idrss + r0->ru_isrss)) / t));
		break;

	    case 'K':		/* (average) total data memory used  */
		(void) fprintf(cshout, "%ld", t == 0 ? 0L :
			(long)(((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);
		break;

	    case 'F':		/* page faults */
		(void) fprintf(cshout, "%ld", r1->ru_majflt - r0->ru_majflt);
		break;

	    case 'R':		/* page reclaims */
		(void) fprintf(cshout, "%ld", r1->ru_minflt - r0->ru_minflt);
		break;

	    case 'I':		/* FS blocks in */
		(void) fprintf(cshout, "%ld", r1->ru_inblock - r0->ru_inblock);
		break;

	    case 'O':		/* FS blocks out */
		(void) fprintf(cshout, "%ld", r1->ru_oublock - r0->ru_oublock);
		break;

	    case 'r':		/* socket messages received */
		(void) fprintf(cshout, "%ld", r1->ru_msgrcv - r0->ru_msgrcv);
		break;

	    case 's':		/* socket messages sent */
		(void) fprintf(cshout, "%ld", r1->ru_msgsnd - r0->ru_msgsnd);
		break;

	    case 'k':		/* number of signals received */
		(void) fprintf(cshout, "%ld", r1->ru_nsignals-r0->ru_nsignals);
		break;

	    case 'w':		/* num. voluntary context switches (waits) */
		(void) fprintf(cshout, "%ld", r1->ru_nvcsw - r0->ru_nvcsw);
		break;

	    case 'c':		/* num. involuntary context switches */
		(void) fprintf(cshout, "%ld", r1->ru_nivcsw - r0->ru_nivcsw);
		break;
	    }
    (void) fputc('\n', cshout);
}
Exemplo n.º 2
0
void
prusage(struct rusage *r0, struct rusage *r1, struct timeval *e,
	struct timeval *b)
{
#define	pgtok(p)	((p * pgsize) / 1024)
	static int	pgsize;

	time_t t =
	    (r1->ru_utime.tv_sec - r0->ru_utime.tv_sec) * 100 +
	    (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;
	tchar *cp;
	int i;
	struct varent *vp = adrof(S_time);
	int ms =
	    (e->tv_sec - b->tv_sec) * 100 + (e->tv_usec - b->tv_usec) / 10000;

#ifdef TRACE
	tprintf("TRACE- prusage()\n");
#endif
	if (pgsize == 0) {
		pgsize = getpagesize();
	}

	cp = S_USAGEFORMAT;	/* "%Uu %Ss %E %P %X+%Dk %I+%Oio %Fpf+%Ww" */
	if (vp && vp->vec[0] && vp->vec[1]) {
		cp = vp->vec[1];
	}
	for (; *cp; cp++) {
		if (*cp != '%') {
			Putchar(*cp);
		} else if (cp[1]) {
			switch (*++cp) {

			case 'U':
				pdeltat(&r1->ru_utime, &r0->ru_utime);
				break;

			case 'S':
				pdeltat(&r1->ru_stime, &r0->ru_stime);
				break;

			case 'E':
				psecs_int(ms / 100);
				break;

			case 'P':
				printf("%d%%", (int)(t * 100 /
				    ((ms ? ms : 1))));
				break;

			case 'W':
				i = r1->ru_nswap - r0->ru_nswap;
				printf("%d", i);
				break;

			case 'X':
				printf("%d", t == 0 ? 0 :
				    pgtok((r1->ru_ixrss - r0->ru_ixrss) / t));
				break;

			case 'D':
				printf("%d", t == 0 ? 0 :
				    pgtok((r1->ru_idrss + r1->ru_isrss-
				    (r0->ru_idrss + r0->ru_isrss)) / t));
				break;

			case 'K':
				printf("%d", t == 0 ? 0 :
				    pgtok(((r1->ru_ixrss + r1->ru_isrss +
				    r1->ru_idrss) - (r0->ru_ixrss +
				    r0->ru_idrss + r0->ru_isrss)) / t));
				break;

			case 'M':
				printf("%d", r1->ru_maxrss / 2);
				break;

			case 'F':
				printf("%d", r1->ru_majflt - r0->ru_majflt);
				break;

			case 'R':
				printf("%d", r1->ru_minflt - r0->ru_minflt);
				break;

			case 'I':
				printf("%d", r1->ru_inblock - r0->ru_inblock);
				break;

			case 'O':
				printf("%d", r1->ru_oublock - r0->ru_oublock);
				break;
			}
		}
	}
	Putchar('\n');
#undef	pgtok
}
Exemplo n.º 3
0
void
prusage1(FILE *fp, const char *cp, struct rusage *r0, struct rusage *r1,
    struct timespec *e, struct timespec *b)
{
    long i;
    time_t t;
    time_t ms;

    ms = (e->tv_sec - b->tv_sec) * 100 + (e->tv_nsec - b->tv_nsec) / 10000000;
    t = (r1->ru_utime.tv_sec - r0->ru_utime.tv_sec) * 100 +
        (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;

    for (; *cp; cp++)
	if (*cp != '%')
	    (void) fputc(*cp, fp);
	else if (cp[1])
	    switch (*++cp) {
	    case 'D':		/* (average) unshared data size */
		(void)fprintf(fp, "%ld", t == 0 ? 0L :
			(long)((r1->ru_idrss + r1->ru_isrss -
			 (r0->ru_idrss + r0->ru_isrss)) / t));
		break;
	    case 'E':		/* elapsed (wall-clock) time */
		pcsecs(fp, (long) ms);
		break;
	    case 'F':		/* page faults */
		(void)fprintf(fp, "%ld", r1->ru_majflt - r0->ru_majflt);
		break;
	    case 'I':		/* FS blocks in */
		(void)fprintf(fp, "%ld", r1->ru_inblock - r0->ru_inblock);
		break;
	    case 'K':		/* (average) total data memory used  */
		(void)fprintf(fp, "%ld", t == 0 ? 0L :
			(long)(((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(fp, "%ld", r1->ru_maxrss / 2L);
		break;
	    case 'O':		/* FS blocks out */
		(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%", fp);
		} else {
			char pb[32];
			(void)fputs(strpct(pb, sizeof(pb),
			    (uintmax_t)t, (uintmax_t)ms, 1), fp);
			(void)fputc('%', fp);
		}
		break;
	    case 'R':		/* page reclaims */
		(void)fprintf(fp, "%ld", r1->ru_minflt - r0->ru_minflt);
		break;
	    case 'S':		/* system CPU time used */
		pdeltat(fp, &r1->ru_stime, &r0->ru_stime);
		break;
	    case 'U':		/* user CPU time used */
		pdeltat(fp, &r1->ru_utime, &r0->ru_utime);
		break;
	    case 'W':		/* number of swaps */
		i = r1->ru_nswap - r0->ru_nswap;
		(void)fprintf(fp, "%ld", i);
		break;
	    case 'X':		/* (average) shared text size */
		(void)fprintf(fp, "%ld", t == 0 ? 0L : 
			       (long)((r1->ru_ixrss - r0->ru_ixrss) / t));
		break;
	    case 'c':		/* num. involuntary context switches */
		(void)fprintf(fp, "%ld", r1->ru_nivcsw - r0->ru_nivcsw);
		break;
	    case 'k':		/* number of signals received */
		(void)fprintf(fp, "%ld", r1->ru_nsignals-r0->ru_nsignals);
		break;
	    case 'r':		/* socket messages received */
		(void)fprintf(fp, "%ld", r1->ru_msgrcv - r0->ru_msgrcv);
		break;
	    case 's':		/* socket messages sent */
		(void)fprintf(fp, "%ld", r1->ru_msgsnd - r0->ru_msgsnd);
		break;
	    case 'w':		/* num. voluntary context switches (waits) */
		(void)fprintf(fp, "%ld", r1->ru_nvcsw - r0->ru_nvcsw);
		break;
	    }
    (void)fputc('\n', fp);
}