]> granicus.if.org Git - sysstat/commitdiff
Don't compute global system uptime when reading CPU stats
authorSebastien GODARD <sysstat@users.noreply.github.com>
Fri, 13 Oct 2017 12:20:30 +0000 (14:20 +0200)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Mon, 16 Oct 2017 15:18:01 +0000 (17:18 +0200)
Don't compute "global system uptime" (i.e. total number of jiffies spent
by all processors) in read_stat_cpu() function so that we don't have to
pass the result from one function to another.
Global system uptime is used only when displaying CPU statistics, so
this is now done locally in the functions displaying CPU statistics.
Also as a consequence, field uptime has been removed from the
record_header structure associated with every sample statistics in
sar/sadc.

Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
17 files changed:
activity.c
iostat.c
json_stats.c
mpstat.c
pidstat.c
pr_stats.c
rd_stats.c
rd_stats.h
rndr_stats.c
sa.h
sa_common.c
sa_wrap.c
sadc.c
sadf.c
sar.c
svg_stats.c
xml_stats.c

index 8da2bfb0a5a6dcc501496421e36147f36208c53e..da30a5cb80bcd67044e524376d9816ea89f17a6a 100644 (file)
@@ -71,7 +71,7 @@ struct act_bitmap irq_bitmap = {
  */
 struct activity cpu_act = {
        .id             = A_CPU,
-       .options        = AO_COLLECTED + AO_VOLATILE + AO_GLOBAL_ITV + AO_MULTIPLE_OUTPUTS +
+       .options        = AO_COLLECTED + AO_VOLATILE + AO_MULTIPLE_OUTPUTS +
                          AO_GRAPH_PER_ITEM,
        .magic          = ACTIVITY_MAGIC_BASE,
        .group          = G_DEFAULT,
index 8425830d0e19e3da7316675400d6f03d957a94d4..742c39a0d1aabf25365c5161055a8cb05cf5ad64 100644 (file)
--- a/iostat.c
+++ b/iostat.c
@@ -54,8 +54,8 @@ char *sccsid(void) { return (SCCSID); }
 #endif
 
 struct stats_cpu *st_cpu[2];
-unsigned long long uptime[2]  = {0, 0};
 unsigned long long uptime0[2] = {0, 0};
+unsigned long long tot_jiffies[2] = {0, 0};
 struct io_stats *st_iodev[2];
 struct io_hdr_stats *st_hdr_iodev;
 struct io_dlist *st_dev_list;
@@ -848,17 +848,18 @@ void write_sample_timestamp(int tab, struct tm *rectime)
  *
  * IN:
  * @curr       Index in array for current sample statistics.
- * @itv                Interval of time.
+ * @deltot_jiffies
+ *             Number of jiffies spent on the interval by all processors.
  ***************************************************************************
  */
-void write_plain_cpu_stat(int curr, unsigned long long itv)
+void write_plain_cpu_stat(int curr, unsigned long long deltot_jiffies)
 {
        printf("avg-cpu:  %%user   %%nice %%system %%iowait  %%steal   %%idle\n");
 
        printf("       ");
        cprintf_pc(DISPLAY_UNIT(flags), 6, 7, 2,
-                  ll_sp_value(st_cpu[!curr]->cpu_user,   st_cpu[curr]->cpu_user,   itv),
-                  ll_sp_value(st_cpu[!curr]->cpu_nice,   st_cpu[curr]->cpu_nice,   itv),
+                  ll_sp_value(st_cpu[!curr]->cpu_user, st_cpu[curr]->cpu_user, deltot_jiffies),
+                  ll_sp_value(st_cpu[!curr]->cpu_nice, st_cpu[curr]->cpu_nice, deltot_jiffies),
                   /*
                    * Time spent in system mode also includes time spent servicing
                    * hard and soft interrupts.
@@ -866,12 +867,12 @@ void write_plain_cpu_stat(int curr, unsigned long long itv)
                   ll_sp_value(st_cpu[!curr]->cpu_sys + st_cpu[!curr]->cpu_softirq +
                               st_cpu[!curr]->cpu_hardirq,
                               st_cpu[curr]->cpu_sys + st_cpu[curr]->cpu_softirq +
-                              st_cpu[curr]->cpu_hardirq, itv),
-                  ll_sp_value(st_cpu[!curr]->cpu_iowait, st_cpu[curr]->cpu_iowait, itv),
-                  ll_sp_value(st_cpu[!curr]->cpu_steal,  st_cpu[curr]->cpu_steal,  itv),
+                              st_cpu[curr]->cpu_hardirq, deltot_jiffies),
+                  ll_sp_value(st_cpu[!curr]->cpu_iowait, st_cpu[curr]->cpu_iowait, deltot_jiffies),
+                  ll_sp_value(st_cpu[!curr]->cpu_steal, st_cpu[curr]->cpu_steal, deltot_jiffies),
                   (st_cpu[curr]->cpu_idle < st_cpu[!curr]->cpu_idle) ?
                   0.0 :
-                  ll_sp_value(st_cpu[!curr]->cpu_idle,   st_cpu[curr]->cpu_idle,   itv));
+                  ll_sp_value(st_cpu[!curr]->cpu_idle, st_cpu[curr]->cpu_idle, deltot_jiffies));
 
        printf("\n\n");
 }
@@ -883,15 +884,16 @@ void write_plain_cpu_stat(int curr, unsigned long long itv)
  * IN:
  * @tab                Number of tabs to print.
  * @curr       Index in array for current sample statistics.
- * @itv                Interval of time.
+ * @deltot_jiffies
+ *             Number of jiffies spent on the interval by all processors.
  ***************************************************************************
  */
-void write_json_cpu_stat(int tab, int curr, unsigned long long itv)
+void write_json_cpu_stat(int tab, int curr, unsigned long long deltot_jiffies)
 {
        xprintf0(tab, "\"avg-cpu\":  {\"user\": %.2f, \"nice\": %.2f, \"system\": %.2f,"
                      " \"iowait\": %.2f, \"steal\": %.2f, \"idle\": %.2f}",
-                ll_sp_value(st_cpu[!curr]->cpu_user,   st_cpu[curr]->cpu_user,   itv),
-                ll_sp_value(st_cpu[!curr]->cpu_nice,   st_cpu[curr]->cpu_nice,   itv),
+                ll_sp_value(st_cpu[!curr]->cpu_user, st_cpu[curr]->cpu_user, deltot_jiffies),
+                ll_sp_value(st_cpu[!curr]->cpu_nice, st_cpu[curr]->cpu_nice, deltot_jiffies),
                 /*
                  * Time spent in system mode also includes time spent servicing
                  * hard and soft interrupts.
@@ -899,12 +901,12 @@ void write_json_cpu_stat(int tab, int curr, unsigned long long itv)
                 ll_sp_value(st_cpu[!curr]->cpu_sys + st_cpu[!curr]->cpu_softirq +
                             st_cpu[!curr]->cpu_hardirq,
                             st_cpu[curr]->cpu_sys + st_cpu[curr]->cpu_softirq +
-                            st_cpu[curr]->cpu_hardirq, itv),
-                ll_sp_value(st_cpu[!curr]->cpu_iowait, st_cpu[curr]->cpu_iowait, itv),
-                ll_sp_value(st_cpu[!curr]->cpu_steal,  st_cpu[curr]->cpu_steal,  itv),
+                            st_cpu[curr]->cpu_hardirq, deltot_jiffies),
+                ll_sp_value(st_cpu[!curr]->cpu_iowait, st_cpu[curr]->cpu_iowait, deltot_jiffies),
+                ll_sp_value(st_cpu[!curr]->cpu_steal, st_cpu[curr]->cpu_steal, deltot_jiffies),
                 (st_cpu[curr]->cpu_idle < st_cpu[!curr]->cpu_idle) ?
                 0.0 :
-                ll_sp_value(st_cpu[!curr]->cpu_idle,   st_cpu[curr]->cpu_idle,   itv));
+                ll_sp_value(st_cpu[!curr]->cpu_idle, st_cpu[curr]->cpu_idle, deltot_jiffies));
 }
 
 /*
@@ -913,17 +915,52 @@ void write_json_cpu_stat(int tab, int curr, unsigned long long itv)
  *
  * IN:
  * @curr       Index in array for current sample statistics.
- * @itv                Interval of time.
  * @tab                Number of tabs to print (JSON format only).
  ***************************************************************************
  */
-void write_cpu_stat(int curr, unsigned long long itv, int tab)
+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]);
+
+#ifdef DEBUG
+               if (DISPLAY_DEBUG(flags)) {
+                       /* Debug output */
+                       fprintf(stderr, "deltot_jiffies=%llu st_cpu[curr]{ cpu_user=%llu cpu_nice=%llu "
+                                       "cpu_sys=%llu cpu_idle=%llu cpu_iowait=%llu cpu_steal=%llu "
+                                       "cpu_hardirq=%llu cpu_softirq=%llu cpu_guest=%llu "
+                                       "cpu_guest_nice=%llu }\n",
+                               deltot_jiffies,
+                               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_steal,
+                               st_cpu[curr]->cpu_hardirq,
+                               st_cpu[curr]->cpu_softirq,
+                               st_cpu[curr]->cpu_guest,
+                               st_cpu[curr]->cpu_guest_nice);
+               }
+#endif
+
        if (DISPLAY_JSON_OUTPUT(flags)) {
-               write_json_cpu_stat(tab, curr, itv);
+               write_json_cpu_stat(tab, curr, deltot_jiffies);
        }
        else {
-               write_plain_cpu_stat(curr, itv);
+               write_plain_cpu_stat(curr, deltot_jiffies);
        }
 }
 
@@ -1456,33 +1493,9 @@ void write_stats(int curr, struct tm *rectime)
 #endif
        }
 
-       /* Interval is multiplied by the number of processors */
-       itv = get_interval(uptime[!curr], uptime[curr]);
-
        if (DISPLAY_CPU(flags)) {
-#ifdef DEBUG
-               if (DISPLAY_DEBUG(flags)) {
-                       /* Debug output */
-                       fprintf(stderr, "itv=%llu st_cpu[curr]{ cpu_user=%llu cpu_nice=%llu "
-                                       "cpu_sys=%llu cpu_idle=%llu cpu_iowait=%llu cpu_steal=%llu "
-                                       "cpu_hardirq=%llu cpu_softirq=%llu cpu_guest=%llu "
-                                       "cpu_guest_nice=%llu }\n",
-                               itv,
-                               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_steal,
-                               st_cpu[curr]->cpu_hardirq,
-                               st_cpu[curr]->cpu_softirq,
-                               st_cpu[curr]->cpu_guest,
-                               st_cpu[curr]->cpu_guest_nice);
-               }
-#endif
-
                /* Display CPU utilization */
-               write_cpu_stat(curr, itv, tab);
+               write_cpu_stat(curr, tab);
 
                if (DISPLAY_JSON_OUTPUT(flags)) {
                        if (DISPLAY_DISK(flags)) {
@@ -1492,10 +1505,8 @@ void write_stats(int curr, struct tm *rectime)
                }
        }
 
-       if (cpu_nr > 1) {
-               /* On SMP machines, reduce itv to one processor (see note above) */
-               itv = get_interval(uptime0[!curr], uptime0[curr]);
-       }
+       /* Calculate time interval in jiffies */
+       itv = get_interval(uptime0[!curr], uptime0[curr]);
 
        if (DISPLAY_DISK(flags)) {
                struct io_stats *ioi, *ioj;
@@ -1619,13 +1630,11 @@ void rw_io_stat_loop(long int count, struct tm *rectime)
        setbuf(stdout, NULL);
 
        do {
-               if (cpu_nr > 1) {
-                       /* Read system uptime (only for SMP machines) */
-                       read_uptime(&(uptime0[curr]));
-               }
+               /* Read system uptime (only for SMP machines) */
+               read_uptime(&(uptime0[curr]));
 
-               /* Read stats for CPU "all" and system uptime in jiffies */
-               read_stat_cpu(st_cpu[curr], 1, &(uptime[curr]));
+               /* Read stats for CPU "all" */
+               read_stat_cpu(st_cpu[curr], 1);
 
                if (dlist_idx) {
                        /*
index 82f4ac8c1a050c2cf9950bc6b38980833f55949e..f023873f33531c4f3b92a2323e47741ffc5524d8 100644 (file)
@@ -103,15 +103,17 @@ void json_markup_power_management(int tab, int action)
  * @a          Activity structure with statistics.
  * @curr       Index in array for current sample statistics.
  * @tab                Indentation in output.
- * @g_itv      Interval of time in jiffies mutliplied by the number of
- *             processors.
+ * @itv                Interval of time in jiffies (independent of the number of
+ *             processors). Unused here.
  ***************************************************************************
  */
 __print_funct_t json_print_cpu_stats(struct activity *a, int curr, int tab,
-                                    unsigned long long g_itv)
+                                    unsigned long long itv)
 {
        int i, cpu_offline;
        int sep = FALSE;
+       unsigned long long tot_jiffies[3];
+       unsigned long long deltot_jiffies;
        struct stats_cpu *scc, *scp;
        char cpuno[8];
 
@@ -127,7 +129,22 @@ __print_funct_t json_print_cpu_stats(struct activity *a, int curr, int tab,
                        /* No */
                        continue;
 
-               /* Yes: Display current CPU stats */
+               /*
+                * Yes: Compute the total number of jiffies spent by current processor.
+                * NB: Don't add cpu_guest/cpu_guest_nice because cpu_user/cpu_nice
+                * already include them.
+                */
+               tot_jiffies[curr] = scc->cpu_user + scc->cpu_nice +
+                                   scc->cpu_sys + scc->cpu_idle +
+                                   scc->cpu_iowait + scc->cpu_hardirq +
+                                   scc->cpu_steal + scc->cpu_softirq;
+               tot_jiffies[!curr] = scp->cpu_user + scp->cpu_nice +
+                                    scp->cpu_sys + scp->cpu_idle +
+                                    scp->cpu_iowait + scp->cpu_hardirq +
+                                    scp->cpu_steal + scp->cpu_softirq;
+
+               /* Total number of jiffies spent on the interval */
+               deltot_jiffies = get_interval(tot_jiffies[!curr], tot_jiffies[curr]);
 
                if (sep) {
                        printf(",\n");
@@ -147,9 +164,7 @@ __print_funct_t json_print_cpu_stats(struct activity *a, int curr, int tab,
                         * (Remember that guest/guest_nice times are already included in
                         * user/nice modes.)
                         */
-                       if ((scc->cpu_user    + scc->cpu_nice + scc->cpu_sys   +
-                            scc->cpu_iowait  + scc->cpu_idle + scc->cpu_steal +
-                            scc->cpu_hardirq + scc->cpu_softirq) == 0) {
+                       if (tot_jiffies[curr] == 0) {
                                /*
                                 * Set current struct fields (which have been set to zero)
                                 * to values from previous iteration. Hence their values won't
@@ -157,7 +172,7 @@ __print_funct_t json_print_cpu_stats(struct activity *a, int curr, int tab,
                                 */
                                *scc = *scp;
 
-                               g_itv = 0;
+                               deltot_jiffies = 0;
                                cpu_offline = TRUE;
                        }
                        else {
@@ -165,11 +180,11 @@ __print_funct_t json_print_cpu_stats(struct activity *a, int curr, int tab,
                                 * Recalculate interval for current proc.
                                 * If result is 0 then current CPU is a tickless one.
                                 */
-                               g_itv = get_per_cpu_interval(scc, scp);
+                               deltot_jiffies = get_per_cpu_interval(scc, scp);
                                cpu_offline = FALSE;
                        }
 
-                       if (!g_itv) {
+                       if (!deltot_jiffies) {
                                /* Current CPU is offline or tickless */
                                if (DISPLAY_CPU_DEF(a->opt_flags)) {
                                        xprintf0(tab, "{\"cpu\": \"%d\", "
@@ -211,16 +226,16 @@ __print_funct_t json_print_cpu_stats(struct activity *a, int curr, int tab,
                                 "\"steal\": %.2f, "
                                 "\"idle\": %.2f}",
                                 cpuno,
-                                ll_sp_value(scp->cpu_user, scc->cpu_user, g_itv),
-                                ll_sp_value(scp->cpu_nice, scc->cpu_nice, g_itv),
+                                ll_sp_value(scp->cpu_user, scc->cpu_user, deltot_jiffies),
+                                ll_sp_value(scp->cpu_nice, scc->cpu_nice, deltot_jiffies),
                                 ll_sp_value(scp->cpu_sys + scp->cpu_hardirq + scp->cpu_softirq,
                                             scc->cpu_sys + scc->cpu_hardirq + scc->cpu_softirq,
-                                            g_itv),
-                                ll_sp_value(scp->cpu_iowait, scc->cpu_iowait, g_itv),
-                                ll_sp_value(scp->cpu_steal, scc->cpu_steal, g_itv),
+                                            deltot_jiffies),
+                                ll_sp_value(scp->cpu_iowait, scc->cpu_iowait, deltot_jiffies),
+                                ll_sp_value(scp->cpu_steal, scc->cpu_steal, deltot_jiffies),
                                 scc->cpu_idle < scp->cpu_idle ?
                                 0.0 :
-                                ll_sp_value(scp->cpu_idle, scc->cpu_idle, g_itv));
+                                ll_sp_value(scp->cpu_idle, scc->cpu_idle, deltot_jiffies));
                }
                else if (DISPLAY_CPU_ALL(a->opt_flags)) {
                        xprintf0(tab, "{\"cpu\": \"%s\", "
@@ -238,21 +253,21 @@ __print_funct_t json_print_cpu_stats(struct activity *a, int curr, int tab,
                                 (scc->cpu_user - scc->cpu_guest) < (scp->cpu_user - scp->cpu_guest) ?
                                 0.0 :
                                 ll_sp_value(scp->cpu_user - scp->cpu_guest,
-                                            scc->cpu_user - scc->cpu_guest, g_itv),
+                                            scc->cpu_user - scc->cpu_guest, deltot_jiffies),
                                 (scc->cpu_nice - scc->cpu_guest_nice) < (scp->cpu_nice - scp->cpu_guest_nice) ?
                                 0.0 :
                                 ll_sp_value(scp->cpu_nice - scp->cpu_guest_nice,
-                                            scc->cpu_nice - scc->cpu_guest_nice, g_itv),
-                                ll_sp_value(scp->cpu_sys, scc->cpu_sys, g_itv),
-                                ll_sp_value(scp->cpu_iowait, scc->cpu_iowait, g_itv),
-                                ll_sp_value(scp->cpu_steal, scc->cpu_steal, g_itv),
-                                ll_sp_value(scp->cpu_hardirq, scc->cpu_hardirq, g_itv),
-                                ll_sp_value(scp->cpu_softirq, scc->cpu_softirq, g_itv),
-                                ll_sp_value(scp->cpu_guest, scc->cpu_guest, g_itv),
-                                ll_sp_value(scp->cpu_guest_nice, scc->cpu_guest_nice, g_itv),
+                                            scc->cpu_nice - scc->cpu_guest_nice, deltot_jiffies),
+                                ll_sp_value(scp->cpu_sys, scc->cpu_sys, deltot_jiffies),
+                                ll_sp_value(scp->cpu_iowait, scc->cpu_iowait, deltot_jiffies),
+                                ll_sp_value(scp->cpu_steal, scc->cpu_steal, deltot_jiffies),
+                                ll_sp_value(scp->cpu_hardirq, scc->cpu_hardirq, deltot_jiffies),
+                                ll_sp_value(scp->cpu_softirq, scc->cpu_softirq, deltot_jiffies),
+                                ll_sp_value(scp->cpu_guest, scc->cpu_guest, deltot_jiffies),
+                                ll_sp_value(scp->cpu_guest_nice, scc->cpu_guest_nice, deltot_jiffies),
                                 scc->cpu_idle < scp->cpu_idle ?
                                 0.0 :
-                                ll_sp_value(scp->cpu_idle, scc->cpu_idle, g_itv));
+                                ll_sp_value(scp->cpu_idle, scc->cpu_idle, deltot_jiffies));
                }
        }
 
index 8485f9b20827faef6d53c271007e226db8b061ca..7481d4d90a95a1400f6c30630df97473304fda7a 100644 (file)
--- a/mpstat.c
+++ b/mpstat.c
@@ -48,7 +48,7 @@
 char *sccsid(void) { return (SCCSID); }
 #endif
 
-unsigned long long uptime[3] = {0, 0, 0};
+unsigned long long tot_jiffies[3] = {0, 0, 0};
 unsigned long long uptime0[3] = {0, 0, 0};
 
 /* NOTE: Use array of _char_ for bitmaps to avoid endianness problems...*/
@@ -364,7 +364,8 @@ void set_node_cpu_stats(struct stats_cpu *st_node, struct stats_cpu *st_cpu)
  *
  * IN:
  * @dis                TRUE if a header line must be printed.
- * @g_itv      Interval value in jiffies multiplied by the number of CPU.
+ * @deltot_jiffies
+ *             Number of jiffies spent on the interval by all processors.
  * @prev       Position in array where statistics used as reference are.
  *             Stats used as reference may be the previous ones read, or
  *             the very first ones when calculating the average.
@@ -377,7 +378,7 @@ void set_node_cpu_stats(struct stats_cpu *st_node, struct stats_cpu *st_cpu)
  *             when displaying average stats.
  ***************************************************************************
  */
-void write_plain_cpu_stats(int dis, unsigned long long g_itv, int prev, int curr,
+void write_plain_cpu_stats(int dis, unsigned long long deltot_jiffies, int prev, int curr,
                           char *prev_string, char *curr_string)
 {
        struct stats_cpu *scc, *scp;
@@ -402,39 +403,39 @@ void write_plain_cpu_stats(int dis, unsigned long long g_itv, int prev, int curr
                           0.0 :
                           ll_sp_value(st_cpu[prev]->cpu_user - st_cpu[prev]->cpu_guest,
                                       st_cpu[curr]->cpu_user - st_cpu[curr]->cpu_guest,
-                                      g_itv),
+                                      deltot_jiffies),
                           (st_cpu[curr]->cpu_nice - st_cpu[curr]->cpu_guest_nice) <
                           (st_cpu[prev]->cpu_nice - st_cpu[prev]->cpu_guest_nice) ?
                           0.0 :
                           ll_sp_value(st_cpu[prev]->cpu_nice - st_cpu[prev]->cpu_guest_nice,
                                       st_cpu[curr]->cpu_nice - st_cpu[curr]->cpu_guest_nice,
-                                      g_itv),
+                                      deltot_jiffies),
                           ll_sp_value(st_cpu[prev]->cpu_sys,
                                       st_cpu[curr]->cpu_sys,
-                                      g_itv),
+                                      deltot_jiffies),
                           ll_sp_value(st_cpu[prev]->cpu_iowait,
                                       st_cpu[curr]->cpu_iowait,
-                                      g_itv),
+                                      deltot_jiffies),
                           ll_sp_value(st_cpu[prev]->cpu_hardirq,
                                       st_cpu[curr]->cpu_hardirq,
-                                      g_itv),
+                                      deltot_jiffies),
                           ll_sp_value(st_cpu[prev]->cpu_softirq,
                                       st_cpu[curr]->cpu_softirq,
-                                      g_itv),
+                                      deltot_jiffies),
                           ll_sp_value(st_cpu[prev]->cpu_steal,
                                       st_cpu[curr]->cpu_steal,
-                                      g_itv),
+                                      deltot_jiffies),
                           ll_sp_value(st_cpu[prev]->cpu_guest,
                                       st_cpu[curr]->cpu_guest,
-                                      g_itv),
+                                      deltot_jiffies),
                           ll_sp_value(st_cpu[prev]->cpu_guest_nice,
                                       st_cpu[curr]->cpu_guest_nice,
-                                      g_itv),
+                                      deltot_jiffies),
                           (st_cpu[curr]->cpu_idle < st_cpu[prev]->cpu_idle) ?
                           0.0 :
                           ll_sp_value(st_cpu[prev]->cpu_idle,
                                       st_cpu[curr]->cpu_idle,
-                                      g_itv));
+                                      deltot_jiffies));
                printf("\n");
        }
 
@@ -532,14 +533,15 @@ void write_plain_cpu_stats(int dis, unsigned long long g_itv, int prev, int curr
  *
  * IN:
  * @tab                Number of tabs to print.
- * @g_itv      Interval value in jiffies multiplied by the number of CPU.
+ * @deltot_jiffies
+ *             Number of jiffies spent on the interval by all processors.
  * @prev       Position in array where statistics used as reference are.
  *             Stats used as reference may be the previous ones read, or
  *             the very first ones when calculating the average.
  * @curr       Position in array where current statistics will be saved.
  ***************************************************************************
  */
-void write_json_cpu_stats(int tab, unsigned long long g_itv, int prev, int curr)
+void write_json_cpu_stats(int tab, unsigned long long deltot_jiffies, int prev, int curr)
 {
        struct stats_cpu *scc, *scp;
        unsigned long long pc_itv;
@@ -559,39 +561,39 @@ void write_json_cpu_stats(int tab, unsigned long long g_itv, int prev, int curr)
                         0.0 :
                         ll_sp_value(st_cpu[prev]->cpu_user - st_cpu[prev]->cpu_guest,
                                     st_cpu[curr]->cpu_user - st_cpu[curr]->cpu_guest,
-                                    g_itv),
+                                    deltot_jiffies),
                         (st_cpu[curr]->cpu_nice - st_cpu[curr]->cpu_guest_nice) <
                         (st_cpu[prev]->cpu_nice - st_cpu[prev]->cpu_guest_nice) ?
                         0.0 :
                         ll_sp_value(st_cpu[prev]->cpu_nice - st_cpu[prev]->cpu_guest_nice,
                                     st_cpu[curr]->cpu_nice - st_cpu[curr]->cpu_guest_nice,
-                                    g_itv),
+                                    deltot_jiffies),
                         ll_sp_value(st_cpu[prev]->cpu_sys,
                                     st_cpu[curr]->cpu_sys,
-                                    g_itv),
+                                    deltot_jiffies),
                         ll_sp_value(st_cpu[prev]->cpu_iowait,
                                     st_cpu[curr]->cpu_iowait,
-                                    g_itv),
+                                    deltot_jiffies),
                         ll_sp_value(st_cpu[prev]->cpu_hardirq,
                                     st_cpu[curr]->cpu_hardirq,
-                                    g_itv),
+                                    deltot_jiffies),
                         ll_sp_value(st_cpu[prev]->cpu_softirq,
                                     st_cpu[curr]->cpu_softirq,
-                                    g_itv),
+                                    deltot_jiffies),
                         ll_sp_value(st_cpu[prev]->cpu_steal,
                                     st_cpu[curr]->cpu_steal,
-                                    g_itv),
+                                    deltot_jiffies),
                         ll_sp_value(st_cpu[prev]->cpu_guest,
                                     st_cpu[curr]->cpu_guest,
-                                    g_itv),
+                                    deltot_jiffies),
                         ll_sp_value(st_cpu[prev]->cpu_guest_nice,
                                     st_cpu[curr]->cpu_guest_nice,
-                                    g_itv),
+                                    deltot_jiffies),
                         (st_cpu[curr]->cpu_idle < st_cpu[prev]->cpu_idle) ?
                         0.0 :
                         ll_sp_value(st_cpu[prev]->cpu_idle,
                                     st_cpu[curr]->cpu_idle,
-                                    g_itv));
+                                    deltot_jiffies));
        }
 
        for (cpu = 1; cpu <= cpu_nr; cpu++) {
@@ -693,7 +695,8 @@ void write_json_cpu_stats(int tab, unsigned long long g_itv, int prev, int curr)
  *
  * IN:
  * @dis                TRUE if a header line must be printed.
- * @g_itv      Interval value in jiffies multiplied by the number of CPU.
+ * @deltot_jiffies
+ *             Number of jiffies spent on the interval by all processors.
  * @prev       Position in array where statistics used as reference are.
  *             Stats used as reference may be the previous ones read, or
  *             the very first ones when calculating the average.
@@ -709,7 +712,7 @@ void write_json_cpu_stats(int tab, unsigned long long g_itv, int prev, int curr)
  *             only).
  ***************************************************************************
  */
-void write_cpu_stats(int dis, unsigned long long g_itv, int prev, int curr,
+void write_cpu_stats(int dis, unsigned long long deltot_jiffies, int prev, int curr,
                     char *prev_string, char *curr_string, int tab, int *next)
 {
        if (DISPLAY_JSON_OUTPUT(flags)) {
@@ -717,10 +720,10 @@ void write_cpu_stats(int dis, unsigned long long g_itv, int prev, int curr,
                        printf(",\n");
                }
                *next = TRUE;
-               write_json_cpu_stats(tab, g_itv, prev, curr);
+               write_json_cpu_stats(tab, deltot_jiffies, prev, curr);
        }
        else {
-               write_plain_cpu_stats(dis, g_itv, prev, curr, prev_string, curr_string);
+               write_plain_cpu_stats(dis, deltot_jiffies, prev, curr, prev_string, curr_string);
        }
 }
 
@@ -730,7 +733,8 @@ void write_cpu_stats(int dis, unsigned long long g_itv, int prev, int curr,
  *
  * IN:
  * @dis                TRUE if a header line must be printed.
- * @g_itv      Interval value in jiffies multiplied by the number of CPU.
+ * @deltot_jiffies
+ *             Number of jiffies spent on the interval by all processors.
  * @itv                Interval value.
  * @prev       Position in array where statistics used as reference are.
  *             Stats used as reference may be the previous ones read, or
@@ -744,7 +748,7 @@ void write_cpu_stats(int dis, unsigned long long g_itv, int prev, int curr,
  *             when displaying average stats.
  ***************************************************************************
  */
-void write_plain_node_stats(int dis, unsigned long long g_itv, unsigned long long itv,
+void write_plain_node_stats(int dis, unsigned long long deltot_jiffies, unsigned long long itv,
                            int prev, int curr, char *prev_string, char *curr_string)
 {
        struct stats_cpu *snc, *snp;
@@ -771,39 +775,39 @@ void write_plain_node_stats(int dis, unsigned long long g_itv, unsigned long lon
                           0.0 :
                           ll_sp_value(st_cpu[prev]->cpu_user - st_cpu[prev]->cpu_guest,
                                       st_cpu[curr]->cpu_user - st_cpu[curr]->cpu_guest,
-                                      g_itv),
+                                      deltot_jiffies),
                           (st_cpu[curr]->cpu_nice - st_cpu[curr]->cpu_guest_nice) <
                           (st_cpu[prev]->cpu_nice - st_cpu[prev]->cpu_guest_nice) ?
                           0.0 :
                           ll_sp_value(st_cpu[prev]->cpu_nice - st_cpu[prev]->cpu_guest_nice,
                                       st_cpu[curr]->cpu_nice - st_cpu[curr]->cpu_guest_nice,
-                                      g_itv),
+                                      deltot_jiffies),
                           ll_sp_value(st_cpu[prev]->cpu_sys,
                                       st_cpu[curr]->cpu_sys,
-                                      g_itv),
+                                      deltot_jiffies),
                           ll_sp_value(st_cpu[prev]->cpu_iowait,
                                       st_cpu[curr]->cpu_iowait,
-                                      g_itv),
+                                      deltot_jiffies),
                           ll_sp_value(st_cpu[prev]->cpu_hardirq,
                                       st_cpu[curr]->cpu_hardirq,
-                                      g_itv),
+                                      deltot_jiffies),
                           ll_sp_value(st_cpu[prev]->cpu_softirq,
                                       st_cpu[curr]->cpu_softirq,
-                                      g_itv),
+                                      deltot_jiffies),
                           ll_sp_value(st_cpu[prev]->cpu_steal,
                                       st_cpu[curr]->cpu_steal,
-                                      g_itv),
+                                      deltot_jiffies),
                           ll_sp_value(st_cpu[prev]->cpu_guest,
                                       st_cpu[curr]->cpu_guest,
-                                      g_itv),
+                                      deltot_jiffies),
                           ll_sp_value(st_cpu[prev]->cpu_guest_nice,
                                       st_cpu[curr]->cpu_guest_nice,
-                                      g_itv),
+                                      deltot_jiffies),
                           (st_cpu[curr]->cpu_idle < st_cpu[prev]->cpu_idle) ?
                           0.0 :
                           ll_sp_value(st_cpu[prev]->cpu_idle,
                                       st_cpu[curr]->cpu_idle,
-                                      g_itv));
+                                      deltot_jiffies));
                printf("\n");
        }
 
@@ -870,7 +874,8 @@ void write_plain_node_stats(int dis, unsigned long long g_itv, unsigned long lon
  *
  * IN:
  * @tab                Number of tabs to print.
- * @g_itv      Interval value in jiffies multiplied by the number of CPU.
+ * @deltot_jiffies
+ *             Number of jiffies spent on the interval by all processors.
  * @itv                Interval value.
  * @prev       Position in array where statistics used as reference are.
  *             Stats used as reference may be the previous ones read, or
@@ -878,7 +883,7 @@ void write_plain_node_stats(int dis, unsigned long long g_itv, unsigned long lon
  * @curr       Position in array where current statistics will be saved.
  ***************************************************************************
  */
-void write_json_node_stats(int tab, unsigned long long g_itv, unsigned long long itv,
+void write_json_node_stats(int tab, unsigned long long deltot_jiffies, unsigned long long itv,
                           int prev, int curr)
 {
        struct stats_cpu *snc, *snp;
@@ -898,39 +903,39 @@ void write_json_node_stats(int tab, unsigned long long g_itv, unsigned long long
                         0.0 :
                         ll_sp_value(st_cpu[prev]->cpu_user - st_cpu[prev]->cpu_guest,
                                     st_cpu[curr]->cpu_user - st_cpu[curr]->cpu_guest,
-                                    g_itv),
+                                    deltot_jiffies),
                         (st_cpu[curr]->cpu_nice - st_cpu[curr]->cpu_guest_nice) <
                         (st_cpu[prev]->cpu_nice - st_cpu[prev]->cpu_guest_nice) ?
                         0.0 :
                         ll_sp_value(st_cpu[prev]->cpu_nice - st_cpu[prev]->cpu_guest_nice,
                                     st_cpu[curr]->cpu_nice - st_cpu[curr]->cpu_guest_nice,
-                                    g_itv),
+                                    deltot_jiffies),
                         ll_sp_value(st_cpu[prev]->cpu_sys,
                                     st_cpu[curr]->cpu_sys,
-                                    g_itv),
+                                    deltot_jiffies),
                         ll_sp_value(st_cpu[prev]->cpu_iowait,
                                     st_cpu[curr]->cpu_iowait,
-                                    g_itv),
+                                    deltot_jiffies),
                         ll_sp_value(st_cpu[prev]->cpu_hardirq,
                                     st_cpu[curr]->cpu_hardirq,
-                                    g_itv),
+                                    deltot_jiffies),
                         ll_sp_value(st_cpu[prev]->cpu_softirq,
                                     st_cpu[curr]->cpu_softirq,
-                                    g_itv),
+                                    deltot_jiffies),
                         ll_sp_value(st_cpu[prev]->cpu_steal,
                                     st_cpu[curr]->cpu_steal,
-                                    g_itv),
+                                    deltot_jiffies),
                         ll_sp_value(st_cpu[prev]->cpu_guest,
                                     st_cpu[curr]->cpu_guest,
-                                    g_itv),
+                                    deltot_jiffies),
                         ll_sp_value(st_cpu[prev]->cpu_guest_nice,
                                     st_cpu[curr]->cpu_guest_nice,
-                                    g_itv),
+                                    deltot_jiffies),
                         (st_cpu[curr]->cpu_idle < st_cpu[prev]->cpu_idle) ?
                         0.0 :
                         ll_sp_value(st_cpu[prev]->cpu_idle,
                                     st_cpu[curr]->cpu_idle,
-                                    g_itv));
+                                    deltot_jiffies));
        }
 
        for (node = 0; node <= node_nr; node++) {
@@ -1001,7 +1006,8 @@ void write_json_node_stats(int tab, unsigned long long g_itv, unsigned long long
  *
  * IN:
  * @dis                TRUE if a header line must be printed.
- * @g_itv      Interval value in jiffies multiplied by the number of CPU.
+ * @deltot_jiffies
+ *             Number of jiffies spent on the interval by all processors.
  * @itv                Interval value.
  * @prev       Position in array where statistics used as reference are.
  *             Stats used as reference may be the previous ones read, or
@@ -1018,7 +1024,7 @@ void write_json_node_stats(int tab, unsigned long long g_itv, unsigned long long
  *             only).
  ***************************************************************************
  */
-void write_node_stats(int dis, unsigned long long g_itv, unsigned long long itv,
+void write_node_stats(int dis, unsigned long long deltot_jiffies, unsigned long long itv,
                      int prev, int curr, char *prev_string, char *curr_string,
                      int tab, int *next)
 {
@@ -1027,10 +1033,11 @@ void write_node_stats(int dis, unsigned long long g_itv, unsigned long long itv,
                        printf(",\n");
                }
                *next = TRUE;
-               write_json_node_stats(tab, g_itv, itv, prev, curr);
+               write_json_node_stats(tab, deltot_jiffies, itv, prev, curr);
        }
        else {
-               write_plain_node_stats(dis, g_itv, itv, prev, curr, prev_string, curr_string);
+               write_plain_node_stats(dis, deltot_jiffies, itv, prev, curr,
+                                      prev_string, curr_string);
        }
 }
 
@@ -1583,7 +1590,7 @@ void write_stats_core(int prev, int curr, int dis,
                      char *prev_string, char *curr_string)
 {
        struct stats_cpu *scc, *scp;
-       unsigned long long itv, g_itv;
+       unsigned long long itv, deltot_jiffies;
        int cpu, tab = 4, next = FALSE;
 
        /* Test stdout */
@@ -1594,27 +1601,31 @@ void write_stats_core(int prev, int curr, int dis,
                xprintf(tab, "\"timestamp\": \"%s\",", curr_string);
        }
 
-       /* Compute time interval */
-       g_itv = get_interval(uptime[prev], uptime[curr]);
+       /*
+        * 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[prev], tot_jiffies[curr]);
 
-       /* Reduce interval value to one processor */
-       if (cpu_nr > 1) {
-               itv = get_interval(uptime0[prev], uptime0[curr]);
-       }
-       else {
-               itv = g_itv;
-       }
+       /* Get time interval */
+       itv = get_interval(uptime0[prev], uptime0[curr]);
 
        /* Print CPU stats */
        if (DISPLAY_CPU(actflags)) {
-               write_cpu_stats(dis, g_itv, prev, curr, prev_string, curr_string,
-                               tab, &next);
+               write_cpu_stats(dis, deltot_jiffies, prev, curr, prev_string,
+                               curr_string, tab, &next);
        }
 
        /* Print node CPU stats */
        if (DISPLAY_NODE(actflags)) {
-               write_node_stats(dis, g_itv, itv, prev, curr, prev_string, curr_string,
-                                tab, &next);
+               write_node_stats(dis, deltot_jiffies, itv, prev, curr, prev_string,
+                                curr_string, tab, &next);
        }
 
        /* Print total number of interrupts per processor */
@@ -1830,12 +1841,13 @@ void rw_mpstat_loop(int dis_hdr, int rows)
        /* Dont buffer data if redirected to a pipe */
        setbuf(stdout, NULL);
 
-       /* Read uptime and CPU stats */
-       if (cpu_nr > 1) {
-               /* Read system uptime (only for SMP machines) */
-               read_uptime(&(uptime0[0]));
-       }
-       read_stat_cpu(st_cpu[0], cpu_nr + 1, &(uptime[0]));
+       /* Read system uptime and CPU stats */
+       read_uptime(&(uptime0[0]));
+       read_stat_cpu(st_cpu[0], cpu_nr + 1);
+       tot_jiffies[0] = st_cpu[0]->cpu_user + st_cpu[0]->cpu_nice +
+                        st_cpu[0]->cpu_sys + st_cpu[0]->cpu_idle +
+                        st_cpu[0]->cpu_iowait + st_cpu[0]->cpu_hardirq +
+                        st_cpu[0]->cpu_steal + st_cpu[0]->cpu_softirq;
        if (DISPLAY_NODE(actflags)) {
                set_node_cpu_stats(st_node[0], st_cpu[0]);
        }
@@ -1885,7 +1897,7 @@ void rw_mpstat_loop(int dis_hdr, int rows)
 
        /* Save the first stats collected. Will be used to compute the average */
        mp_tstamp[2] = mp_tstamp[0];
-       uptime[2] = uptime[0];
+       tot_jiffies[2] = tot_jiffies[0];
        uptime0[2] = uptime0[0];
        memcpy(st_cpu[2], st_cpu[0], STATS_CPU_SIZE * (cpu_nr + 1));
        memcpy(st_node[2], st_node[0], STATS_CPU_SIZE * (cpu_nr + 1));
@@ -1927,10 +1939,8 @@ void rw_mpstat_loop(int dis_hdr, int rows)
                get_localtime(&(mp_tstamp[curr]), 0);
 
                /* Read uptime and CPU stats */
-               if (cpu_nr > 1) {
-                       read_uptime(&(uptime0[curr]));
-               }
-               read_stat_cpu(st_cpu[curr], cpu_nr + 1, &(uptime[curr]));
+               read_uptime(&(uptime0[curr]));
+               read_stat_cpu(st_cpu[curr], cpu_nr + 1);
                if (DISPLAY_NODE(actflags)) {
                        set_node_cpu_stats(st_node[curr], st_cpu[curr]);
                }
index 6d419d76ed85eb32d9c7eb354e2e593489c4672e..5b628ffa090192bf3e744d05fb033b928dc328b5 100644 (file)
--- a/pidstat.c
+++ b/pidstat.c
@@ -52,7 +52,7 @@
 char *sccsid(void) { return (SCCSID); }
 #endif
 
-unsigned long long uptime[3] = {0, 0, 0};
+unsigned long long tot_jiffies[3] = {0, 0, 0};
 unsigned long long uptime0[3] = {0, 0, 0};
 struct pid_stats *st_pid_list[3] = {NULL, NULL, NULL};
 unsigned int *pid_array = NULL;
@@ -1007,8 +1007,18 @@ void read_stats(int curr)
                perror("malloc");
                exit(4);
        }
-       /* Read statistics for CPUs "all" and system uptime (in jiffies) */
-       read_stat_cpu(st_cpu, 1, &uptime[curr]);
+       /* Read statistics for CPUs "all" */
+       read_stat_cpu(st_cpu, 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->cpu_user + st_cpu->cpu_nice +
+                           st_cpu->cpu_sys + st_cpu->cpu_idle +
+                           st_cpu->cpu_iowait + st_cpu->cpu_hardirq +
+                           st_cpu->cpu_steal + st_cpu->cpu_softirq;
        free(st_cpu);
 
        if (DISPLAY_ALL_PID(pidflag)) {
@@ -1389,8 +1399,8 @@ void print_line_id(char *timestamp, struct pid_stats *pst)
  * @curr_string        String displayed at the beginning of current sample stats.
  *             This is the timestamp of the current sample.
  * @itv                Interval of time in jiffies.
- * @g_itv      Interval of time in jiffies multiplied by the number of
- *             processors.
+ * @deltot_jiffies
+ *             Number of jiffies spent on the interval by all processors.
  *
  * RETURNS:
  * 0 if all the processes to display have terminated.
@@ -1400,7 +1410,7 @@ void print_line_id(char *timestamp, struct pid_stats *pst)
 int write_pid_task_all_stats(int prev, int curr, int dis,
                             char *prev_string, char *curr_string,
                             unsigned long long itv,
-                            unsigned long long g_itv)
+                            unsigned long long deltot_jiffies)
 {
        struct pid_stats *pstc, *pstp;
        char dstr[32];
@@ -1453,7 +1463,7 @@ int write_pid_task_all_stats(int prev, int curr, int dis,
                                   /* User time already includes guest time */
                                   IRIX_MODE_OFF(pidflag) ?
                                   SP_VALUE_100(pstp->utime + pstp->stime,
-                                           pstc->utime + pstc->stime, g_itv) :
+                                           pstc->utime + pstc->stime, deltot_jiffies) :
                                   SP_VALUE_100(pstp->utime + pstp->stime,
                                            pstc->utime + pstc->stime, itv));
 
@@ -1626,8 +1636,8 @@ int write_pid_child_all_stats(int prev, int curr, int dis,
  *             This is the timestamp of the current sample, or "Average"
  *             when displaying average stats.
  * @itv                Interval of time in jiffies.
- * @g_itv      Interval of time in jiffies multiplied by the number of
- *             processors.
+ * @deltot_jiffies
+ *             Number of jiffies spent on the interval by all processors.
  *
  * RETURNS:
  * 0 if all the processes to display have terminated.
@@ -1637,7 +1647,7 @@ int write_pid_child_all_stats(int prev, int curr, int dis,
 int write_pid_task_cpu_stats(int prev, int curr, int dis, int disp_avg,
                             char *prev_string, char *curr_string,
                             unsigned long long itv,
-                            unsigned long long g_itv)
+                            unsigned long long deltot_jiffies)
 {
        struct pid_stats *pstc, *pstp;
        unsigned int p;
@@ -1666,7 +1676,7 @@ int write_pid_task_cpu_stats(int prev, int curr, int dis, int disp_avg,
                           /* User time already includes guest time */
                           IRIX_MODE_OFF(pidflag) ?
                           SP_VALUE_100(pstp->utime + pstp->stime,
-                                   pstc->utime + pstc->stime, g_itv) :
+                                   pstc->utime + pstc->stime, deltot_jiffies) :
                           SP_VALUE_100(pstp->utime + pstp->stime,
                                    pstc->utime + pstc->stime, itv));
 
@@ -2293,23 +2303,16 @@ int write_pid_ktab_stats(int prev, int curr, int dis, int disp_avg,
 int write_stats_core(int prev, int curr, int dis, int disp_avg,
                     char *prev_string, char *curr_string)
 {
-       unsigned long long itv, g_itv;
+       unsigned long long itv, deltot_jiffies;
        int again = 0;
 
        /* Test stdout */
        TEST_STDOUT(STDOUT_FILENO);
 
-       /* g_itv is multiplied by the number of processors */
-       g_itv = get_interval(uptime[prev], uptime[curr]);
+       /* Total number of jiffies spent on the interval */
+       deltot_jiffies = get_interval(tot_jiffies[prev], tot_jiffies[curr]);
 
-       if (cpu_nr > 1) {
-               /* SMP machines */
-               itv = get_interval(uptime0[prev], uptime0[curr]);
-       }
-       else {
-               /* UP machines */
-               itv = g_itv;
-       }
+       itv = get_interval(uptime0[prev], uptime0[curr]);
 
        if (PROCESS_STRING(pidflag)) {
                /* Reset "show threads" flag */
@@ -2319,7 +2322,7 @@ int write_stats_core(int prev, int curr, int dis, int disp_avg,
        if (DISPLAY_ONELINE(pidflag)) {
                if (DISPLAY_TASK_STATS(tskflag)) {
                        again += write_pid_task_all_stats(prev, curr, dis, prev_string, curr_string,
-                                                         itv, g_itv);
+                                                         itv, deltot_jiffies);
                }
                if (DISPLAY_CHILD_STATS(tskflag)) {
                        again += write_pid_child_all_stats(prev, curr, dis, prev_string, curr_string,
@@ -2333,7 +2336,7 @@ int write_stats_core(int prev, int curr, int dis, int disp_avg,
                        if (DISPLAY_TASK_STATS(tskflag)) {
                                again += write_pid_task_cpu_stats(prev, curr, dis, disp_avg,
                                                                  prev_string, curr_string,
-                                                                 itv, g_itv);
+                                                                 itv, deltot_jiffies);
                        }
                        if (DISPLAY_CHILD_STATS(tskflag)) {
                                again += write_pid_child_cpu_stats(prev, curr, dis, disp_avg,
@@ -2476,10 +2479,8 @@ void rw_pidstat_loop(int dis_hdr, int rows)
        /* Don't buffer data if redirected to a pipe */
        setbuf(stdout, NULL);
 
-       if (cpu_nr > 1) {
-               /* Read system uptime (only for SMP machines) */
-               read_uptime(&uptime0[0]);
-       }
+       /* Read system uptime */
+       read_uptime(&uptime0[0]);
        read_stats(0);
 
        if (DISPLAY_MEM(actflag)) {
@@ -2503,7 +2504,7 @@ void rw_pidstat_loop(int dis_hdr, int rows)
 
        /* Save the first stats collected. Will be used to compute the average */
        ps_tstamp[2] = ps_tstamp[0];
-       uptime[2] = uptime[0];
+       tot_jiffies[2] = tot_jiffies[0];
        uptime0[2] = uptime0[0];
        memcpy(st_pid_list[2], st_pid_list[0], PID_STATS_SIZE * pid_nr);
 
@@ -2523,10 +2524,8 @@ void rw_pidstat_loop(int dis_hdr, int rows)
                /* Get time */
                get_localtime(&ps_tstamp[curr], 0);
 
-               if (cpu_nr > 1) {
-                       /* Read system uptime (only for SMP machines) */
-                       read_uptime(&(uptime0[curr]));
-               }
+               /* Read system uptime */
+               read_uptime(&(uptime0[curr]));
 
                /* Read stats */
                read_stats(curr);
index 72dc641d4f98ed40b33c967a0823d4091b16f814..cb64fb31b7c201c188a5e895655d791b06bcfd22 100644 (file)
@@ -109,19 +109,25 @@ void print_hdr_line(char *timestamp, struct activity *a, int pos, int iwidth, in
 /*
  ***************************************************************************
  * Display CPU statistics.
+ * NB: The stats are only calculated over the part of the time interval when
+ * the CPU was online. As a consequence, the sum (%user + %nice + ... + %idle)
+ * will always be 100% on the time interval even if the CPU has been offline
+ * most of the time.
  *
  * IN:
  * @a          Activity structure with statistics.
  * @prev       Index in array where stats used as reference are.
  * @curr       Index in array for current sample statistics.
- * @g_itv      Interval of time in jiffies multiplied by the number
- *             of processors.
+ * @itv                Interval of time in jiffies (independent of the number of
+ *             processors). Unused here.
  ***************************************************************************
  */
 __print_funct_t print_cpu_stats(struct activity *a, int prev, int curr,
-                               unsigned long long g_itv)
+                               unsigned long long itv)
 {
        int i;
+       unsigned long long tot_jiffies[3];
+       unsigned long long deltot_jiffies;
        struct stats_cpu *scc, *scp;
 
        if (dis) {
@@ -152,7 +158,23 @@ __print_funct_t print_cpu_stats(struct activity *a, int prev, int curr,
                        /* No */
                        continue;
 
-               /* Yes: Display it */
+               /*
+                * Yes: Compute the total number of jiffies spent by current processor.
+                * NB: Don't add cpu_guest/cpu_guest_nice because cpu_user/cpu_nice
+                * already include them.
+                */
+               tot_jiffies[curr] = scc->cpu_user + scc->cpu_nice +
+                                   scc->cpu_sys + scc->cpu_idle +
+                                   scc->cpu_iowait + scc->cpu_hardirq +
+                                   scc->cpu_steal + scc->cpu_softirq;
+               tot_jiffies[prev] = scp->cpu_user + scp->cpu_nice +
+                                   scp->cpu_sys + scp->cpu_idle +
+                                   scp->cpu_iowait + scp->cpu_hardirq +
+                                   scp->cpu_steal + scp->cpu_softirq;
+
+               /* Total number of jiffies spent on the interval */
+               deltot_jiffies = get_interval(tot_jiffies[prev], tot_jiffies[curr]);
+
                printf("%-11s", timestamp[curr]);
 
                if (!i) {
@@ -168,9 +190,7 @@ __print_funct_t print_cpu_stats(struct activity *a, int prev, int curr,
                         * (Remember that guest/guest_nice times are already included in
                         * user/nice modes.)
                         */
-                       if ((scc->cpu_user    + scc->cpu_nice + scc->cpu_sys   +
-                            scc->cpu_iowait  + scc->cpu_idle + scc->cpu_steal +
-                            scc->cpu_hardirq + scc->cpu_softirq) == 0) {
+                       if (tot_jiffies[curr] == 0) {
                                /*
                                 * Set current struct fields (which have been set to zero)
                                 * to values from previous iteration. Hence their values won't
@@ -195,9 +215,9 @@ __print_funct_t print_cpu_stats(struct activity *a, int prev, int curr,
                        }
 
                        /* Recalculate interval for current proc */
-                       g_itv = get_per_cpu_interval(scc, scp);
+                       deltot_jiffies = get_per_cpu_interval(scc, scp);
 
-                       if (!g_itv) {
+                       if (!deltot_jiffies) {
                                /*
                                 * If the CPU is tickless then there is no change in CPU values
                                 * but the sum of values is not zero.
@@ -225,16 +245,16 @@ __print_funct_t print_cpu_stats(struct activity *a, int prev, int curr,
 
                if (DISPLAY_CPU_DEF(a->opt_flags)) {
                        cprintf_pc(DISPLAY_UNIT(flags), 6, 9, 2,
-                                  ll_sp_value(scp->cpu_user, scc->cpu_user, g_itv),
-                                  ll_sp_value(scp->cpu_nice, scc->cpu_nice, g_itv),
+                                  ll_sp_value(scp->cpu_user, scc->cpu_user, deltot_jiffies),
+                                  ll_sp_value(scp->cpu_nice, scc->cpu_nice, deltot_jiffies),
                                   ll_sp_value(scp->cpu_sys + scp->cpu_hardirq + scp->cpu_softirq,
                                               scc->cpu_sys + scc->cpu_hardirq + scc->cpu_softirq,
-                                              g_itv),
-                                  ll_sp_value(scp->cpu_iowait, scc->cpu_iowait, g_itv),
-                                  ll_sp_value(scp->cpu_steal, scc->cpu_steal, g_itv),
+                                              deltot_jiffies),
+                                  ll_sp_value(scp->cpu_iowait, scc->cpu_iowait, deltot_jiffies),
+                                  ll_sp_value(scp->cpu_steal, scc->cpu_steal, deltot_jiffies),
                                   scc->cpu_idle < scp->cpu_idle ?
                                   0.0 :
-                                  ll_sp_value(scp->cpu_idle, scc->cpu_idle, g_itv));
+                                  ll_sp_value(scp->cpu_idle, scc->cpu_idle, deltot_jiffies));
                        printf("\n");
                }
                else if (DISPLAY_CPU_ALL(a->opt_flags)) {
@@ -242,21 +262,21 @@ __print_funct_t print_cpu_stats(struct activity *a, int prev, int curr,
                                   (scc->cpu_user - scc->cpu_guest) < (scp->cpu_user - scp->cpu_guest) ?
                                   0.0 :
                                   ll_sp_value(scp->cpu_user - scp->cpu_guest,
-                                              scc->cpu_user - scc->cpu_guest, g_itv),
+                                              scc->cpu_user - scc->cpu_guest, deltot_jiffies),
                                               (scc->cpu_nice - scc->cpu_guest_nice) < (scp->cpu_nice - scp->cpu_guest_nice) ?
                                   0.0 :
                                   ll_sp_value(scp->cpu_nice - scp->cpu_guest_nice,
-                                              scc->cpu_nice - scc->cpu_guest_nice, g_itv),
-                                  ll_sp_value(scp->cpu_sys, scc->cpu_sys, g_itv),
-                                  ll_sp_value(scp->cpu_iowait, scc->cpu_iowait, g_itv),
-                                  ll_sp_value(scp->cpu_steal, scc->cpu_steal, g_itv),
-                                  ll_sp_value(scp->cpu_hardirq, scc->cpu_hardirq, g_itv),
-                                  ll_sp_value(scp->cpu_softirq, scc->cpu_softirq, g_itv),
-                                  ll_sp_value(scp->cpu_guest, scc->cpu_guest, g_itv),
-                                  ll_sp_value(scp->cpu_guest_nice, scc->cpu_guest_nice, g_itv),
+                                              scc->cpu_nice - scc->cpu_guest_nice, deltot_jiffies),
+                                  ll_sp_value(scp->cpu_sys, scc->cpu_sys, deltot_jiffies),
+                                  ll_sp_value(scp->cpu_iowait, scc->cpu_iowait, deltot_jiffies),
+                                  ll_sp_value(scp->cpu_steal, scc->cpu_steal, deltot_jiffies),
+                                  ll_sp_value(scp->cpu_hardirq, scc->cpu_hardirq, deltot_jiffies),
+                                  ll_sp_value(scp->cpu_softirq, scc->cpu_softirq, deltot_jiffies),
+                                  ll_sp_value(scp->cpu_guest, scc->cpu_guest, deltot_jiffies),
+                                  ll_sp_value(scp->cpu_guest_nice, scc->cpu_guest_nice, deltot_jiffies),
                                   scc->cpu_idle < scp->cpu_idle ?
                                   0.0 :
-                                  ll_sp_value(scp->cpu_idle, scc->cpu_idle, g_itv));
+                                  ll_sp_value(scp->cpu_idle, scc->cpu_idle, deltot_jiffies));
                        printf("\n");
                }
        }
index a397ea85d186f44760e33178de7c7c2babcef40e..bae02130f9d0e990877a85f239b72ee55f5cc3da 100644 (file)
@@ -44,7 +44,7 @@
 
 /*
  ***************************************************************************
- * Read CPU statistics and machine uptime.
+ * Read CPU statistics.
  *
  * IN:
  * @st_cpu     Structure where stats will be saved.
  *
  * OUT:
  * @st_cpu     Structure with statistics.
- * @uptime     Machine uptime multiplied by the number of processors.
  ***************************************************************************
  */
-void read_stat_cpu(struct stats_cpu *st_cpu, int nbr, unsigned long long *uptime)
+void read_stat_cpu(struct stats_cpu *st_cpu, int nbr)
 {
        FILE *fp;
        struct stats_cpu *st_cpu_i;
@@ -94,19 +93,6 @@ void read_stat_cpu(struct stats_cpu *st_cpu, int nbr, unsigned long long *uptime
                               &st_cpu->cpu_steal,
                               &st_cpu->cpu_guest,
                               &st_cpu->cpu_guest_nice);
-
-                       /*
-                        * Compute the uptime of the system in jiffies (1/100ths of a second
-                        * if HZ=100).
-                        * Machine uptime is multiplied by the number of processors here.
-                        *
-                        * NB: Don't add cpu_guest/cpu_guest_nice because cpu_user/cpu_nice
-                        * already include them.
-                        */
-                       *uptime = st_cpu->cpu_user + st_cpu->cpu_nice    +
-                               st_cpu->cpu_sys    + st_cpu->cpu_idle    +
-                               st_cpu->cpu_iowait + st_cpu->cpu_hardirq +
-                               st_cpu->cpu_steal  + st_cpu->cpu_softirq;
                }
 
                else if (!strncmp(line, "cpu", 3)) {
index f2b6a383e5bb31f36e82d213f45192302fde735b..fc6be2effd8bcd2e1aaffd96a2b620c184f98fc3 100644 (file)
@@ -595,7 +595,7 @@ struct stats_softnet {
 void oct2chr
        (char *);
 void read_stat_cpu
-       (struct stats_cpu *, int, unsigned long long *);
+       (struct stats_cpu *, int);
 void read_stat_irq
        (struct stats_irq *, int);
 void read_meminfo
index e63cf55ee9ddf30dfbb416230db5c01ad31f1876..bdcaef415686eafc26ea99bb604e6ad22e2da88a 100644 (file)
@@ -163,14 +163,16 @@ static void render(int isdb, char *pre, int rflags, const char *pptxt,
  * @isdb       Flag, true if db printing, false if ppc printing.
  * @pre                Prefix string for output entries
  * @curr       Index in array for current sample statistics.
- * @g_itv      Interval of time in jiffies multiplied by the number
- *             of processors.
+ * @itv                Interval of time in jiffies (independent of the number of
+ *             processors). Unused here.
  ***************************************************************************
  */
 __print_funct_t render_cpu_stats(struct activity *a, int isdb, char *pre,
-                                int curr, unsigned long long g_itv)
+                                int curr, unsigned long long itv)
 {
        int i, cpu_offline;
+       unsigned long long tot_jiffies[3];
+       unsigned long long deltot_jiffies;
        struct stats_cpu *scc, *scp;
        int pt_newlin
                = (DISPLAY_HORIZONTALLY(flags) ? PT_NOFLAG : PT_NEWLIN);
@@ -185,6 +187,23 @@ __print_funct_t render_cpu_stats(struct activity *a, int isdb, char *pre,
                        /* No */
                        continue;
 
+               /*
+                * Yes: Compute the total number of jiffies spent by current processor.
+                * NB: Don't add cpu_guest/cpu_guest_nice because cpu_user/cpu_nice
+                * already include them.
+                */
+               tot_jiffies[curr] = scc->cpu_user + scc->cpu_nice +
+                                   scc->cpu_sys + scc->cpu_idle +
+                                   scc->cpu_iowait + scc->cpu_hardirq +
+                                   scc->cpu_steal + scc->cpu_softirq;
+               tot_jiffies[!curr] = scp->cpu_user + scp->cpu_nice +
+                                    scp->cpu_sys + scp->cpu_idle +
+                                    scp->cpu_iowait + scp->cpu_hardirq +
+                                    scp->cpu_steal + scp->cpu_softirq;
+
+               /* Total number of jiffies spent on the interval */
+               deltot_jiffies = get_interval(tot_jiffies[!curr], tot_jiffies[curr]);
+
                if (!i) {
                        /* This is CPU "all" */
                        if (DISPLAY_CPU_DEF(a->opt_flags)) {
@@ -194,7 +213,7 @@ __print_funct_t render_cpu_stats(struct activity *a, int isdb, char *pre,
                                       "-1",            /* look! dbtext */
                                       NULL,            /* no args */
                                       NOVAL,           /* another 0, named for readability */
-                                      ll_sp_value(scp->cpu_user, scc->cpu_user, g_itv),
+                                      ll_sp_value(scp->cpu_user, scc->cpu_user, deltot_jiffies),
                                       NULL);           /* No string arg */
                        }
                        else if (DISPLAY_CPU_ALL(a->opt_flags)) {
@@ -205,7 +224,7 @@ __print_funct_t render_cpu_stats(struct activity *a, int isdb, char *pre,
                                       0.0 :
                                       ll_sp_value(scp->cpu_user - scp->cpu_guest,
                                                   scc->cpu_user - scc->cpu_guest,
-                                                  g_itv),
+                                                  deltot_jiffies),
                                       NULL);
                        }
 
@@ -213,7 +232,7 @@ __print_funct_t render_cpu_stats(struct activity *a, int isdb, char *pre,
                                render(isdb, pre, PT_NOFLAG,
                                       "all\t%%nice", NULL, NULL,
                                       NOVAL,
-                                      ll_sp_value(scp->cpu_nice, scc->cpu_nice, g_itv),
+                                      ll_sp_value(scp->cpu_nice, scc->cpu_nice, deltot_jiffies),
                                       NULL);
                        }
                        else if (DISPLAY_CPU_ALL(a->opt_flags)) {
@@ -224,7 +243,7 @@ __print_funct_t render_cpu_stats(struct activity *a, int isdb, char *pre,
                                       0.0 :
                                       ll_sp_value(scp->cpu_nice - scp->cpu_guest_nice,
                                                   scc->cpu_nice - scc->cpu_guest_nice,
-                                                  g_itv),
+                                                  deltot_jiffies),
                                       NULL);
                        }
 
@@ -234,52 +253,52 @@ __print_funct_t render_cpu_stats(struct activity *a, int isdb, char *pre,
                                       NOVAL,
                                       ll_sp_value(scp->cpu_sys + scp->cpu_hardirq + scp->cpu_softirq,
                                                   scc->cpu_sys + scc->cpu_hardirq + scc->cpu_softirq,
-                                                  g_itv),
+                                                  deltot_jiffies),
                                       NULL);
                        }
                        else if (DISPLAY_CPU_ALL(a->opt_flags)) {
                                render(isdb, pre, PT_NOFLAG,
                                       "all\t%%sys", NULL, NULL,
                                       NOVAL,
-                                      ll_sp_value(scp->cpu_sys, scc->cpu_sys, g_itv),
+                                      ll_sp_value(scp->cpu_sys, scc->cpu_sys, deltot_jiffies),
                                       NULL);
                        }
 
                        render(isdb, pre, PT_NOFLAG,
                               "all\t%%iowait", NULL, NULL,
                               NOVAL,
-                              ll_sp_value(scp->cpu_iowait, scc->cpu_iowait, g_itv),
+                              ll_sp_value(scp->cpu_iowait, scc->cpu_iowait, deltot_jiffies),
                               NULL);
 
                        render(isdb, pre, PT_NOFLAG,
                               "all\t%%steal", NULL, NULL,
                               NOVAL,
-                              ll_sp_value(scp->cpu_steal, scc->cpu_steal, g_itv),
+                              ll_sp_value(scp->cpu_steal, scc->cpu_steal, deltot_jiffies),
                               NULL);
 
                        if (DISPLAY_CPU_ALL(a->opt_flags)) {
                                render(isdb, pre, PT_NOFLAG,
                                       "all\t%%irq", NULL, NULL,
                                       NOVAL,
-                                      ll_sp_value(scp->cpu_hardirq, scc->cpu_hardirq, g_itv),
+                                      ll_sp_value(scp->cpu_hardirq, scc->cpu_hardirq, deltot_jiffies),
                                       NULL);
 
                                render(isdb, pre, PT_NOFLAG,
                                       "all\t%%soft", NULL, NULL,
                                       NOVAL,
-                                      ll_sp_value(scp->cpu_softirq, scc->cpu_softirq, g_itv),
+                                      ll_sp_value(scp->cpu_softirq, scc->cpu_softirq, deltot_jiffies),
                                       NULL);
 
                                render(isdb, pre, PT_NOFLAG,
                                       "all\t%%guest", NULL, NULL,
                                       NOVAL,
-                                      ll_sp_value(scp->cpu_guest, scc->cpu_guest, g_itv),
+                                      ll_sp_value(scp->cpu_guest, scc->cpu_guest, deltot_jiffies),
                                       NULL);
 
                                render(isdb, pre, PT_NOFLAG,
                                       "all\t%%gnice", NULL, NULL,
                                       NOVAL,
-                                      ll_sp_value(scp->cpu_guest_nice, scc->cpu_guest_nice, g_itv),
+                                      ll_sp_value(scp->cpu_guest_nice, scc->cpu_guest_nice, deltot_jiffies),
                                       NULL);
                        }
 
@@ -288,7 +307,7 @@ __print_funct_t render_cpu_stats(struct activity *a, int isdb, char *pre,
                               NOVAL,
                               (scc->cpu_idle < scp->cpu_idle) ?
                               0.0 :
-                              ll_sp_value(scp->cpu_idle, scc->cpu_idle, g_itv),
+                              ll_sp_value(scp->cpu_idle, scc->cpu_idle, deltot_jiffies),
                               NULL);
                }
                else {
@@ -298,9 +317,7 @@ __print_funct_t render_cpu_stats(struct activity *a, int isdb, char *pre,
                         * (Remember that guest/guest_nice times are already included in
                         * user/nice modes.)
                         */
-                       if ((scc->cpu_user    + scc->cpu_nice + scc->cpu_sys   +
-                            scc->cpu_iowait  + scc->cpu_idle + scc->cpu_steal +
-                            scc->cpu_hardirq + scc->cpu_softirq) == 0) {
+                       if (tot_jiffies[curr] == 0) {
                                /*
                                 * Set current struct fields (which have been set to zero)
                                 * to values from previous iteration. Hence their values won't
@@ -308,7 +325,7 @@ __print_funct_t render_cpu_stats(struct activity *a, int isdb, char *pre,
                                 */
                                *scc = *scp;
 
-                               g_itv = 0;
+                               deltot_jiffies = 0;
                                cpu_offline = TRUE;
                        }
                        else {
@@ -316,7 +333,7 @@ __print_funct_t render_cpu_stats(struct activity *a, int isdb, char *pre,
                                 * Recalculate itv for current proc.
                                 * If the result is 0, then current CPU is a tickless one.
                                 */
-                               g_itv = get_per_cpu_interval(scc, scp);
+                               deltot_jiffies = get_per_cpu_interval(scc, scp);
                                cpu_offline = FALSE;
                        }
 
@@ -326,20 +343,20 @@ __print_funct_t render_cpu_stats(struct activity *a, int isdb, char *pre,
                                       "%d",                    /* db text with format char */
                                       cons(iv, i - 1, NOVAL),  /* how we pass format args  */
                                       NOVAL,
-                                      !g_itv ?
+                                      !deltot_jiffies ?
                                       0.0 :                    /* CPU is offline or tickless */
-                                      ll_sp_value(scp->cpu_user, scc->cpu_user, g_itv),
+                                      ll_sp_value(scp->cpu_user, scc->cpu_user, deltot_jiffies),
                                       NULL);
                        }
                        else if (DISPLAY_CPU_ALL(a->opt_flags)) {
                                render(isdb, pre, PT_NOFLAG,
                                       "cpu%d\t%%usr", "%d", cons(iv, i - 1, NOVAL),
                                       NOVAL,
-                                      (!g_itv ||
+                                      (!deltot_jiffies ||
                                       ((scc->cpu_user - scc->cpu_guest) < (scp->cpu_user - scp->cpu_guest))) ?
                                       0.0 :
                                       ll_sp_value(scp->cpu_user - scp->cpu_guest,
-                                                  scc->cpu_user - scc->cpu_guest, g_itv),
+                                                  scc->cpu_user - scc->cpu_guest, deltot_jiffies),
                                       NULL);
                        }
 
@@ -347,20 +364,20 @@ __print_funct_t render_cpu_stats(struct activity *a, int isdb, char *pre,
                                render(isdb, pre, PT_NOFLAG,
                                       "cpu%d\t%%nice", NULL, cons(iv, i - 1, NOVAL),
                                       NOVAL,
-                                      !g_itv ?
+                                      !deltot_jiffies ?
                                       0.0 :
-                                      ll_sp_value(scp->cpu_nice, scc->cpu_nice, g_itv),
+                                      ll_sp_value(scp->cpu_nice, scc->cpu_nice, deltot_jiffies),
                                       NULL);
                        }
                        else if (DISPLAY_CPU_ALL(a->opt_flags)) {
                                render(isdb, pre, PT_NOFLAG,
                                       "cpu%d\t%%nice", NULL, cons(iv, i - 1, NOVAL),
                                       NOVAL,
-                                      (!g_itv ||
+                                      (!deltot_jiffies ||
                                       ((scc->cpu_nice - scc->cpu_guest_nice) < (scp->cpu_nice - scp->cpu_guest_nice))) ?
                                       0.0 :
                                       ll_sp_value(scp->cpu_nice - scp->cpu_guest_nice,
-                                                  scc->cpu_nice - scc->cpu_guest_nice, g_itv),
+                                                  scc->cpu_nice - scc->cpu_guest_nice, deltot_jiffies),
                                       NULL);
                        }
 
@@ -368,74 +385,74 @@ __print_funct_t render_cpu_stats(struct activity *a, int isdb, char *pre,
                                render(isdb, pre, PT_NOFLAG,
                                       "cpu%d\t%%system", NULL, cons(iv, i - 1, NOVAL),
                                       NOVAL,
-                                      !g_itv ?
+                                      !deltot_jiffies ?
                                       0.0 :
                                       ll_sp_value(scp->cpu_sys + scp->cpu_hardirq + scp->cpu_softirq,
                                                   scc->cpu_sys + scc->cpu_hardirq + scc->cpu_softirq,
-                                                  g_itv),
+                                                  deltot_jiffies),
                                       NULL);
                        }
                        else if (DISPLAY_CPU_ALL(a->opt_flags)) {
                                render(isdb, pre, PT_NOFLAG,
                                       "cpu%d\t%%sys", NULL, cons(iv, i - 1, NOVAL),
                                       NOVAL,
-                                      !g_itv ?
+                                      !deltot_jiffies ?
                                       0.0 :
-                                      ll_sp_value(scp->cpu_sys, scc->cpu_sys, g_itv),
+                                      ll_sp_value(scp->cpu_sys, scc->cpu_sys, deltot_jiffies),
                                       NULL);
                        }
 
                        render(isdb, pre, PT_NOFLAG,
                               "cpu%d\t%%iowait", NULL, cons(iv, i - 1, NOVAL),
                               NOVAL,
-                              !g_itv ?
+                              !deltot_jiffies ?
                               0.0 :
-                              ll_sp_value(scp->cpu_iowait, scc->cpu_iowait, g_itv),
+                              ll_sp_value(scp->cpu_iowait, scc->cpu_iowait, deltot_jiffies),
                               NULL);
 
                        render(isdb, pre, PT_NOFLAG,
                               "cpu%d\t%%steal", NULL, cons(iv, i - 1, NOVAL),
                               NOVAL,
-                              !g_itv ?
+                              !deltot_jiffies ?
                               0.0 :
-                              ll_sp_value(scp->cpu_steal, scc->cpu_steal, g_itv),
+                              ll_sp_value(scp->cpu_steal, scc->cpu_steal, deltot_jiffies),
                               NULL);
 
                        if (DISPLAY_CPU_ALL(a->opt_flags)) {
                                render(isdb, pre, PT_NOFLAG,
                                       "cpu%d\t%%irq", NULL, cons(iv, i - 1, NOVAL),
                                       NOVAL,
-                                      !g_itv ?
+                                      !deltot_jiffies ?
                                       0.0 :
-                                      ll_sp_value(scp->cpu_hardirq, scc->cpu_hardirq, g_itv),
+                                      ll_sp_value(scp->cpu_hardirq, scc->cpu_hardirq, deltot_jiffies),
                                       NULL);
 
                                render(isdb, pre, PT_NOFLAG,
                                       "cpu%d\t%%soft", NULL, cons(iv, i - 1, NOVAL),
                                       NOVAL,
-                                      !g_itv ?
+                                      !deltot_jiffies ?
                                       0.0 :
-                                      ll_sp_value(scp->cpu_softirq, scc->cpu_softirq, g_itv),
+                                      ll_sp_value(scp->cpu_softirq, scc->cpu_softirq, deltot_jiffies),
                                       NULL);
 
                                render(isdb, pre, PT_NOFLAG,
                                       "cpu%d\t%%guest", NULL, cons(iv, i - 1, NOVAL),
                                       NOVAL,
-                                      !g_itv ?
+                                      !deltot_jiffies ?
                                       0.0 :
-                                      ll_sp_value(scp->cpu_guest, scc->cpu_guest, g_itv),
+                                      ll_sp_value(scp->cpu_guest, scc->cpu_guest, deltot_jiffies),
                                       NULL);
 
                                render(isdb, pre, PT_NOFLAG,
                                       "cpu%d\t%%gnice", NULL, cons(iv, i - 1, NOVAL),
                                       NOVAL,
-                                      !g_itv ?
+                                      !deltot_jiffies ?
                                       0.0 :
-                                      ll_sp_value(scp->cpu_guest_nice, scc->cpu_guest_nice, g_itv),
+                                      ll_sp_value(scp->cpu_guest_nice, scc->cpu_guest_nice, deltot_jiffies),
                                       NULL);
                        }
 
-                       if (!g_itv) {
+                       if (!deltot_jiffies) {
                                /* CPU is offline or tickless */
                                render(isdb, pre, pt_newlin,
                                       "cpu%d\t%%idle", NULL, cons(iv, i - 1, NOVAL),
@@ -450,7 +467,7 @@ __print_funct_t render_cpu_stats(struct activity *a, int isdb, char *pre,
                                       NOVAL,
                                       (scc->cpu_idle < scp->cpu_idle) ?
                                       0.0 :
-                                      ll_sp_value(scp->cpu_idle, scc->cpu_idle, g_itv),
+                                      ll_sp_value(scp->cpu_idle, scc->cpu_idle, deltot_jiffies),
                                       NULL);
                        }
                }
diff --git a/sa.h b/sa.h
index 3e6bed61b20efeb821ef4f6d7327061b29f8f842..0fdc7a84dd5b6ee2bda50e4e05ab336ea186bcf0 100644 (file)
--- a/sa.h
+++ b/sa.h
@@ -569,11 +569,7 @@ struct file_activity {
 /* Header structure for every record */
 struct record_header {
        /*
-        * Machine uptime (multiplied by the # of proc).
-        */
-       unsigned long long uptime;
-       /*
-        * Uptime reduced to one processor. Always set, even on UP machines.
+        * Machine uptime in jiffies (independent of the number of processors).
         */
        unsigned long long uptime0;
        /*
@@ -595,7 +591,7 @@ struct record_header {
 
 #define RECORD_HEADER_SIZE     (sizeof(struct record_header))
 #define MAX_RECORD_HEADER_SIZE 512     /* Used for sanity check */
-#define RECORD_HEADER_ULL_NR   3       /* Nr of unsigned long long in record_header structure */
+#define RECORD_HEADER_ULL_NR   2       /* Nr of unsigned long long in record_header structure */
 #define RECORD_HEADER_UL_NR    0       /* Nr of unsigned long in record_header structure */
 #define RECORD_HEADER_U_NR     0       /* Nr of unsigned int in record_header structure */
 
@@ -626,11 +622,8 @@ struct record_header {
  */
 #define AO_VOLATILE            0x04
 /*
- * Indicate that the interval of time, given to f_print() function
- * displaying statistics, should be the interval of time in jiffies
- * multiplied by the number of processors.
+ * 0x08: Unused.
  */
-#define AO_GLOBAL_ITV          0x08
 /*
  * This flag should be set for every activity closing a markup used
  * by several activities. Used by sadf f_xml_print() functions to
@@ -658,7 +651,6 @@ struct record_header {
 #define IS_COLLECTED(m)                (((m) & AO_COLLECTED)        == AO_COLLECTED)
 #define IS_SELECTED(m)         (((m) & AO_SELECTED)         == AO_SELECTED)
 #define IS_VOLATILE(m)         (((m) & AO_VOLATILE)         == AO_VOLATILE)
-#define NEED_GLOBAL_ITV(m)     (((m) & AO_GLOBAL_ITV)       == AO_GLOBAL_ITV)
 #define CLOSE_MARKUP(m)                (((m) & AO_CLOSE_MARKUP)     == AO_CLOSE_MARKUP)
 #define HAS_MULTIPLE_OUTPUTS(m)        (((m) & AO_MULTIPLE_OUTPUTS) == AO_MULTIPLE_OUTPUTS)
 #define ONE_GRAPH_PER_ITEM(m)  (((m) & AO_GRAPH_PER_ITEM)   == AO_GRAPH_PER_ITEM)
@@ -1209,7 +1201,7 @@ void get_file_timestamp_struct
        (unsigned int, struct tm *, struct file_header *);
 void get_itv_value
        (struct record_header *, struct record_header *, unsigned int,
-        unsigned long long *, unsigned long long *);
+        unsigned long long *);
 void handle_invalid_sa_file
        (int *, struct file_magic *, char *, int);
 int next_slice
index 8757030615a223790669c2488c74b507108c9a85..6527f1717daad7dc796a39c8a9317ef20f1e3b8c 100644 (file)
@@ -505,26 +505,16 @@ int check_alt_sa_dir(char *datafile, int d_off, int sa_name)
  * @nr_proc            Number of CPU, including CPU "all".
  *
  * OUT:
- * @itv                        Interval in jiffies.
- * @g_itv              Interval in jiffies multiplied by the # of proc.
+ * @itv                        Interval of time in jiffies.
  ***************************************************************************
  */
 void get_itv_value(struct record_header *record_hdr_curr,
                   struct record_header *record_hdr_prev,
-                  unsigned int nr_proc,
-                  unsigned long long *itv, unsigned long long *g_itv)
+                  unsigned int nr_proc, unsigned long long *itv)
 {
        /* Interval value in jiffies */
-       *g_itv = get_interval(record_hdr_prev->uptime,
-                             record_hdr_curr->uptime);
-
-       if (nr_proc > 2) {
-               *itv = get_interval(record_hdr_prev->uptime0,
-                                   record_hdr_curr->uptime0);
-       }
-       else {
-               *itv = *g_itv;
-       }
+       *itv = get_interval(record_hdr_prev->uptime0,
+                           record_hdr_curr->uptime0);
 }
 
 /*
index 12f99ca304b59332ad5e54103269bfe81a024866..79020a2bca89080ec75b7f45146a301a7f68f2d2 100644 (file)
--- a/sa_wrap.c
+++ b/sa_wrap.c
@@ -47,7 +47,7 @@ __read_funct_t wrap_read_stat_cpu(struct activity *a)
                = (struct stats_cpu *) a->_buf0;
 
        /* Read CPU statistics */
-       read_stat_cpu(st_cpu, a->nr, &record_hdr.uptime);
+       read_stat_cpu(st_cpu, a->nr);
 
        return;
 }
diff --git a/sadc.c b/sadc.c
index c4eb4eaffb4b17fe93b8a6c922b42212ee4a9834..b9285654e349b7b76d9418ab1513e9dd1c5b271f 100644 (file)
--- a/sadc.c
+++ b/sadc.c
@@ -1065,12 +1065,9 @@ append_error:
 void read_stats(void)
 {
        int i;
-       __nr_t cpu_nr = act[get_activity_position(act, A_CPU, EXIT_IF_NOT_FOUND)]->nr;
 
-       if (cpu_nr > 1) {
-               /* Read system uptime in jiffies */
-               read_uptime(&(record_hdr.uptime0));
-       }
+       /* Read system uptime in jiffies */
+       read_uptime(&(record_hdr.uptime0));
 
        for (i = 0; i < NR_ACT; i++) {
                if (IS_COLLECTED(act[i]->options)) {
@@ -1078,16 +1075,6 @@ void read_stats(void)
                        (*act[i]->f_read)(act[i]);
                }
        }
-
-       if (cpu_nr == 1) {
-               /*
-                * If cpu_nr = 1, uptime0 and uptime are equal.
-                * Remember that cpu_nr = 1 means one CPU and no SMP kernel
-                * (one structure for CPU "all") and cpu_nr = 2 means one CPU
-                * and an SMP kernel (two structures for CPUs "all" and "0").
-                */
-               record_hdr.uptime0 = record_hdr.uptime;
-       }
 }
 
 /*
diff --git a/sadf.c b/sadf.c
index 17654dfcf24f981790c89453ae88aabfd9c0463e..9c3f9f8e2762cc156851205c28e15caeba7ce8bd 100644 (file)
--- a/sadf.c
+++ b/sadf.c
@@ -609,7 +609,7 @@ int generic_write_stats(int curr, int use_tm_start, int use_tm_end, int reset,
                        struct tm *loctime, int reset_cd, unsigned int act_id)
 {
        int i;
-       unsigned long long dt, itv, g_itv;
+       unsigned long long dt, itv;
        char cur_date[TIMESTAMP_LEN], cur_time[TIMESTAMP_LEN], *pre = NULL;
        static int cross_day = FALSE;
 
@@ -657,7 +657,7 @@ int generic_write_stats(int curr, int use_tm_start, int use_tm_end, int reset,
 
        /* Get interval values */
        get_itv_value(&record_hdr[curr], &record_hdr[!curr],
-                     cpu_nr, &itv, &g_itv);
+                     cpu_nr, &itv);
 
        /* Check time (3) */
        if (use_tm_end && (datecmp(loctime, &tm_end) > 0)) {
@@ -701,16 +701,14 @@ int generic_write_stats(int curr, int use_tm_start, int use_tm_end, int reset,
                                                                                dt, &file_hdr, flags);
                                        }
                                }
-                               (*act[i]->f_json_print)(act[i], curr, *tab, NEED_GLOBAL_ITV(act[i]->options) ?
-                                                       g_itv : itv);
+                               (*act[i]->f_json_print)(act[i], curr, *tab, itv);
                        }
 
                        else if (format == F_XML_OUTPUT) {
                                /* XML output */
                                int *tab = (int *) parm;
 
-                               (*act[i]->f_xml_print)(act[i], curr, *tab, NEED_GLOBAL_ITV(act[i]->options) ?
-                                                      g_itv : itv);
+                               (*act[i]->f_xml_print)(act[i], curr, *tab, itv);
                        }
 
                        else if (format == F_SVG_OUTPUT) {
@@ -718,9 +716,7 @@ int generic_write_stats(int curr, int use_tm_start, int use_tm_end, int reset,
                                struct svg_parm *svg_p = (struct svg_parm *) parm;
 
                                svg_p->dt = (unsigned long) dt;
-                               (*act[i]->f_svg_print)(act[i], curr, F_MAIN, svg_p,
-                                                      NEED_GLOBAL_ITV(act[i]->options) ? g_itv : itv,
-                                                      &record_hdr[curr]);
+                               (*act[i]->f_svg_print)(act[i], curr, F_MAIN, svg_p, itv, &record_hdr[curr]);
                        }
 
                        else if (format == F_RAW_OUTPUT) {
@@ -730,8 +726,7 @@ int generic_write_stats(int curr, int use_tm_start, int use_tm_end, int reset,
 
                        else {
                                /* Other output formats: db, ppc */
-                               (*act[i]->f_render)(act[i], (format == F_DB_OUTPUT), pre, curr,
-                                                   NEED_GLOBAL_ITV(act[i]->options) ? g_itv : itv);
+                               (*act[i]->f_render)(act[i], (format == F_DB_OUTPUT), pre, curr, itv);
                        }
                }
        }
diff --git a/sar.c b/sar.c
index 7833ce3784356f298430ca9fdf3903101445260d..e01ad5025ab2f1741dce109e4809b5f592a75431 100644 (file)
--- a/sar.c
+++ b/sar.c
@@ -348,19 +348,14 @@ int check_line_hdr(void)
 void write_stats_avg(int curr, int read_from_file, unsigned int act_id)
 {
        int i;
-       unsigned long long itv, g_itv;
+       unsigned long long itv;
        static __nr_t cpu_nr = -1;
 
        if (cpu_nr < 0)
                cpu_nr = act[get_activity_position(act, A_CPU, EXIT_IF_NOT_FOUND)]->nr;
 
        /* Interval value in jiffies */
-       g_itv = get_interval(record_hdr[2].uptime, record_hdr[curr].uptime);
-
-       if (cpu_nr > 1)
-               itv = get_interval(record_hdr[2].uptime0, record_hdr[curr].uptime0);
-       else
-               itv = g_itv;
+       itv = get_interval(record_hdr[2].uptime0, record_hdr[curr].uptime0);
 
        strncpy(timestamp[curr], _("Average:"), TIMESTAMP_LEN);
        timestamp[curr][TIMESTAMP_LEN - 1] = '\0';
@@ -376,8 +371,7 @@ void write_stats_avg(int curr, int read_from_file, unsigned int act_id)
 
                if (IS_SELECTED(act[i]->options) && (act[i]->nr > 0)) {
                        /* Display current average activity statistics */
-                       (*act[i]->f_print_avg)(act[i], 2, curr,
-                                              NEED_GLOBAL_ITV(act[i]->options) ? g_itv : itv);
+                       (*act[i]->f_print_avg)(act[i], 2, curr, itv);
                }
        }
 
@@ -419,7 +413,7 @@ int write_stats(int curr, int read_from_file, long *cnt, int use_tm_start,
                int use_tm_end, int reset, unsigned int act_id, int reset_cd)
 {
        int i;
-       unsigned long long itv, g_itv;
+       unsigned long long itv;
        static int cross_day = 0;
        static __nr_t cpu_nr = -1;
 
@@ -488,7 +482,7 @@ int write_stats(int curr, int read_from_file, long *cnt, int use_tm_start,
 
        /* Get interval values */
        get_itv_value(&record_hdr[curr], &record_hdr[!curr],
-                     cpu_nr, &itv, &g_itv);
+                     cpu_nr, &itv);
 
        /* Check time (3) */
        if (use_tm_end && (datecmp(&rectime, &tm_end) > 0)) {
@@ -509,8 +503,7 @@ int write_stats(int curr, int read_from_file, long *cnt, int use_tm_start,
 
                if (IS_SELECTED(act[i]->options) && (act[i]->nr > 0)) {
                        /* Display current activity statistics */
-                       (*act[i]->f_print)(act[i], !curr, curr,
-                                          NEED_GLOBAL_ITV(act[i]->options) ? g_itv : itv);
+                       (*act[i]->f_print)(act[i], !curr, curr, itv);
                }
        }
 
index 2444ed1ac3e02b959de8ab52afa84c470068d636..bc5b03cf129bca9575f72978f96018d47d193a70 100644 (file)
@@ -1002,13 +1002,16 @@ void draw_activity_graphs(int g_nr, int g_type[], char *title[], char *g_title[]
  *             found (.@restart), and time used for the X axis origin
  *             (@ust_time_ref).
  * @itv                Interval of time in jiffies (only with F_MAIN action).
+ *             Unused here.
  * @record_hdr Pointer on record header of current stats sample.
  ***************************************************************************
  */
 __print_funct_t svg_print_cpu_stats(struct activity *a, int curr, int action, struct svg_parm *svg_p,
-                                   unsigned long long g_itv, struct record_header *record_hdr)
+                                   unsigned long long itv, struct record_header *record_hdr)
 {
        struct stats_cpu *scc, *scp;
+       unsigned long long tot_jiffies[3];
+       unsigned long long deltot_jiffies;
        int group1[] = {5};
        int group2[] = {9};
        int g_type[] = {SVG_BAR_GRAPH};
@@ -1042,6 +1045,23 @@ __print_funct_t svg_print_cpu_stats(struct activity *a, int curr, int action, st
                                /* No */
                                continue;
 
+                       /*
+                        * Yes: Compute the total number of jiffies spent by current processor.
+                        * NB: Don't add cpu_guest/cpu_guest_nice because cpu_user/cpu_nice
+                        * already include them.
+                        */
+                       tot_jiffies[curr] = scc->cpu_user + scc->cpu_nice +
+                                           scc->cpu_sys + scc->cpu_idle +
+                                           scc->cpu_iowait + scc->cpu_hardirq +
+                                           scc->cpu_steal + scc->cpu_softirq;
+                       tot_jiffies[!curr] = scp->cpu_user + scp->cpu_nice +
+                                            scp->cpu_sys + scp->cpu_idle +
+                                            scp->cpu_iowait + scp->cpu_hardirq +
+                                            scp->cpu_steal + scp->cpu_softirq;
+
+                       /* Total number of jiffies spent on the interval */
+                       deltot_jiffies = get_interval(tot_jiffies[!curr], tot_jiffies[curr]);
+
                        pos = i * 10;
                        offset = 0.0;
 
@@ -1052,9 +1072,7 @@ __print_funct_t svg_print_cpu_stats(struct activity *a, int curr, int action, st
                                 * (Remember that guest/guest_nice times are already included in
                                 * user/nice modes.)
                                 */
-                               if ((scc->cpu_user    + scc->cpu_nice + scc->cpu_sys   +
-                                    scc->cpu_iowait  + scc->cpu_idle + scc->cpu_steal +
-                                    scc->cpu_hardirq + scc->cpu_softirq) == 0) {
+                               if (tot_jiffies[curr] == 0) {
                                        /*
                                         * Set current struct fields (which have been set to zero)
                                         * to values from previous iteration. Hence their values won't
@@ -1062,7 +1080,7 @@ __print_funct_t svg_print_cpu_stats(struct activity *a, int curr, int action, st
                                         */
                                        *scc = *scp;
 
-                                       g_itv = 0;
+                                       deltot_jiffies = 0;
                                        cpu_offline = TRUE;
                                }
                                else {
@@ -1070,11 +1088,11 @@ __print_funct_t svg_print_cpu_stats(struct activity *a, int curr, int action, st
                                         * Recalculate interval for current proc.
                                         * If result is 0 then current CPU is a tickless one.
                                         */
-                                       g_itv = get_per_cpu_interval(scc, scp);
+                                       deltot_jiffies = get_per_cpu_interval(scc, scp);
                                        cpu_offline = FALSE;
                                }
 
-                               if (!g_itv) {   /* Current CPU is offline or tickless */
+                               if (!deltot_jiffies) {  /* Current CPU is offline or tickless */
 
                                        val = (cpu_offline ? 0.0        /* Offline CPU: %idle = 0% */
                                                           : 100.0);    /* Tickless CPU: %idle = 100% */
@@ -1108,7 +1126,7 @@ __print_funct_t svg_print_cpu_stats(struct activity *a, int curr, int action, st
                        if (DISPLAY_CPU_DEF(a->opt_flags)) {
                                /* %user */
                                cpuappend(record_hdr->ust_time - svg_p->ust_time_ref,
-                                         &offset, ll_sp_value(scp->cpu_user, scc->cpu_user, g_itv),
+                                         &offset, ll_sp_value(scp->cpu_user, scc->cpu_user, deltot_jiffies),
                                          out + pos, outsize + pos, svg_p->dt,
                                          spmin + pos, spmax + pos);
                        }
@@ -1119,7 +1137,7 @@ __print_funct_t svg_print_cpu_stats(struct activity *a, int curr, int action, st
                                          (scc->cpu_user - scc->cpu_guest) < (scp->cpu_user - scp->cpu_guest) ?
                                           0.0 :
                                           ll_sp_value(scp->cpu_user - scp->cpu_guest,
-                                                      scc->cpu_user - scc->cpu_guest, g_itv),
+                                                      scc->cpu_user - scc->cpu_guest, deltot_jiffies),
                                          out + pos, outsize + pos, svg_p->dt,
                                          spmin + pos, spmax + pos);
                        }
@@ -1127,7 +1145,7 @@ __print_funct_t svg_print_cpu_stats(struct activity *a, int curr, int action, st
                        if (DISPLAY_CPU_DEF(a->opt_flags)) {
                                /* %nice */
                                cpuappend(record_hdr->ust_time - svg_p->ust_time_ref,
-                                         &offset, ll_sp_value(scp->cpu_nice, scc->cpu_nice, g_itv),
+                                         &offset, ll_sp_value(scp->cpu_nice, scc->cpu_nice, deltot_jiffies),
                                          out + pos + 1, outsize + pos + 1, svg_p->dt,
                                          spmin + pos + 1, spmax + pos + 1);
                        }
@@ -1138,7 +1156,7 @@ __print_funct_t svg_print_cpu_stats(struct activity *a, int curr, int action, st
                                          (scc->cpu_nice - scc->cpu_guest_nice) < (scp->cpu_nice - scp->cpu_guest_nice) ?
                                           0.0 :
                                           ll_sp_value(scp->cpu_nice - scp->cpu_guest_nice,
-                                                      scc->cpu_nice - scc->cpu_guest_nice, g_itv),
+                                                      scc->cpu_nice - scc->cpu_guest_nice, deltot_jiffies),
                                          out + pos + 1, outsize + pos + 1, svg_p->dt,
                                          spmin + pos + 1, spmax + pos + 1);
                        }
@@ -1149,48 +1167,48 @@ __print_funct_t svg_print_cpu_stats(struct activity *a, int curr, int action, st
                                          &offset,
                                          ll_sp_value(scp->cpu_sys + scp->cpu_hardirq + scp->cpu_softirq,
                                                      scc->cpu_sys + scc->cpu_hardirq + scc->cpu_softirq,
-                                                     g_itv),
+                                                     deltot_jiffies),
                                          out + pos + 2, outsize + pos + 2, svg_p->dt,
                                          spmin + pos + 2, spmax + pos + 2);
                        }
                        else {
                                /* %sys */
                                cpuappend(record_hdr->ust_time - svg_p->ust_time_ref,
-                                         &offset, ll_sp_value(scp->cpu_sys, scc->cpu_sys, g_itv),
+                                         &offset, ll_sp_value(scp->cpu_sys, scc->cpu_sys, deltot_jiffies),
                                          out + pos + 2, outsize + pos + 2, svg_p->dt,
                                          spmin + pos + 2, spmax + pos + 2);
                        }
 
                        /* %iowait */
                        cpuappend(record_hdr->ust_time - svg_p->ust_time_ref,
-                                 &offset, ll_sp_value(scp->cpu_iowait, scc->cpu_iowait, g_itv),
+                                 &offset, ll_sp_value(scp->cpu_iowait, scc->cpu_iowait, deltot_jiffies),
                                  out + pos + 3, outsize + pos + 3, svg_p->dt,
                                  spmin + pos + 3, spmax + pos + 3);
                        /* %steal */
                        cpuappend(record_hdr->ust_time - svg_p->ust_time_ref,
-                                 &offset, ll_sp_value(scp->cpu_steal, scc->cpu_steal, g_itv),
+                                 &offset, ll_sp_value(scp->cpu_steal, scc->cpu_steal, deltot_jiffies),
                                  out + pos + 4, outsize + pos + 4, svg_p->dt,
                                  spmin + pos + 4, spmax + pos + 4);
 
                        if (DISPLAY_CPU_ALL(a->opt_flags)) {
                                /* %irq */
                                cpuappend(record_hdr->ust_time - svg_p->ust_time_ref,
-                                         &offset, ll_sp_value(scp->cpu_hardirq, scc->cpu_hardirq, g_itv),
+                                         &offset, ll_sp_value(scp->cpu_hardirq, scc->cpu_hardirq, deltot_jiffies),
                                          out + pos + 5, outsize + pos + 5, svg_p->dt,
                                          spmin + pos + 5, spmax + pos + 5);
                                /* %soft */
                                cpuappend(record_hdr->ust_time - svg_p->ust_time_ref,
-                                         &offset, ll_sp_value(scp->cpu_softirq, scc->cpu_softirq, g_itv),
+                                         &offset, ll_sp_value(scp->cpu_softirq, scc->cpu_softirq, deltot_jiffies),
                                          out + pos + 6, outsize + pos + 6, svg_p->dt,
                                          spmin + pos + 6, spmax + pos + 6);
                                /* %guest */
                                cpuappend(record_hdr->ust_time - svg_p->ust_time_ref,
-                                         &offset, ll_sp_value(scp->cpu_guest, scc->cpu_guest, g_itv),
+                                         &offset, ll_sp_value(scp->cpu_guest, scc->cpu_guest, deltot_jiffies),
                                          out + pos + 7, outsize + pos + 7, svg_p->dt,
                                          spmin + pos + 7, spmax + pos + 7);
                                /* %gnice */
                                cpuappend(record_hdr->ust_time - svg_p->ust_time_ref,
-                                         &offset, ll_sp_value(scp->cpu_guest_nice, scc->cpu_guest_nice, g_itv),
+                                         &offset, ll_sp_value(scp->cpu_guest_nice, scc->cpu_guest_nice, deltot_jiffies),
                                          out + pos + 8, outsize + pos + 8, svg_p->dt,
                                          spmin + pos + 8, spmax + pos + 8);
 
@@ -1204,7 +1222,7 @@ __print_funct_t svg_print_cpu_stats(struct activity *a, int curr, int action, st
                        cpuappend(record_hdr->ust_time - svg_p->ust_time_ref,
                                  &offset,
                                  (scc->cpu_idle < scp->cpu_idle ? 0.0 :
-                                  ll_sp_value(scp->cpu_idle, scc->cpu_idle, g_itv)),
+                                  ll_sp_value(scp->cpu_idle, scc->cpu_idle, deltot_jiffies)),
                                  out + pos + j, outsize + pos + j, svg_p->dt,
                                  spmin + pos + j, spmax + pos + j);
                }
index 97fd2586f887aefaaa9c790eb4dce4bf0245995b..b5e06c3714dafa5d52af09a5e1cb3b0af09c1bd8 100644 (file)
@@ -101,14 +101,16 @@ void xml_markup_power_management(int tab, int action)
  * @a          Activity structure with statistics.
  * @curr       Index in array for current sample statistics.
  * @tab                Indentation in XML output.
- * @g_itv      Interval of time in jiffies mutliplied by the number of
- *             processors.
+ * @itv                Interval of time in jiffies (independent of the number of
+ *             processors). Unused here.
  ***************************************************************************
  */
 __print_funct_t xml_print_cpu_stats(struct activity *a, int curr, int tab,
-                                   unsigned long long g_itv)
+                                   unsigned long long itv)
 {
        int i, cpu_offline;
+       unsigned long long tot_jiffies[3];
+       unsigned long long deltot_jiffies;
        struct stats_cpu *scc, *scp;
        char cpuno[8];
 
@@ -124,7 +126,23 @@ __print_funct_t xml_print_cpu_stats(struct activity *a, int curr, int tab,
                        /* No */
                        continue;
 
-               /* Yes: Display it */
+               /*
+                * Yes: Compute the total number of jiffies spent by current processor.
+                * NB: Don't add cpu_guest/cpu_guest_nice because cpu_user/cpu_nice
+                * already include them.
+                */
+               tot_jiffies[curr] = scc->cpu_user + scc->cpu_nice +
+                                   scc->cpu_sys + scc->cpu_idle +
+                                   scc->cpu_iowait + scc->cpu_hardirq +
+                                   scc->cpu_steal + scc->cpu_softirq;
+               tot_jiffies[!curr] = scp->cpu_user + scp->cpu_nice +
+                                    scp->cpu_sys + scp->cpu_idle +
+                                    scp->cpu_iowait + scp->cpu_hardirq +
+                                    scp->cpu_steal + scp->cpu_softirq;
+
+               /* Total number of jiffies spent on the interval */
+               deltot_jiffies = get_interval(tot_jiffies[!curr], tot_jiffies[curr]);
+
                if (!i) {
                        /* This is CPU "all" */
                        strcpy(cpuno, "all");
@@ -138,9 +156,7 @@ __print_funct_t xml_print_cpu_stats(struct activity *a, int curr, int tab,
                         * (Remember that guest/guest_nice times are already included in
                         * user/nice modes.)
                         */
-                       if ((scc->cpu_user + scc->cpu_nice + scc->cpu_sys +
-                            scc->cpu_iowait + scc->cpu_idle + scc->cpu_steal +
-                            scc->cpu_hardirq + scc->cpu_softirq) == 0) {
+                       if (tot_jiffies[curr] == 0) {
                                /*
                                 * Set current struct fields (which have been set to zero)
                                 * to values from previous iteration. Hence their values won't
@@ -148,7 +164,7 @@ __print_funct_t xml_print_cpu_stats(struct activity *a, int curr, int tab,
                                 */
                                *scc = *scp;
 
-                               g_itv = 0;
+                               deltot_jiffies = 0;
                                cpu_offline = TRUE;
                        }
                        else {
@@ -156,11 +172,11 @@ __print_funct_t xml_print_cpu_stats(struct activity *a, int curr, int tab,
                                 * Recalculate interval for current proc.
                                 * If result is 0 then current CPU is a tickless one.
                                 */
-                               g_itv = get_per_cpu_interval(scc, scp);
+                               deltot_jiffies = get_per_cpu_interval(scc, scp);
                                cpu_offline = FALSE;
                        }
 
-                       if (!g_itv) {
+                       if (!deltot_jiffies) {
                                /* Current CPU is offline or tickless */
                                if (DISPLAY_CPU_DEF(a->opt_flags)) {
                                        xprintf(tab, "<cpu number=\"%d\" "
@@ -202,16 +218,16 @@ __print_funct_t xml_print_cpu_stats(struct activity *a, int curr, int tab,
                                "steal=\"%.2f\" "
                                "idle=\"%.2f\"/>",
                                cpuno,
-                               ll_sp_value(scp->cpu_user,   scc->cpu_user,   g_itv),
-                               ll_sp_value(scp->cpu_nice,   scc->cpu_nice,   g_itv),
+                               ll_sp_value(scp->cpu_user, scc->cpu_user, deltot_jiffies),
+                               ll_sp_value(scp->cpu_nice, scc->cpu_nice, deltot_jiffies),
                                ll_sp_value(scp->cpu_sys + scp->cpu_hardirq + scp->cpu_softirq,
                                            scc->cpu_sys + scc->cpu_hardirq + scc->cpu_softirq,
-                                           g_itv),
-                               ll_sp_value(scp->cpu_iowait, scc->cpu_iowait, g_itv),
-                               ll_sp_value(scp->cpu_steal,  scc->cpu_steal,  g_itv),
+                                           deltot_jiffies),
+                               ll_sp_value(scp->cpu_iowait, scc->cpu_iowait, deltot_jiffies),
+                               ll_sp_value(scp->cpu_steal,  scc->cpu_steal, deltot_jiffies),
                                scc->cpu_idle < scp->cpu_idle ?
                                0.0 :
-                               ll_sp_value(scp->cpu_idle,   scc->cpu_idle,   g_itv));
+                               ll_sp_value(scp->cpu_idle, scc->cpu_idle, deltot_jiffies));
                }
                else if (DISPLAY_CPU_ALL(a->opt_flags)) {
                        xprintf(tab, "<cpu number=\"%s\" "
@@ -229,21 +245,21 @@ __print_funct_t xml_print_cpu_stats(struct activity *a, int curr, int tab,
                                (scc->cpu_user - scc->cpu_guest) < (scp->cpu_user - scp->cpu_guest) ?
                                0.0 :
                                ll_sp_value(scp->cpu_user - scp->cpu_guest,
-                                           scc->cpu_user - scc->cpu_guest, g_itv),
+                                           scc->cpu_user - scc->cpu_guest, deltot_jiffies),
                                (scc->cpu_nice - scc->cpu_guest_nice) < (scp->cpu_nice - scp->cpu_guest_nice) ?
                                0.0 :
                                ll_sp_value(scp->cpu_nice - scp->cpu_guest_nice,
-                                           scc->cpu_nice - scc->cpu_guest_nice, g_itv),
-                               ll_sp_value(scp->cpu_sys, scc->cpu_sys, g_itv),
-                               ll_sp_value(scp->cpu_iowait, scc->cpu_iowait, g_itv),
-                               ll_sp_value(scp->cpu_steal, scc->cpu_steal, g_itv),
-                               ll_sp_value(scp->cpu_hardirq, scc->cpu_hardirq, g_itv),
-                               ll_sp_value(scp->cpu_softirq, scc->cpu_softirq, g_itv),
-                               ll_sp_value(scp->cpu_guest, scc->cpu_guest, g_itv),
-                               ll_sp_value(scp->cpu_guest_nice, scc->cpu_guest_nice, g_itv),
+                                           scc->cpu_nice - scc->cpu_guest_nice, deltot_jiffies),
+                               ll_sp_value(scp->cpu_sys, scc->cpu_sys, deltot_jiffies),
+                               ll_sp_value(scp->cpu_iowait, scc->cpu_iowait, deltot_jiffies),
+                               ll_sp_value(scp->cpu_steal, scc->cpu_steal, deltot_jiffies),
+                               ll_sp_value(scp->cpu_hardirq, scc->cpu_hardirq, deltot_jiffies),
+                               ll_sp_value(scp->cpu_softirq, scc->cpu_softirq, deltot_jiffies),
+                               ll_sp_value(scp->cpu_guest, scc->cpu_guest, deltot_jiffies),
+                               ll_sp_value(scp->cpu_guest_nice, scc->cpu_guest_nice, deltot_jiffies),
                                scc->cpu_idle < scp->cpu_idle ?
                                0.0 :
-                               ll_sp_value(scp->cpu_idle, scc->cpu_idle, g_itv));
+                               ll_sp_value(scp->cpu_idle, scc->cpu_idle, deltot_jiffies));
                }
        }