2 * Copyright (c) 1983, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
6 * Rick Macklem at The University of Guelph.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * Copyright (c) 2004, 2008, 2009 Silicon Graphics International Corp.
34 * All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions, and the following disclaimer,
41 * without modification.
42 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
43 * substantially similar to the "NO WARRANTY" disclaimer below
44 * ("Disclaimer") and any redistribution must be conditioned upon
45 * including a substantially similar Disclaimer requirement for further
46 * binary redistribution.
49 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
50 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
51 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
52 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
53 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR 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,
57 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
58 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
59 * POSSIBILITY OF SUCH DAMAGES.
64 static const char copyright[] =
65 "@(#) Copyright (c) 1983, 1989, 1993\n\
66 The Regents of the University of California. All rights reserved.\n";
71 static char sccsid[] = "@(#)nfsstat.c 8.2 (Berkeley) 3/31/95";
73 static const char rcsid[] =
77 #include <sys/param.h>
78 #include <sys/module.h>
79 #include <sys/mount.h>
81 #include <sys/sysctl.h>
82 #include <nfs/nfssvc.h>
84 #include <fs/nfs/nfsproto.h>
85 #include <fs/nfs/nfsport.h>
102 #include <libxo/xo.h>
104 static int widemode = 0;
105 static int zflag = 0;
106 static int printtitle = 1;
107 static struct nfsstatsv1 ext_nfsstats;
108 static int extra_output = 0;
110 static void intpr(int, int);
111 static void printhdr(int, int, int);
112 static void usage(void) __dead2;
113 static char *sperc1(int, int);
114 static char *sperc2(int, int);
115 static void exp_intpr(int, int, int);
116 static void exp_sidewaysintpr(u_int, int, int, int);
117 static void compute_new_stats(struct nfsstatsv1 *cur_stats,
118 struct nfsstatsv1 *prev_stats, int curop, long double etime,
119 long double *mbsec, long double *kb_per_transfer,
120 long double *transfers_per_second, long double *ms_per_transfer,
121 uint64_t *queue_len, long double *busy_pct);
123 #define DELTA(field) (nfsstats.field - lastst.field)
125 #define STAT_TYPE_READ 0
126 #define STAT_TYPE_WRITE 1
127 #define STAT_TYPE_COMMIT 2
128 #define NUM_STAT_TYPES 3
134 static struct stattypes statstruct[] = {
135 {STAT_TYPE_READ, NFSV4OP_READ},
136 {STAT_TYPE_WRITE, NFSV4OP_WRITE},
137 {STAT_TYPE_COMMIT, NFSV4OP_COMMIT}
140 #define STAT_TYPE_TO_NFS(stat_type) statstruct[stat_type].nfs_type
142 #define NFSSTAT_XO_VERSION "1"
145 main(int argc, char **argv)
154 struct statfs *mntbuf;
155 struct nfscl_dumpmntopts dumpmntopts;
159 argc = xo_parse_args(argc, argv);
163 xo_set_version(NFSSTAT_XO_VERSION);
165 while ((ch = getopt(argc, argv, "cdEesWM:mN:w:zq")) != -1)
168 printf("*** -M option deprecated, ignored\n\n");
171 /* Display mount options for NFS mount points. */
172 mntlen = getmntinfo(&mntbuf, MNT_NOWAIT);
173 for (i = 0; i < mntlen; i++) {
174 if (strcmp(mntbuf->f_fstypename, "nfs") == 0) {
175 dumpmntopts.ndmnt_fname =
177 dumpmntopts.ndmnt_buf = buf;
178 dumpmntopts.ndmnt_blen = sizeof(buf);
179 if (nfssvc(NFSSVC_DUMPMNTOPTS,
181 printf("%s on %s\n%s\n",
182 mntbuf->f_mntfromname,
183 mntbuf->f_mntonname, buf);
184 else if (errno == EPERM)
185 errx(1, "Only privileged users"
186 " can use the -m option");
192 printf("*** -N option deprecated, ignored\n\n");
198 interval = atoi(optarg);
219 if (extra_output != 0)
220 xo_err(1, "-e and -E are mutually exclusive");
224 if (extra_output != 0)
225 xo_err(1, "-e and -E are mutually exclusive");
238 #define BACKWARD_COMPATIBILITY
239 #ifdef BACKWARD_COMPATIBILITY
241 interval = atoi(*argv);
243 if (modfind("nfscommon") < 0)
244 xo_err(1, "NFS client/server not loaded");
247 exp_sidewaysintpr(interval, clientOnly, serverOnly,
250 xo_open_container("nfsstat");
251 if (extra_output != 0)
252 exp_intpr(clientOnly, serverOnly, extra_output - 1);
254 intpr(clientOnly, serverOnly);
255 xo_close_container("nfsstat");
263 * Print a description of the nfs stats.
266 intpr(int clientOnly, int serverOnly)
270 nfssvc_flag = NFSSVC_GETSTATS | NFSSVC_NEWSTRUCT;
273 nfssvc_flag |= NFSSVC_ZEROCLTSTATS;
275 nfssvc_flag |= NFSSVC_ZEROSRVSTATS;
277 ext_nfsstats.vers = NFSSTATS_V1;
278 if (nfssvc(nfssvc_flag, &ext_nfsstats) < 0)
279 xo_err(1, "Can't get stats");
281 xo_open_container("clientstats");
284 xo_emit("{T:Client Info:\n");
286 xo_open_container("operations");
287 xo_emit("{T:Rpc Counts:}\n");
289 xo_emit("{T:Getattr/%13.13s}{T:Setattr/%13.13s}"
290 "{T:Lookup/%13.13s}{T:Readlink/%13.13s}"
291 "{T:Read/%13.13s}{T:Write/%13.13s}"
292 "{T:Create/%13.13s}{T:Remove/%13.13s}\n");
293 xo_emit("{:getattr/%13ju}{:setattr/%13ju}"
294 "{:lookup/%13ju}{:readlink/%13ju}"
295 "{:read/%13ju}{:write/%13ju}"
296 "{:create/%13ju}{:remove/%13ju}\n",
297 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_GETATTR],
298 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_SETATTR],
299 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LOOKUP],
300 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_READLINK],
301 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_READ],
302 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_WRITE],
303 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_CREATE],
304 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_REMOVE]);
306 xo_emit("{T:Rename/%13.13s}{T:Link/%13.13s}"
307 "{T:Symlink/%13.13s}{T:Mkdir/%13.13s}"
308 "{T:Rmdir/%13.13s}{T:Readdir/%13.13s}"
309 "{T:RdirPlus/%13.13s}{T:Access/%13.13s}\n");
310 xo_emit("{:rename/%13ju}{:link/%13ju}"
311 "{:symlink/%13ju}{:mkdir/%13ju}"
312 "{:rmdir/%13ju}{:readdir/%13ju}"
313 "{:rdirplus/%13ju}{:access/%13ju}\n",
314 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_RENAME],
315 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LINK],
316 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_SYMLINK],
317 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_MKDIR],
318 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_RMDIR],
319 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_READDIR],
320 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_READDIRPLUS],
321 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_ACCESS]);
323 xo_emit("{T:Mknod/%13.13s}{T:Fsstat/%13.13s}"
324 "{T:Fsinfo/%13.13s}{T:PathConf/%13.13s}"
325 "{T:Commit/%13.13s}\n");
326 xo_emit("{:mknod/%13ju}{:fsstat/%13ju}"
327 "{:fsinfo/%13ju}{:pathconf/%13ju}"
329 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_MKNOD],
330 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_FSSTAT],
331 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_FSINFO],
332 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_PATHCONF],
333 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_COMMIT]);
335 xo_close_container("operations");
337 xo_open_container("rpcs");
338 xo_emit("{T:Rpc Info:}\n");
340 xo_emit("{T:TimedOut/%13.13s}{T:Invalid/%13.13s}"
341 "{T:X Replies/%13.13s}{T:Retries/%13.13s}"
342 "{T:Requests/%13.13s}\n");
343 xo_emit("{:timedout/%13ju}{:invalid/%13ju}"
344 "{:xreplies/%13ju}{:retries/%13ju}"
345 "{:requests/%13ju}\n",
346 (uintmax_t)ext_nfsstats.rpctimeouts,
347 (uintmax_t)ext_nfsstats.rpcinvalid,
348 (uintmax_t)ext_nfsstats.rpcunexpected,
349 (uintmax_t)ext_nfsstats.rpcretries,
350 (uintmax_t)ext_nfsstats.rpcrequests);
351 xo_close_container("rpcs");
353 xo_open_container("cache");
354 xo_emit("{T:Cache Info:}\n");
356 xo_emit("{T:Attr Hits/%13.13s}{T:Attr Misses/%13.13s}"
357 "{T:Lkup Hits/%13.13s}{T:Lkup Misses/%13.13s}"
358 "{T:BioR Hits/%13.13s}{T:BioR Misses/%13.13s}"
359 "{T:BioW Hits/%13.13s}{T:BioW Misses/%13.13s}\n");
360 xo_emit("{:attrhits/%13ju}{:attrmisses/%13ju}"
361 "{:lkuphits/%13ju}{:lkupmisses/%13ju}"
362 "{:biorhits/%13ju}{:biormisses/%13ju}"
363 "{:biowhits/%13ju}{:biowmisses/%13ju}\n",
364 (uintmax_t)ext_nfsstats.attrcache_hits,
365 (uintmax_t)ext_nfsstats.attrcache_misses,
366 (uintmax_t)ext_nfsstats.lookupcache_hits,
367 (uintmax_t)ext_nfsstats.lookupcache_misses,
368 (uintmax_t)(ext_nfsstats.biocache_reads -
369 ext_nfsstats.read_bios),
370 (uintmax_t)ext_nfsstats.read_bios,
371 (uintmax_t)(ext_nfsstats.biocache_writes -
372 ext_nfsstats.write_bios),
373 (uintmax_t)ext_nfsstats.write_bios);
375 xo_emit("{T:BioRL Hits/%13.13s}{T:BioRL Misses/%13.13s}"
376 "{T:BioD Hits/%13.13s}{T:BioD Misses/%13.13s}"
377 "{T:DirE Hits/%13.13s}{T:DirE Misses/%13.13s}"
378 "{T:Accs Hits/%13.13s}{T:Accs Misses/%13.13s}\n");
379 xo_emit("{:biosrlhits/%13ju}{:biorlmisses/%13ju}"
380 "{:biodhits/%13ju}{:biodmisses/%13ju}"
381 "{:direhits/%13ju}{:diremisses/%13ju}"
382 "{:accshits/%13ju}{:accsmisses/%13ju}\n",
383 (uintmax_t)(ext_nfsstats.biocache_readlinks -
384 ext_nfsstats.readlink_bios),
385 (uintmax_t)ext_nfsstats.readlink_bios,
386 (uintmax_t)(ext_nfsstats.biocache_readdirs -
387 ext_nfsstats.readdir_bios),
388 (uintmax_t)ext_nfsstats.readdir_bios,
389 (uintmax_t)ext_nfsstats.direofcache_hits,
390 (uintmax_t)ext_nfsstats.direofcache_misses,
391 (uintmax_t)ext_nfsstats.accesscache_hits,
392 (uintmax_t)ext_nfsstats.accesscache_misses);
394 xo_close_container("cache");
396 xo_close_container("clientstats");
399 xo_open_container("serverstats");
401 xo_emit("{T:Server Info:}\n");
402 xo_open_container("operations");
404 xo_emit("{T:Getattr/%13.13s}{T:Setattr/%13.13s}"
405 "{T:Lookup/%13.13s}{T:Readlink/%13.13s}"
406 "{T:Read/%13.13s}{T:Write/%13.13s}"
407 "{T:Create/%13.13s}{T:Remove/%13.13s}\n");
408 xo_emit("{:getattr/%13ju}{:setattr/%13ju}"
409 "{:lookup/%13ju}{:readlink/%13ju}"
410 "{:read/%13ju}{:write/%13ju}"
411 "{:create/%13ju}{:remove/%13ju}\n",
412 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_GETATTR],
413 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SETATTR],
414 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LOOKUP],
415 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_READLINK],
416 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_READ],
417 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_WRITE],
418 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_CREATE],
419 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_REMOVE]);
421 xo_emit("{T:Rename/%13.13s}{T:Link/%13.13s}"
422 "{T:Symlink/%13.13s}{T:Mkdir/%13.13s}"
423 "{T:Rmdir/%13.13s}{T:Readdir/%13.13s}"
424 "{T:RdirPlus/%13.13s}{T:Access/%13.13s}\n");
425 xo_emit("{:rename/%13ju}{:link/%13ju}"
426 "{:symlink/%13ju}{:mkdir/%13ju}"
427 "{:rmdir/%13ju}{:readdir/%13ju}"
428 "{:rdirplus/%13ju}{:access/%13ju}\n",
429 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_RENAME],
430 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LINK],
431 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SYMLINK],
432 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_MKDIR],
433 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_RMDIR],
434 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_READDIR],
435 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_READDIRPLUS],
436 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_ACCESS]);
438 xo_emit("{T:Mknod/%13.13s}{T:Fsstat/%13.13s}"
439 "{T:Fsinfo/%13.13s}{T:PathConf/%13.13s}"
440 "{T:Commit/%13.13s}\n");
441 xo_emit("{:mknod/%13ju}{:fsstat/%13ju}"
442 "{:fsinfo/%13ju}{:pathconf/%13ju}"
444 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_MKNOD],
445 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_FSSTAT],
446 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_FSINFO],
447 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_PATHCONF],
448 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_COMMIT]);
450 xo_close_container("operations");
452 xo_open_container("server");
454 xo_emit("{T:Server Write Gathering:/%13.13s}\n");
456 xo_emit("{T:WriteOps/%13.13s}{T:WriteRPC/%13.13s}"
457 "{T:Opsaved/%13.13s}\n");
458 xo_emit("{:writeops/%13ju}{:writerpc/%13ju}"
459 "{:opsaved/%13ju}\n",
461 * The new client doesn't do write gathering. It was
462 * only useful for NFSv2.
464 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_WRITE],
465 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_WRITE], 0);
467 xo_close_container("server");
469 xo_open_container("cache");
470 xo_emit("{T:Server Cache Stats:/%13.13s}\n");
471 xo_emit("{T:Inprog/%13.13s}"
472 "{T:Non-Idem/%13.13s}{T:Misses/%13.13s}\n");
473 xo_emit("{:inprog/%13ju}{:nonidem/%13ju}{:misses/%13ju}\n",
474 (uintmax_t)ext_nfsstats.srvcache_inproghits,
475 (uintmax_t)ext_nfsstats.srvcache_nonidemdonehits,
476 (uintmax_t)ext_nfsstats.srvcache_misses);
477 xo_close_container("cache");
479 xo_close_container("serverstats");
484 printhdr(int clientOnly, int serverOnly, int newStats)
488 printf(" [%s Read %s] [%s Write %s] "
489 "%s[=========== Total ============]\n"
490 " KB/t tps MB/s%s KB/t tps MB/s%s "
491 "%sKB/t tps MB/s ms ql %%b",
492 widemode ? "========" : "=====",
493 widemode ? "========" : "=====",
494 widemode ? "========" : "=====",
495 widemode ? "=======" : "====",
496 widemode ? "[Commit ] " : "",
497 widemode ? " ms" : "",
498 widemode ? " ms" : "",
499 widemode ? "tps ms " : "");
501 printf("%s%6.6s %6.6s %6.6s %6.6s %6.6s %6.6s %6.6s %6.6s",
502 ((serverOnly && clientOnly) ? " " : " "),
503 "GtAttr", "Lookup", "Rdlink", "Read", "Write", "Rename",
505 if (widemode && clientOnly) {
506 printf(" Attr Lkup BioR BioW Accs BioD");
516 (void)fprintf(stderr,
517 "usage: nfsstat [-cdemszW] [-w wait]\n");
521 static char SPBuf[64][8];
525 sperc1(int hits, int misses)
527 char *p = SPBuf[SPIndex];
531 (int)(char)((quad_t)hits * 100 / (hits + misses)));
535 SPIndex = (SPIndex + 1) & 63;
540 sperc2(int ttl, int misses)
542 char *p = SPBuf[SPIndex];
546 (int)(char)((quad_t)(ttl - misses) * 100 / ttl));
550 SPIndex = (SPIndex + 1) & 63;
554 #define DELTA_T(field) \
555 devstat_compute_etime(&cur_stats->field, \
556 (prev_stats ? &prev_stats->field : NULL))
559 * XXX KDM mostly copied from ctlstat. We should commonize the code (and
560 * the devstat code) somehow.
563 compute_new_stats(struct nfsstatsv1 *cur_stats,
564 struct nfsstatsv1 *prev_stats, int curop,
565 long double etime, long double *mbsec,
566 long double *kb_per_transfer,
567 long double *transfers_per_second,
568 long double *ms_per_transfer, uint64_t *queue_len,
569 long double *busy_pct)
571 uint64_t total_bytes = 0, total_operations = 0;
572 struct bintime total_time_bt;
573 struct timespec total_time_ts;
575 bzero(&total_time_bt, sizeof(total_time_bt));
576 bzero(&total_time_ts, sizeof(total_time_ts));
578 total_bytes = cur_stats->srvbytes[curop];
579 total_operations = cur_stats->srvops[curop];
580 if (prev_stats != NULL) {
581 total_bytes -= prev_stats->srvbytes[curop];
582 total_operations -= prev_stats->srvops[curop];
585 *mbsec = total_bytes;
586 *mbsec /= 1024 * 1024;
588 *busy_pct = DELTA_T(busytime);
600 *kb_per_transfer = total_bytes;
601 *kb_per_transfer /= 1024;
602 if (total_operations > 0)
603 *kb_per_transfer /= total_operations;
605 *kb_per_transfer = 0;
607 *transfers_per_second = total_operations;
608 *transfers_per_second /= etime;
610 *transfers_per_second = 0.0;
613 if (total_operations > 0) {
614 *ms_per_transfer = DELTA_T(srvduration[curop]);
615 *ms_per_transfer /= total_operations;
616 *ms_per_transfer *= 1000;
618 *ms_per_transfer = 0.0;
620 *queue_len = cur_stats->srvstartcnt - cur_stats->srvdonecnt;
624 * Print a description of the nfs stats for the client/server,
628 exp_intpr(int clientOnly, int serverOnly, int nfs41)
632 xo_open_container("nfsv4");
634 nfssvc_flag = NFSSVC_GETSTATS | NFSSVC_NEWSTRUCT;
637 nfssvc_flag |= NFSSVC_ZEROCLTSTATS;
639 nfssvc_flag |= NFSSVC_ZEROSRVSTATS;
641 ext_nfsstats.vers = NFSSTATS_V1;
642 if (nfssvc(nfssvc_flag, &ext_nfsstats) < 0)
643 xo_err(1, "Can't get stats");
644 if (clientOnly != 0) {
645 xo_open_container("clientstats");
647 xo_open_container("operations");
649 xo_emit("{T:Client Info:}\n");
650 xo_emit("{T:RPC Counts:}\n");
652 xo_emit("{T:Getattr/%13.13s}{T:Setattr/%13.13s}"
653 "{T:Lookup/%13.13s}{T:Readlink/%13.13s}"
654 "{T:Read/%13.13s}{T:Write/%13.13s}\n");
655 xo_emit("{:getattr/%13ju}{:setattr/%13ju}{:lookup/%13ju}"
656 "{:readlink/%13ju}{:read/%13ju}{:write/%13ju}\n",
657 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_GETATTR],
658 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_SETATTR],
659 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LOOKUP],
660 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_READLINK],
661 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_READ],
662 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_WRITE]);
663 xo_emit("{T:Create/%13.13s}{T:Remove/%13.13s}"
664 "{T:Rename/%13.13s}{T:Link/%13.13s}"
665 "{T:Symlink/%13.13s}{T:Mkdir/%13.13s}\n");
666 xo_emit("{:create/%13ju}{:remove/%13ju}{:rename/%13ju}"
667 "{:link/%13ju}{:symlink/%13ju}{:mkdir/%13ju}\n",
668 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_CREATE],
669 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_REMOVE],
670 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_RENAME],
671 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LINK],
672 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_SYMLINK],
673 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_MKDIR]);
674 xo_emit("{T:Rmdir/%13.13s}{T:Readdir/%13.13s}"
675 "{T:RdirPlus/%13.13s}{T:Access/%13.13s}"
676 "{T:Mknod/%13.13s}{T:Fsstat/%13.13s}\n");
677 xo_emit("{:rmdir/%13ju}{:readdir/%13ju}{:rdirplus/%13ju}"
678 "{:access/%13ju}{:mknod/%13ju}{:fsstat/%13ju}\n",
679 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_RMDIR],
680 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_READDIR],
681 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_READDIRPLUS],
682 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_ACCESS],
683 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_MKNOD],
684 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_FSSTAT]);
685 xo_emit("{T:FSinfo/%13.13s}{T:pathConf/%13.13s}"
686 "{T:Commit/%13.13s}{T:SetClId/%13.13s}"
687 "{T:SetClIdCf/%13.13s}{T:Lock/%13.13s}\n");
688 xo_emit("{:fsinfo/%13ju}{:pathconf/%13ju}{:commit/%13ju}"
689 "{:setclientid/%13ju}{:setclientidcf/%13ju}{:lock/%13ju}\n",
690 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_FSINFO],
691 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_PATHCONF],
692 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_COMMIT],
693 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_SETCLIENTID],
694 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_SETCLIENTIDCFRM],
695 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LOCK]);
696 xo_emit("{T:LockT/%13.13s}{T:LockU/%13.13s}"
697 "{T:Open/%13.13s}{T:OpenCfr/%13.13s}\n");
698 xo_emit("{:lockt/%13ju}{:locku/%13ju}"
699 "{:open/%13ju}{:opencfr/%13ju}\n",
700 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LOCKT],
701 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LOCKU],
702 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_OPEN],
703 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_OPENCONFIRM]);
706 xo_open_container("nfsv41");
708 xo_emit("{T:OpenDownGr/%13.13s}{T:Close/%13.13s}\n");
709 xo_emit("{:opendowngr/%13ju}{:close/%13ju}\n",
710 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_OPENDOWNGRADE],
711 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_CLOSE]);
713 xo_emit("{T:RelLckOwn/%13.13s}{T:FreeStateID/%13.13s}"
714 "{T:PutRootFH/%13.13s}{T:DelegRet/%13.13s}"
715 "{T:GetAcl/%13.13s}{T:SetAcl/%13.13s}\n");
716 xo_emit("{:rellckown/%13ju}{:freestateid/%13ju}"
717 "{:putrootfh/%13ju}{:delegret/%13ju}"
718 "{:getacl/%13ju}{:setacl/%13ju}\n",
719 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_RELEASELCKOWN],
720 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_FREESTATEID],
721 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_PUTROOTFH],
722 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_DELEGRETURN],
723 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_GETACL],
724 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_SETACL]);
726 xo_emit("{T:ExchangeId/%13.13s}{T:CreateSess/%13.13s}"
727 "{T:DestroySess/%13.13s}{T:DestroyClId/%13.13s}"
728 "{T:LayoutGet/%13.13s}{T:GetDevInfo/%13.13s}\n");
729 xo_emit("{:exchangeid/%13ju}{:createsess/%13ju}"
730 "{:destroysess/%13ju}{:destroyclid/%13ju}"
731 "{:layoutget/%13ju}{:getdevinfo/%13ju}\n",
732 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_EXCHANGEID],
733 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_CREATESESSION],
734 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_DESTROYSESSION],
735 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_DESTROYCLIENT],
736 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LAYOUTGET],
737 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_GETDEVICEINFO]);
739 xo_emit("{T:LayoutCommit/%13.13s}{T:LayoutReturn/%13.13s}"
740 "{T:ReclaimCompl/%13.13s}{T:ReadDataS/%13.13s}"
741 "{T:WriteDataS/%13.13s}{T:CommitDataS/%13.13s}\n");
742 xo_emit("{:layoutcomit/%13ju}{:layoutreturn/%13ju}"
743 "{:reclaimcompl/%13ju}{:readdatas/%13ju}"
744 "{:writedatas/%13ju}{:commitdatas/%13ju}\n",
745 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LAYOUTCOMMIT],
746 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LAYOUTRETURN],
747 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_RECLAIMCOMPL],
748 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_READDS],
749 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_WRITEDS],
750 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_COMMITDS]);
752 xo_emit("{T:OpenLayout/%13.13s}{T:CreateLayout/%13.13s}"
753 "{T:BindConnSess/%13.13s}{T:LookupOpen/%13.13s}"
754 "{T:AppendWrite/%13.13s}\n");
755 xo_emit("{:openlayout/%13ju}{:createlayout/%13ju}"
756 "{:bindconnsess/%13ju}{:lookupopen/%13ju}"
757 "{:appendwrite/%13ju}\n",
758 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_OPENLAYGET],
759 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_CREATELAYGET],
760 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_BINDCONNTOSESS],
761 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LOOKUPOPEN],
762 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_APPENDWRITE]);
764 xo_close_container("nfsv41");
766 xo_open_container("nfsv42");
768 xo_emit("{T:IOAdvise/%13.13s}{T:Allocate/%13.13s}"
769 "{T:Copy/%13.13s}{T:Seek/%13.13s}"
770 "{T:SeekDataS/%13.13s}{T:GetExtattr/%13.13s}\n");
771 xo_emit("{:ioadvise/%13ju}{:allocate/%13ju}"
772 "{:copy/%13ju}{:seek/%13ju}"
773 "{:seekdatas/%13ju}{:getextattr/%13ju}\n",
774 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_IOADVISE],
775 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_ALLOCATE],
776 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_COPY],
777 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_SEEK],
778 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_SEEKDS],
779 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_GETEXTATTR]);
781 xo_emit("{T:SetExtattr/%13.13s}{T:RmExtattr/%13.13s}"
782 "{T:ListExtattr/%13.13s}{T:Deallocate/%13.13s}"
783 "{T:LayoutError/%13.13s}\n");
784 xo_emit("{:setextattr/%13ju}{:rmextattr/%13ju}"
785 "{:listextattr/%13ju}{:deallocate/%13ju}"
786 "{:layouterror/%13ju}\n",
787 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_SETEXTATTR],
788 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_RMEXTATTR],
789 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LISTEXTATTR],
790 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_DEALLOCATE],
791 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LAYOUTERROR]);
793 xo_close_container("nfsv42");
795 xo_close_container("operations");
798 xo_emit("{T:Client:}\n");
799 xo_open_container("client");
800 xo_emit("{T:OpenOwner/%13.13s}{T:Opens/%13.13s}"
801 "{T:LockOwner/%13.13s}{T:Locks/%13.13s}"
802 "{T:Delegs/%13.13s}{T:LocalOwn/%13.13s}\n");
803 xo_emit("{:openowner/%13ju}{:opens/%13ju}"
804 "{:lockowner/%13ju}{:locks/%13ju}"
805 "{:delegs/%13ju}{:localown/%13ju}\n",
806 (uintmax_t)ext_nfsstats.clopenowners,
807 (uintmax_t)ext_nfsstats.clopens,
808 (uintmax_t)ext_nfsstats.cllockowners,
809 (uintmax_t)ext_nfsstats.cllocks,
810 (uintmax_t)ext_nfsstats.cldelegates,
811 (uintmax_t)ext_nfsstats.cllocalopenowners);
813 xo_emit("{T:LocalOpen/%13.13s}{T:LocalLown/%13.13s}"
814 "{T:LocalLock/%13.13s}{T:Layouts/%13.13s}\n");
815 xo_emit("{:localopen/%13ju}{:locallown/%13ju}"
816 "{:locallock/%13ju}{:layouts/%13ju}\n",
817 (uintmax_t)ext_nfsstats.cllocalopens,
818 (uintmax_t)ext_nfsstats.cllocallockowners,
819 (uintmax_t)ext_nfsstats.cllocallocks,
820 (uintmax_t)ext_nfsstats.cllayouts);
821 xo_close_container("client");
823 xo_open_container("rpc");
825 xo_emit("{T:Rpc Info:}\n");
826 xo_emit("{T:TimedOut/%13.13s}{T:Invalid/%13.13s}"
827 "{T:X Replies/%13.13s}{T:Retries/%13.13s}"
828 "{T:Requests/%13.13s}\n");
829 xo_emit("{:timedout/%13ju}{:invalid/%13ju}"
830 "{:xreplies/%13ju}{:retries/%13ju}"
831 "{:requests/%13ju}\n",
832 (uintmax_t)ext_nfsstats.rpctimeouts,
833 (uintmax_t)ext_nfsstats.rpcinvalid,
834 (uintmax_t)ext_nfsstats.rpcunexpected,
835 (uintmax_t)ext_nfsstats.rpcretries,
836 (uintmax_t)ext_nfsstats.rpcrequests);
837 xo_close_container("rpc");
839 xo_open_container("cache");
841 xo_emit("{T:Cache Info:}\n");
842 xo_emit("{T:Attr Hits/%13.13s}{T:Attr Misses/%13.13s}"
843 "{T:Lkup Hits/%13.13s}{T:Lkup Misses/%13.13s}\n");
844 xo_emit("{:attrhits/%13ju}{:attrmisses/%13ju}"
845 "{:lkuphits/%13ju}{:lkupmisses/%13ju}\n",
846 (uintmax_t)ext_nfsstats.attrcache_hits,
847 (uintmax_t)ext_nfsstats.attrcache_misses,
848 (uintmax_t)ext_nfsstats.lookupcache_hits,
849 (uintmax_t)ext_nfsstats.lookupcache_misses);
851 xo_emit("{T:BioR Hits/%13.13s}{T:BioR Misses/%13.13s}"
852 "{T:BioW Hits/%13.13s}{T:BioW Misses/%13.13s}\n");
853 xo_emit("{:biorhits/%13ju}{:biormisses/%13ju}"
854 "{:biowhits/%13ju}{:biowmisses/%13ju}\n",
855 (uintmax_t)(ext_nfsstats.biocache_reads -
856 ext_nfsstats.read_bios),
857 (uintmax_t)ext_nfsstats.read_bios,
858 (uintmax_t)(ext_nfsstats.biocache_writes -
859 ext_nfsstats.write_bios),
860 (uintmax_t)ext_nfsstats.write_bios);
862 xo_emit("{T:BioRL Hits/%13.13s}{T:BioRL Misses/%13.13s}"
863 "{T:BioD Hits/%13.13s}{T:BioD Misses/%13.13s}\n");
864 xo_emit("{:biorlhits/%13ju}{:biorlmisses/%13ju}"
865 "{:biodhits/%13ju}{:biodmisses/%13ju}\n",
866 (uintmax_t)(ext_nfsstats.biocache_readlinks -
867 ext_nfsstats.readlink_bios),
868 (uintmax_t)ext_nfsstats.readlink_bios,
869 (uintmax_t)(ext_nfsstats.biocache_readdirs -
870 ext_nfsstats.readdir_bios),
871 (uintmax_t)ext_nfsstats.readdir_bios);
873 xo_emit("{T:DirE Hits/%13.13s}{T:DirE Misses/%13.13s}\n");
874 xo_emit("{:direhits/%13ju}{:diremisses/%13ju}\n",
875 (uintmax_t)ext_nfsstats.direofcache_hits,
876 (uintmax_t)ext_nfsstats.direofcache_misses);
877 xo_open_container("cache");
879 xo_close_container("clientstats");
881 if (serverOnly != 0) {
882 xo_open_container("serverstats");
884 xo_open_container("operations");
886 xo_emit("{T:Server Info:}\n");
887 xo_emit("{T:Getattr/%13.13s}{T:Setattr/%13.13s}"
888 "{T:Lookup/%13.13s}{T:Readlink/%13.13s}"
889 "{T:Read/%13.13s}{T:Write/%13.13s}\n");
890 xo_emit("{:getattr/%13ju}{:setattr/%13ju}{:lookup/%13ju}"
891 "{:readlink/%13ju}{:read/%13ju}{:write/%13ju}\n",
892 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_GETATTR],
893 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SETATTR],
894 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LOOKUP],
895 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_READLINK],
896 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_READ],
897 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_WRITE]);
898 xo_emit("{T:Create/%13.13s}{T:Remove/%13.13s}"
899 "{T:Rename/%13.13s}{T:Link/%13.13s}"
900 "{T:Symlink/%13.13s}{T:Mkdir/%13.13s}\n");
901 xo_emit("{:create/%13ju}{:remove/%13ju}{:rename/%13ju}"
902 "{:link/%13ju}{:symlink/%13ju}{:mkdir/%13ju}\n",
903 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_V3CREATE],
904 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_REMOVE],
905 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_RENAME],
906 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LINK],
907 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SYMLINK],
908 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_MKDIR]);
909 xo_emit("{T:Rmdir/%13.13s}{T:Readdir/%13.13s}"
910 "{T:RdirPlus/%13.13s}{T:Access/%13.13s}"
911 "{T:Mknod/%13.13s}{T:Fsstat/%13.13s}\n");
912 xo_emit("{:rmdir/%13ju}{:readdir/%13ju}{:rdirplus/%13ju}"
913 "{:access/%13ju}{:mknod/%13ju}{:fsstat/%13ju}\n",
914 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_RMDIR],
915 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_READDIR],
916 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_READDIRPLUS],
917 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_ACCESS],
918 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_MKNOD],
919 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_FSSTAT]);
920 xo_emit("{T:FSinfo/%13.13s}{T:pathConf/%13.13s}"
921 "{T:Commit/%13.13s}{T:LookupP/%13.13s}"
922 "{T:SetClId/%13.13s}{T:SetClIdCf/%13.13s}\n");
923 xo_emit("{:fsinfo/%13ju}{:pathconf/%13ju}{:commit/%13ju}"
924 "{:lookupp/%13ju}{:setclientid/%13ju}{:setclientidcfrm/%13ju}\n",
925 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_FSINFO],
926 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_PATHCONF],
927 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_COMMIT],
928 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LOOKUPP],
929 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SETCLIENTID],
930 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SETCLIENTIDCFRM]);
931 xo_emit("{T:Open/%13.13s}{T:OpenAttr/%13.13s}"
932 "{T:OpenDwnGr/%13.13s}{T:OpenCfrm/%13.13s}"
933 "{T:DelePurge/%13.13s}{T:DelRet/%13.13s}\n");
934 xo_emit("{:open/%13ju}{:openattr/%13ju}{:opendwgr/%13ju}"
935 "{:opencfrm/%13ju}{:delepurge/%13ju}{:delreg/%13ju}\n",
936 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_OPEN],
937 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_OPENATTR],
938 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_OPENDOWNGRADE],
939 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_OPENCONFIRM],
940 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_DELEGPURGE],
941 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_DELEGRETURN]);
942 xo_emit("{T:GetFH/%13.13s}{T:Lock/%13.13s}"
943 "{T:LockT/%13.13s}{T:LockU/%13.13s}"
944 "{T:Close/%13.13s}{T:Verify/%13.13s}\n");
945 xo_emit("{:getfh/%13ju}{:lock/%13ju}{:lockt/%13ju}"
946 "{:locku/%13ju}{:close/%13ju}{:verify/%13ju}\n",
947 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_GETFH],
948 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LOCK],
949 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LOCKT],
950 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LOCKU],
951 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_CLOSE],
952 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_VERIFY]);
953 xo_emit("{T:NVerify/%13.13s}{T:PutFH/%13.13s}"
954 "{T:PutPubFH/%13.13s}{T:PutRootFH/%13.13s}"
955 "{T:Renew/%13.13s}{T:RestoreFH/%13.13s}\n");
956 xo_emit("{:nverify/%13ju}{:putfh/%13ju}{:putpubfh/%13ju}"
957 "{:putrootfh/%13ju}{:renew/%13ju}{:restore/%13ju}\n",
958 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_NVERIFY],
959 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_PUTFH],
960 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_PUTPUBFH],
961 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_PUTROOTFH],
962 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_RENEW],
963 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_RESTOREFH]);
964 xo_emit("{T:SaveFH/%13.13s}{T:Secinfo/%13.13s}"
965 "{T:RelLockOwn/%13.13s}{T:V4Create/%13.13s}\n");
966 xo_emit("{:savefh/%13ju}{:secinfo/%13ju}{:rellockown/%13ju}"
967 "{:v4create/%13ju}\n",
968 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SAVEFH],
969 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SECINFO],
970 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_RELEASELCKOWN],
971 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_CREATE]);
973 xo_open_container("nfsv41");
974 xo_emit("{T:BackChannelCtrl/%13.13s}{T:BindConnToSess/%13.13s}"
975 "{T:ExchangeID/%13.13s}{T:CreateSess/%13.13s}"
976 "{T:DestroySess/%13.13s}{T:FreeStateID/%13.13s}\n");
977 xo_emit("{:backchannelctrl/%13ju}{:bindconntosess/%13ju}"
978 "{:exchangeid/%13ju}{:createsess/%13ju}"
979 "{:destroysess/%13ju}{:freestateid/%13ju}\n",
980 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_BACKCHANNELCTL],
981 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_BINDCONNTOSESS],
982 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_EXCHANGEID],
983 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_CREATESESSION],
984 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_DESTROYSESSION],
985 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_FREESTATEID]),
987 xo_emit("{T:GetDirDeleg/%13.13s}{T:GetDevInfo/%13.13s}"
988 "{T:GetDevList/%13.13s}{T:layoutCommit/%13.13s}"
989 "{T:LayoutGet/%13.13s}{T:LayoutReturn/%13.13s}\n");
990 xo_emit("{:getdirdeleg/%13ju}{:getdevinfo/%13ju}"
991 "{:getdevlist/%13ju}{:layoutcommit/%13ju}"
992 "{:layoutget/%13ju}{:layoutreturn/%13ju}\n",
993 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_GETDIRDELEG],
994 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_GETDEVINFO],
995 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_GETDEVLIST],
996 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LAYOUTCOMMIT],
997 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LAYOUTGET],
998 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LAYOUTRETURN]);
1000 xo_emit("{T:SecInfNoName/%13.13s}{T:Sequence/%13.13s}"
1001 "{T:SetSSV/%13.13s}{T:TestStateID/%13.13s}"
1002 "{T:WantDeleg/%13.13s}{T:DestroyClId/%13.13s}\n");
1003 xo_emit("{:secinfnoname/%13ju}{:sequence/%13ju}"
1004 "{:setssv/%13ju}{:teststateid/%13ju}{:wantdeleg/%13ju}"
1005 "{:destroyclid/%13ju}\n",
1006 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SECINFONONAME],
1007 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SEQUENCE],
1008 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SETSSV],
1009 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_TESTSTATEID],
1010 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_WANTDELEG],
1011 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_DESTROYCLIENTID]);
1013 xo_emit("{T:ReclaimCompl/%13.13s}\n");
1014 xo_emit("{:reclaimcompl/%13ju}\n",
1015 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_RECLAIMCOMPL]);
1017 xo_close_container("nfsv41");
1019 xo_open_container("nfsv42");
1021 xo_emit("{T:Allocate/%13.13s}{T:Copy/%13.13s}"
1022 "{T:CopyNotify/%13.13s}{T:Deallocate/%13.13s}"
1023 "{T:IOAdvise/%13.13s}{T:LayoutError/%13.13s}\n");
1024 xo_emit("{:allocate/%13ju}{:copy/%13ju}"
1025 "{:copynotify/%13ju}{:deallocate/%13ju}"
1026 "{:ioadvise/%13ju}{:layouterror/%13ju}\n",
1027 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_ALLOCATE],
1028 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_COPY],
1029 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_COPYNOTIFY],
1030 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_DEALLOCATE],
1031 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_IOADVISE],
1032 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LAYOUTERROR]);
1034 xo_emit("{T:LayoutStats/%13.13s}{T:OffloadCncl/%13.13s}"
1035 "{T:OffloadStat/%13.13s}{T:ReadPlus/%13.13s}"
1036 "{T:Seek/%13.13s}{T:WriteSame/%13.13s}\n");
1037 xo_emit("{:layoutstats/%13ju}{:offloadcncl/%13ju}"
1038 "{:offloadstat/%13ju}{:readplus/%13ju}"
1039 "{:seek/%13ju}{:writesame/%13ju}\n",
1040 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LAYOUTSTATS],
1041 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_OFFLOADCANCEL],
1042 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_OFFLOADSTATUS],
1043 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_READPLUS],
1044 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SEEK],
1045 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_WRITESAME]);
1047 xo_emit("{T:Clone/%13.13s}{T:GetExtattr/%13.13s}"
1048 "{T:SetExtattr/%13.13s}{T:ListExtattr/%13.13s}"
1049 "{T:RmExtattr/%13.13s}\n");
1050 xo_emit("{:clone/%13ju}{:getextattr/%13ju}"
1051 "{:setextattr/%13ju}{:listextattr/%13ju}"
1052 "{:rmextattr/%13ju}\n",
1053 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_CLONE],
1054 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_GETXATTR],
1055 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SETXATTR],
1056 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LISTXATTRS],
1057 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_REMOVEXATTR]);
1059 xo_close_container("nfsv42");
1062 xo_close_container("operations");
1065 xo_emit("{T:Server:}\n");
1066 xo_open_container("server");
1067 xo_emit("{T:Clients/%13.13s}{T:OpenOwner/%13.13s}"
1068 "{T:Opens/%13.13s}{T:LockOwner/%13.13s}{T:Locks/%13.13s}"
1069 "{T:Delegs/%13.13s}\n");
1070 xo_emit("{:clients/%13ju}{:openowner/%13ju}{:opens/%13ju}"
1071 "{:lockowner/%13ju}{:locks/%13ju}{:delegs/%13ju}\n",
1072 (uintmax_t)ext_nfsstats.srvclients,
1073 (uintmax_t)ext_nfsstats.srvopenowners,
1074 (uintmax_t)ext_nfsstats.srvopens,
1075 (uintmax_t)ext_nfsstats.srvlockowners,
1076 (uintmax_t)ext_nfsstats.srvlocks,
1077 (uintmax_t)ext_nfsstats.srvdelegates);
1078 xo_emit("{T:Layouts/%13.13s}\n");
1079 xo_emit("{:layouts/%13ju}\n",
1080 (uintmax_t)ext_nfsstats.srvlayouts);
1081 xo_close_container("server");
1084 xo_emit("{T:Server Cache Stats:}\n");
1085 xo_open_container("cache");
1086 xo_emit("{T:Inprog/%13.13s}"
1087 "{T:Non-idem/%13.13s}{T:Misses/%13.13s}"
1088 "{T:CacheSize/%13.13s}{T:TCPPeak/%13.13s}\n");
1089 xo_emit("{:inprog/%13ju}{:nonidem/%13ju}"
1090 "{:misses/%13ju}{:cachesize/%13ju}{:tcppeak/%13ju}\n",
1091 (uintmax_t)ext_nfsstats.srvcache_inproghits,
1092 (uintmax_t)ext_nfsstats.srvcache_nonidemdonehits,
1093 (uintmax_t)ext_nfsstats.srvcache_misses,
1094 (uintmax_t)ext_nfsstats.srvcache_size,
1095 (uintmax_t)ext_nfsstats.srvcache_tcppeak);
1096 xo_close_container("cache");
1098 xo_close_container("serverstats");
1101 xo_close_container("nfsv4");
1105 compute_totals(struct nfsstatsv1 *total_stats, struct nfsstatsv1 *cur_stats)
1109 bzero(total_stats, sizeof(*total_stats));
1110 for (i = 0; i < (NFSV42_NOPS + NFSV4OP_FAKENOPS); i++) {
1111 total_stats->srvbytes[0] += cur_stats->srvbytes[i];
1112 total_stats->srvops[0] += cur_stats->srvops[i];
1113 bintime_add(&total_stats->srvduration[0],
1114 &cur_stats->srvduration[i]);
1115 total_stats->srvrpccnt[i] = cur_stats->srvrpccnt[i];
1117 total_stats->srvstartcnt = cur_stats->srvstartcnt;
1118 total_stats->srvdonecnt = cur_stats->srvdonecnt;
1119 total_stats->busytime = cur_stats->busytime;
1124 * Print a running summary of nfs statistics for the experimental client and/or
1126 * Repeat display every interval seconds, showing statistics
1127 * collected over that interval. Assumes that interval is non-zero.
1128 * First line printed at top of screen is always cumulative.
1131 exp_sidewaysintpr(u_int interval, int clientOnly, int serverOnly,
1134 struct nfsstatsv1 nfsstats, lastst, *ext_nfsstatsp;
1135 struct nfsstatsv1 curtotal, lasttotal;
1136 struct timespec ts, lastts;
1139 ext_nfsstatsp = &lastst;
1140 ext_nfsstatsp->vers = NFSSTATS_V1;
1141 if (nfssvc(NFSSVC_GETSTATS | NFSSVC_NEWSTRUCT, ext_nfsstatsp) < 0)
1142 err(1, "Can't get stats");
1143 clock_gettime(CLOCK_MONOTONIC, &lastts);
1144 compute_totals(&lasttotal, ext_nfsstatsp);
1148 ext_nfsstatsp = &nfsstats;
1149 ext_nfsstatsp->vers = NFSSTATS_V1;
1150 if (nfssvc(NFSSVC_GETSTATS | NFSSVC_NEWSTRUCT, ext_nfsstatsp)
1152 err(1, "Can't get stats");
1153 clock_gettime(CLOCK_MONOTONIC, &ts);
1155 if (--hdrcnt == 0) {
1156 printhdr(clientOnly, serverOnly, newStats);
1159 else if (clientOnly && serverOnly)
1164 if (clientOnly && newStats == 0) {
1165 printf("%s %6ju %6ju %6ju %6ju %6ju %6ju %6ju %6ju",
1166 ((clientOnly && serverOnly) ? "Client:" : ""),
1167 (uintmax_t)DELTA(rpccnt[NFSPROC_GETATTR]),
1168 (uintmax_t)DELTA(rpccnt[NFSPROC_LOOKUP]),
1169 (uintmax_t)DELTA(rpccnt[NFSPROC_READLINK]),
1170 (uintmax_t)DELTA(rpccnt[NFSPROC_READ]),
1171 (uintmax_t)DELTA(rpccnt[NFSPROC_WRITE]),
1172 (uintmax_t)DELTA(rpccnt[NFSPROC_RENAME]),
1173 (uintmax_t)DELTA(rpccnt[NFSPROC_ACCESS]),
1174 (uintmax_t)(DELTA(rpccnt[NFSPROC_READDIR]) +
1175 DELTA(rpccnt[NFSPROC_READDIRPLUS]))
1178 printf(" %s %s %s %s %s %s",
1179 sperc1(DELTA(attrcache_hits),
1180 DELTA(attrcache_misses)),
1181 sperc1(DELTA(lookupcache_hits),
1182 DELTA(lookupcache_misses)),
1183 sperc2(DELTA(biocache_reads),
1185 sperc2(DELTA(biocache_writes),
1187 sperc1(DELTA(accesscache_hits),
1188 DELTA(accesscache_misses)),
1189 sperc2(DELTA(biocache_readdirs),
1190 DELTA(readdir_bios))
1196 if (serverOnly && newStats) {
1197 long double cur_secs, last_secs, etime;
1199 long double kb_per_transfer;
1200 long double transfers_per_second;
1201 long double ms_per_transfer;
1203 long double busy_pct;
1206 cur_secs = ts.tv_sec +
1207 ((long double)ts.tv_nsec / 1000000000);
1208 last_secs = lastts.tv_sec +
1209 ((long double)lastts.tv_nsec / 1000000000);
1210 etime = cur_secs - last_secs;
1212 compute_totals(&curtotal, &nfsstats);
1214 for (i = 0; i < NUM_STAT_TYPES; i++) {
1215 compute_new_stats(&nfsstats, &lastst,
1216 STAT_TYPE_TO_NFS(i), etime, &mbsec,
1218 &transfers_per_second,
1219 &ms_per_transfer, &queue_len,
1222 if (i == STAT_TYPE_COMMIT) {
1226 printf("%2.0Lf %7.2Lf ",
1227 transfers_per_second,
1230 printf("%5.2Lf %5.0Lf %7.2Lf ",
1232 transfers_per_second, mbsec);
1239 compute_new_stats(&curtotal, &lasttotal, 0, etime,
1240 &mbsec, &kb_per_transfer, &transfers_per_second,
1241 &ms_per_transfer, &queue_len, &busy_pct);
1243 printf("%5.2Lf %5.0Lf %7.2Lf %5.2Lf %3ju %3.0Lf\n",
1244 kb_per_transfer, transfers_per_second, mbsec,
1245 ms_per_transfer, queue_len, busy_pct);
1246 } else if (serverOnly) {
1247 printf("%s %6ju %6ju %6ju %6ju %6ju %6ju %6ju %6ju",
1248 ((clientOnly && serverOnly) ? "Server:" : ""),
1249 (uintmax_t)DELTA(srvrpccnt[NFSV4OP_GETATTR]),
1250 (uintmax_t)DELTA(srvrpccnt[NFSV4OP_LOOKUP]),
1251 (uintmax_t)DELTA(srvrpccnt[NFSV4OP_READLINK]),
1252 (uintmax_t)DELTA(srvrpccnt[NFSV4OP_READ]),
1253 (uintmax_t)DELTA(srvrpccnt[NFSV4OP_WRITE]),
1254 (uintmax_t)DELTA(srvrpccnt[NFSV4OP_RENAME]),
1255 (uintmax_t)DELTA(srvrpccnt[NFSV4OP_ACCESS]),
1256 (uintmax_t)(DELTA(srvrpccnt[NFSV4OP_READDIR]) +
1257 DELTA(srvrpccnt[NFSV4OP_READDIRPLUS])));
1260 bcopy(&nfsstats, &lastst, sizeof(lastst));
1261 bcopy(&curtotal, &lasttotal, sizeof(lasttotal));