]> granicus.if.org Git - sysstat/commitdiff
sar: Fix code trying to guess when a header line needs to be displayed
authorSebastien GODARD <sysstat@users.noreply.github.com>
Sun, 31 Dec 2017 14:35:00 +0000 (15:35 +0100)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Sun, 31 Dec 2017 14:35:00 +0000 (15:35 +0100)
sar should repeat the header line for each activity at regular intervals
when displaying stats from file.
The code previously used needs to be updated as the number of items may
now vary with each sample.

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

diff --git a/sar.c b/sar.c
index 2d6e4eda3d877bdb2e528d04969ecb84494bf521..36f7ce71790b12a9294737093db8e5b4142c05f2 100644 (file)
--- a/sar.c
+++ b/sar.c
@@ -733,7 +733,7 @@ void handle_curr_act_stats(int ifd, off_t fpos, int *curr, long *cnt, int *eosaf
        int p, reset_cd;
        unsigned long lines = 0;
        unsigned char rtype;
-       int davg = 0, next, inc;
+       int davg = 0, next, inc = 0;
 
        if (lseek(ifd, fpos, SEEK_SET) < fpos) {
                perror("lseek");
@@ -748,16 +748,12 @@ void handle_curr_act_stats(int ifd, off_t fpos, int *curr, long *cnt, int *eosaf
 
        *cnt  = count;
 
-       /* Assess number of lines printed */
+       /* Assess number of lines printed when a bitmap is used */
        p = get_activity_position(act, act_id, EXIT_IF_NOT_FOUND);
        if (act[p]->bitmap) {
                inc = count_bits(act[p]->bitmap->b_array,
                                 BITMAP_SIZE(act[p]->bitmap->b_size));
        }
-       else {
-               inc = act[p]->nr[*curr];
-       }
-
        reset_cd = 1;
 
        do {
@@ -805,10 +801,17 @@ void handle_curr_act_stats(int ifd, off_t fpos, int *curr, long *cnt, int *eosaf
                        if (next && (*cnt > 0)) {
                                (*cnt)--;
                        }
+
                        if (next) {
                                davg++;
-                               *curr ^=1;
-                               lines += inc;
+                               *curr ^= 1;
+
+                               if (inc) {
+                                       lines += inc;
+                               }
+                               else {
+                                       lines += act[p]->nr[*curr];
+                               }
                        }
                        *reset = FALSE;
                }