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); 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}\n"); 754 xo_emit("{:openlayout/%13ju}{:createlayout/%13ju}" 755 "{:bindconnsess/%13ju}{:lookupopen/%13ju}\n", 756 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_OPENLAYGET], 757 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_CREATELAYGET], 758 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_BINDCONNTOSESS], 759 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LOOKUPOPEN]); 760 761 xo_close_container("nfsv41"); 762 763 xo_open_container("nfsv42"); 764 765 xo_emit("{T:IOAdvise/%13.13s}{T:Allocate/%13.13s}" 766 "{T:Copy/%13.13s}{T:Seek/%13.13s}" 767 "{T:SeekDataS/%13.13s}{T:GetExtattr/%13.13s}\n"); 768 xo_emit("{:ioadvise/%13ju}{:allocate/%13ju}" 769 "{:copy/%13ju}{:seek/%13ju}" 770 "{:seekdatas/%13ju}{:getextattr/%13ju}\n", 771 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_IOADVISE], 772 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_ALLOCATE], 773 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_COPY], 774 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_SEEK], 775 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_SEEKDS], 776 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_GETEXTATTR]); 777 778 xo_emit("{T:SetExtattr/%13.13s}{T:RmExtattr/%13.13s}" 779 "{T:ListExtattr/%13.13s}{T:Deallocate/%13.13s}" 780 "{T:LayoutError/%13.13s}\n"); 781 xo_emit("{:setextattr/%13ju}{:rmextattr/%13ju}" 782 "{:listextattr/%13ju}{:deallocate/%13ju}" 783 "{:layouterror/%13ju}\n", 784 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_SETEXTATTR], 785 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_RMEXTATTR], 786 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LISTEXTATTR], 787 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_DEALLOCATE], 788 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LAYOUTERROR]); 789 790 xo_close_container("nfsv42"); 791 } 792 xo_close_container("operations"); 793 794 if (printtitle) 795 xo_emit("{T:Client:}\n"); 796 xo_open_container("client"); 797 xo_emit("{T:OpenOwner/%13.13s}{T:Opens/%13.13s}" 798 "{T:LockOwner/%13.13s}{T:Locks/%13.13s}" 799 "{T:Delegs/%13.13s}{T:LocalOwn/%13.13s}\n"); 800 xo_emit("{:openowner/%13ju}{:opens/%13ju}" 801 "{:lockowner/%13ju}{:locks/%13ju}" 802 "{:delegs/%13ju}{:localown/%13ju}\n", 803 (uintmax_t)ext_nfsstats.clopenowners, 804 (uintmax_t)ext_nfsstats.clopens, 805 (uintmax_t)ext_nfsstats.cllockowners, 806 (uintmax_t)ext_nfsstats.cllocks, 807 (uintmax_t)ext_nfsstats.cldelegates, 808 (uintmax_t)ext_nfsstats.cllocalopenowners); 809 810 xo_emit("{T:LocalOpen/%13.13s}{T:LocalLown/%13.13s}" 811 "{T:LocalLock/%13.13s}{T:Layouts/%13.13s}\n"); 812 xo_emit("{:localopen/%13ju}{:locallown/%13ju}" 813 "{:locallock/%13ju}{:layouts/%13ju}\n", 814 (uintmax_t)ext_nfsstats.cllocalopens, 815 (uintmax_t)ext_nfsstats.cllocallockowners, 816 (uintmax_t)ext_nfsstats.cllocallocks, 817 (uintmax_t)ext_nfsstats.cllayouts); 818 xo_close_container("client"); 819 820 xo_open_container("rpc"); 821 if (printtitle) 822 xo_emit("{T:Rpc Info:}\n"); 823 xo_emit("{T:TimedOut/%13.13s}{T:Invalid/%13.13s}" 824 "{T:X Replies/%13.13s}{T:Retries/%13.13s}" 825 "{T:Requests/%13.13s}\n"); 826 xo_emit("{:timedout/%13ju}{:invalid/%13ju}" 827 "{:xreplies/%13ju}{:retries/%13ju}" 828 "{:requests/%13ju}\n", 829 (uintmax_t)ext_nfsstats.rpctimeouts, 830 (uintmax_t)ext_nfsstats.rpcinvalid, 831 (uintmax_t)ext_nfsstats.rpcunexpected, 832 (uintmax_t)ext_nfsstats.rpcretries, 833 (uintmax_t)ext_nfsstats.rpcrequests); 834 xo_close_container("rpc"); 835 836 xo_open_container("cache"); 837 if (printtitle) 838 xo_emit("{T:Cache Info:}\n"); 839 xo_emit("{T:Attr Hits/%13.13s}{T:Attr Misses/%13.13s}" 840 "{T:Lkup Hits/%13.13s}{T:Lkup Misses/%13.13s}\n"); 841 xo_emit("{:attrhits/%13ju}{:attrmisses/%13ju}" 842 "{:lkuphits/%13ju}{:lkupmisses/%13ju}\n", 843 (uintmax_t)ext_nfsstats.attrcache_hits, 844 (uintmax_t)ext_nfsstats.attrcache_misses, 845 (uintmax_t)ext_nfsstats.lookupcache_hits, 846 (uintmax_t)ext_nfsstats.lookupcache_misses); 847 848 xo_emit("{T:BioR Hits/%13.13s}{T:BioR Misses/%13.13s}" 849 "{T:BioW Hits/%13.13s}{T:BioW Misses/%13.13s}\n"); 850 xo_emit("{:biorhits/%13ju}{:biormisses/%13ju}" 851 "{:biowhits/%13ju}{:biowmisses/%13ju}\n", 852 (uintmax_t)(ext_nfsstats.biocache_reads - 853 ext_nfsstats.read_bios), 854 (uintmax_t)ext_nfsstats.read_bios, 855 (uintmax_t)(ext_nfsstats.biocache_writes - 856 ext_nfsstats.write_bios), 857 (uintmax_t)ext_nfsstats.write_bios); 858 859 xo_emit("{T:BioRL Hits/%13.13s}{T:BioRL Misses/%13.13s}" 860 "{T:BioD Hits/%13.13s}{T:BioD Misses/%13.13s}\n"); 861 xo_emit("{:biorlhits/%13ju}{:biorlmisses/%13ju}" 862 "{:biodhits/%13ju}{:biodmisses/%13ju}\n", 863 (uintmax_t)(ext_nfsstats.biocache_readlinks - 864 ext_nfsstats.readlink_bios), 865 (uintmax_t)ext_nfsstats.readlink_bios, 866 (uintmax_t)(ext_nfsstats.biocache_readdirs - 867 ext_nfsstats.readdir_bios), 868 (uintmax_t)ext_nfsstats.readdir_bios); 869 870 xo_emit("{T:DirE Hits/%13.13s}{T:DirE Misses/%13.13s}\n"); 871 xo_emit("{:direhits/%13ju}{:diremisses/%13ju}\n", 872 (uintmax_t)ext_nfsstats.direofcache_hits, 873 (uintmax_t)ext_nfsstats.direofcache_misses); 874 xo_open_container("cache"); 875 876 xo_close_container("clientstats"); 877 } 878 if (serverOnly != 0) { 879 xo_open_container("serverstats"); 880 881 xo_open_container("operations"); 882 if (printtitle) 883 xo_emit("{T:Server Info:}\n"); 884 xo_emit("{T:Getattr/%13.13s}{T:Setattr/%13.13s}" 885 "{T:Lookup/%13.13s}{T:Readlink/%13.13s}" 886 "{T:Read/%13.13s}{T:Write/%13.13s}\n"); 887 xo_emit("{:getattr/%13ju}{:setattr/%13ju}{:lookup/%13ju}" 888 "{:readlink/%13ju}{:read/%13ju}{:write/%13ju}\n", 889 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_GETATTR], 890 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SETATTR], 891 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LOOKUP], 892 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_READLINK], 893 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_READ], 894 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_WRITE]); 895 xo_emit("{T:Create/%13.13s}{T:Remove/%13.13s}" 896 "{T:Rename/%13.13s}{T:Link/%13.13s}" 897 "{T:Symlink/%13.13s}{T:Mkdir/%13.13s}\n"); 898 xo_emit("{:create/%13ju}{:remove/%13ju}{:rename/%13ju}" 899 "{:link/%13ju}{:symlink/%13ju}{:mkdir/%13ju}\n", 900 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_V3CREATE], 901 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_REMOVE], 902 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_RENAME], 903 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LINK], 904 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SYMLINK], 905 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_MKDIR]); 906 xo_emit("{T:Rmdir/%13.13s}{T:Readdir/%13.13s}" 907 "{T:RdirPlus/%13.13s}{T:Access/%13.13s}" 908 "{T:Mknod/%13.13s}{T:Fsstat/%13.13s}\n"); 909 xo_emit("{:rmdir/%13ju}{:readdir/%13ju}{:rdirplus/%13ju}" 910 "{:access/%13ju}{:mknod/%13ju}{:fsstat/%13ju}\n", 911 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_RMDIR], 912 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_READDIR], 913 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_READDIRPLUS], 914 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_ACCESS], 915 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_MKNOD], 916 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_FSSTAT]); 917 xo_emit("{T:FSinfo/%13.13s}{T:pathConf/%13.13s}" 918 "{T:Commit/%13.13s}{T:LookupP/%13.13s}" 919 "{T:SetClId/%13.13s}{T:SetClIdCf/%13.13s}\n"); 920 xo_emit("{:fsinfo/%13ju}{:pathconf/%13ju}{:commit/%13ju}" 921 "{:lookupp/%13ju}{:setclientid/%13ju}{:setclientidcfrm/%13ju}\n", 922 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_FSINFO], 923 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_PATHCONF], 924 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_COMMIT], 925 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LOOKUPP], 926 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SETCLIENTID], 927 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SETCLIENTIDCFRM]); 928 xo_emit("{T:Open/%13.13s}{T:OpenAttr/%13.13s}" 929 "{T:OpenDwnGr/%13.13s}{T:OpenCfrm/%13.13s}" 930 "{T:DelePurge/%13.13s}{T:DelRet/%13.13s}\n"); 931 xo_emit("{:open/%13ju}{:openattr/%13ju}{:opendwgr/%13ju}" 932 "{:opencfrm/%13ju}{:delepurge/%13ju}{:delreg/%13ju}\n", 933 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_OPEN], 934 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_OPENATTR], 935 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_OPENDOWNGRADE], 936 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_OPENCONFIRM], 937 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_DELEGPURGE], 938 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_DELEGRETURN]); 939 xo_emit("{T:GetFH/%13.13s}{T:Lock/%13.13s}" 940 "{T:LockT/%13.13s}{T:LockU/%13.13s}" 941 "{T:Close/%13.13s}{T:Verify/%13.13s}\n"); 942 xo_emit("{:getfh/%13ju}{:lock/%13ju}{:lockt/%13ju}" 943 "{:locku/%13ju}{:close/%13ju}{:verify/%13ju}\n", 944 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_GETFH], 945 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LOCK], 946 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LOCKT], 947 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LOCKU], 948 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_CLOSE], 949 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_VERIFY]); 950 xo_emit("{T:NVerify/%13.13s}{T:PutFH/%13.13s}" 951 "{T:PutPubFH/%13.13s}{T:PutRootFH/%13.13s}" 952 "{T:Renew/%13.13s}{T:RestoreFH/%13.13s}\n"); 953 xo_emit("{:nverify/%13ju}{:putfh/%13ju}{:putpubfh/%13ju}" 954 "{:putrootfh/%13ju}{:renew/%13ju}{:restore/%13ju}\n", 955 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_NVERIFY], 956 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_PUTFH], 957 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_PUTPUBFH], 958 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_PUTROOTFH], 959 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_RENEW], 960 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_RESTOREFH]); 961 xo_emit("{T:SaveFH/%13.13s}{T:Secinfo/%13.13s}" 962 "{T:RelLockOwn/%13.13s}{T:V4Create/%13.13s}\n"); 963 xo_emit("{:savefh/%13ju}{:secinfo/%13ju}{:rellockown/%13ju}" 964 "{:v4create/%13ju}\n", 965 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SAVEFH], 966 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SECINFO], 967 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_RELEASELCKOWN], 968 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_CREATE]); 969 if (nfs41) { 970 xo_open_container("nfsv41"); 971 xo_emit("{T:BackChannelCtrl/%13.13s}{T:BindConnToSess/%13.13s}" 972 "{T:ExchangeID/%13.13s}{T:CreateSess/%13.13s}" 973 "{T:DestroySess/%13.13s}{T:FreeStateID/%13.13s}\n"); 974 xo_emit("{:backchannelctrl/%13ju}{:bindconntosess/%13ju}" 975 "{:exchangeid/%13ju}{:createsess/%13ju}" 976 "{:destroysess/%13ju}{:freestateid/%13ju}\n", 977 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_BACKCHANNELCTL], 978 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_BINDCONNTOSESS], 979 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_EXCHANGEID], 980 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_CREATESESSION], 981 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_DESTROYSESSION], 982 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_FREESTATEID]), 983 984 xo_emit("{T:GetDirDeleg/%13.13s}{T:GetDevInfo/%13.13s}" 985 "{T:GetDevList/%13.13s}{T:layoutCommit/%13.13s}" 986 "{T:LayoutGet/%13.13s}{T:LayoutReturn/%13.13s}\n"); 987 xo_emit("{:getdirdeleg/%13ju}{:getdevinfo/%13ju}" 988 "{:getdevlist/%13ju}{:layoutcommit/%13ju}" 989 "{:layoutget/%13ju}{:layoutreturn/%13ju}\n", 990 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_GETDIRDELEG], 991 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_GETDEVINFO], 992 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_GETDEVLIST], 993 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LAYOUTCOMMIT], 994 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LAYOUTGET], 995 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LAYOUTRETURN]); 996 997 xo_emit("{T:SecInfNoName/%13.13s}{T:Sequence/%13.13s}" 998 "{T:SetSSV/%13.13s}{T:TestStateID/%13.13s}" 999 "{T:WantDeleg/%13.13s}{T:DestroyClId/%13.13s}\n"); 1000 xo_emit("{:secinfnoname/%13ju}{:sequence/%13ju}" 1001 "{:setssv/%13ju}{:teststateid/%13ju}{:wantdeleg/%13ju}" 1002 "{:destroyclid/%13ju}\n", 1003 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SECINFONONAME], 1004 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SEQUENCE], 1005 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SETSSV], 1006 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_TESTSTATEID], 1007 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_WANTDELEG], 1008 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_DESTROYCLIENTID]); 1009 1010 xo_emit("{T:ReclaimCompl/%13.13s}\n"); 1011 xo_emit("{:reclaimcompl/%13ju}\n", 1012 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_RECLAIMCOMPL]); 1013 1014 xo_close_container("nfsv41"); 1015 1016 xo_open_container("nfsv42"); 1017 1018 xo_emit("{T:Allocate/%13.13s}{T:Copy/%13.13s}" 1019 "{T:CopyNotify/%13.13s}{T:Deallocate/%13.13s}" 1020 "{T:IOAdvise/%13.13s}{T:LayoutError/%13.13s}\n"); 1021 xo_emit("{:allocate/%13ju}{:copy/%13ju}" 1022 "{:copynotify/%13ju}{:deallocate/%13ju}" 1023 "{:ioadvise/%13ju}{:layouterror/%13ju}\n", 1024 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_ALLOCATE], 1025 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_COPY], 1026 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_COPYNOTIFY], 1027 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_DEALLOCATE], 1028 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_IOADVISE], 1029 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LAYOUTERROR]); 1030 1031 xo_emit("{T:LayoutStats/%13.13s}{T:OffloadCncl/%13.13s}" 1032 "{T:OffloadStat/%13.13s}{T:ReadPlus/%13.13s}" 1033 "{T:Seek/%13.13s}{T:WriteSame/%13.13s}\n"); 1034 xo_emit("{:layoutstats/%13ju}{:offloadcncl/%13ju}" 1035 "{:offloadstat/%13ju}{:readplus/%13ju}" 1036 "{:seek/%13ju}{:writesame/%13ju}\n", 1037 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LAYOUTSTATS], 1038 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_OFFLOADCANCEL], 1039 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_OFFLOADSTATUS], 1040 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_READPLUS], 1041 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SEEK], 1042 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_WRITESAME]); 1043 1044 xo_emit("{T:Clone/%13.13s}{T:GetExtattr/%13.13s}" 1045 "{T:SetExtattr/%13.13s}{T:ListExtattr/%13.13s}" 1046 "{T:RmExtattr/%13.13s}\n"); 1047 xo_emit("{:clone/%13ju}{:getextattr/%13ju}" 1048 "{:setextattr/%13ju}{:listextattr/%13ju}" 1049 "{:rmextattr/%13ju}\n", 1050 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_CLONE], 1051 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_GETXATTR], 1052 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SETXATTR], 1053 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LISTXATTRS], 1054 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_REMOVEXATTR]); 1055 1056 xo_close_container("nfsv42"); 1057 } 1058 1059 xo_close_container("operations"); 1060 1061 if (printtitle) 1062 xo_emit("{T:Server:}\n"); 1063 xo_open_container("server"); 1064 xo_emit("{T:Clients/%13.13s}{T:OpenOwner/%13.13s}" 1065 "{T:Opens/%13.13s}{T:LockOwner/%13.13s}{T:Locks/%13.13s}" 1066 "{T:Delegs/%13.13s}\n"); 1067 xo_emit("{:clients/%13ju}{:openowner/%13ju}{:opens/%13ju}" 1068 "{:lockowner/%13ju}{:locks/%13ju}{:delegs/%13ju}\n", 1069 (uintmax_t)ext_nfsstats.srvclients, 1070 (uintmax_t)ext_nfsstats.srvopenowners, 1071 (uintmax_t)ext_nfsstats.srvopens, 1072 (uintmax_t)ext_nfsstats.srvlockowners, 1073 (uintmax_t)ext_nfsstats.srvlocks, 1074 (uintmax_t)ext_nfsstats.srvdelegates); 1075 xo_emit("{T:Layouts/%13.13s}\n"); 1076 xo_emit("{:layouts/%13ju}\n", 1077 (uintmax_t)ext_nfsstats.srvlayouts); 1078 xo_close_container("server"); 1079 1080 if (printtitle) 1081 xo_emit("{T:Server Cache Stats:}\n"); 1082 xo_open_container("cache"); 1083 xo_emit("{T:Inprog/%13.13s}" 1084 "{T:Non-idem/%13.13s}{T:Misses/%13.13s}" 1085 "{T:CacheSize/%13.13s}{T:TCPPeak/%13.13s}\n"); 1086 xo_emit("{:inprog/%13ju}{:nonidem/%13ju}" 1087 "{:misses/%13ju}{:cachesize/%13ju}{:tcppeak/%13ju}\n", 1088 (uintmax_t)ext_nfsstats.srvcache_inproghits, 1089 (uintmax_t)ext_nfsstats.srvcache_nonidemdonehits, 1090 (uintmax_t)ext_nfsstats.srvcache_misses, 1091 (uintmax_t)ext_nfsstats.srvcache_size, 1092 (uintmax_t)ext_nfsstats.srvcache_tcppeak); 1093 xo_close_container("cache"); 1094 1095 xo_close_container("serverstats"); 1096 } 1097 1098 xo_close_container("nfsv4"); 1099 } 1100 1101 static void 1102 compute_totals(struct nfsstatsv1 *total_stats, struct nfsstatsv1 *cur_stats) 1103 { 1104 int i; 1105 1106 bzero(total_stats, sizeof(*total_stats)); 1107 for (i = 0; i < (NFSV42_NOPS + NFSV4OP_FAKENOPS); i++) { 1108 total_stats->srvbytes[0] += cur_stats->srvbytes[i]; 1109 total_stats->srvops[0] += cur_stats->srvops[i]; 1110 bintime_add(&total_stats->srvduration[0], 1111 &cur_stats->srvduration[i]); 1112 total_stats->srvrpccnt[i] = cur_stats->srvrpccnt[i]; 1113 } 1114 total_stats->srvstartcnt = cur_stats->srvstartcnt; 1115 total_stats->srvdonecnt = cur_stats->srvdonecnt; 1116 total_stats->busytime = cur_stats->busytime; 1117 1118 } 1119 1120 /* 1121 * Print a running summary of nfs statistics for the experimental client and/or 1122 * server. 1123 * Repeat display every interval seconds, showing statistics 1124 * collected over that interval. Assumes that interval is non-zero. 1125 * First line printed at top of screen is always cumulative. 1126 */ 1127 static void 1128 exp_sidewaysintpr(u_int interval, int clientOnly, int serverOnly, 1129 int newStats) 1130 { 1131 struct nfsstatsv1 nfsstats, lastst, *ext_nfsstatsp; 1132 struct nfsstatsv1 curtotal, lasttotal; 1133 struct timespec ts, lastts; 1134 int hdrcnt = 1; 1135 1136 ext_nfsstatsp = &lastst; 1137 ext_nfsstatsp->vers = NFSSTATS_V1; 1138 if (nfssvc(NFSSVC_GETSTATS | NFSSVC_NEWSTRUCT, ext_nfsstatsp) < 0) 1139 err(1, "Can't get stats"); 1140 clock_gettime(CLOCK_MONOTONIC, &lastts); 1141 compute_totals(&lasttotal, ext_nfsstatsp); 1142 sleep(interval); 1143 1144 for (;;) { 1145 ext_nfsstatsp = &nfsstats; 1146 ext_nfsstatsp->vers = NFSSTATS_V1; 1147 if (nfssvc(NFSSVC_GETSTATS | NFSSVC_NEWSTRUCT, ext_nfsstatsp) 1148 < 0) 1149 err(1, "Can't get stats"); 1150 clock_gettime(CLOCK_MONOTONIC, &ts); 1151 1152 if (--hdrcnt == 0) { 1153 printhdr(clientOnly, serverOnly, newStats); 1154 if (newStats) 1155 hdrcnt = 20; 1156 else if (clientOnly && serverOnly) 1157 hdrcnt = 10; 1158 else 1159 hdrcnt = 20; 1160 } 1161 if (clientOnly && newStats == 0) { 1162 printf("%s %6ju %6ju %6ju %6ju %6ju %6ju %6ju %6ju", 1163 ((clientOnly && serverOnly) ? "Client:" : ""), 1164 (uintmax_t)DELTA(rpccnt[NFSPROC_GETATTR]), 1165 (uintmax_t)DELTA(rpccnt[NFSPROC_LOOKUP]), 1166 (uintmax_t)DELTA(rpccnt[NFSPROC_READLINK]), 1167 (uintmax_t)DELTA(rpccnt[NFSPROC_READ]), 1168 (uintmax_t)DELTA(rpccnt[NFSPROC_WRITE]), 1169 (uintmax_t)DELTA(rpccnt[NFSPROC_RENAME]), 1170 (uintmax_t)DELTA(rpccnt[NFSPROC_ACCESS]), 1171 (uintmax_t)(DELTA(rpccnt[NFSPROC_READDIR]) + 1172 DELTA(rpccnt[NFSPROC_READDIRPLUS])) 1173 ); 1174 if (widemode) { 1175 printf(" %s %s %s %s %s %s", 1176 sperc1(DELTA(attrcache_hits), 1177 DELTA(attrcache_misses)), 1178 sperc1(DELTA(lookupcache_hits), 1179 DELTA(lookupcache_misses)), 1180 sperc2(DELTA(biocache_reads), 1181 DELTA(read_bios)), 1182 sperc2(DELTA(biocache_writes), 1183 DELTA(write_bios)), 1184 sperc1(DELTA(accesscache_hits), 1185 DELTA(accesscache_misses)), 1186 sperc2(DELTA(biocache_readdirs), 1187 DELTA(readdir_bios)) 1188 ); 1189 } 1190 printf("\n"); 1191 } 1192 1193 if (serverOnly && newStats) { 1194 long double cur_secs, last_secs, etime; 1195 long double mbsec; 1196 long double kb_per_transfer; 1197 long double transfers_per_second; 1198 long double ms_per_transfer; 1199 uint64_t queue_len; 1200 long double busy_pct; 1201 int i; 1202 1203 cur_secs = ts.tv_sec + 1204 ((long double)ts.tv_nsec / 1000000000); 1205 last_secs = lastts.tv_sec + 1206 ((long double)lastts.tv_nsec / 1000000000); 1207 etime = cur_secs - last_secs; 1208 1209 compute_totals(&curtotal, &nfsstats); 1210 1211 for (i = 0; i < NUM_STAT_TYPES; i++) { 1212 compute_new_stats(&nfsstats, &lastst, 1213 STAT_TYPE_TO_NFS(i), etime, &mbsec, 1214 &kb_per_transfer, 1215 &transfers_per_second, 1216 &ms_per_transfer, &queue_len, 1217 &busy_pct); 1218 1219 if (i == STAT_TYPE_COMMIT) { 1220 if (widemode == 0) 1221 continue; 1222 1223 printf("%2.0Lf %7.2Lf ", 1224 transfers_per_second, 1225 ms_per_transfer); 1226 } else { 1227 printf("%5.2Lf %5.0Lf %7.2Lf ", 1228 kb_per_transfer, 1229 transfers_per_second, mbsec); 1230 if (widemode) 1231 printf("%5.2Lf ", 1232 ms_per_transfer); 1233 } 1234 } 1235 1236 compute_new_stats(&curtotal, &lasttotal, 0, etime, 1237 &mbsec, &kb_per_transfer, &transfers_per_second, 1238 &ms_per_transfer, &queue_len, &busy_pct); 1239 1240 printf("%5.2Lf %5.0Lf %7.2Lf %5.2Lf %3ju %3.0Lf\n", 1241 kb_per_transfer, transfers_per_second, mbsec, 1242 ms_per_transfer, queue_len, busy_pct); 1243 } else if (serverOnly) { 1244 printf("%s %6ju %6ju %6ju %6ju %6ju %6ju %6ju %6ju", 1245 ((clientOnly && serverOnly) ? "Server:" : ""), 1246 (uintmax_t)DELTA(srvrpccnt[NFSV4OP_GETATTR]), 1247 (uintmax_t)DELTA(srvrpccnt[NFSV4OP_LOOKUP]), 1248 (uintmax_t)DELTA(srvrpccnt[NFSV4OP_READLINK]), 1249 (uintmax_t)DELTA(srvrpccnt[NFSV4OP_READ]), 1250 (uintmax_t)DELTA(srvrpccnt[NFSV4OP_WRITE]), 1251 (uintmax_t)DELTA(srvrpccnt[NFSV4OP_RENAME]), 1252 (uintmax_t)DELTA(srvrpccnt[NFSV4OP_ACCESS]), 1253 (uintmax_t)(DELTA(srvrpccnt[NFSV4OP_READDIR]) + 1254 DELTA(srvrpccnt[NFSV4OP_READDIRPLUS]))); 1255 printf("\n"); 1256 } 1257 bcopy(&nfsstats, &lastst, sizeof(lastst)); 1258 bcopy(&curtotal, &lasttotal, sizeof(lasttotal)); 1259 lastts = ts; 1260 fflush(stdout); 1261 sleep(interval); 1262 } 1263 /*NOTREACHED*/ 1264 } 1265