Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/systat introduce puthumanint() which calls humanize_...



details:   https://anonhg.NetBSD.org/src/rev/975d00adb96a
branches:  trunk
changeset: 535027:975d00adb96a
user:      abs <abs%NetBSD.org@localhost>
date:      Thu Aug 08 17:06:31 2002 +0000

description:
introduce puthumanint() which calls humanize_number(), and use to
display disk transfer values (Suggested by Simon Burge). Also clip
%busy to 100 and display as an int which has the useful side effect
of stopping it overflowing into the next column (100.0).

diffstat:

 usr.bin/systat/Makefile |   4 ++--
 usr.bin/systat/vmstat.c |  34 +++++++++++++++++++++++++++++-----
 2 files changed, 31 insertions(+), 7 deletions(-)

diffs (92 lines):

diff -r a1b06ecc6f43 -r 975d00adb96a usr.bin/systat/Makefile
--- a/usr.bin/systat/Makefile   Thu Aug 08 17:04:32 2002 +0000
+++ b/usr.bin/systat/Makefile   Thu Aug 08 17:06:31 2002 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.25 2002/08/01 23:36:54 christos Exp $
+#      $NetBSD: Makefile,v 1.26 2002/08/08 17:06:31 abs Exp $
 #      @(#)Makefile    8.1 (Berkeley) 6/6/93
 
 PROG=  systat
@@ -12,7 +12,7 @@
        icmp.c iostat.c ip.c keyboard.c main.c mbufs.c netcmds.c netstat.c \
        pigs.c ps.c swap.c tcp.c vmstat.c utmpentry.c
 DPADD= ${LIBCURSES} ${LIBM} ${LIBKVM}
-LDADD= -lcurses -lm -lkvm
+LDADD= -lutil -lcurses -lm -lkvm
 BINGRP=        kmem
 BINMODE=2555
 LINKS= ${BINDIR}/systat ${BINDIR}/sysstat
diff -r a1b06ecc6f43 -r 975d00adb96a usr.bin/systat/vmstat.c
--- a/usr.bin/systat/vmstat.c   Thu Aug 08 17:04:32 2002 +0000
+++ b/usr.bin/systat/vmstat.c   Thu Aug 08 17:06:31 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vmstat.c,v 1.40 2002/08/01 23:36:55 christos Exp $     */
+/*     $NetBSD: vmstat.c,v 1.41 2002/08/08 17:06:32 abs Exp $  */
 
 /*-
  * Copyright (c) 1983, 1989, 1992, 1993
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)vmstat.c   8.2 (Berkeley) 1/12/94";
 #endif
-__RCSID("$NetBSD: vmstat.c,v 1.40 2002/08/01 23:36:55 christos Exp $");
+__RCSID("$NetBSD: vmstat.c,v 1.41 2002/08/08 17:06:32 abs Exp $");
 #endif /* not lint */
 
 /*
@@ -55,6 +55,7 @@
 
 #include <stdlib.h>
 #include <string.h>
+#include <util.h>
 
 #include "systat.h"
 #include "extern.h"
@@ -286,7 +287,7 @@
        mvprintw(DISKROW, DISKCOL, "Discs");
        mvprintw(DISKROW + 1, DISKCOL, "seeks");
        mvprintw(DISKROW + 2, DISKCOL, "xfers");
-       mvprintw(DISKROW + 3, DISKCOL, "Kbyte");
+       mvprintw(DISKROW + 3, DISKCOL, "bytes");
        mvprintw(DISKROW + 4, DISKCOL, "%%busy");
        j = 0;
        for (i = 0; i < dk_ndrive && j < MAXDRIVES; i++)
@@ -518,6 +519,26 @@
 }
 
 static void
+puthumanint(int n, int l, int c, int w)
+{
+       char b[128];
+
+       move(l, c);
+       if (n == 0) {
+               hline(' ', w);
+               return;
+       }
+       if (humanize_number(b, w, (int64_t)n * 1024, "", HN_AUTOSCALE,
+           HN_NOSPACE) == -1 ) {
+               hline('*', w);
+               return;
+       }
+       hline(' ', w - strlen(b));
+       move(l, c + w - strlen(b));
+       addstr(b);
+}
+
+static void
 putint(int n, int l, int c, int w)
 {
        char b[128];
@@ -613,6 +634,9 @@
 
        putint((int)((float)cur.dk_seek[dn]/etime+0.5), DISKROW + 1, c, 5);
        putint((int)((float)cur.dk_xfer[dn]/etime+0.5), DISKROW + 2, c, 5);
-       putint((int)(words/etime + 0.5), DISKROW + 3, c, 5);
-       putfloat(atime*100.0/etime, DISKROW + 4, c, 5, 1, 1);
+       puthumanint((int)(words/etime + 0.5), DISKROW + 3, c, 5);
+       if (atime*100.0/etime >= 100)
+               putint(100, DISKROW + 4, c, 5);
+       else
+               putfloat(atime*100.0/etime, DISKROW + 4, c, 5, 1, 1);
 }



Home | Main Index | Thread Index | Old Index