Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/systat Use I/O timestamps to compute disk statistics...



details:   https://anonhg.NetBSD.org/src/rev/06b1ac2bd011
branches:  trunk
changeset: 825453:06b1ac2bd011
user:      mlelstv <mlelstv%NetBSD.org@localhost>
date:      Sat Jul 15 08:22:23 2017 +0000

description:
Use I/O timestamps to compute disk statistics for better precisison.

diffstat:

 usr.bin/systat/iostat.c |  30 ++++++++++++++++++------------
 usr.bin/systat/vmstat.c |  21 ++++++++++++++-------
 2 files changed, 32 insertions(+), 19 deletions(-)

diffs (138 lines):

diff -r 59cdf6940e06 -r 06b1ac2bd011 usr.bin/systat/iostat.c
--- a/usr.bin/systat/iostat.c   Sat Jul 15 07:26:02 2017 +0000
+++ b/usr.bin/systat/iostat.c   Sat Jul 15 08:22:23 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: iostat.c,v 1.37 2009/04/13 23:20:27 lukem Exp $        */
+/*     $NetBSD: iostat.c,v 1.38 2017/07/15 08:22:23 mlelstv Exp $      */
 
 /*
  * Copyright (c) 1980, 1992, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)iostat.c   8.1 (Berkeley) 6/6/93";
 #endif
-__RCSID("$NetBSD: iostat.c,v 1.37 2009/04/13 23:20:27 lukem Exp $");
+__RCSID("$NetBSD: iostat.c,v 1.38 2017/07/15 08:22:23 mlelstv Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -46,7 +46,7 @@
 #include "drvstats.h"
 
 static  int linesperregion;
-static  double etime;
+static double etime;
 static  int numbers = 0;               /* default display bar graphs */
 static  int secs = 0;                  /* default seconds shown */
 static  int read_write = 0;            /* default read/write shown */
@@ -252,9 +252,15 @@
 static int
 stats(int row, int col, int dn)
 {
-       double atime, rwords, wwords;
+       double atime, dtime, rwords, wwords;
        uint64_t rxfer;
 
+       /* elapsed time for disk stats */
+       dtime = etime;
+       if (cur.timestamp[dn].tv_sec || cur.timestamp[dn].tv_usec)
+               dtime = (double)cur.timestamp[dn].tv_sec +
+                       ((double)cur.timestamp[dn].tv_usec / (double)1000000);
+
        /* time busy in disk activity */
        atime = (double)cur.time[dn].tv_sec +
                ((double)cur.time[dn].tv_usec / (double)1000000);
@@ -269,30 +275,30 @@
        }
        if (numbers) {
                mvwprintw(wnd, row, col, "%5.0f%4.0f",
-                   rwords / etime, rxfer / etime);
+                   rwords / dtime, rxfer / dtime);
                if (secs)
-                       wprintw(wnd, "%5.1f", atime / etime);
+                       wprintw(wnd, "%5.1f", atime / dtime);
                if (read_write)
                        wprintw(wnd, " %5.0f%4.0f",
-                           wwords / etime, cur.wxfer[dn] / etime);
+                           wwords / dtime, cur.wxfer[dn] / dtime);
                return (row);
        }
 
        wmove(wnd, row++, col);
-       histogram(rwords / etime, 50, 0.5);
+       histogram(rwords / dtime, 50, 0.5);
        wmove(wnd, row++, col);
-       histogram(rxfer / etime, 50, 0.5);
+       histogram(rxfer / dtime, 50, 0.5);
        if (read_write) {
                wmove(wnd, row++, col);
-               histogram(wwords / etime, 50, 0.5);
+               histogram(wwords / dtime, 50, 0.5);
                wmove(wnd, row++, col);
-               histogram(cur.wxfer[dn] / etime, 50, 0.5);
+               histogram(cur.wxfer[dn] / dtime, 50, 0.5);
        }
 
        if (secs) {
                wmove(wnd, row++, col);
                atime *= 1000;  /* In milliseconds */
-               histogram(atime / etime, 50, 0.5);
+               histogram(atime / dtime, 50, 0.5);
        }
        return (row);
 }
diff -r 59cdf6940e06 -r 06b1ac2bd011 usr.bin/systat/vmstat.c
--- a/usr.bin/systat/vmstat.c   Sat Jul 15 07:26:02 2017 +0000
+++ b/usr.bin/systat/vmstat.c   Sat Jul 15 08:22:23 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vmstat.c,v 1.81 2014/12/24 20:01:22 dennis Exp $       */
+/*     $NetBSD: vmstat.c,v 1.82 2017/07/15 08:22:23 mlelstv Exp $      */
 
 /*-
  * Copyright (c) 1983, 1989, 1992, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)vmstat.c   8.2 (Berkeley) 1/12/94";
 #endif
-__RCSID("$NetBSD: vmstat.c,v 1.81 2014/12/24 20:01:22 dennis Exp $");
+__RCSID("$NetBSD: vmstat.c,v 1.82 2017/07/15 08:22:23 mlelstv Exp $");
 #endif /* not lint */
 
 /*
@@ -827,24 +827,31 @@
 static void
 dinfo(int dn, int r, int c)
 {
-       double atime;
+       double atime, dtime;
 #define ADV if (disk_horiz) r++; else c += DISKCOLWIDTH
 
+       /* elapsed time for disk stats */
+       dtime = etime;
+       if (cur.timestamp[dn].tv_sec || cur.timestamp[dn].tv_usec) {
+               dtime = (double)cur.timestamp[dn].tv_sec +
+                       ((double)cur.timestamp[dn].tv_usec / (double)1000000);
+       }
+
        mvprintw(r, c, "%*.*s", DISKCOLWIDTH, DISKCOLWIDTH, dr_name[dn]);
        ADV;
 
-       putint((int)(cur.seek[dn]/etime+0.5), r, c, DISKCOLWIDTH);
+       putint((int)(cur.seek[dn]/dtime+0.5), r, c, DISKCOLWIDTH);
        ADV;
-       putint((int)((cur.rxfer[dn]+cur.wxfer[dn])/etime+0.5),
+       putint((int)((cur.rxfer[dn]+cur.wxfer[dn])/dtime+0.5),
            r, c, DISKCOLWIDTH);
        ADV;
-       puthumanint((cur.rbytes[dn] + cur.wbytes[dn]) / etime + 0.5,
+       puthumanint((cur.rbytes[dn] + cur.wbytes[dn]) / dtime + 0.5,
                    r, c, DISKCOLWIDTH);
        ADV;
 
        /* time busy in disk activity */
        atime = cur.time[dn].tv_sec + cur.time[dn].tv_usec / 1000000.0;
-       atime = atime * 100.0 / etime;
+       atime = atime * 100.0 / dtime;
        if (atime >= 100)
                putint(100, r, c, DISKCOLWIDTH);
        else



Home | Main Index | Thread Index | Old Index