From 9368f38e9001c26ba3816b217f1a82e64174e570 Mon Sep 17 00:00:00 2001 From: mlelstv Date: Sat, 15 Jul 2017 08:22:23 +0000 Subject: [PATCH] Use I/O timestamps to compute disk statistics for better precisison. --- usr.bin/systat/iostat.c | 30 ++++++++++++++++++------------ usr.bin/systat/vmstat.c | 21 ++++++++++++++------- 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/usr.bin/systat/iostat.c b/usr.bin/systat/iostat.c index 3594aa888544..64587af942e7 100644 --- a/usr.bin/systat/iostat.c +++ b/usr.bin/systat/iostat.c @@ -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 @@ -46,7 +46,7 @@ __RCSID("$NetBSD: iostat.c,v 1.37 2009/04/13 23:20:27 lukem Exp $"); #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 @@ showiostat(void) 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 @@ stats(int row, int col, int dn) } 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 --git a/usr.bin/systat/vmstat.c b/usr.bin/systat/vmstat.c index 29a8e1101156..06bd123e42c8 100644 --- a/usr.bin/systat/vmstat.c +++ b/usr.bin/systat/vmstat.c @@ -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 @@ copyinfo(struct Info *from, struct Info *to) 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