From 7910965d1a982ee48fab5cf18d8bd07a7d809980 Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Fri, 21 Jun 2019 17:48:44 +0200 Subject: [PATCH] iostat: Fix wrong CPU stats displayed with option -y 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 --- iostat.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/iostat.c b/iostat.c index 897104e..debfd25 100644 --- 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 -- 2.40.0