Deleted Added
full compact
39c39
< __FBSDID("$FreeBSD: head/usr.sbin/sa/main.c 169670 2007-05-18 12:36:10Z dds $");
---
> __FBSDID("$FreeBSD: head/usr.sbin/sa/main.c 169857 2007-05-22 06:51:38Z dds $");
48a49
> #include <errno.h>
59,69c60,69
< static int acct_load(const char *, int);
< static u_quad_t decode_comp_t(comp_t);
< static int cmp_comm(const char *, const char *);
< static int cmp_usrsys(const DBT *, const DBT *);
< static int cmp_avgusrsys(const DBT *, const DBT *);
< static int cmp_dkio(const DBT *, const DBT *);
< static int cmp_avgdkio(const DBT *, const DBT *);
< static int cmp_cpumem(const DBT *, const DBT *);
< static int cmp_avgcpumem(const DBT *, const DBT *);
< static int cmp_calls(const DBT *, const DBT *);
< static void usage(void);
---
> static FILE *acct_load(const char *, int);
> static int cmp_comm(const char *, const char *);
> static int cmp_usrsys(const DBT *, const DBT *);
> static int cmp_avgusrsys(const DBT *, const DBT *);
> static int cmp_dkio(const DBT *, const DBT *);
> static int cmp_avgdkio(const DBT *, const DBT *);
> static int cmp_cpumem(const DBT *, const DBT *);
> static int cmp_avgcpumem(const DBT *, const DBT *);
> static int cmp_calls(const DBT *, const DBT *);
> static void usage(void);
85a86
> FILE *f;
213,214d213
< int fd;
<
219,220c218,219
< fd = acct_load(argv[0], sflag);
< if (fd < 0)
---
> f = acct_load(argv[0], sflag);
> if (f == NULL)
251c250
< if (ftruncate(fd, 0) == -1) {
---
> if (ftruncate(fileno(f), 0) == -1) {
278,279c277,278
< if (close(fd) == -1) {
< warn("close %s", *argv);
---
> if (fclose(f) == EOF) {
> warn("fclose %s", *argv);
311c310
< static int
---
> static FILE *
314c313
< struct acct ac;
---
> struct acctv2 ac;
317c316,317
< int fd, i;
---
> FILE *f;
> int i;
322,323c322,323
< fd = open(pn, wr ? O_RDWR : O_RDONLY, 0);
< if (fd == -1) {
---
> f = fopen(pn, wr ? "r+" : "r");
> if (f == NULL) {
325c325
< return (-1);
---
> return (NULL);
334,339c334,337
< rv = read(fd, &ac, sizeof(struct acct));
< if (rv == -1)
< warn("error reading %s", pn);
< else if (rv > 0 && rv < (int)sizeof(struct acct))
< warnx("short read of accounting data in %s", pn);
< if (rv != sizeof(struct acct))
---
> rv = readrec_forward(f, &ac);
> if (rv != 1) {
> if (rv == EOF)
> warn("error reading %s", pn);
340a339
> }
354c353
< if (ac.ac_flag & AFORK)
---
> if (ac.ac_flagx & AFORK)
357,359c356,358
< ci.ci_etime = decode_comp_t(ac.ac_etime);
< ci.ci_utime = decode_comp_t(ac.ac_utime);
< ci.ci_stime = decode_comp_t(ac.ac_stime);
---
> ci.ci_etime = ac.ac_etime;
> ci.ci_utime = ac.ac_utime;
> ci.ci_stime = ac.ac_stime;
362c361
< ci.ci_io = decode_comp_t(ac.ac_io) / AHZ;
---
> ci.ci_io = ac.ac_io;
371c370
< printf("%6lu %12.2f cpu %12juk mem %12ju io %s\n",
---
> printf("%6u %12.3lf cpu %12.0lfk mem %12.0lf io %s\n",
373,374c372,373
< (ci.ci_utime + ci.ci_stime) / (double) AHZ,
< (uintmax_t)ci.ci_mem, (uintmax_t)ci.ci_io,
---
> (ci.ci_utime + ci.ci_stime) / 1000000,
> ci.ci_mem, ci.ci_io,
378,379c377,378
< /* finally, return the file descriptor for possible truncation */
< return (fd);
---
> /* Finally, return the file stream for possible truncation. */
> return (f);
382,400d380
< static u_quad_t
< decode_comp_t(comp_t comp)
< {
< u_quad_t rv;
<
< /*
< * for more info on the comp_t format, see:
< * /usr/src/sys/kern/kern_acct.c
< * /usr/src/sys/sys/acct.h
< * /usr/src/usr.bin/lastcomm/lastcomm.c
< */
< rv = comp & 0x1fff; /* 13 bit fraction */
< comp >>= 13; /* 3 bit base-8 exponent */
< while (comp--)
< rv <<= 3;
<
< return (rv);
< }
<
418c398
< u_quad_t t1, t2;
---
> double t1, t2;
485,486c465,466
< n1 = (double) c1.ci_io / (double) (c1.ci_calls ? c1.ci_calls : 1);
< n2 = (double) c2.ci_io / (double) (c2.ci_calls ? c2.ci_calls : 1);
---
> n1 = c1.ci_io / (double) (c1.ci_calls ? c1.ci_calls : 1);
> n2 = c2.ci_io / (double) (c2.ci_calls ? c2.ci_calls : 1);
518c498
< u_quad_t t1, t2;
---
> double t1, t2;
527,528c507,508
< n1 = (double) c1.ci_mem / (double) (t1 ? t1 : 1);
< n2 = (double) c2.ci_mem / (double) (t2 ? t2 : 1);
---
> n1 = c1.ci_mem / (t1 ? t1 : 1);
> n2 = c2.ci_mem / (t2 ? t2 : 1);