1 #!/usr/sbin/dtrace -s
   2 
   3 /*
   4  * This file and its contents are supplied under the terms of the
   5  * Common Development and Distribution License ("CDDL"), version 1.0.
   6  * You may only use this file in accordance with the terms of version
   7  * 1.0 of the CDDL.
   8  *
   9  * A full copy of the text of the CDDL should have accompanied this
  10  * source.  A copy of the CDDL is also available via the Internet at
  11  * http://www.illumos.org/license/CDDL.
  12  */
  13 
  14 /*
  15  * Copyright 2019, Nexenta Systems, Inc. All rights reserved.
  16  */
  17 
  18 #pragma D option defaultargs
  19 #pragma D option quiet
  20 
  21 dtrace:::BEGIN
  22 / $1 == 0 /
  23 {
  24         printf("Tracing... Hit Ctrl-C to end.\n");
  25         timeout = $1;
  26 }
  27 dtrace:::BEGIN
  28 / $1 != 0 /
  29 {
  30         printf("Tracing... for %d seconds\n", $1);
  31         timeout = $1;
  32 }
  33 
  34 nfsv3:::op-read-done
  35 {
  36         @readbytes[args[1]->noi_curpath] = sum(args[2]->res_u.ok.data.data_len);
  37         @readiops[args[1]->noi_curpath] = count();
  38         @readbs[args[1]->noi_curpath] = avg(args[2]->res_u.ok.data.data_len);
  39 }
  40 
  41 nfsv4:::op-read-done
  42 {
  43         @readbytes[args[1]->noi_curpath] = sum(args[2]->data_len);
  44         @readiops[args[1]->noi_curpath] = count();
  45         @readbs[args[1]->noi_curpath] = avg(args[2]->data_len);
  46 }
  47 
  48 /* sync writes, committed != 0 */
  49 nfsv3:::op-write-done
  50 / args[2]->status == 0 && args[2]->res_u.ok.committed != 0 /
  51 {
  52         @swritebytes[args[1]->noi_curpath] = sum(args[2]->res_u.ok.count);
  53         @swriteiops[args[1]->noi_curpath] = count();
  54         @swritebs[args[1]->noi_curpath] = avg(args[2]->res_u.ok.count);
  55 }
  56 
  57 /* async writes, committed == 0 */
  58 nfsv3:::op-write-done
  59 / args[2]->status == 0 && args[2]->res_u.ok.committed == 0 /
  60 {
  61         @awritebytes[args[1]->noi_curpath] = sum(args[2]->res_u.ok.count);
  62         @awriteiops[args[1]->noi_curpath] = count();
  63         @awritebs[args[1]->noi_curpath] = avg(args[2]->res_u.ok.count);
  64 }
  65 
  66 /* sync writes, committed != 0 */
  67 nfsv4:::op-write-done
  68 / args[2]->status == 0 && args[2]->committed != 0 /
  69 {
  70         @swritebytes[args[1]->noi_curpath] = sum(args[2]->count);
  71         @swriteiops[args[1]->noi_curpath] = count();
  72         @swritebs[args[1]->noi_curpath] = avg(args[2]->count);
  73 }
  74 
  75 /* async writes, committed == 0 */
  76 nfsv4:::op-write-done
  77 / args[2]->status == 0 && args[2]->committed == 0 /
  78 {
  79         @awritebytes[args[1]->noi_curpath] = sum(args[2]->count);
  80         @awriteiops[args[1]->noi_curpath] = count();
  81         @awritebs[args[1]->noi_curpath] = avg(args[2]->count);
  82 }
  83 
  84 tick-1s
  85 / $1 != 0 && (--timeout == 0) /
  86 {
  87         exit(0);
  88 }
  89 
  90 dtrace:::END
  91 {
  92         printf("\n%12s %12s %12s %12s %12s %12s%12s %12s %12s %s\n",
  93             "Rbytes", "Rops", "Rbs", "SWbytes", "SWOps", "SWbs", "AWbytes", "AWOps", "AWbs", "Pathname");
  94         printa("%@12d %@12d %@12d %@12d %@12d %@12d %@12d %@12d %@12d %s\n",
  95             @readbytes, @readiops, @readbs, @swritebytes, @swriteiops, @swritebs, @awritebytes, @awriteiops, @awritebs );
  96 }