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 char *memf, *nlistf; 153 int mntlen, i; 154 char buf[1024]; 155 struct statfs *mntbuf; 156 struct nfscl_dumpmntopts dumpmntopts; 157 158 interval = 0; 159 memf = nlistf = NULL; 160 161 argc = xo_parse_args(argc, argv); 162 if (argc < 0) 163 exit(1); 164 165 xo_set_version(NFSSTAT_XO_VERSION); 166 167 while ((ch = getopt(argc, argv, "cdEesWM:mN:w:zq")) != -1) 168 switch(ch) { 169 case 'M': 170 memf = optarg; 171 break; 172 case 'm': 173 /* Display mount options for NFS mount points. */ 174 mntlen = getmntinfo(&mntbuf, MNT_NOWAIT); 175 for (i = 0; i < mntlen; i++) { 176 if (strcmp(mntbuf->f_fstypename, "nfs") == 0) { 177 dumpmntopts.ndmnt_fname = 178 mntbuf->f_mntonname; 179 dumpmntopts.ndmnt_buf = buf; 180 dumpmntopts.ndmnt_blen = sizeof(buf); 181 if (nfssvc(NFSSVC_DUMPMNTOPTS, 182 &dumpmntopts) >= 0) 183 printf("%s on %s\n%s\n", 184 mntbuf->f_mntfromname, 185 mntbuf->f_mntonname, buf); 186 else if (errno == EPERM) 187 errx(1, "Only priviledged users" 188 " can use the -m option"); 189 } 190 mntbuf++; 191 } 192 exit(0); 193 case 'N': 194 nlistf = optarg; 195 break; 196 case 'W': 197 widemode = 1; 198 break; 199 case 'w': 200 interval = atoi(optarg); 201 break; 202 case 'c': 203 clientOnly = 1; 204 if (serverOnly < 0) 205 serverOnly = 0; 206 break; 207 case 'd': 208 newStats = 1; 209 if (interval == 0) 210 interval = 1; 211 break; 212 case 's': 213 serverOnly = 1; 214 if (clientOnly < 0) 215 clientOnly = 0; 216 break; 217 case 'z': 218 zflag = 1; 219 break; 220 case 'E': 221 if (extra_output != 0) 222 xo_err(1, "-e and -E are mutually exclusive"); 223 extra_output = 2; 224 break; 225 case 'e': 226 if (extra_output != 0) 227 xo_err(1, "-e and -E are mutually exclusive"); 228 extra_output = 1; 229 break; 230 case 'q': 231 printtitle = 0; 232 break; 233 case '?': 234 default: 235 usage(); 236 } 237 argc -= optind; 238 argv += optind; 239 240 #define BACKWARD_COMPATIBILITY 241 #ifdef BACKWARD_COMPATIBILITY 242 if (*argv) { 243 interval = atoi(*argv); 244 if (*++argv) { 245 nlistf = *argv; 246 if (*++argv) 247 memf = *argv; 248 } 249 } 250 #endif 251 if (modfind("nfscommon") < 0) 252 xo_err(1, "NFS client/server not loaded"); 253 254 if (interval) { 255 exp_sidewaysintpr(interval, clientOnly, serverOnly, 256 newStats); 257 } else { 258 xo_open_container("nfsstat"); 259 if (extra_output != 0) 260 exp_intpr(clientOnly, serverOnly, extra_output - 1); 261 else 262 intpr(clientOnly, serverOnly); 263 xo_close_container("nfsstat"); 264 } 265 266 xo_finish(); 267 exit(0); 268 } 269 270 /* 271 * Print a description of the nfs stats. 272 */ 273 static void 274 intpr(int clientOnly, int serverOnly) 275 { 276 int nfssvc_flag; 277 278 nfssvc_flag = NFSSVC_GETSTATS | NFSSVC_NEWSTRUCT; 279 if (zflag != 0) { 280 if (clientOnly != 0) 281 nfssvc_flag |= NFSSVC_ZEROCLTSTATS; 282 if (serverOnly != 0) 283 nfssvc_flag |= NFSSVC_ZEROSRVSTATS; 284 } 285 ext_nfsstats.vers = NFSSTATS_V1; 286 if (nfssvc(nfssvc_flag, &ext_nfsstats) < 0) 287 xo_err(1, "Can't get stats"); 288 if (clientOnly) { 289 xo_open_container("clientstats"); 290 291 if (printtitle) 292 xo_emit("{T:Client Info:\n"); 293 294 xo_open_container("operations"); 295 xo_emit("{T:Rpc Counts:}\n"); 296 297 xo_emit("{T:Getattr/%13.13s}{T:Setattr/%13.13s}" 298 "{T:Lookup/%13.13s}{T:Readlink/%13.13s}" 299 "{T:Read/%13.13s}{T:Write/%13.13s}" 300 "{T:Create/%13.13s}{T:Remove/%13.13s}\n"); 301 xo_emit("{:getattr/%13ju}{:setattr/%13ju}" 302 "{:lookup/%13ju}{:readlink/%13ju}" 303 "{:read/%13ju}{:write/%13ju}" 304 "{:create/%13ju}{:remove/%13ju}\n", 305 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_GETATTR], 306 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_SETATTR], 307 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LOOKUP], 308 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_READLINK], 309 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_READ], 310 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_WRITE], 311 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_CREATE], 312 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_REMOVE]); 313 314 xo_emit("{T:Rename/%13.13s}{T:Link/%13.13s}" 315 "{T:Symlink/%13.13s}{T:Mkdir/%13.13s}" 316 "{T:Rmdir/%13.13s}{T:Readdir/%13.13s}" 317 "{T:RdirPlus/%13.13s}{T:Access/%13.13s}\n"); 318 xo_emit("{:rename/%13ju}{:link/%13ju}" 319 "{:symlink/%13ju}{:mkdir/%13ju}" 320 "{:rmdir/%13ju}{:readdir/%13ju}" 321 "{:rdirplus/%13ju}{:access/%13ju}\n", 322 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_RENAME], 323 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LINK], 324 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_SYMLINK], 325 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_MKDIR], 326 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_RMDIR], 327 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_READDIR], 328 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_READDIRPLUS], 329 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_ACCESS]); 330 331 xo_emit("{T:Mknod/%13.13s}{T:Fsstat/%13.13s}" 332 "{T:Fsinfo/%13.13s}{T:PathConf/%13.13s}" 333 "{T:Commit/%13.13s}\n"); 334 xo_emit("{:mknod/%13ju}{:fsstat/%13ju}" 335 "{:fsinfo/%13ju}{:pathconf/%13ju}" 336 "{:commit/%13ju}\n", 337 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_MKNOD], 338 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_FSSTAT], 339 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_FSINFO], 340 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_PATHCONF], 341 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_COMMIT]); 342 343 xo_close_container("operations"); 344 345 xo_open_container("rpcs"); 346 xo_emit("{T:Rpc Info:}\n"); 347 348 xo_emit("{T:TimedOut/%13.13s}{T:Invalid/%13.13s}" 349 "{T:X Replies/%13.13s}{T:Retries/%13.13s}" 350 "{T:Requests/%13.13s}\n"); 351 xo_emit("{:timedout/%13ju}{:invalid/%13ju}" 352 "{:xreplies/%13ju}{:retries/%13ju}" 353 "{:requests/%13ju}\n", 354 (uintmax_t)ext_nfsstats.rpctimeouts, 355 (uintmax_t)ext_nfsstats.rpcinvalid, 356 (uintmax_t)ext_nfsstats.rpcunexpected, 357 (uintmax_t)ext_nfsstats.rpcretries, 358 (uintmax_t)ext_nfsstats.rpcrequests); 359 xo_close_container("rpcs"); 360 361 xo_open_container("cache"); 362 xo_emit("{T:Cache Info:}\n"); 363 364 xo_emit("{T:Attr Hits/%13.13s}{T:Attr Misses/%13.13s}" 365 "{T:Lkup Hits/%13.13s}{T:Lkup Misses/%13.13s}" 366 "{T:BioR Hits/%13.13s}{T:BioR Misses/%13.13s}" 367 "{T:BioW Hits/%13.13s}{T:BioW Misses/%13.13s}\n"); 368 xo_emit("{:attrhits/%13ju}{:attrmisses/%13ju}" 369 "{:lkuphits/%13ju}{:lkupmisses/%13ju}" 370 "{:biorhits/%13ju}{:biormisses/%13ju}" 371 "{:biowhits/%13ju}{:biowmisses/%13ju}\n", 372 (uintmax_t)ext_nfsstats.attrcache_hits, 373 (uintmax_t)ext_nfsstats.attrcache_misses, 374 (uintmax_t)ext_nfsstats.lookupcache_hits, 375 (uintmax_t)ext_nfsstats.lookupcache_misses, 376 (uintmax_t)(ext_nfsstats.biocache_reads - 377 ext_nfsstats.read_bios), 378 (uintmax_t)ext_nfsstats.read_bios, 379 (uintmax_t)(ext_nfsstats.biocache_writes - 380 ext_nfsstats.write_bios), 381 (uintmax_t)ext_nfsstats.write_bios); 382 383 xo_emit("{T:BioRL Hits/%13.13s}{T:BioRL Misses/%13.13s}" 384 "{T:BioD Hits/%13.13s}{T:BioD Misses/%13.13s}" 385 "{T:DirE Hits/%13.13s}{T:DirE Misses/%13.13s}" 386 "{T:Accs Hits/%13.13s}{T:Accs Misses/%13.13s}\n"); 387 xo_emit("{:biosrlhits/%13ju}{:biorlmisses/%13ju}" 388 "{:biodhits/%13ju}{:biodmisses/%13ju}" 389 "{:direhits/%13ju}{:diremisses/%13ju}" 390 "{:accshits/%13ju}{:accsmisses/%13ju}\n", 391 (uintmax_t)(ext_nfsstats.biocache_readlinks - 392 ext_nfsstats.readlink_bios), 393 (uintmax_t)ext_nfsstats.readlink_bios, 394 (uintmax_t)(ext_nfsstats.biocache_readdirs - 395 ext_nfsstats.readdir_bios), 396 (uintmax_t)ext_nfsstats.readdir_bios, 397 (uintmax_t)ext_nfsstats.direofcache_hits, 398 (uintmax_t)ext_nfsstats.direofcache_misses, 399 (uintmax_t)ext_nfsstats.accesscache_hits, 400 (uintmax_t)ext_nfsstats.accesscache_misses); 401 402 xo_close_container("cache"); 403 404 xo_close_container("clientstats"); 405 } 406 if (serverOnly) { 407 xo_open_container("serverstats"); 408 409 xo_emit("{T:Server Info:}\n"); 410 xo_open_container("operations"); 411 412 xo_emit("{T:Getattr/%13.13s}{T:Setattr/%13.13s}" 413 "{T:Lookup/%13.13s}{T:Readlink/%13.13s}" 414 "{T:Read/%13.13s}{T:Write/%13.13s}" 415 "{T:Create/%13.13s}{T:Remove/%13.13s}\n"); 416 xo_emit("{:getattr/%13ju}{:setattr/%13ju}" 417 "{:lookup/%13ju}{:readlink/%13ju}" 418 "{:read/%13ju}{:write/%13ju}" 419 "{:create/%13ju}{:remove/%13ju}\n", 420 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_GETATTR], 421 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SETATTR], 422 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LOOKUP], 423 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_READLINK], 424 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_READ], 425 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_WRITE], 426 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_CREATE], 427 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_REMOVE]); 428 429 xo_emit("{T:Rename/%13.13s}{T:Link/%13.13s}" 430 "{T:Symlink/%13.13s}{T:Mkdir/%13.13s}" 431 "{T:Rmdir/%13.13s}{T:Readdir/%13.13s}" 432 "{T:RdirPlus/%13.13s}{T:Access/%13.13s}\n"); 433 xo_emit("{:rename/%13ju}{:link/%13ju}" 434 "{:symlink/%13ju}{:mkdir/%13ju}" 435 "{:rmdir/%13ju}{:readdir/%13ju}" 436 "{:rdirplus/%13ju}{:access/%13ju}\n", 437 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_RENAME], 438 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LINK], 439 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SYMLINK], 440 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_MKDIR], 441 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_RMDIR], 442 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_READDIR], 443 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_READDIRPLUS], 444 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_ACCESS]); 445 446 xo_emit("{T:Mknod/%13.13s}{T:Fsstat/%13.13s}" 447 "{T:Fsinfo/%13.13s}{T:PathConf/%13.13s}" 448 "{T:Commit/%13.13s}\n"); 449 xo_emit("{:mknod/%13ju}{:fsstat/%13ju}" 450 "{:fsinfo/%13ju}{:pathconf/%13ju}" 451 "{:commit/%13ju}\n", 452 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_MKNOD], 453 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_FSSTAT], 454 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_FSINFO], 455 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_PATHCONF], 456 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_COMMIT]); 457 458 xo_close_container("operations"); 459 460 xo_open_container("server"); 461 xo_emit("{T:Server Re-Failed}\n"); 462 xo_emit("{:retfailed/%16ju}\n", (uintmax_t)ext_nfsstats.srvrpc_errs); 463 464 xo_emit("{T:Server Faults}\n"); 465 xo_emit("{:faults/%13ju}\n", (uintmax_t)ext_nfsstats.srv_errs); 466 467 xo_emit("{T:Server Write Gathering:/%13.13s}\n"); 468 469 xo_emit("{T:WriteOps/%13.13s}{T:WriteRPC/%13.13s}" 470 "{T:Opsaved/%13.13s}\n"); 471 xo_emit("{:writeops/%13ju}{:writerpc/%13ju}" 472 "{:opsaved/%13ju}\n", 473 /* 474 * The new client doesn't do write gathering. It was 475 * only useful for NFSv2. 476 */ 477 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_WRITE], 478 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_WRITE], 0); 479 480 xo_close_container("server"); 481 482 xo_open_container("cache"); 483 xo_emit("{T:Server Cache Stats:/%13.13s}\n"); 484 xo_emit("{T:Inprog/%13.13s}{T:Idem/%13.13s}" 485 "{T:Non-Idem/%13.13s}{T:Misses/%13.13s}\n"); 486 xo_emit("{:inprog/%13ju}{:idem/%13ju}" 487 "{:nonidem/%13ju}{:misses/%13ju}\n", 488 (uintmax_t)ext_nfsstats.srvcache_inproghits, 489 (uintmax_t)ext_nfsstats.srvcache_idemdonehits, 490 (uintmax_t)ext_nfsstats.srvcache_nonidemdonehits, 491 (uintmax_t)ext_nfsstats.srvcache_misses); 492 xo_close_container("cache"); 493 494 xo_close_container("serverstats"); 495 } 496 } 497 498 static void 499 printhdr(int clientOnly, int serverOnly, int newStats) 500 { 501 502 if (newStats) { 503 printf(" [%s Read %s] [%s Write %s] " 504 "%s[=========== Total ============]\n" 505 " KB/t tps MB/s%s KB/t tps MB/s%s " 506 "%sKB/t tps MB/s ms ql %%b", 507 widemode ? "========" : "=====", 508 widemode ? "========" : "=====", 509 widemode ? "========" : "=====", 510 widemode ? "=======" : "====", 511 widemode ? "[Commit ] " : "", 512 widemode ? " ms" : "", 513 widemode ? " ms" : "", 514 widemode ? "tps ms " : ""); 515 } else { 516 printf("%s%6.6s %6.6s %6.6s %6.6s %6.6s %6.6s %6.6s %6.6s", 517 ((serverOnly && clientOnly) ? " " : " "), 518 "GtAttr", "Lookup", "Rdlink", "Read", "Write", "Rename", 519 "Access", "Rddir"); 520 if (widemode && clientOnly) { 521 printf(" Attr Lkup BioR BioW Accs BioD"); 522 } 523 } 524 printf("\n"); 525 fflush(stdout); 526 } 527 528 static void 529 usage(void) 530 { 531 (void)fprintf(stderr, 532 "usage: nfsstat [-cdemszW] [-M core] [-N system] [-w wait]\n"); 533 exit(1); 534 } 535 536 static char SPBuf[64][8]; 537 static int SPIndex; 538 539 static char * 540 sperc1(int hits, int misses) 541 { 542 char *p = SPBuf[SPIndex]; 543 544 if (hits + misses) { 545 sprintf(p, "%3d%%", 546 (int)(char)((quad_t)hits * 100 / (hits + misses))); 547 } else { 548 sprintf(p, " -"); 549 } 550 SPIndex = (SPIndex + 1) & 63; 551 return(p); 552 } 553 554 static char * 555 sperc2(int ttl, int misses) 556 { 557 char *p = SPBuf[SPIndex]; 558 559 if (ttl) { 560 sprintf(p, "%3d%%", 561 (int)(char)((quad_t)(ttl - misses) * 100 / ttl)); 562 } else { 563 sprintf(p, " -"); 564 } 565 SPIndex = (SPIndex + 1) & 63; 566 return(p); 567 } 568 569 #define DELTA_T(field) \ 570 devstat_compute_etime(&cur_stats->field, \ 571 (prev_stats ? &prev_stats->field : NULL)) 572 573 /* 574 * XXX KDM mostly copied from ctlstat. We should commonize the code (and 575 * the devstat code) somehow. 576 */ 577 static void 578 compute_new_stats(struct nfsstatsv1 *cur_stats, 579 struct nfsstatsv1 *prev_stats, int curop, 580 long double etime, long double *mbsec, 581 long double *kb_per_transfer, 582 long double *transfers_per_second, 583 long double *ms_per_transfer, uint64_t *queue_len, 584 long double *busy_pct) 585 { 586 uint64_t total_bytes = 0, total_operations = 0; 587 struct bintime total_time_bt; 588 struct timespec total_time_ts; 589 590 bzero(&total_time_bt, sizeof(total_time_bt)); 591 bzero(&total_time_ts, sizeof(total_time_ts)); 592 593 total_bytes = cur_stats->srvbytes[curop]; 594 total_operations = cur_stats->srvops[curop]; 595 if (prev_stats != NULL) { 596 total_bytes -= prev_stats->srvbytes[curop]; 597 total_operations -= prev_stats->srvops[curop]; 598 } 599 600 *mbsec = total_bytes; 601 *mbsec /= 1024 * 1024; 602 if (etime > 0.0) { 603 *busy_pct = DELTA_T(busytime); 604 if (*busy_pct < 0) 605 *busy_pct = 0; 606 *busy_pct /= etime; 607 *busy_pct *= 100; 608 if (*busy_pct < 0) 609 *busy_pct = 0; 610 *mbsec /= etime; 611 } else { 612 *busy_pct = 0; 613 *mbsec = 0; 614 } 615 *kb_per_transfer = total_bytes; 616 *kb_per_transfer /= 1024; 617 if (total_operations > 0) 618 *kb_per_transfer /= total_operations; 619 else 620 *kb_per_transfer = 0; 621 if (etime > 0.0) { 622 *transfers_per_second = total_operations; 623 *transfers_per_second /= etime; 624 } else { 625 *transfers_per_second = 0.0; 626 } 627 628 if (total_operations > 0) { 629 *ms_per_transfer = DELTA_T(srvduration[curop]); 630 *ms_per_transfer /= total_operations; 631 *ms_per_transfer *= 1000; 632 } else 633 *ms_per_transfer = 0.0; 634 635 *queue_len = cur_stats->srvstartcnt - cur_stats->srvdonecnt; 636 } 637 638 /* 639 * Print a description of the nfs stats for the client/server, 640 * including NFSv4.1. 641 */ 642 static void 643 exp_intpr(int clientOnly, int serverOnly, int nfs41) 644 { 645 int nfssvc_flag; 646 647 xo_open_container("nfsv4"); 648 649 nfssvc_flag = NFSSVC_GETSTATS | NFSSVC_NEWSTRUCT; 650 if (zflag != 0) { 651 if (clientOnly != 0) 652 nfssvc_flag |= NFSSVC_ZEROCLTSTATS; 653 if (serverOnly != 0) 654 nfssvc_flag |= NFSSVC_ZEROSRVSTATS; 655 } 656 ext_nfsstats.vers = NFSSTATS_V1; 657 if (nfssvc(nfssvc_flag, &ext_nfsstats) < 0) 658 xo_err(1, "Can't get stats"); 659 if (clientOnly != 0) { 660 xo_open_container("clientstats"); 661 662 xo_open_container("operations"); 663 if (printtitle) { 664 xo_emit("{T:Client Info:}\n"); 665 xo_emit("{T:RPC Counts:}\n"); 666 } 667 xo_emit("{T:Getattr/%13.13s}{T:Setattr/%13.13s}" 668 "{T:Lookup/%13.13s}{T:Readlink/%13.13s}" 669 "{T:Read/%13.13s}{T:Write/%13.13s}\n"); 670 xo_emit("{:getattr/%13ju}{:setattr/%13ju}{:lookup/%13ju}" 671 "{:readlink/%13ju}{:read/%13ju}{:write/%13ju}\n", 672 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_GETATTR], 673 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_SETATTR], 674 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LOOKUP], 675 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_READLINK], 676 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_READ], 677 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_WRITE]); 678 xo_emit("{T:Create/%13.13s}{T:Remove/%13.13s}" 679 "{T:Rename/%13.13s}{T:Link/%13.13s}" 680 "{T:Symlink/%13.13s}{T:Mkdir/%13.13s}\n"); 681 xo_emit("{:create/%13ju}{:remove/%13ju}{:rename/%13ju}" 682 "{:link/%13ju}{:symlink/%13ju}{:mkdir/%13ju}\n", 683 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_CREATE], 684 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_REMOVE], 685 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_RENAME], 686 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LINK], 687 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_SYMLINK], 688 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_MKDIR]); 689 xo_emit("{T:Rmdir/%13.13s}{T:Readdir/%13.13s}" 690 "{T:RdirPlus/%13.13s}{T:Access/%13.13s}" 691 "{T:Mknod/%13.13s}{T:Fsstat/%13.13s}\n"); 692 xo_emit("{:rmdir/%13ju}{:readdir/%13ju}{:rdirplus/%13ju}" 693 "{:access/%13ju}{:mknod/%13ju}{:fsstat/%13ju}\n", 694 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_RMDIR], 695 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_READDIR], 696 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_READDIRPLUS], 697 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_ACCESS], 698 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_MKNOD], 699 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_FSSTAT]); 700 xo_emit("{T:FSinfo/%13.13s}{T:pathConf/%13.13s}" 701 "{T:Commit/%13.13s}{T:SetClId/%13.13s}" 702 "{T:SetClIdCf/%13.13s}{T:Lock/%13.13s}\n"); 703 xo_emit("{:fsinfo/%13ju}{:pathconf/%13ju}{:commit/%13ju}" 704 "{:setclientid/%13ju}{:setclientidcf/%13ju}{:lock/%13ju}\n", 705 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_FSINFO], 706 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_PATHCONF], 707 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_COMMIT], 708 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_SETCLIENTID], 709 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_SETCLIENTIDCFRM], 710 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LOCK]); 711 xo_emit("{T:LockT/%13.13s}{T:LockU/%13.13s}" 712 "{T:Open/%13.13s}{T:OpenCfr/%13.13s}\n"); 713 xo_emit("{:lockt/%13ju}{:locku/%13ju}" 714 "{:open/%13ju}{:opencfr/%13ju}\n", 715 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LOCKT], 716 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LOCKU], 717 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_OPEN], 718 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_OPENCONFIRM]); 719 720 if (nfs41) { 721 xo_open_container("nfsv41"); 722 723 xo_emit("{T:OpenDownGr/%13.13s}{T:Close/%13.13s}\n"); 724 xo_emit("{:opendowngr/%13ju}{:close/%13ju}\n", 725 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_OPENDOWNGRADE], 726 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_CLOSE]); 727 728 xo_emit("{T:RelLckOwn/%13.13s}{T:FreeStateID/%13.13s}" 729 "{T:PutRootFH/%13.13s}{T:DelegRet/%13.13s}" 730 "{T:GetAcl/%13.13s}{T:SetAcl/%13.13s}\n"); 731 xo_emit("{:rellckown/%13ju}{:freestateid/%13ju}" 732 "{:getacl/%13ju}{:delegret/%13ju}" 733 "{:getacl/%13ju}{:setacl/%13ju}\n", 734 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_RELEASELCKOWN], 735 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_FREESTATEID], 736 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_PUTROOTFH], 737 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_DELEGRETURN], 738 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_GETACL], 739 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_SETACL]); 740 741 xo_emit("{T:ExchangeId/%13.13s}{T:CreateSess/%13.13s}" 742 "{T:DestroySess/%13.13s}{T:DestroyClId/%13.13s}" 743 "{T:LayoutGet/%13.13s}{T:GetDevInfo/%13.13s}\n"); 744 xo_emit("{:exchangeid/%13ju}{:createsess/%13ju}" 745 "{:destroysess/%13ju}{:destroyclid/%13ju}" 746 "{:layoutget/%13ju}{:getdevinfo/%13ju}\n", 747 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_EXCHANGEID], 748 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_CREATESESSION], 749 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_DESTROYSESSION], 750 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_DESTROYCLIENT], 751 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LAYOUTGET], 752 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_GETDEVICEINFO]); 753 754 xo_emit("{T:LayoutCommit/%13.13s}{T:LayoutReturn/%13.13s}" 755 "{T:ReclaimCompl/%13.13s}{T:ReadDataS/%13.13s}" 756 "{T:WriteDataS/%13.13s}{T:CommitDataS/%13.13s}\n"); 757 xo_emit("{:layoutcomit/%13ju}{:layoutreturn/%13ju}" 758 "{:reclaimcompl/%13ju}{:readdatas/%13ju}" 759 "{:writedatas/%13ju}{:commitdatas/%13ju}\n", 760 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LAYOUTCOMMIT], 761 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LAYOUTRETURN], 762 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_RECLAIMCOMPL], 763 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_READDS], 764 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_WRITEDS], 765 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_COMMITDS]); 766 767 xo_emit("{T:OpenLayout/%13.13s}{T:CreateLayout/%13.13s}\n"); 768 xo_emit("{:openlayout/%13ju}{:createlayout/%13ju}\n", 769 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_OPENLAYGET], 770 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_CREATELAYGET]); 771 772 xo_close_container("nfsv41"); 773 774 xo_open_container("nfsv42"); 775 776 xo_emit("{T:IOAdvise/%13.13s}{T:Allocate/%13.13s}" 777 "{T:Copy/%13.13s}{T:Seek/%13.13s}" 778 "{T:SeekDataS/%13.13s}{T:GetExtattr/%13.13s}\n"); 779 xo_emit("{:ioadvise/%13ju}{:allocate/%13ju}" 780 "{:copy/%13ju}{:seek/%13ju}" 781 "{:seekdatas/%13ju}{:getextattr/%13ju}\n", 782 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_IOADVISE], 783 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_ALLOCATE], 784 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_COPY], 785 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_SEEK], 786 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_SEEKDS], 787 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_GETEXTATTR]); 788 789 xo_emit("{T:SetExtattr/%13.13s}{T:RmExtattr/%13.13s}" 790 "{T:ListExtattr/%13.13s}\n"); 791 xo_emit("{:setextattr/%13ju}{:rmextattr/%13ju}" 792 "{:listextattr/%13ju}\n", 793 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_SETEXTATTR], 794 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_RMEXTATTR], 795 (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LISTEXTATTR]); 796 797 xo_close_container("nfsv42"); 798 } 799 xo_close_container("operations"); 800 801 xo_open_container("client"); 802 xo_emit("{T:OpenOwner/%13.13s}{T:Opens/%13.13s}" 803 "{T:LockOwner/%13.13s}{T:Locks/%13.13s}" 804 "{T:Delegs/%13.13s}{T:LocalOwn/%13.13s}\n"); 805 xo_emit("{:openowner/%13ju}{:opens/%13ju}" 806 "{:lockowner/%13ju}{:locks/%13ju}" 807 "{:delegs/%13ju}{:localown/%13ju}\n", 808 (uintmax_t)ext_nfsstats.clopenowners, 809 (uintmax_t)ext_nfsstats.clopens, 810 (uintmax_t)ext_nfsstats.cllockowners, 811 (uintmax_t)ext_nfsstats.cllocks, 812 (uintmax_t)ext_nfsstats.cldelegates, 813 (uintmax_t)ext_nfsstats.cllocalopenowners); 814 815 xo_emit("{T:LocalOpen/%13.13s}{T:LocalLown/%13.13s}" 816 "{T:LocalLock/%13.13s}\n"); 817 xo_emit("{:localopen/%13ju}{:locallown/%13ju}" 818 "{:locallock/%13ju}\n", 819 (uintmax_t)ext_nfsstats.cllocalopens, 820 (uintmax_t)ext_nfsstats.cllocallockowners, 821 (uintmax_t)ext_nfsstats.cllocallocks); 822 xo_close_container("client"); 823 824 xo_open_container("rpc"); 825 if (printtitle) 826 xo_emit("{T:Rpc Info:}\n"); 827 xo_emit("{T:TimedOut/%13.13s}{T:Invalid/%13.13s}" 828 "{T:X Replies/%13.13s}{T:Retries/%13.13s}" 829 "{T:Requests/%13.13s}\n"); 830 xo_emit("{:timedout/%13ju}{:invalid/%13ju}" 831 "{:xreplies/%13ju}{:retries/%13ju}" 832 "{:requests/%13ju}\n", 833 (uintmax_t)ext_nfsstats.rpctimeouts, 834 (uintmax_t)ext_nfsstats.rpcinvalid, 835 (uintmax_t)ext_nfsstats.rpcunexpected, 836 (uintmax_t)ext_nfsstats.rpcretries, 837 (uintmax_t)ext_nfsstats.rpcrequests); 838 xo_close_container("rpc"); 839 840 xo_open_container("cache"); 841 if (printtitle) 842 xo_emit("{T:Cache Info:}\n"); 843 xo_emit("{T:Attr Hits/%13.13s}{T:Attr Misses/%13.13s}" 844 "{T:Lkup Hits/%13.13s}{T:Lkup Misses/%13.13s}\n"); 845 xo_emit("{:attrhits/%13ju}{:attrmisses/%13ju}" 846 "{:lkuphits/%13ju}{:lkupmisses/%13ju}\n", 847 (uintmax_t)ext_nfsstats.attrcache_hits, 848 (uintmax_t)ext_nfsstats.attrcache_misses, 849 (uintmax_t)ext_nfsstats.lookupcache_hits, 850 (uintmax_t)ext_nfsstats.lookupcache_misses); 851 852 xo_emit("{T:BioR Hits/%13.13s}{T:BioR Misses/%13.13s}" 853 "{T:BioW Hits/%13.13s}{T:BioW Misses/%13.13s}\n"); 854 xo_emit("{:biorhits/%13ju}{:biormisses/%13ju}" 855 "{:biowhits/%13ju}{:biowmisses/%13ju}\n", 856 (uintmax_t)(ext_nfsstats.biocache_reads - 857 ext_nfsstats.read_bios), 858 (uintmax_t)ext_nfsstats.read_bios, 859 (uintmax_t)(ext_nfsstats.biocache_writes - 860 ext_nfsstats.write_bios), 861 (uintmax_t)ext_nfsstats.write_bios); 862 863 xo_emit("{T:BioRL Hits/%13.13s}{T:BioRL Misses/%13.13s}" 864 "{T:BioD Hits/%13.13s}{T:BioD Misses/%13.13s}\n"); 865 xo_emit("{:biorlhits/%13ju}{:biorlmisses/%13ju}" 866 "{:biodhits/%13ju}{:biodmisses/%13ju}\n", 867 (uintmax_t)(ext_nfsstats.biocache_readlinks - 868 ext_nfsstats.readlink_bios), 869 (uintmax_t)ext_nfsstats.readlink_bios, 870 (uintmax_t)(ext_nfsstats.biocache_readdirs - 871 ext_nfsstats.readdir_bios), 872 (uintmax_t)ext_nfsstats.readdir_bios); 873 874 xo_emit("{T:DirE Hits/%13.13s}{T:DirE Misses/%13.13s}\n"); 875 xo_emit("{:direhits/%13ju}{:diremisses/%13ju}\n", 876 (uintmax_t)ext_nfsstats.direofcache_hits, 877 (uintmax_t)ext_nfsstats.direofcache_misses); 878 xo_open_container("cache"); 879 880 xo_close_container("clientstats"); 881 } 882 if (serverOnly != 0) { 883 xo_open_container("serverstats"); 884 885 xo_open_container("operations"); 886 if (printtitle) 887 xo_emit("{T:Server Info:}\n"); 888 xo_emit("{T:Getattr/%13.13s}{T:Setattr/%13.13s}" 889 "{T:Lookup/%13.13s}{T:Readlink/%13.13s}" 890 "{T:Read/%13.13s}{T:Write/%13.13s}\n"); 891 xo_emit("{:getattr/%13ju}{:setattr/%13ju}{:lookup/%13ju}" 892 "{:readlink/%13ju}{:read/%13ju}{:write/%13ju}\n", 893 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_GETATTR], 894 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SETATTR], 895 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LOOKUP], 896 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_READLINK], 897 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_READ], 898 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_WRITE]); 899 xo_emit("{T:Create/%13.13s}{T:Remove/%13.13s}" 900 "{T:Rename/%13.13s}{T:Link/%13.13s}" 901 "{T:Symlink/%13.13s}{T:Mkdir/%13.13s}\n"); 902 xo_emit("{:create/%13ju}{:remove/%13ju}{:rename/%13ju}" 903 "{:link/%13ju}{:symlink/%13ju}{:mkdir/%13ju}\n", 904 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_V3CREATE], 905 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_REMOVE], 906 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_RENAME], 907 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LINK], 908 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SYMLINK], 909 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_MKDIR]); 910 xo_emit("{T:Rmdir/%13.13s}{T:Readdir/%13.13s}" 911 "{T:RdirPlus/%13.13s}{T:Access/%13.13s}" 912 "{T:Mknod/%13.13s}{T:Fsstat/%13.13s}\n"); 913 xo_emit("{:rmdir/%13ju}{:readdir/%13ju}{:rdirplus/%13ju}" 914 "{:access/%13ju}{:mknod/%13ju}{:fsstat/%13ju}\n", 915 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_RMDIR], 916 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_READDIR], 917 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_READDIRPLUS], 918 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_ACCESS], 919 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_MKNOD], 920 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_FSSTAT]); 921 xo_emit("{T:FSinfo/%13.13s}{T:pathConf/%13.13s}" 922 "{T:Commit/%13.13s}{T:LookupP/%13.13s}" 923 "{T:SetClId/%13.13s}{T:SetClIdCf/%13.13s}\n"); 924 xo_emit("{:fsinfo/%13ju}{:pathconf/%13ju}{:commit/%13ju}" 925 "{:lookupp/%13ju}{:setclientid/%13ju}{:setclientidcfrm/%13ju}\n", 926 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_FSINFO], 927 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_PATHCONF], 928 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_COMMIT], 929 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LOOKUPP], 930 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SETCLIENTID], 931 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SETCLIENTIDCFRM]); 932 xo_emit("{T:Open/%13.13s}{T:OpenAttr/%13.13s}" 933 "{T:OpenDwnGr/%13.13s}{T:OpenCfrm/%13.13s}" 934 "{T:DelePurge/%13.13s}{T:DelRet/%13.13s}\n"); 935 xo_emit("{:open/%13ju}{:openattr/%13ju}{:opendwgr/%13ju}" 936 "{:opencfrm/%13ju}{:delepurge/%13ju}{:delreg/%13ju}\n", 937 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_OPEN], 938 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_OPENATTR], 939 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_OPENDOWNGRADE], 940 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_OPENCONFIRM], 941 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_DELEGPURGE], 942 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_DELEGRETURN]); 943 xo_emit("{T:GetFH/%13.13s}{T:Lock/%13.13s}" 944 "{T:LockT/%13.13s}{T:LockU/%13.13s}" 945 "{T:Close/%13.13s}{T:Verify/%13.13s}\n"); 946 xo_emit("{:getfh/%13ju}{:lock/%13ju}{:lockt/%13ju}" 947 "{:locku/%13ju}{:close/%13ju}{:verify/%13ju}\n", 948 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_GETFH], 949 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LOCK], 950 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LOCKT], 951 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LOCKU], 952 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_CLOSE], 953 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_VERIFY]); 954 xo_emit("{T:NVerify/%13.13s}{T:PutFH/%13.13s}" 955 "{T:PutPubFH/%13.13s}{T:PutRootFH/%13.13s}" 956 "{T:Renew/%13.13s}{T:RestoreFH/%13.13s}\n"); 957 xo_emit("{:nverify/%13ju}{:putfh/%13ju}{:putpubfh/%13ju}" 958 "{:putrootfh/%13ju}{:renew/%13ju}{:restore/%13ju}\n", 959 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_NVERIFY], 960 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_PUTFH], 961 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_PUTPUBFH], 962 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_PUTROOTFH], 963 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_RENEW], 964 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_RESTOREFH]); 965 xo_emit("{T:SaveFH/%13.13s}{T:Secinfo/%13.13s}" 966 "{T:RelLockOwn/%13.13s}{T:V4Create/%13.13s}\n"); 967 xo_emit("{:savefh/%13ju}{:secinfo/%13ju}{:rellockown/%13ju}" 968 "{:v4create/%13ju}\n", 969 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SAVEFH], 970 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SECINFO], 971 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_RELEASELCKOWN], 972 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_CREATE]); 973 if (nfs41) { 974 xo_open_container("nfsv41"); 975 xo_emit("{T:BackChannelCtrl/%13.13s}{T:BindConnToSess/%13.13s}" 976 "{T:ExchangeID/%13.13s}{T:CreateSess/%13.13s}" 977 "{T:DestroySess/%13.13s}{T:FreeStateID/%13.13s}\n"); 978 xo_emit("{:backchannelctrl/%13ju}{:bindconntosess/%13ju}" 979 "{:exchangeid/%13ju}{:createsess/%13ju}" 980 "{:destroysess/%13ju}{:freestateid/%13ju}\n", 981 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_BACKCHANNELCTL], 982 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_BINDCONNTOSESS], 983 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_EXCHANGEID], 984 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_CREATESESSION], 985 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_DESTROYSESSION], 986 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_FREESTATEID]), 987 988 xo_emit("{T:GetDirDeleg/%13.13s}{T:GetDevInfo/%13.13s}" 989 "{T:GetDevList/%13.13s}{T:layoutCommit/%13.13s}" 990 "{T:LayoutGet/%13.13s}{T:LayoutReturn/%13.13s}\n"); 991 xo_emit("{:getdirdeleg/%13ju}{:getdevinfo/%13ju}" 992 "{:getdevlist/%13ju}{:layoutcommit/%13ju}" 993 "{:layoutget/%13ju}{:layoutreturn/%13ju}\n", 994 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_GETDIRDELEG], 995 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_GETDEVINFO], 996 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_GETDEVLIST], 997 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LAYOUTCOMMIT], 998 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LAYOUTGET], 999 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LAYOUTRETURN]); 1000 1001 xo_emit("{T:SecInfNoName/%13.13s}{T:Sequence/%13.13s}" 1002 "{T:SetSSV/%13.13s}{T:TestStateID/%13.13s}" 1003 "{T:WantDeleg/%13.13s}{T:DestroyClId/%13.13s}\n"); 1004 xo_emit("{:secinfnoname/%13ju}{:sequence/%13ju}" 1005 "{:setssv/%13ju}{:teststateid/%13ju}{:wantdeleg/%13ju}" 1006 "{:destroyclid/%13ju}\n", 1007 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SECINFONONAME], 1008 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SEQUENCE], 1009 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SETSSV], 1010 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_TESTSTATEID], 1011 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_WANTDELEG], 1012 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_DESTROYCLIENTID]); 1013 1014 xo_emit("{T:ReclaimCompl/%13.13s}\n"); 1015 xo_emit("{:reclaimcompl/%13ju}\n", 1016 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_RECLAIMCOMPL]); 1017 1018 xo_close_container("nfsv41"); 1019 1020 xo_open_container("nfsv42"); 1021 1022 xo_emit("{T:Allocate/%13.13s}{T:Copy/%13.13s}" 1023 "{T:CopyNotify/%13.13s}{T:Deallocate/%13.13s}" 1024 "{T:IOAdvise/%13.13s}{T:LayoutError/%13.13s}\n"); 1025 xo_emit("{:allocate/%13ju}{:copy/%13ju}" 1026 "{:copynotify/%13ju}{:deallocate/%13ju}" 1027 "{:ioadvise/%13ju}{:layouterror/%13ju}\n", 1028 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_ALLOCATE], 1029 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_COPY], 1030 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_COPYNOTIFY], 1031 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_DEALLOCATE], 1032 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_IOADVISE], 1033 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LAYOUTERROR]); 1034 1035 xo_emit("{T:LayoutStats/%13.13s}{T:OffloadCncl/%13.13s}" 1036 "{T:OffloadStat/%13.13s}{T:ReadPlus/%13.13s}" 1037 "{T:Seek/%13.13s}{T:WriteSame/%13.13s}\n"); 1038 xo_emit("{:layoutstats/%13ju}{:offloadcncl/%13ju}" 1039 "{:offloadstat/%13ju}{:readplus/%13ju}" 1040 "{:seek/%13ju}{:writesame/%13ju}\n", 1041 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LAYOUTSTATS], 1042 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_OFFLOADCANCEL], 1043 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_OFFLOADSTATUS], 1044 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_READPLUS], 1045 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SEEK], 1046 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_WRITESAME]); 1047 1048 xo_emit("{T:Clone/%13.13s}{T:GetExtattr/%13.13s}" 1049 "{T:SetExtattr/%13.13s}{T:ListExtattr/%13.13s}" 1050 "{T:RmExtattr/%13.13s}\n"); 1051 xo_emit("{:clone/%13ju}{:getextattr/%13ju}" 1052 "{:setextattr/%13ju}{:listextattr/%13ju}" 1053 "{:rmextattr/%13ju}\n", 1054 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_CLONE], 1055 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_GETXATTR], 1056 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SETXATTR], 1057 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LISTXATTRS], 1058 (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_REMOVEXATTR]); 1059 1060 xo_close_container("nfsv42"); 1061 } 1062 1063 xo_close_container("operations"); 1064 1065 if (printtitle) 1066 xo_emit("{T:Server:}\n"); 1067 xo_open_container("server"); 1068 xo_emit("{T:Retfailed/%13.13s}{T:Faults/%13.13s}" 1069 "{T:Clients/%13.13s}\n"); 1070 xo_emit("{:retfailed/%13ju}{:faults/%13ju}{:clients/%13ju}\n", 1071 (uintmax_t)ext_nfsstats.srv_errs, 1072 (uintmax_t)ext_nfsstats.srvrpc_errs, 1073 (uintmax_t)ext_nfsstats.srvclients); 1074 xo_emit("{T:OpenOwner/%13.13s}{T:Opens/%13.13s}" 1075 "{T:LockOwner/%13.13s}{T:Locks/%13.13s}" 1076 "{T:Delegs/%13.13s}\n"); 1077 xo_emit("{:openowner/%13ju}{:opens/%13ju}{:lockowner/%13ju}" 1078 "{:locks/%13ju}{:delegs/%13ju}\n", 1079 (uintmax_t)ext_nfsstats.srvopenowners, 1080 (uintmax_t)ext_nfsstats.srvopens, 1081 (uintmax_t)ext_nfsstats.srvlockowners, 1082 (uintmax_t)ext_nfsstats.srvlocks, 1083 (uintmax_t)ext_nfsstats.srvdelegates); 1084 xo_close_container("server"); 1085 1086 if (printtitle) 1087 xo_emit("{T:Server Cache Stats:}\n"); 1088 xo_open_container("cache"); 1089 xo_emit("{T:Inprog/%13.13s}{T:Idem/%13.13s}" 1090 "{T:Non-idem/%13.13s}{T:Misses/%13.13s}" 1091 "{T:CacheSize/%13.13s}{T:TCPPeak/%13.13s}\n"); 1092 xo_emit("{:inprog/%13ju}{:idem/%13ju}{:nonidem/%13ju}" 1093 "{:misses/%13ju}{:cachesize/%13ju}{:tcppeak/%13ju}\n", 1094 (uintmax_t)ext_nfsstats.srvcache_inproghits, 1095 (uintmax_t)ext_nfsstats.srvcache_idemdonehits, 1096 (uintmax_t)ext_nfsstats.srvcache_nonidemdonehits, 1097 (uintmax_t)ext_nfsstats.srvcache_misses, 1098 (uintmax_t)ext_nfsstats.srvcache_size, 1099 (uintmax_t)ext_nfsstats.srvcache_tcppeak); 1100 xo_close_container("cache"); 1101 1102 xo_close_container("serverstats"); 1103 } 1104 1105 xo_close_container("nfsv4"); 1106 } 1107 1108 static void 1109 compute_totals(struct nfsstatsv1 *total_stats, struct nfsstatsv1 *cur_stats) 1110 { 1111 int i; 1112 1113 bzero(total_stats, sizeof(*total_stats)); 1114 for (i = 0; i < (NFSV42_NOPS + NFSV4OP_FAKENOPS); i++) { 1115 total_stats->srvbytes[0] += cur_stats->srvbytes[i]; 1116 total_stats->srvops[0] += cur_stats->srvops[i]; 1117 bintime_add(&total_stats->srvduration[0], 1118 &cur_stats->srvduration[i]); 1119 total_stats->srvrpccnt[i] = cur_stats->srvrpccnt[i]; 1120 } 1121 total_stats->srvstartcnt = cur_stats->srvstartcnt; 1122 total_stats->srvdonecnt = cur_stats->srvdonecnt; 1123 total_stats->busytime = cur_stats->busytime; 1124 1125 } 1126 1127 /* 1128 * Print a running summary of nfs statistics for the experimental client and/or 1129 * server. 1130 * Repeat display every interval seconds, showing statistics 1131 * collected over that interval. Assumes that interval is non-zero. 1132 * First line printed at top of screen is always cumulative. 1133 */ 1134 static void 1135 exp_sidewaysintpr(u_int interval, int clientOnly, int serverOnly, 1136 int newStats) 1137 { 1138 struct nfsstatsv1 nfsstats, lastst, *ext_nfsstatsp; 1139 struct nfsstatsv1 curtotal, lasttotal; 1140 struct timespec ts, lastts; 1141 int hdrcnt = 1; 1142 1143 ext_nfsstatsp = &lastst; 1144 ext_nfsstatsp->vers = NFSSTATS_V1; 1145 if (nfssvc(NFSSVC_GETSTATS | NFSSVC_NEWSTRUCT, ext_nfsstatsp) < 0) 1146 err(1, "Can't get stats"); 1147 clock_gettime(CLOCK_MONOTONIC, &lastts); 1148 compute_totals(&lasttotal, ext_nfsstatsp); 1149 sleep(interval); 1150 1151 for (;;) { 1152 ext_nfsstatsp = &nfsstats; 1153 ext_nfsstatsp->vers = NFSSTATS_V1; 1154 if (nfssvc(NFSSVC_GETSTATS | NFSSVC_NEWSTRUCT, ext_nfsstatsp) 1155 < 0) 1156 err(1, "Can't get stats"); 1157 clock_gettime(CLOCK_MONOTONIC, &ts); 1158 1159 if (--hdrcnt == 0) { 1160 printhdr(clientOnly, serverOnly, newStats); 1161 if (newStats) 1162 hdrcnt = 20; 1163 else if (clientOnly && serverOnly) 1164 hdrcnt = 10; 1165 else 1166 hdrcnt = 20; 1167 } 1168 if (clientOnly && newStats == 0) { 1169 printf("%s %6ju %6ju %6ju %6ju %6ju %6ju %6ju %6ju", 1170 ((clientOnly && serverOnly) ? "Client:" : ""), 1171 (uintmax_t)DELTA(rpccnt[NFSPROC_GETATTR]), 1172 (uintmax_t)DELTA(rpccnt[NFSPROC_LOOKUP]), 1173 (uintmax_t)DELTA(rpccnt[NFSPROC_READLINK]), 1174 (uintmax_t)DELTA(rpccnt[NFSPROC_READ]), 1175 (uintmax_t)DELTA(rpccnt[NFSPROC_WRITE]), 1176 (uintmax_t)DELTA(rpccnt[NFSPROC_RENAME]), 1177 (uintmax_t)DELTA(rpccnt[NFSPROC_ACCESS]), 1178 (uintmax_t)(DELTA(rpccnt[NFSPROC_READDIR]) + 1179 DELTA(rpccnt[NFSPROC_READDIRPLUS])) 1180 ); 1181 if (widemode) { 1182 printf(" %s %s %s %s %s %s", 1183 sperc1(DELTA(attrcache_hits), 1184 DELTA(attrcache_misses)), 1185 sperc1(DELTA(lookupcache_hits), 1186 DELTA(lookupcache_misses)), 1187 sperc2(DELTA(biocache_reads), 1188 DELTA(read_bios)), 1189 sperc2(DELTA(biocache_writes), 1190 DELTA(write_bios)), 1191 sperc1(DELTA(accesscache_hits), 1192 DELTA(accesscache_misses)), 1193 sperc2(DELTA(biocache_readdirs), 1194 DELTA(readdir_bios)) 1195 ); 1196 } 1197 printf("\n"); 1198 } 1199 1200 if (serverOnly && newStats) { 1201 long double cur_secs, last_secs, etime; 1202 long double mbsec; 1203 long double kb_per_transfer; 1204 long double transfers_per_second; 1205 long double ms_per_transfer; 1206 uint64_t queue_len; 1207 long double busy_pct; 1208 int i; 1209 1210 cur_secs = ts.tv_sec + 1211 ((long double)ts.tv_nsec / 1000000000); 1212 last_secs = lastts.tv_sec + 1213 ((long double)lastts.tv_nsec / 1000000000); 1214 etime = cur_secs - last_secs; 1215 1216 compute_totals(&curtotal, &nfsstats); 1217 1218 for (i = 0; i < NUM_STAT_TYPES; i++) { 1219 compute_new_stats(&nfsstats, &lastst, 1220 STAT_TYPE_TO_NFS(i), etime, &mbsec, 1221 &kb_per_transfer, 1222 &transfers_per_second, 1223 &ms_per_transfer, &queue_len, 1224 &busy_pct); 1225 1226 if (i == STAT_TYPE_COMMIT) { 1227 if (widemode == 0) 1228 continue; 1229 1230 printf("%2.0Lf %7.2Lf ", 1231 transfers_per_second, 1232 ms_per_transfer); 1233 } else { 1234 printf("%5.2Lf %5.0Lf %7.2Lf ", 1235 kb_per_transfer, 1236 transfers_per_second, mbsec); 1237 if (widemode) 1238 printf("%5.2Lf ", 1239 ms_per_transfer); 1240 } 1241 } 1242 1243 compute_new_stats(&curtotal, &lasttotal, 0, etime, 1244 &mbsec, &kb_per_transfer, &transfers_per_second, 1245 &ms_per_transfer, &queue_len, &busy_pct); 1246 1247 printf("%5.2Lf %5.0Lf %7.2Lf %5.2Lf %3ju %3.0Lf\n", 1248 kb_per_transfer, transfers_per_second, mbsec, 1249 ms_per_transfer, queue_len, busy_pct); 1250 } else if (serverOnly) { 1251 printf("%s %6ju %6ju %6ju %6ju %6ju %6ju %6ju %6ju", 1252 ((clientOnly && serverOnly) ? "Server:" : ""), 1253 (uintmax_t)DELTA(srvrpccnt[NFSV4OP_GETATTR]), 1254 (uintmax_t)DELTA(srvrpccnt[NFSV4OP_LOOKUP]), 1255 (uintmax_t)DELTA(srvrpccnt[NFSV4OP_READLINK]), 1256 (uintmax_t)DELTA(srvrpccnt[NFSV4OP_READ]), 1257 (uintmax_t)DELTA(srvrpccnt[NFSV4OP_WRITE]), 1258 (uintmax_t)DELTA(srvrpccnt[NFSV4OP_RENAME]), 1259 (uintmax_t)DELTA(srvrpccnt[NFSV4OP_ACCESS]), 1260 (uintmax_t)(DELTA(srvrpccnt[NFSV4OP_READDIR]) + 1261 DELTA(srvrpccnt[NFSV4OP_READDIRPLUS]))); 1262 printf("\n"); 1263 } 1264 bcopy(&nfsstats, &lastst, sizeof(lastst)); 1265 bcopy(&curtotal, &lasttotal, sizeof(lasttotal)); 1266 lastts = ts; 1267 fflush(stdout); 1268 sleep(interval); 1269 } 1270 /*NOTREACHED*/ 1271 } 1272