]> granicus.if.org Git - procps-ng/commitdiff
vmstat: Fixed initial si,so,bi,bo,in & cs values
authorSanskriti Sharma <sansharm@redhat.com>
Wed, 18 Jan 2023 05:54:25 +0000 (16:54 +1100)
committerCraig Small <csmall@dropbear.xyz>
Wed, 18 Jan 2023 05:56:24 +0000 (16:56 +1100)
In the default display option, the first line of stats output in the
above mentioned columns was incorrect.

References:
 https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=668580
 procps-ng/procps!74
 procps-ng/procps#15

Signed-off-by: Craig Small <csmall@dropbear.xyz>
NEWS
src/vmstat.c

diff --git a/NEWS b/NEWS
index 0c473c73c1180f6639916fd84277d84f29486328..cec971efaeab94cdbf3feb6e8f29e9d9eda3de4e 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,8 @@ procps-ng-NEXT
   * skill: Match on -p again                               Debian #1025915
   * top: E/P-core toggle ('5' key) added to help
   * vmstat: Referesh memory statistics                     Debian #1027963
+  * vmstat: Fix initial si,so,bi,bo,in & cs values         issue #15
+                                                           Debian #668580
   * w: Add --pids option                                   merge #159
   * watch: Pass through beep                               issue #104
   * watch: -r option to not re-exec on SIGWINCH            merge #125
index d076cf219ea26611762be017806724a1801e49de..b4bcb8ff167db8f2b36d3e4052f1cbfb969bd5ff 100644 (file)
@@ -365,6 +365,7 @@ static void new_format(void)
     struct tm *tm_ptr;
     time_t the_time;
     char timebuf[32];
+    double uptime;
     struct vmstat_info *vm_info = NULL;
     struct stat_info *stat_info = NULL;
     struct stat_stack *stat_stack;
@@ -380,6 +381,10 @@ static void new_format(void)
         xerrx(EXIT_FAILURE, _("Unable to create system stat structure"));
     if (procps_meminfo_new(&mem_info) < 0)
         xerrx(EXIT_FAILURE, _("Unable to create meminfo structure"));
+    if (procps_uptime(&uptime, NULL) < 0)
+        xerr(EXIT_FAILURE, _("Unable to get uptime"));
+    if (0.0 == uptime)
+        uptime = 1.0;
     new_header();
 
     pgpgin[tog] = VMSTAT_GET(vm_info, VMSTAT_PGPGIN, ul_int);
@@ -425,12 +430,12 @@ static void new_format(void)
                unitConvert(MEMv(mem_FREE)),
                unitConvert((a_option?MEMv(mem_INA):MEMv(mem_BUF))),
                unitConvert((a_option?MEMv(mem_ACT):MEMv(mem_CAC))),
-               (unsigned)( (unitConvert(VMSTAT_GET(vm_info, VMSTAT_PSWPIN, ul_int)  * kb_per_page) * hz + divo2) / Div ),
-               (unsigned)( (unitConvert(VMSTAT_GET(vm_info, VMSTAT_PSWPOUT, ul_int)  * kb_per_page) * hz + divo2) / Div ),
-               (unsigned)( (VMSTAT_GET(vm_info, VMSTAT_PGPGIN, ul_int) * hz + divo2) / Div ),
-               (unsigned)( (VMSTAT_GET(vm_info, VMSTAT_PGPGOUT, ul_int) * hz + divo2) / Div ),
-               (unsigned)( (SYSv(stat_INT)           * hz + divo2) / Div ),
-               (unsigned)( (SYSv(stat_CTX)           * hz + divo2) / Div ),
+               (unsigned)( unitConvert(VMSTAT_GET(vm_info, VMSTAT_PSWPIN, ul_int)  * kb_per_page) / uptime ),
+               (unsigned)( unitConvert(VMSTAT_GET(vm_info, VMSTAT_PSWPOUT, ul_int)  * kb_per_page) / uptime ),
+               (unsigned)( VMSTAT_GET(vm_info, VMSTAT_PGPGIN, ul_int) / uptime ),
+               (unsigned)( VMSTAT_GET(vm_info, VMSTAT_PGPGOUT, ul_int) / uptime ),
+               (unsigned)( SYSv(stat_INT) / uptime ),
+               (unsigned)( SYSv(stat_CTX) / Div ),
                (unsigned)( (100*cpu_use        + divo2) / Div ),
                (unsigned)( (100*cpu_sys        + divo2) / Div ),
                (unsigned)( (100*cpu_idl        + divo2) / Div ),
@@ -764,7 +769,7 @@ static void slabformat (void)
         slab_AOBJS, slab_OBJS, slab_OSIZE, slab_OPS, slab_NAME };
 
     if (procps_slabinfo_new(&slab_info) < 0)
-        xerrx(EXIT_FAILURE, _("Unable to create slabinfo structure"));
+        xerr(EXIT_FAILURE, _("Unable to create slabinfo structure"));
 
     if (!moreheaders)
         slabheader();