summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormickey <mickey@openbsd.org>2006-03-26 17:47:10 +0000
committermickey <mickey@openbsd.org>2006-03-26 17:47:10 +0000
commitb1cf27f7d2c97c06b21f0130514fda54d69a33f7 (patch)
tree04cd028d798cfa7df4a7acf8ac845a9d08eee4c9
parentdo not permit out of range house counts; af.dingo@gmail (diff)
downloadwireguard-openbsd-b1cf27f7d2c97c06b21f0130514fda54d69a33f7.tar.xz
wireguard-openbsd-b1cf27f7d2c97c06b21f0130514fda54d69a33f7.zip
do per file io accounting and show that in fstat as well; pedro@ marco@ ok
-rw-r--r--sys/kern/sys_generic.c17
-rw-r--r--sys/kern/uipc_syscalls.c11
-rw-r--r--sys/kern/vfs_syscalls.c3
-rw-r--r--sys/sys/file.h7
-rw-r--r--usr.bin/fstat/fstat.c84
-rw-r--r--usr.bin/fstat/fstat.h6
6 files changed, 88 insertions, 40 deletions
diff --git a/sys/kern/sys_generic.c b/sys/kern/sys_generic.c
index 548b2ef82fb..f620f8c3217 100644
--- a/sys/kern/sys_generic.c
+++ b/sys/kern/sys_generic.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sys_generic.c,v 1.52 2006/03/15 11:22:16 claudio Exp $ */
+/* $OpenBSD: sys_generic.c,v 1.53 2006/03/26 17:47:10 mickey Exp $ */
/* $NetBSD: sys_generic.c,v 1.24 1996/03/29 00:25:32 cgd Exp $ */
/*
@@ -138,6 +138,9 @@ dofileread(struct proc *p, int fd, struct file *fp, void *buf, size_t nbyte,
error == EINTR || error == EWOULDBLOCK))
error = 0;
cnt -= auio.uio_resid;
+
+ fp->f_rxfer++;
+ fp->f_rbytes += cnt;
#ifdef KTRACE
if (KTRPOINT(p, KTR_GENIO) && error == 0)
ktrgenio(p, fd, UIO_READ, &ktriov, cnt, error);
@@ -243,6 +246,9 @@ dofilereadv(struct proc *p, int fd, struct file *fp, const struct iovec *iovp,
error == EINTR || error == EWOULDBLOCK))
error = 0;
cnt -= auio.uio_resid;
+
+ fp->f_rxfer++;
+ fp->f_rbytes += cnt;
#ifdef KTRACE
if (ktriov != NULL) {
if (error == 0)
@@ -334,6 +340,9 @@ dofilewrite(struct proc *p, int fd, struct file *fp, const void *buf,
psignal(p, SIGPIPE);
}
cnt -= auio.uio_resid;
+
+ fp->f_wxfer++;
+ fp->f_wbytes += cnt;
#ifdef KTRACE
if (KTRPOINT(p, KTR_GENIO) && error == 0)
ktrgenio(p, fd, UIO_WRITE, &ktriov, cnt, error);
@@ -442,11 +451,13 @@ dofilewritev(struct proc *p, int fd, struct file *fp, const struct iovec *iovp,
psignal(p, SIGPIPE);
}
cnt -= auio.uio_resid;
+
+ fp->f_wxfer++;
+ fp->f_wbytes += cnt;
#ifdef KTRACE
if (ktriov != NULL) {
if (error == 0)
- ktrgenio(p, fd, UIO_WRITE, ktriov, cnt,
- error);
+ ktrgenio(p, fd, UIO_WRITE, ktriov, cnt, error);
free(ktriov, M_TEMP);
}
#endif
diff --git a/sys/kern/uipc_syscalls.c b/sys/kern/uipc_syscalls.c
index f0379902744..33255ad4844 100644
--- a/sys/kern/uipc_syscalls.c
+++ b/sys/kern/uipc_syscalls.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uipc_syscalls.c,v 1.62 2006/01/05 05:05:07 jsg Exp $ */
+/* $OpenBSD: uipc_syscalls.c,v 1.63 2006/03/26 17:47:10 mickey Exp $ */
/* $NetBSD: uipc_syscalls.c,v 1.19 1996/02/09 19:00:48 christos Exp $ */
/*
@@ -522,8 +522,11 @@ sendit(struct proc *p, int s, struct msghdr *mp, int flags, register_t *retsize)
if (error == EPIPE)
psignal(p, SIGPIPE);
}
- if (error == 0)
+ if (error == 0) {
*retsize = len - auio.uio_resid;
+ fp->f_wxfer++;
+ fp->f_wbytes += *retsize;
+ }
#ifdef KTRACE
if (ktriov != NULL) {
if (error == 0)
@@ -756,6 +759,10 @@ recvit(struct proc *p, int s, struct msghdr *mp, caddr_t namelenp,
}
mp->msg_controllen = len;
}
+ if (!error) {
+ fp->f_rxfer++;
+ fp->f_rbytes += *retsize;
+ }
out:
FRELE(fp);
if (from)
diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c
index 9958f5c179c..93c5171593a 100644
--- a/sys/kern/vfs_syscalls.c
+++ b/sys/kern/vfs_syscalls.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vfs_syscalls.c,v 1.131 2006/01/07 07:39:55 deraadt Exp $ */
+/* $OpenBSD: vfs_syscalls.c,v 1.132 2006/03/26 17:47:10 mickey Exp $ */
/* $NetBSD: vfs_syscalls.c,v 1.71 1996/04/23 10:29:02 mycroft Exp $ */
/*
@@ -1439,6 +1439,7 @@ sys_lseek(struct proc *p, void *v, register_t *retval)
return (EINVAL);
}
*(off_t *)retval = fp->f_offset;
+ fp->f_seek++;
return (0);
}
diff --git a/sys/sys/file.h b/sys/sys/file.h
index cad1e3ea418..f57eccd28b3 100644
--- a/sys/sys/file.h
+++ b/sys/sys/file.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: file.h,v 1.23 2003/09/23 16:51:13 millert Exp $ */
+/* $OpenBSD: file.h,v 1.24 2006/03/26 17:47:10 mickey Exp $ */
/* $NetBSD: file.h,v 1.11 1995/03/26 20:24:13 jtc Exp $ */
/*
@@ -79,6 +79,11 @@ struct file {
void *f_data; /* private data */
int f_iflags; /* internal flags */
int f_usecount; /* number of users (temporary references). */
+ u_int64_t f_rxfer; /* total number of read transfers */
+ u_int64_t f_wxfer; /* total number of write transfers */
+ u_int64_t f_seek; /* total independent seek operations */
+ u_int64_t f_rbytes; /* total bytes read */
+ u_int64_t f_wbytes; /* total bytes written */
};
#define FIF_WANTCLOSE 0x01 /* a close is waiting for usecount */
diff --git a/usr.bin/fstat/fstat.c b/usr.bin/fstat/fstat.c
index 57e97a890ed..21582a92149 100644
--- a/usr.bin/fstat/fstat.c
+++ b/usr.bin/fstat/fstat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fstat.c,v 1.55 2005/12/28 20:48:18 pedro Exp $ */
+/* $OpenBSD: fstat.c,v 1.56 2006/03/26 17:47:11 mickey Exp $ */
/*-
* Copyright (c) 1988, 1993
@@ -37,7 +37,7 @@ static char copyright[] =
#ifndef lint
/*static char sccsid[] = "from: @(#)fstat.c 8.1 (Berkeley) 6/6/93";*/
-static char *rcsid = "$OpenBSD: fstat.c,v 1.55 2005/12/28 20:48:18 pedro Exp $";
+static char *rcsid = "$OpenBSD: fstat.c,v 1.56 2006/03/26 17:47:11 mickey Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -123,6 +123,7 @@ int uflg; /* show files open by a particular (effective) user */
int checkfile; /* true if restricting to particular files or filesystems */
int nflg; /* (numerical) display f.s. and rdev as dev_t */
int oflg; /* display file offset */
+int sflg; /* display file xfer/bytes counters */
int vflg; /* display errors in locating kernel data objects etc... */
struct file **ofiles; /* buffer of pointers to file structures */
@@ -152,14 +153,14 @@ int nfs_filestat(struct vnode *, struct filestat *);
int xfs_filestat(struct vnode *, struct filestat *);
void dofiles(struct kinfo_proc2 *);
void getinetproto(int);
-void socktrans(struct socket *, int);
void usage(void);
-void vtrans(struct vnode *, int, int, off_t);
int getfname(char *);
-void pipetrans(struct pipe *, int);
-void kqueuetrans(struct kqueue *, int);
-void cryptotrans(void *, int);
-void systracetrans(struct fsystrace *, int);
+void socktrans(struct socket *, int, struct file *);
+void vtrans(struct vnode *, int, int, struct file *);
+void pipetrans(struct pipe *, int, struct file *);
+void kqueuetrans(struct kqueue *, int, struct file *);
+void cryptotrans(void *, int, struct file *);
+void systracetrans(struct fsystrace *, int, struct file *);
char *getmnton(struct mount *);
const char *inet6_addrstr(struct in6_addr *);
@@ -180,7 +181,7 @@ main(int argc, char *argv[])
what = KERN_PROC_ALL;
nlistf = memf = NULL;
oflg = 0;
- while ((ch = getopt(argc, argv, "fnop:u:vN:M:")) != -1)
+ while ((ch = getopt(argc, argv, "fnop:su:vN:M:")) != -1)
switch((char)ch) {
case 'f':
fsflg = 1;
@@ -207,6 +208,9 @@ main(int argc, char *argv[])
what = KERN_PROC_PID;
arg = atoi(optarg);
break;
+ case 's':
+ sflg = 1;
+ break;
case 'u':
if (uflg++)
usage();
@@ -267,9 +271,10 @@ main(int argc, char *argv[])
if (oflg)
printf("%s", ":OFFSET ");
if (checkfile && fsflg == 0)
- printf(" NAME\n");
- else
- putchar('\n');
+ printf(" NAME");
+ if (sflg)
+ printf(" XFERS KBYTES");
+ putchar('\n');
for (plast = &p[cnt]; p < plast; ++p) {
if (p->p_stat == SZOMB)
@@ -335,16 +340,17 @@ dofiles(struct kinfo_proc2 *kp)
* root directory vnode, if one
*/
if (filed.fd_rdir)
- vtrans(filed.fd_rdir, RDIR, FREAD, 0);
+ vtrans(filed.fd_rdir, RDIR, FREAD, NULL);
/*
* current working directory vnode
*/
- vtrans(filed.fd_cdir, CDIR, FREAD, 0);
+ vtrans(filed.fd_cdir, CDIR, FREAD, NULL);
+
/*
* ktrace vnode, if one
*/
if (kp->p_tracep)
- vtrans((struct vnode *)(u_long)kp->p_tracep, TRACE, FREAD|FWRITE, 0);
+ vtrans((struct vnode *)(u_long)kp->p_tracep, TRACE, FREAD|FWRITE, NULL);
/*
* open files
*/
@@ -369,22 +375,25 @@ dofiles(struct kinfo_proc2 *kp)
}
if (file.f_type == DTYPE_VNODE)
vtrans((struct vnode *)file.f_data, i, file.f_flag,
- file.f_offset);
+ &file);
else if (file.f_type == DTYPE_SOCKET) {
if (checkfile == 0)
- socktrans((struct socket *)file.f_data, i);
+ socktrans((struct socket *)file.f_data, i,
+ &file);
} else if (file.f_type == DTYPE_PIPE) {
if (checkfile == 0)
- pipetrans((struct pipe *)file.f_data, i);
+ pipetrans((struct pipe *)file.f_data, i, &file);
} else if (file.f_type == DTYPE_KQUEUE) {
if (checkfile == 0)
- kqueuetrans((struct kqueue *)file.f_data, i);
+ kqueuetrans((struct kqueue *)file.f_data, i,
+ &file);
} else if (file.f_type == DTYPE_CRYPTO) {
if (checkfile == 0)
- cryptotrans(file.f_data, i);
+ cryptotrans(file.f_data, i, &file);
} else if (file.f_type == DTYPE_SYSTRACE) {
if (checkfile == 0)
- systracetrans((struct fsystrace *)file.f_data, i);
+ systracetrans((struct fsystrace *)file.f_data,
+ i, &file);
} else {
dprintf("unknown file type %d for file %d of pid %ld",
file.f_type, i, (long)Pid);
@@ -393,7 +402,7 @@ dofiles(struct kinfo_proc2 *kp)
}
void
-vtrans(struct vnode *vp, int i, int flag, off_t offset)
+vtrans(struct vnode *vp, int i, int flag, struct file *fp)
{
struct vnode vn;
struct filestat fst;
@@ -498,8 +507,12 @@ vtrans(struct vnode *vp, int i, int flag, off_t offset)
default:
printf(" %8lld", (long long)fst.size);
if (oflg)
- printf(":%-8lld", (long long)offset);
+ printf(":%-8lld", (long long)(fp? fp->f_offset : 0));
}
+ if (sflg)
+ printf(" %8lld %8lld",
+ (long long)(fp? fp->f_rxfer + fp->f_wxfer : 0),
+ (long long)(fp? fp->f_rbytes + fp->f_wbytes : 0) / 1024);
if (filename && !fsflg)
printf(" %s", filename);
putchar('\n');
@@ -677,7 +690,7 @@ getmnton(struct mount *m)
}
void
-pipetrans(struct pipe *pipe, int i)
+pipetrans(struct pipe *pipe, int i, struct file *fp)
{
struct pipe pi;
void *maxaddr;
@@ -700,17 +713,22 @@ pipetrans(struct pipe *pipe, int i)
*/
maxaddr = MAX(pipe, pi.pipe_peer);
- printf("pipe %p state: %s%s%s\n", maxaddr,
+ printf("pipe %p state: %s%s%s", maxaddr,
(pi.pipe_state & PIPE_WANTR) ? "R" : "",
(pi.pipe_state & PIPE_WANTW) ? "W" : "",
(pi.pipe_state & PIPE_EOF) ? "E" : "");
+ if (sflg)
+ printf("\t%8lld %8lld",
+ (long long)(fp? fp->f_rxfer + fp->f_wxfer : 0),
+ (long long)(fp? fp->f_rbytes + fp->f_wbytes : 0) / 1024);
+ printf("\n");
return;
bad:
printf("* error\n");
}
void
-kqueuetrans(struct kqueue *kq, int i)
+kqueuetrans(struct kqueue *kq, int i, struct file *fp)
{
struct kqueue kqi;
@@ -724,7 +742,7 @@ kqueuetrans(struct kqueue *kq, int i)
goto bad;
}
- printf("kqueue %p %d state: %s%s\n", kq, kqi.kq_count,
+ printf("kqueue %p %d state: %s%s", kq, kqi.kq_count,
(kqi.kq_state & KQ_SEL) ? "S" : "",
(kqi.kq_state & KQ_SLEEP) ? "W" : "");
return;
@@ -733,7 +751,7 @@ bad:
}
void
-cryptotrans(void *f, int i)
+cryptotrans(void *f, int i, struct file *fp)
{
PREFIX(i);
@@ -743,7 +761,7 @@ cryptotrans(void *f, int i)
}
void
-systracetrans(struct fsystrace *f, int i)
+systracetrans(struct fsystrace *f, int i, struct file *fp)
{
struct fsystrace fi;
@@ -791,7 +809,7 @@ inet6_addrstr(struct in6_addr *p)
#endif
void
-socktrans(struct socket *sock, int i)
+socktrans(struct socket *sock, int i, struct file *fp)
{
static char *stypename[] = {
"unused", /* 0 */
@@ -986,6 +1004,10 @@ socktrans(struct socket *sock, int i)
/* print protocol number and socket address */
printf(" %d %p", proto.pr_protocol, sock);
}
+ if (sflg)
+ printf("\t%8lld %8lld",
+ (long long)(fp? fp->f_rxfer + fp->f_wxfer : 0),
+ (long long)(fp? fp->f_rbytes + fp->f_wbytes : 0) / 1024);
printf("\n");
return;
bad:
@@ -1035,7 +1057,7 @@ getfname(char *filename)
void
usage(void)
{
- fprintf(stderr, "usage: fstat [-fnov] [-M core] [-N system] "
+ fprintf(stderr, "usage: fstat [-fnosv] [-M core] [-N system] "
"[-p pid] [-u user] [file ...]\n");
exit(1);
}
diff --git a/usr.bin/fstat/fstat.h b/usr.bin/fstat/fstat.h
index 3dda480e194..6274ec1d259 100644
--- a/usr.bin/fstat/fstat.h
+++ b/usr.bin/fstat/fstat.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: fstat.h,v 1.3 2003/06/03 02:56:08 millert Exp $ */
+/* $OpenBSD: fstat.h,v 1.4 2006/03/26 17:47:11 mickey Exp $ */
/*-
* Copyright (c) 1988, 1993
@@ -33,8 +33,10 @@ struct filestat {
long fsid;
long fileid;
mode_t mode;
- u_int64_t size;
dev_t rdev;
+ u_int64_t size;
+ u_int64_t xfers;
+ u_int64_t kbytes;
};
/*