Deleted Added
full compact
nfsstat.c (1591) nfsstat.c (3819)
1/*
2 * Copyright (c) 1983, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Rick Macklem at The University of Guelph.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 27 unchanged lines hidden (view full) ---

36
37#ifndef lint
38static char copyright[] =
39"@(#) Copyright (c) 1983, 1989, 1993\n\
40 The Regents of the University of California. All rights reserved.\n";
41#endif /* not lint */
42
43#ifndef lint
1/*
2 * Copyright (c) 1983, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Rick Macklem at The University of Guelph.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 27 unchanged lines hidden (view full) ---

36
37#ifndef lint
38static char copyright[] =
39"@(#) Copyright (c) 1983, 1989, 1993\n\
40 The Regents of the University of California. All rights reserved.\n";
41#endif /* not lint */
42
43#ifndef lint
44static char sccsid[] = "@(#)nfsstat.c 8.1 (Berkeley) 6/6/93";
44/*static char sccsid[] = "From: @(#)nfsstat.c 8.1 (Berkeley) 6/6/93";*/
45static const char rcsid[] =
46 "$Id$";
45#endif /* not lint */
46
47#include <sys/param.h>
47#endif /* not lint */
48
49#include <sys/param.h>
48#if BSD >= 199103
49#define NEWVM
50#endif
51#ifndef NEWVM
52#include <sys/vmmac.h>
53#include <sys/ucred.h>
54#include <machine/pte.h>
55#endif
56#include <sys/mount.h>
50#include <sys/mount.h>
51#include <sys/sysctl.h>
57#include <nfs/nfsv2.h>
58#include <nfs/nfs.h>
59#include <signal.h>
60#include <fcntl.h>
61#include <ctype.h>
62#include <errno.h>
63#include <kvm.h>
64#include <nlist.h>
65#include <unistd.h>
66#include <stdio.h>
67#include <stdlib.h>
68#include <string.h>
69#include <paths.h>
52#include <nfs/nfsv2.h>
53#include <nfs/nfs.h>
54#include <signal.h>
55#include <fcntl.h>
56#include <ctype.h>
57#include <errno.h>
58#include <kvm.h>
59#include <nlist.h>
60#include <unistd.h>
61#include <stdio.h>
62#include <stdlib.h>
63#include <string.h>
64#include <paths.h>
65#include <err.h>
70
71struct nlist nl[] = {
72#define N_NFSSTAT 0
73 { "_nfsstats" },
74 "",
75};
76kvm_t *kd;
77
66
67struct nlist nl[] = {
68#define N_NFSSTAT 0
69 { "_nfsstats" },
70 "",
71};
72kvm_t *kd;
73
78void intpr(), printhdr(), sidewaysintpr(), usage();
74static int deadkernel = 0;
79
75
76void intpr(void), printhdr(void), sidewaysintpr(u_int), usage(void);
77
80main(argc, argv)
81 int argc;
82 char **argv;
83{
84 extern int optind;
85 extern char *optarg;
86 u_int interval;
87 int ch;

--- 30 unchanged lines hidden (view full) ---

118 memf = *argv;
119 }
120 }
121#endif
122 /*
123 * Discard setgid privileges if not the running kernel so that bad
124 * guys can't print interesting stuff from kernel memory.
125 */
78main(argc, argv)
79 int argc;
80 char **argv;
81{
82 extern int optind;
83 extern char *optarg;
84 u_int interval;
85 int ch;

--- 30 unchanged lines hidden (view full) ---

116 memf = *argv;
117 }
118 }
119#endif
120 /*
121 * Discard setgid privileges if not the running kernel so that bad
122 * guys can't print interesting stuff from kernel memory.
123 */
126 if (nlistf != NULL || memf != NULL)
124 if (nlistf != NULL || memf != NULL) {
127 setgid(getgid());
125 setgid(getgid());
126 deadkernel = 1;
128
127
129 if ((kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, errbuf)) == 0) {
130 fprintf(stderr, "nfsstat: kvm_openfiles: %s\n", errbuf);
131 exit(1);
128 if ((kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY,
129 errbuf)) == 0) {
130 errx(1, "kvm_openfiles: %s", errbuf);
131 }
132 if (kvm_nlist(kd, nl) != 0) {
133 errx(1, "kvm_nlist: can't get names");
134 }
132 }
135 }
133 if (kvm_nlist(kd, nl) != 0) {
134 fprintf(stderr, "nfsstat: kvm_nlist: can't get names\n");
135 exit(1);
136 }
137
138 if (interval)
136
137 if (interval)
139 sidewaysintpr(interval, nl[N_NFSSTAT].n_value);
138 sidewaysintpr(interval);
140 else
139 else
141 intpr(nl[N_NFSSTAT].n_value);
140 intpr();
142 exit(0);
143}
144
145/*
141 exit(0);
142}
143
144/*
145 * Read the nfs stats using sysctl(3) for live kernels, or kvm_read
146 * for dead ones.
147 */
148void
149readstats(struct nfsstats *stp)
150{
151 if(deadkernel) {
152 if(kvm_read(kd, (u_long)nl[N_NFSSTAT].n_value, stp,
153 sizeof *stp) < 0) {
154 err(1, "kvm_read");
155 }
156 } else {
157 int name[3];
158 size_t buflen = sizeof *stp;
159
160 name[0] = CTL_FS;
161 name[1] = MOUNT_NFS;
162 name[2] = NFS_NFSSTATS;
163
164 if(sysctl(name, 3, stp, &buflen, (void *)0, (size_t)0) < 0) {
165 err(1, "sysctl");
166 }
167 }
168}
169
170/*
146 * Print a description of the nfs stats.
147 */
148void
171 * Print a description of the nfs stats.
172 */
173void
149intpr(nfsstataddr)
150 u_long nfsstataddr;
174intpr(void)
151{
152 struct nfsstats nfsstats;
153
175{
176 struct nfsstats nfsstats;
177
154 if (kvm_read(kd, (u_long)nfsstataddr, (char *)&nfsstats, sizeof(struct nfsstats)) < 0) {
155 fprintf(stderr, "nfsstat: kvm_read failed\n");
156 exit(1);
157 }
178 readstats(&nfsstats);
179
158 printf("Client Info:\n");
159 printf("Rpc Counts:\n");
160 printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n",
161 "Getattr", "Setattr", "Lookup", "Readlink", "Read",
162 "Write", "Create", "Remove");
163 printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
164 nfsstats.rpccnt[NFSPROC_GETATTR],
165 nfsstats.rpccnt[NFSPROC_SETATTR],

--- 109 unchanged lines hidden (view full) ---

275
276/*
277 * Print a running summary of nfs statistics.
278 * Repeat display every interval seconds, showing statistics
279 * collected over that interval. Assumes that interval is non-zero.
280 * First line printed at top of screen is always cumulative.
281 */
282void
180 printf("Client Info:\n");
181 printf("Rpc Counts:\n");
182 printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n",
183 "Getattr", "Setattr", "Lookup", "Readlink", "Read",
184 "Write", "Create", "Remove");
185 printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
186 nfsstats.rpccnt[NFSPROC_GETATTR],
187 nfsstats.rpccnt[NFSPROC_SETATTR],

--- 109 unchanged lines hidden (view full) ---

297
298/*
299 * Print a running summary of nfs statistics.
300 * Repeat display every interval seconds, showing statistics
301 * collected over that interval. Assumes that interval is non-zero.
302 * First line printed at top of screen is always cumulative.
303 */
304void
283sidewaysintpr(interval, off)
305sidewaysintpr(interval)
284 u_int interval;
306 u_int interval;
285 u_long off;
286{
287 struct nfsstats nfsstats, lastst;
288 int hdrcnt, oldmask;
289 void catchalarm();
290
291 (void)signal(SIGALRM, catchalarm);
292 signalled = 0;
293 (void)alarm(interval);
294 bzero((caddr_t)&lastst, sizeof(lastst));
295
296 for (hdrcnt = 1;;) {
297 if (!--hdrcnt) {
298 printhdr();
299 hdrcnt = 20;
300 }
307{
308 struct nfsstats nfsstats, lastst;
309 int hdrcnt, oldmask;
310 void catchalarm();
311
312 (void)signal(SIGALRM, catchalarm);
313 signalled = 0;
314 (void)alarm(interval);
315 bzero((caddr_t)&lastst, sizeof(lastst));
316
317 for (hdrcnt = 1;;) {
318 if (!--hdrcnt) {
319 printhdr();
320 hdrcnt = 20;
321 }
301 if (kvm_read(kd, off, (char *)&nfsstats, sizeof nfsstats) < 0) {
302 fprintf(stderr, "nfsstat: kvm_read failed\n");
303 exit(1);
304 }
322 readstats(&nfsstats);
305 printf("Client: %8d %8d %8d %8d %8d %8d %8d %8d\n",
306 nfsstats.rpccnt[1]-lastst.rpccnt[1],
307 nfsstats.rpccnt[4]-lastst.rpccnt[4],
308 nfsstats.rpccnt[5]-lastst.rpccnt[5],
309 nfsstats.rpccnt[6]-lastst.rpccnt[6],
310 nfsstats.rpccnt[8]-lastst.rpccnt[8],
311 nfsstats.rpccnt[11]-lastst.rpccnt[11],
312 nfsstats.rpccnt[12]-lastst.rpccnt[12],

--- 48 unchanged lines hidden ---
323 printf("Client: %8d %8d %8d %8d %8d %8d %8d %8d\n",
324 nfsstats.rpccnt[1]-lastst.rpccnt[1],
325 nfsstats.rpccnt[4]-lastst.rpccnt[4],
326 nfsstats.rpccnt[5]-lastst.rpccnt[5],
327 nfsstats.rpccnt[6]-lastst.rpccnt[6],
328 nfsstats.rpccnt[8]-lastst.rpccnt[8],
329 nfsstats.rpccnt[11]-lastst.rpccnt[11],
330 nfsstats.rpccnt[12]-lastst.rpccnt[12],

--- 48 unchanged lines hidden ---