Unix Technical Forum

Re: [patch] vmstat output fix

This is a discussion on Re: [patch] vmstat output fix within the mailing.openbsd.tech forums, part of the OpenBSD category; --> Otto Moerbeek wrote: > I don't know yet if we want human stuff here. But printing an > errno ...


Go Back   Unix Technical Forum > Unix Operating Systems > OpenBSD > mailing.openbsd.tech

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-27-2008, 11:19 AM
Han Boetes
 
Posts: n/a
Default Re: [patch] vmstat output fix

Otto Moerbeek wrote:
> I don't know yet if we want human stuff here. But printing an
> errno with errx(3) is a bit silly when you have err(3).


You are right. I also noticed the size of my memory was a factor
1024 off so here is an updated patch for your consideration.

Index: Makefile
================================================== =================
RCS file: /cvs/src/usr.bin/vmstat/Makefile,v
retrieving revision 1.7
diff -u -p -r1.7 Makefile
--- Makefile 27 Jun 2001 06:16:50 -0000 1.7
+++ Makefile 27 Feb 2008 10:36:20 -0000
@@ -5,9 +5,8 @@ PROG= vmstat
SRCS= dkstats.c vmstat.c
MAN= vmstat.8
DPADD= ${LIBKVM}
-LDADD= -lkvm
+LDADD= -lkvm -lutil
BINGRP= kmem
BINMODE=2555

.include <bsd.prog.mk>
-
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 27 Feb 2008 10:36:20 -0000
@@ -38,7 +38,7 @@
.Nd report statistics about kernel activities
.Sh SYNOPSIS
.Nm vmstat
-.Op Fl fimstvz
+.Op Fl fhimstvz
.Nm vmstat
.Op Fl c Ar count
.Op Fl M Ar core
@@ -75,6 +75,8 @@ and
.Xr vfork 2
system calls as well as kernel thread creations since system startup,
and the number of pages of virtual memory involved in each.
+.It Fl h
+Print memory information in human readable format.
.It Fl i
Report on the number of interrupts taken by each device since system
startup.
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 27 Feb 2008 10:36:20 -0000
@@ -70,6 +70,7 @@ static const char rcsid[] = "$OpenBSD: v
#include <string.h>
#include <paths.h>
#include <limits.h>
+#include <util.h>
#include "dkstats.h"

#include <uvm/uvm_object.h>
@@ -145,6 +146,7 @@ extern char *__progname;

int verbose = 0;
int zflag = 0;
+int human = 0;

int ncpu;

@@ -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:fhiM:mN:stw:vz")) != -1) {
switch (c) {
case 'c':
reps = atoi(optarg);
@@ -166,6 +168,9 @@ main(int argc, char *argv[])
case 'f':
todo |= FORKSTAT;
break;
+ case 'h':
+ human = 1;
+ break;
case 'i':
todo |= INTRSTAT;
break;
@@ -416,8 +421,20 @@ dovmstat(u_int interval, int reps)
total.t_rq - 1, total.t_dw + total.t_pw, total.t_sw);
#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));
+ if (human == 0)
+ (void)printf("%7u %7u ",
+ pgtok(total.t_avm), pgtok(total.t_free));
+ else {
+ char buf[FMT_SCALED_STRSIZE];
+ if (fmt_scaled(pgtok(total.t_avm) * 1024, buf) == 0)
+ printf("%7s ", buf);
+ else
+ err(1, "fmt scaled failed");
+ if (fmt_scaled(pgtok(total.t_free) * 1024, buf) == 0)
+ printf("%7s ", buf);
+ else
+ err(1, "fmt scaled failed");
+ }
(void)printf("%4u ", rate(uvmexp.faults - ouvmexp.faults));
(void)printf("%3u ", rate(uvmexp.pdreact - ouvmexp.pdreact));
(void)printf("%3u ", rate(uvmexp.pageins - ouvmexp.pageins));



# Han

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 03:54 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com