Mailing List Archive

Support open source code!


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

Re: strange vmstat() behavior on linux



Scott M Stone <sstone@example.com> writes in tlug@example.com:

> ok, this is my DSL firewall box, running a custom 2.2.16 kernel
> (turbolinux 6.0 server base install, then I redid the kernel and such, of
> course).  vmstat on my Sparc4 works normally, but on the Linux box, it
> reports 0% user CPU, 0% system CPU, 14% idle CPU, _all the time_, when I
> run vmstat *once*.  If I run "vmstat 2 10", or any other permutation that
> causes it to look at cpu usage more than once, it reports the 0/0/14 on
> the first pass and then reports accurate numbers on each subsequent pass.
> WTF is going on here??  Like I said, it works normally on my SPARC-4
> running Solaris 2.7.. seems to be a linux-specific issue.

There's a special hack in vmstat.c for printing the statistics out the
first time through, so I'm not surprised the computation is off.  Does
this patch do what you want?


--- procps-2.0.6/vmstat.c.vmstat	Wed Nov  3 00:44:58 1999
+++ procps-2.0.6/vmstat.c	Thu Aug  3 17:24:34 2000
@@ -80,7 +80,7 @@
   setlinebuf(stdout);
   argc=0; /* redefined as number of integer arguments */
   per=1;
-  num=0;
+  num=1;
   for (argv++;*argv;argv++) {
     if ('-' ==(**argv)) {
       switch (*(++(*argv))) {
@@ -118,32 +118,15 @@
   }    
 
   pero2=(per/2);
-  showheader();
   getrunners(&running,&blocked,&swapped);
   getmeminfo(&memfree,&membuff,&swapused,&memcache);
   getstat(cpu_use,cpu_nic,cpu_sys,cpu_idl,
 	  pgpgin,pgpgout,pswpin,pswpout,
 	  inter,ticks,ctxt);
-  duse= *(cpu_use)+ *(cpu_nic); 
-  dsys= *(cpu_sys);
-  didl= (*(cpu_idl))%UINT_MAX;
-  div= (duse+dsys+didl);
-  hz=sysconf(_SC_CLK_TCK); /* get ticks/s from system */
-  divo2= div/2;
-  printf(format,
-	 running,blocked,swapped,
-	 swapused,memfree,membuff,memcache,
-	 (*(pswpin)*4*hz+divo2)/div,
-	 (*(pswpout)*4*hz+divo2)/div,
-	 (*(pgpgin)*hz+divo2)/div,
-	 (*(pgpgout)*hz+divo2)/div,
-	 (*(inter)*hz+divo2)/div,
-	 (*(ctxt)*hz+divo2)/div,
-	 (100*duse+divo2)/div,(100*dsys+divo2)/div,(100*didl+divo2)/div);
 
-  for(i=1;i<num;i++) { /* \\\\\\\\\\\\\\\\\\\\ main loop ////////////////// */
+  for(i=1;i<=num;i++) { /* \\\\\\\\\\\\\\\\\\\\ main loop ////////////////// */
     sleep(per);
-    if (moreheaders && ((i%height)==0)) showheader();
+    if (i == 1 || (moreheaders && ((i%height)==0))) showheader();
     tog= !tog;
     getrunners(&running,&blocked,&swapped);
     getmeminfo(&memfree,&membuff,&swapused,&memcache);



Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links