This is a discussion on [patch] vmstat output fix within the mailing.openbsd.tech forums, part of the OpenBSD category; --> In a discussion on #OpenBSD on freenode David complained that the memory usage of his xeon box with over ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| In a discussion on #OpenBSD on freenode David complained that the memory usage of his xeon box with over 2.5Gb memory was not accurately displayed. Looking at the code it's clear that the number simply overflowed in the output. (void)printf("%7u %7u ", pgtok(total.t_avm), pgtok(total.t_free)); So I added an option inspired by the GNU-version of vmstat which makes it possible to divide the output. Index: vmstat.8 ================================================== ================= RCS file: /cvs/src/usr.bin/vmstat/vmstat.8,v retrieving revision 1.35 diff -u -p -r1.35 vmstat.8 --- vmstat.8 31 May 2007 19:20:19 -0000 1.35 +++ vmstat.8 26 Feb 2008 22:48:44 -0000 @@ -44,6 +44,7 @@ .Op Fl M Ar core .Op Fl N Ar system .Op Fl w Ar wait +.Op Fl S Ar unit .Op Ar disk ... .Sh DESCRIPTION .Nm @@ -109,6 +110,9 @@ is specified, the default is infinity. When used with .Fl i , also list devices which have not yet generated an interrupt. +.It Fl S +followed by k or K or m or M switches memory output between 1000, +1024, 1000000, or 1048576 bytes. .El .Pp By default, Index: vmstat.c ================================================== ================= RCS file: /cvs/src/usr.bin/vmstat/vmstat.c,v retrieving revision 1.106 diff -u -p -r1.106 vmstat.c --- vmstat.c 26 Oct 2007 14:15:25 -0000 1.106 +++ vmstat.c 26 Feb 2008 22:48:44 -0000 @@ -148,6 +148,8 @@ int zflag = 0; int ncpu; +u_int divide = 1; + int main(int argc, char *argv[]) { @@ -158,7 +160,7 @@ main(int argc, char *argv[]) size_t size; gid_t gid; - while ((c = getopt(argc, argv, "c:fiM:mN:stw:vz")) != -1) { + while ((c = getopt(argc, argv, "c:fiM:mN:stw:vzS:")) != -1) { switch (c) { case 'c': reps = atoi(optarg); @@ -181,6 +183,24 @@ main(int argc, char *argv[]) case 's': todo |= SUMSTAT; break; + case 'S': + switch (optarg[0]) { + case 'k': + divide = 1000; + break; + case 'K': + divide = 1024; + break; + case 'm': + divide = 1000 * 1000; + break; + case 'M': + divide = 1024 * 1024; + break; + default: + usage(); + } + break; case 't': todo |= TIMESTAT; break; @@ -417,7 +437,7 @@ dovmstat(u_int interval, int reps) #define rate(x) (((x) + halfuptime) / uptime) /* round */ #define pgtok(a) ((a) * ((unsigned int)uvmexp.pagesize >> 10)) (void)printf("%7u %7u ", - pgtok(total.t_avm), pgtok(total.t_free)); + pgtok(total.t_avm) / divide, pgtok(total.t_free) / divide); (void)printf("%4u ", rate(uvmexp.faults - ouvmexp.faults)); (void)printf("%3u ", rate(uvmexp.pdreact - ouvmexp.pdreact)); (void)printf("%3u ", rate(uvmexp.pageins - ouvmexp.pageins)); @@ -1163,6 +1183,6 @@ void usage(void) { (void)fprintf(stderr, "usage: %s [-fimstvz] [-c count] [-M core] " - "[-N system] [-w wait] [disks]\n", __progname); + "[-N system] [-w wait] [-S unit] [disks]\n", __progname); exit(1); } # Han |
| Thread Tools | |
| Display Modes | |
|
|