]>
git.saurik.com Git - apple/network_cmds.git/blob - nfsstat.tproj/nfsstat.c
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.0 (the 'License'). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
25 * Copyright (c) 1997 Apple Computer, Inc. All Rights Reserved
27 * Copyright (c) 1983, 1989, 1993
28 * The Regents of the University of California. All rights reserved.
30 * This code is derived from software contributed to Berkeley by
31 * Rick Macklem at The University of Guelph.
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
36 * 1. Redistributions of source code must retain the above copyright
37 * notice, this list of conditions and the following disclaimer.
38 * 2. Redistributions in binary form must reproduce the above copyright
39 * notice, this list of conditions and the following disclaimer in the
40 * documentation and/or other materials provided with the distribution.
41 * 3. All advertising materials mentioning features or use of this software
42 * must display the following acknowledgement:
43 * This product includes software developed by the University of
44 * California, Berkeley and its contributors.
45 * 4. Neither the name of the University nor the names of its contributors
46 * may be used to endorse or promote products derived from this software
47 * without specific prior written permission.
49 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
50 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * @(#)nfsstat.c 8.2 (Berkeley) 3/31/95
64 #include <sys/param.h>
65 #include <sys/mount.h>
66 #include <sys/sysctl.h>
67 #include <nfs/rpcv2.h>
68 #include <nfs/nfsproto.h>
83 #define SHOW_SERVER 0x01
84 #define SHOW_CLIENT 0x02
85 #define SHOW_ALL (SHOW_SERVER | SHOW_CLIENT)
94 static int deadkernel
= 0;
96 void intpr
__P((u_long
, u_int
));
97 void printhdr
__P((void));
98 void sidewaysintpr
__P((u_int
, u_long
, u_int
));
99 void usage
__P((void));
109 u_int display
= SHOW_ALL
;
115 memf
= nlistf
= NULL
;
116 while ((ch
= getopt(argc
, argv
, "M:N:w:sc")) != EOF
)
125 interval
= atoi(optarg
);
128 display
= SHOW_SERVER
;
131 display
= SHOW_CLIENT
;
140 #define BACKWARD_COMPATIBILITY
141 #ifdef BACKWARD_COMPATIBILITY
143 interval
= atoi(*argv
);
152 * Discard setgid privileges if not the running kernel so that bad
153 * guys can't print interesting stuff from kernel memory.
155 if (nlistf
!= NULL
|| memf
!= NULL
) {
160 if ((kd
= kvm_openfiles(nlistf
, memf
, NULL
, O_RDONLY
,
162 errx(1, "kvm_openfiles: %s", errbuf
);
164 if (kvm_nlist(kd
, nl
) != 0) {
165 errx(1, "kvm_nlist: can't get names");
170 sidewaysintpr(interval
, nl
[N_NFSSTAT
].n_value
, display
);
172 intpr(nl
[N_NFSSTAT
].n_value
, display
);
177 * Read the nfs stats using sysctl(3) for live kernels, or kvm_read
182 struct nfsstats
*stp
;
185 if(kvm_read(kd
, (u_long
)nl
[N_NFSSTAT
].n_value
, stp
,
191 size_t buflen
= sizeof *stp
;
193 extern int getvfsbyname(char *, struct vfsconf
*);
195 if (getvfsbyname("nfs", &vfc
) < 0)
196 err(1, "getvfsbyname: NFS not compiled into kernel");
198 name
[1] = vfc
.vfc_typenum
;
199 name
[2] = NFS_NFSSTATS
;
200 if (sysctl(name
, 3, stp
, &buflen
, (void *)0, (size_t)0) < 0) {
207 * Print a description of the nfs stats.
210 intpr(nfsstataddr
, display
)
214 struct nfsstats nfsstats
;
216 readstats(&nfsstats
);
218 if (display
& SHOW_CLIENT
) {
219 printf("Client Info:\n");
220 printf("Rpc Counts:\n");
221 printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n",
222 "Getattr", "Setattr", "Lookup", "Readlink", "Read",
223 "Write", "Create", "Remove");
224 printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
225 nfsstats
.rpccnt
[NFSPROC_GETATTR
],
226 nfsstats
.rpccnt
[NFSPROC_SETATTR
],
227 nfsstats
.rpccnt
[NFSPROC_LOOKUP
],
228 nfsstats
.rpccnt
[NFSPROC_READLINK
],
229 nfsstats
.rpccnt
[NFSPROC_READ
],
230 nfsstats
.rpccnt
[NFSPROC_WRITE
],
231 nfsstats
.rpccnt
[NFSPROC_CREATE
],
232 nfsstats
.rpccnt
[NFSPROC_REMOVE
]);
233 printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n",
234 "Rename", "Link", "Symlink", "Mkdir", "Rmdir",
235 "Readdir", "RdirPlus", "Access");
236 printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
237 nfsstats
.rpccnt
[NFSPROC_RENAME
],
238 nfsstats
.rpccnt
[NFSPROC_LINK
],
239 nfsstats
.rpccnt
[NFSPROC_SYMLINK
],
240 nfsstats
.rpccnt
[NFSPROC_MKDIR
],
241 nfsstats
.rpccnt
[NFSPROC_RMDIR
],
242 nfsstats
.rpccnt
[NFSPROC_READDIR
],
243 nfsstats
.rpccnt
[NFSPROC_READDIRPLUS
],
244 nfsstats
.rpccnt
[NFSPROC_ACCESS
]);
245 printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n",
246 "Mknod", "Fsstat", "Fsinfo", "PathConf", "Commit",
247 "GLease", "Vacate", "Evict");
248 printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
249 nfsstats
.rpccnt
[NFSPROC_MKNOD
],
250 nfsstats
.rpccnt
[NFSPROC_FSSTAT
],
251 nfsstats
.rpccnt
[NFSPROC_FSINFO
],
252 nfsstats
.rpccnt
[NFSPROC_PATHCONF
],
253 nfsstats
.rpccnt
[NFSPROC_COMMIT
],
254 nfsstats
.rpccnt
[NQNFSPROC_GETLEASE
],
255 nfsstats
.rpccnt
[NQNFSPROC_VACATED
],
256 nfsstats
.rpccnt
[NQNFSPROC_EVICTED
]);
257 printf("Rpc Info:\n");
258 printf("%9.9s %9.9s %9.9s %9.9s %9.9s\n",
259 "TimedOut", "Invalid", "X Replies", "Retries", "Requests");
260 printf("%9d %9d %9d %9d %9d\n",
261 nfsstats
.rpctimeouts
,
263 nfsstats
.rpcunexpected
,
265 nfsstats
.rpcrequests
);
266 printf("Cache Info:\n");
267 printf("%9.9s %9.9s %9.9s %9.9s",
268 "Attr Hits", "Misses", "Lkup Hits", "Misses");
269 printf(" %9.9s %9.9s %9.9s %9.9s\n",
270 "BioR Hits", "Misses", "BioW Hits", "Misses");
271 printf("%9d %9d %9d %9d",
272 nfsstats
.attrcache_hits
, nfsstats
.attrcache_misses
,
273 nfsstats
.lookupcache_hits
, nfsstats
.lookupcache_misses
);
274 printf(" %9d %9d %9d %9d\n",
275 nfsstats
.biocache_reads
-nfsstats
.read_bios
,
277 nfsstats
.biocache_writes
-nfsstats
.write_bios
,
278 nfsstats
.write_bios
);
279 printf("%9.9s %9.9s %9.9s %9.9s",
280 "BioRLHits", "Misses", "BioD Hits", "Misses");
281 printf(" %9.9s %9.9s\n", "DirE Hits", "Misses");
282 printf("%9d %9d %9d %9d",
283 nfsstats
.biocache_readlinks
-nfsstats
.readlink_bios
,
284 nfsstats
.readlink_bios
,
285 nfsstats
.biocache_readdirs
-nfsstats
.readdir_bios
,
286 nfsstats
.readdir_bios
);
288 nfsstats
.direofcache_hits
, nfsstats
.direofcache_misses
);
290 if (display
& SHOW_SERVER
) {
291 printf("\nServer Info:\n");
292 printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n",
293 "Getattr", "Setattr", "Lookup", "Readlink", "Read",
294 "Write", "Create", "Remove");
295 printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
296 nfsstats
.srvrpccnt
[NFSPROC_GETATTR
],
297 nfsstats
.srvrpccnt
[NFSPROC_SETATTR
],
298 nfsstats
.srvrpccnt
[NFSPROC_LOOKUP
],
299 nfsstats
.srvrpccnt
[NFSPROC_READLINK
],
300 nfsstats
.srvrpccnt
[NFSPROC_READ
],
301 nfsstats
.srvrpccnt
[NFSPROC_WRITE
],
302 nfsstats
.srvrpccnt
[NFSPROC_CREATE
],
303 nfsstats
.srvrpccnt
[NFSPROC_REMOVE
]);
304 printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n",
305 "Rename", "Link", "Symlink", "Mkdir", "Rmdir",
306 "Readdir", "RdirPlus", "Access");
307 printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
308 nfsstats
.srvrpccnt
[NFSPROC_RENAME
],
309 nfsstats
.srvrpccnt
[NFSPROC_LINK
],
310 nfsstats
.srvrpccnt
[NFSPROC_SYMLINK
],
311 nfsstats
.srvrpccnt
[NFSPROC_MKDIR
],
312 nfsstats
.srvrpccnt
[NFSPROC_RMDIR
],
313 nfsstats
.srvrpccnt
[NFSPROC_READDIR
],
314 nfsstats
.srvrpccnt
[NFSPROC_READDIRPLUS
],
315 nfsstats
.srvrpccnt
[NFSPROC_ACCESS
]);
316 printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n",
317 "Mknod", "Fsstat", "Fsinfo", "PathConf", "Commit",
318 "GLease", "Vacate", "Evict");
319 printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
320 nfsstats
.srvrpccnt
[NFSPROC_MKNOD
],
321 nfsstats
.srvrpccnt
[NFSPROC_FSSTAT
],
322 nfsstats
.srvrpccnt
[NFSPROC_FSINFO
],
323 nfsstats
.srvrpccnt
[NFSPROC_PATHCONF
],
324 nfsstats
.srvrpccnt
[NFSPROC_COMMIT
],
325 nfsstats
.srvrpccnt
[NQNFSPROC_GETLEASE
],
326 nfsstats
.srvrpccnt
[NQNFSPROC_VACATED
],
327 nfsstats
.srvrpccnt
[NQNFSPROC_EVICTED
]);
328 printf("Server Ret-Failed\n");
329 printf("%17d\n", nfsstats
.srvrpc_errs
);
330 printf("Server Faults\n");
331 printf("%13d\n", nfsstats
.srv_errs
);
332 printf("Server Cache Stats:\n");
333 printf("%9.9s %9.9s %9.9s %9.9s\n",
334 "Inprog", "Idem", "Non-idem", "Misses");
335 printf("%9d %9d %9d %9d\n",
336 nfsstats
.srvcache_inproghits
,
337 nfsstats
.srvcache_idemdonehits
,
338 nfsstats
.srvcache_nonidemdonehits
,
339 nfsstats
.srvcache_misses
);
340 printf("Server Lease Stats:\n");
341 printf("%9.9s %9.9s %9.9s\n",
342 "Leases", "PeakL", "GLeases");
343 printf("%9d %9d %9d\n",
344 nfsstats
.srvnqnfs_leases
,
345 nfsstats
.srvnqnfs_maxleases
,
346 nfsstats
.srvnqnfs_getleases
);
347 printf("Server Write Gathering:\n");
348 printf("%9.9s %9.9s %9.9s\n",
349 "WriteOps", "WriteRPC", "Opsaved");
350 printf("%9d %9d %9d\n",
351 nfsstats
.srvvop_writes
,
352 nfsstats
.srvrpccnt
[NFSPROC_WRITE
],
353 nfsstats
.srvrpccnt
[NFSPROC_WRITE
] - nfsstats
.srvvop_writes
);
357 u_char signalled
; /* set if alarm goes off "early" */
360 * Print a running summary of nfs statistics.
361 * Repeat display every interval seconds, showing statistics
362 * collected over that interval. Assumes that interval is non-zero.
363 * First line printed at top of screen is always cumulative.
366 sidewaysintpr(interval
, off
, display
)
371 struct nfsstats nfsstats
, lastst
;
375 (void)signal(SIGALRM
, catchalarm
);
377 (void)alarm(interval
);
378 bzero((caddr_t
)&lastst
, sizeof(lastst
));
385 readstats(&nfsstats
);
386 if (display
& SHOW_CLIENT
)
387 printf("Client: %8d %8d %8d %8d %8d %8d %8d %8d\n",
388 nfsstats
.rpccnt
[NFSPROC_GETATTR
]-lastst
.rpccnt
[NFSPROC_GETATTR
],
389 nfsstats
.rpccnt
[NFSPROC_LOOKUP
]-lastst
.rpccnt
[NFSPROC_LOOKUP
],
390 nfsstats
.rpccnt
[NFSPROC_READLINK
]-lastst
.rpccnt
[NFSPROC_READLINK
],
391 nfsstats
.rpccnt
[NFSPROC_READ
]-lastst
.rpccnt
[NFSPROC_READ
],
392 nfsstats
.rpccnt
[NFSPROC_WRITE
]-lastst
.rpccnt
[NFSPROC_WRITE
],
393 nfsstats
.rpccnt
[NFSPROC_RENAME
]-lastst
.rpccnt
[NFSPROC_RENAME
],
394 nfsstats
.rpccnt
[NFSPROC_ACCESS
]-lastst
.rpccnt
[NFSPROC_ACCESS
],
395 (nfsstats
.rpccnt
[NFSPROC_READDIR
]-lastst
.rpccnt
[NFSPROC_READDIR
])
396 +(nfsstats
.rpccnt
[NFSPROC_READDIRPLUS
]-lastst
.rpccnt
[NFSPROC_READDIRPLUS
]));
397 if (display
& SHOW_SERVER
)
398 printf("Server: %8d %8d %8d %8d %8d %8d %8d %8d\n",
399 nfsstats
.srvrpccnt
[NFSPROC_GETATTR
]-lastst
.srvrpccnt
[NFSPROC_GETATTR
],
400 nfsstats
.srvrpccnt
[NFSPROC_LOOKUP
]-lastst
.srvrpccnt
[NFSPROC_LOOKUP
],
401 nfsstats
.srvrpccnt
[NFSPROC_READLINK
]-lastst
.srvrpccnt
[NFSPROC_READLINK
],
402 nfsstats
.srvrpccnt
[NFSPROC_READ
]-lastst
.srvrpccnt
[NFSPROC_READ
],
403 nfsstats
.srvrpccnt
[NFSPROC_WRITE
]-lastst
.srvrpccnt
[NFSPROC_WRITE
],
404 nfsstats
.srvrpccnt
[NFSPROC_RENAME
]-lastst
.srvrpccnt
[NFSPROC_RENAME
],
405 nfsstats
.srvrpccnt
[NFSPROC_ACCESS
]-lastst
.srvrpccnt
[NFSPROC_ACCESS
],
406 (nfsstats
.srvrpccnt
[NFSPROC_READDIR
]-lastst
.srvrpccnt
[NFSPROC_READDIR
])
407 +(nfsstats
.srvrpccnt
[NFSPROC_READDIRPLUS
]-lastst
.srvrpccnt
[NFSPROC_READDIRPLUS
]));
410 oldmask
= sigblock(sigmask(SIGALRM
));
415 (void)alarm(interval
);
423 printf(" %8.8s %8.8s %8.8s %8.8s %8.8s %8.8s %8.8s %8.8s\n",
424 "Getattr", "Lookup", "Readlink", "Read", "Write", "Rename",
425 "Access", "Readdir");
430 * Called if an interval expires before sidewaysintpr has completed a loop.
431 * Sets a flag to not wait for the alarm.
442 (void)fprintf(stderr
,
443 "usage: nfsstat [-cs] [-M core] [-N system] [-w interval]\n");