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 9 * modification, are permitted provided that the following conditions 10 * are met: 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. 19 * 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 30 * SUCH DAMAGE. 31 */ 32 /*- 33 * Copyright (c) 2004, 2008, 2009 Silicon Graphics International Corp. 34 * All rights reserved. 35 * 36 * Redistribution and use in source and binary forms, with or without 37 * modification, are permitted provided that the following conditions 38 * are met: 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. 47 * 48 * NO WARRANTY 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. 60 */ 61 62 63 #ifndef lint 64 static const char copyright[] = 65 "@(#) Copyright (c) 1983, 1989, 1993\n\ 66 The Regents of the University of California. All rights reserved.\n"; 67 #endif /* not lint */ 68 69 #ifndef lint 70 #if 0 71 static char sccsid[] = "@(#)nfsstat.c 8.2 (Berkeley) 3/31/95"; 72 #endif 73 static const char rcsid[] = 74 "$FreeBSD$"; 75 #endif /* not lint */ 76 77 #include <sys/param.h> 78 #include <sys/module.h> 79 #include <sys/mount.h> 80 #include <sys/time.h> 81 #include <sys/sysctl.h> 82 #include <nfs/nfssvc.h> 83 84 #include <fs/nfs/nfsproto.h> 85 #include <fs/nfs/nfsport.h> 86 87 #include <signal.h> 88 #include <fcntl.h> 89 #include <ctype.h> 90 #include <errno.h> 91 #include <limits.h> 92 #include <nlist.h> 93 #include <unistd.h> 94 #include <stdio.h> 95 #include <stdint.h> 96 #include <stdlib.h> 97 #include <string.h> 98 #include <paths.h> 99 #include <devstat.h> 100 #include <err.h> 101 102 #include <libxo/xo.h> 103 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; 109 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); 122 123 #define DELTA(field) (nfsstats.field - lastst.field) 124 125 #define STAT_TYPE_READ 0 126 #define STAT_TYPE_WRITE 1 127 #define STAT_TYPE_COMMIT 2 128 #define NUM_STAT_TYPES 3 129 130 struct stattypes { 131 int stat_type; 132 int nfs_type; 133 }; 134 static struct stattypes statstruct[] = { 135 {STAT_TYPE_READ, NFSV4OP_READ}, 136 {STAT_TYPE_WRITE, NFSV4OP_WRITE}, 137 {STAT_TYPE_COMMIT, NFSV4OP_COMMIT} 138 }; 139 140 #define STAT_TYPE_TO_NFS(stat_type) statstruct[stat_type].nfs_type 141 142 #define NFSSTAT_XO_VERSION "1" 143 144 int 145 main(int argc, char **argv) 146 { 147 u_int interval; 148 int clientOnly = -1; 149 int serverOnly = -1; 150 int newStats = 0; 151 int ch; 152 int mntlen, i; 153 char buf[1024]; 154 struct statfs *mntbuf; 155 struct nfscl_dumpmntopts dumpmntopts; 156 157 interval = 0; 158 159 argc = xo_parse_args(argc, argv); 160 if (argc < 0) 161 exit(1); 162 163 xo_set_version(NFSSTAT_XO_VERSION); 164 165 while ((ch = getopt(argc, argv, "cdEesWM:mN:w:zq")) != -1) 166 switch(ch) { 167 case 'M': 168 printf("*** -M option deprecated, ignored\n\n"); 169 break; 170 case 'm': 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 = 176 mntbuf->f_mntonname; 177 dumpmntopts.ndmnt_buf = buf; 178 dumpmntopts.ndmnt_blen = sizeof(buf); 179 if (nfssvc(NFSSVC_DUMPMNTOPTS, 180 &dumpmntopts) >= 0) 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"); 187 } 188 mntbuf++; 189 } 190 exit(0); 191 case 'N': 192 printf("*** -N option deprecated, ignored\n\n"); 193 break; 194 case 'W': 195 widemode = 1; 196 break; 197 case 'w': 198 interval = atoi(optarg); 199 break; 200 case 'c': 201 clientOnly = 1; 202 if (serverOnly < 0) 203 serverOnly = 0; 204 break; 205 case 'd': 206 newStats = 1; 207 if (interval == 0) 208 interval = 1; 209 break; 210 case 's': 211 serverOnly = 1; 212 if (clientOnly < 0) 213 clientOnly = 0; 214 break; 215 case 'z': 216 zflag = 1; 217 break; 218 case 'E': 219 if (extra_output != 0) 220 xo_err(1, "-e and -E are mutually exclusive"); 221 extra_output = 2; 222 break; 223 case 'e': 224 if (extra_output != 0) 225 xo_err(1, "-e and -E are mutually exclusive"); 226 extra_output = 1; 227 break; 228 case 'q': 229 printtitle = 0; 230 break; 231 case '?': 232 default: 233 usage(); 234 } 235 argc -= optind; 236 argv += optind; 237 238 #define BACKWARD_COMPATIBILITY 239 #ifdef BACKWARD_COMPATIBILITY 240 if (*argv) 241 interval = atoi(*argv); 242 #endif 243 if (modfind("nfscommon") < 0) 244 xo_err(1, "NFS client/server not loaded"); 245 246 if (interval) { 247 exp_sidewaysintpr(interval, clientOnly, serverOnly, 248 newStats); 249 } else { 250 xo_open_container("nfsstat"); 251 if (extra_output != 0) 252 exp_intpr(clientOnly, serverOnly, extra_output - 1); 253 else 254 intpr(clientOnly, serverOnly); 255 xo_close_container("nfsstat"); 256 } 257 258 xo_finish(); 259 exit(0); 260 } 261 262 /* 263 * Print a description of the nfs stats. 264 */ 265 static void 266 intpr(int clientOnly, int serverOnly) 267 { 268 int nfssvc_flag; 269 270 nfssvc_flag = NFSSVC_GETSTATS | NFSSVC_NEWSTRUCT; 271 if (zflag != 0) { 272 if (clientOnly != 0) 273 nfssvc_flag |= NFSSVC_ZEROCLTSTATS; 274 if (serverOnly != 0) 275 nfssvc_flag |= NFSSVC_ZEROSRVSTATS; 276 } 277 ext_nfsstats.vers = NFSSTATS_V1; 278 if (nfssvc(nfssvc_flag, &ext_nfsstats) < 0) 279 xo_err(1, "Can't get stats"); 280 if (clientOnly) { 281 xo_open_container("clientstats"); 282 283 if (printtitle) 284 xo_emit("{T:Client Info:\n"); 285 286 xo_open_container("operations"); 287 xo_emit("{T:Rpc Counts:}\n"); 288 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]); 305 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]); 322 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}" 328 "{:commit/%13ju}\n", 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]); 334 335 xo_close_container("operations"); 336 337 xo_open_container("rpcs"); 338 xo_emit("{T:Rpc Info:}\n"); 339 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"); 352 353 xo_open_container("cache"); 354 xo_emit("{T:Cache Info:}\n"); 355 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); 374 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); 393 394 xo_close_container("cache"); 395 396 xo_close_container("clientstats"); 397 } 398 if (serverOnly) { 399 xo_open_container("serverstats"); 400 401 xo_emit("{T:Server Info:}\n"); 402 xo_open_container("operations"); 403 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]); 420 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]); 437 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}" 443 "{:commit/%13ju}\n", 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]); 449 450 xo_close_container("operations"); 451 452 xo_open_container("server"); 453 454 xo_emit("{T:Server Write Gathering:/%13.13s}\n"); 455 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", 460 /* 461 * The new client doesn't do write gathering. It was 462 * only useful for NFSv2. 463 */ 464 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_WRITE], 465 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_WRITE], 0); 466 467 xo_close_container("server"); 468 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"); 478 479 xo_close_container("serverstats"); 480 } 481 } 482 483 static void 484 printhdr(int clientOnly, int serverOnly, int newStats) 485 { 486 487 if (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 " : ""); 500 } else { 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", 504 "Access", "Rddir"); 505 if (widemode && clientOnly) { 506 printf(" Attr Lkup BioR BioW Accs BioD"); 507 } 508 } 509 printf("\n"); 510 fflush(stdout); 511 } 512 513 static void 514 usage(void) 515 { 516 (void)fprintf(stderr, 517 "usage: nfsstat [-cdemszW] [-w wait]\n"); 518 exit(1); 519 } 520 521 static char SPBuf[64][8]; 522 static int SPIndex; 523 524 static char * 525 sperc1(int hits, int misses) 526 { 527 char *p = SPBuf[SPIndex]; 528 529 if (hits + misses) { 530 sprintf(p, "%3d%%", 531 (int)(char)((quad_t)hits * 100 / (hits + misses))); 532 } else { 533 sprintf(p, " -"); 534 } 535 SPIndex = (SPIndex + 1) & 63; 536 return(p); 537 } 538 539 static char * 540 sperc2(int ttl, int misses) 541 { 542 char *p = SPBuf[SPIndex]; 543 544 if (ttl) { 545 sprintf(p, "%3d%%", 546 (int)(char)((quad_t)(ttl - misses) * 100 / ttl)); 547 } else { 548 sprintf(p, " -"); 549 } 550 SPIndex = (SPIndex + 1) & 63; 551 return(p); 552 } 553 554 #define DELTA_T(field) \ 555 devstat_compute_etime(&cur_stats->field, \ 556 (prev_stats ? &prev_stats->field : NULL)) 557 558 /* 559 * XXX KDM mostly copied from ctlstat. We should commonize the code (and 560 * the devstat code) somehow. 561 */ 562 static void 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) 570 { 571 uint64_t total_bytes = 0, total_operations = 0; 572 struct bintime total_time_bt; 573 struct timespec total_time_ts; 574 575 bzero(&total_time_bt, sizeof(total_time_bt)); 576 bzero(&total_time_ts, sizeof(total_time_ts)); 577 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]; 583 } 584 585 *mbsec = total_bytes; 586 *mbsec /= 1024 * 1024; 587 if (etime > 0.0) { 588 *busy_pct = DELTA_T(busytime); 589 if (*busy_pct < 0) 590 *busy_pct = 0; 591 *busy_pct /= etime; 592 *busy_pct *= 100; 593 if (*busy_pct < 0) 594 *busy_pct = 0; 595 *mbsec /= etime; 596 } else { 597 *busy_pct = 0; 598 *mbsec = 0; 599 } 600 *kb_per_transfer = total_bytes; 601 *kb_per_transfer /= 1024; 602 if (total_operations > 0) 603 *kb_per_transfer /= total_operations; 604 else 605 *kb_per_transfer = 0; 606 if (etime > 0.0) { 607 *transfers_per_second = total_operations; 608 *transfers_per_second /= etime; 609 } else { 610 *transfers_per_second = 0.0; 611 } 612 613 if (total_operations > 0) { 614 *ms_per_transfer = DELTA_T(srvduration[curop]); 615 *ms_per_transfer /= total_operations; 616 *ms_per_transfer *= 1000; 617 } else 618 *ms_per_transfer = 0.0; 619 620 *queue_len = cur_stats->srvstartcnt - cur_stats->srvdonecnt; 621 } 622 623 /* 624 * Print a description of the nfs stats for the client/server, 625 * including NFSv4.1. 626 */ 627 static void 628 exp_intpr(int clientOnly, int serverOnly, int nfs41) 629 { 630 int nfssvc_flag; 631 632 xo_open_container("nfsv4"); 633 634 nfssvc_flag = NFSSVC_GETSTATS | NFSSVC_NEWSTRUCT; 635 if (zflag != 0) { 636 if (clientOnly != 0) 637 nfssvc_flag |= NFSSVC_ZEROCLTSTATS; 638 if (serverOnly != 0) 639 nfssvc_flag |= NFSSVC_ZEROSRVSTATS; 640 } 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"); 646 647 xo_open_container("operations"); 648 if (printtitle) { 649 xo_emit("{T:Client Info:}\n"); 650 xo_emit("{T:RPC Counts:}\n"); 651 } 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]); 704 705 if (nfs41) { 706 xo_open_container("nfsv41"); 707 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]); 712 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]); 725 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]); 738 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]); 751 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]); 763 764 xo_close_container("nfsv41"); 765 766 xo_open_container("nfsv42"); 767 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]); 780 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]); 792 793 xo_close_container("nfsv42"); 794 } 795 xo_close_container("operations"); 796 797 if (printtitle) 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); 812 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"); 822 823 xo_open_container("rpc"); 824 if (printtitle) 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"); 838 839 xo_open_container("cache"); 840 if (printtitle) 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); 850 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); 861 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); 872 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"); 878 879 xo_close_container("clientstats"); 880 } 881 if (serverOnly != 0) { 882 xo_open_container("serverstats"); 883 884 xo_open_container("operations"); 885 if (printtitle) 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]); 972 if (nfs41) { 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]), 986 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]); 999 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]); 1012 1013 xo_emit("{T:ReclaimCompl/%13.13s}\n"); 1014 xo_emit("{:reclaimcompl/%13ju}\n", 1015 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_RECLAIMCOMPL]); 1016 1017 xo_close_container("nfsv41"); 1018 1019 xo_open_container("nfsv42"); 1020 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]); 1033 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]); 1046 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]); 1058 1059 xo_close_container("nfsv42"); 1060 } 1061 1062 xo_close_container("operations"); 1063 1064 if (printtitle) 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"); 1082 1083 if (printtitle) 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"); 1097 1098 xo_close_container("serverstats"); 1099 } 1100 1101 xo_close_container("nfsv4"); 1102 } 1103 1104 static void 1105 compute_totals(struct nfsstatsv1 *total_stats, struct nfsstatsv1 *cur_stats) 1106 { 1107 int i; 1108 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]; 1116 } 1117 total_stats->srvstartcnt = cur_stats->srvstartcnt; 1118 total_stats->srvdonecnt = cur_stats->srvdonecnt; 1119 total_stats->busytime = cur_stats->busytime; 1120 1121 } 1122 1123 /* 1124 * Print a running summary of nfs statistics for the experimental client and/or 1125 * server. 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. 1129 */ 1130 static void 1131 exp_sidewaysintpr(u_int interval, int clientOnly, int serverOnly, 1132 int newStats) 1133 { 1134 struct nfsstatsv1 nfsstats, lastst, *ext_nfsstatsp; 1135 struct nfsstatsv1 curtotal, lasttotal; 1136 struct timespec ts, lastts; 1137 int hdrcnt = 1; 1138 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); 1145 sleep(interval); 1146 1147 for (;;) { 1148 ext_nfsstatsp = &nfsstats; 1149 ext_nfsstatsp->vers = NFSSTATS_V1; 1150 if (nfssvc(NFSSVC_GETSTATS | NFSSVC_NEWSTRUCT, ext_nfsstatsp) 1151 < 0) 1152 err(1, "Can't get stats"); 1153 clock_gettime(CLOCK_MONOTONIC, &ts); 1154 1155 if (--hdrcnt == 0) { 1156 printhdr(clientOnly, serverOnly, newStats); 1157 if (newStats) 1158 hdrcnt = 20; 1159 else if (clientOnly && serverOnly) 1160 hdrcnt = 10; 1161 else 1162 hdrcnt = 20; 1163 } 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])) 1176 ); 1177 if (widemode) { 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), 1184 DELTA(read_bios)), 1185 sperc2(DELTA(biocache_writes), 1186 DELTA(write_bios)), 1187 sperc1(DELTA(accesscache_hits), 1188 DELTA(accesscache_misses)), 1189 sperc2(DELTA(biocache_readdirs), 1190 DELTA(readdir_bios)) 1191 ); 1192 } 1193 printf("\n"); 1194 } 1195 1196 if (serverOnly && newStats) { 1197 long double cur_secs, last_secs, etime; 1198 long double mbsec; 1199 long double kb_per_transfer; 1200 long double transfers_per_second; 1201 long double ms_per_transfer; 1202 uint64_t queue_len; 1203 long double busy_pct; 1204 int i; 1205 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; 1211 1212 compute_totals(&curtotal, &nfsstats); 1213 1214 for (i = 0; i < NUM_STAT_TYPES; i++) { 1215 compute_new_stats(&nfsstats, &lastst, 1216 STAT_TYPE_TO_NFS(i), etime, &mbsec, 1217 &kb_per_transfer, 1218 &transfers_per_second, 1219 &ms_per_transfer, &queue_len, 1220 &busy_pct); 1221 1222 if (i == STAT_TYPE_COMMIT) { 1223 if (widemode == 0) 1224 continue; 1225 1226 printf("%2.0Lf %7.2Lf ", 1227 transfers_per_second, 1228 ms_per_transfer); 1229 } else { 1230 printf("%5.2Lf %5.0Lf %7.2Lf ", 1231 kb_per_transfer, 1232 transfers_per_second, mbsec); 1233 if (widemode) 1234 printf("%5.2Lf ", 1235 ms_per_transfer); 1236 } 1237 } 1238 1239 compute_new_stats(&curtotal, &lasttotal, 0, etime, 1240 &mbsec, &kb_per_transfer, &transfers_per_second, 1241 &ms_per_transfer, &queue_len, &busy_pct); 1242 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]))); 1258 printf("\n"); 1259 } 1260 bcopy(&nfsstats, &lastst, sizeof(lastst)); 1261 bcopy(&curtotal, &lasttotal, sizeof(lasttotal)); 1262 lastts = ts; 1263 fflush(stdout); 1264 sleep(interval); 1265 } 1266 /*NOTREACHED*/ 1267 } 1268