]> granicus.if.org Git - sysstat/commitdiff
iostat: Fix wrong CPU stats displayed with option -y
authorSebastien GODARD <sysstat@users.noreply.github.com>
Fri, 21 Jun 2019 15:48:44 +0000 (17:48 +0200)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Fri, 21 Jun 2019 15:48:44 +0000 (17:48 +0200)
CPU statistics written for the first sample was wrong when option -y was
used. This was because the interval of time used was that since system
startup whereas it should have been the interval of time since last
sample (which is not displayed with option -y).

Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
iostat.c

index 897104ec3d0dc67fb708fbe930e633382e7e1164..debfd2513055d73d5b1018ae5026da2be4ce3655 100644 (file)
--- a/iostat.c
+++ b/iostat.c
@@ -985,16 +985,6 @@ void write_cpu_stat(int curr, int tab)
 {
        unsigned long long deltot_jiffies;
 
-       /*
-        * Compute the total number of jiffies spent by all processors.
-        * NB: Don't add cpu_guest/cpu_guest_nice because cpu_user/cpu_nice
-        * already include them.
-        */
-       tot_jiffies[curr] = st_cpu[curr]->cpu_user + st_cpu[curr]->cpu_nice +
-                           st_cpu[curr]->cpu_sys + st_cpu[curr]->cpu_idle +
-                           st_cpu[curr]->cpu_iowait + st_cpu[curr]->cpu_hardirq +
-                           st_cpu[curr]->cpu_steal + st_cpu[curr]->cpu_softirq;
-
        /* Total number of jiffies spent on the interval */
        deltot_jiffies = get_interval(tot_jiffies[!curr], tot_jiffies[curr]);
 
@@ -1875,6 +1865,16 @@ void rw_io_stat_loop(long int count, struct tm *rectime, int iodev_nr, int dlist
                /* Read stats for CPU "all" */
                read_stat_cpu(st_cpu[curr], 1);
 
+               /*
+                * Compute the total number of jiffies spent by all processors.
+                * NB: Don't add cpu_guest/cpu_guest_nice because cpu_user/cpu_nice
+                * already include them.
+                */
+               tot_jiffies[curr] = st_cpu[curr]->cpu_user + st_cpu[curr]->cpu_nice +
+                                   st_cpu[curr]->cpu_sys + st_cpu[curr]->cpu_idle +
+                                   st_cpu[curr]->cpu_iowait + st_cpu[curr]->cpu_hardirq +
+                                   st_cpu[curr]->cpu_steal + st_cpu[curr]->cpu_softirq;
+
                if (dlist_idx) {
                        /*
                         * A device or partition name was explicitly entered