From 372339579ff08e92610303c3b96276f65faa5f51 Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Sat, 1 Feb 2014 21:42:51 +0100 Subject: [PATCH] sar: Take into account a change of CPU number in sar datafile (3) Update sar so that it now reads the number of CPU associated with a RESTART record. Reallocate CPU structures accordingly, and display the number of CPU with the restart mark. Signed-off-by: Sebastien GODARD --- sa.h | 2 ++ sa_common.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- sar.c | 7 ++++++- 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/sa.h b/sa.h index f760a82..df59374 100644 --- a/sa.h +++ b/sa.h @@ -851,6 +851,8 @@ extern void print_report_hdr(unsigned int, struct tm *, struct file_header *, int); extern void read_file_stat_bunch(struct activity * [], int, int, int, struct file_activity *); +extern unsigned int + read_new_cpu_nr(int, struct activity * []); extern int sa_fread(int, void *, int, int); extern void diff --git a/sa_common.c b/sa_common.c index 52cb3c2..f0338e8 100644 --- a/sa_common.c +++ b/sa_common.c @@ -1177,9 +1177,18 @@ void check_file_actlst(int *ifd, char *dfile, struct activity *act[], if (fal->size > act[p]->msize) { act[p]->msize = fal->size; } - act[p]->fsize = fal->size; + /* + * NOTA BENE: + * If current activity is A_CPU, we are setting + * act[p]->nr to fal->nr, which is the number of CPU for the + * statistics located between the start of the data file and the + * first restart mark. Remember that the number of CPU can vary + * in file. In this case, a RESTART record is followed by the + * new number of CPU. + */ act[p]->nr = fal->nr; act[p]->nr2 = fal->nr2; + act[p]->fsize = fal->size; /* * This is a known activity with a known format * (magical number). Only such activities will be displayed. @@ -1225,6 +1234,45 @@ void check_file_actlst(int *ifd, char *dfile, struct activity *act[], } } +/* + *************************************************************************** + * Read the new CPU count following a RESTART record. Then set corresponding + * number of items for A_CPU activity and reallocate structures. + * + * IN: + * @ifd Input file descriptor. + * @act Array of activities. + * + * RETURNS: + * New number of CPU count. + *************************************************************************** + */ +unsigned int read_new_cpu_nr(int ifd, struct activity *act[]) +{ + unsigned int new_cpu_nr; + int j, p; + + /* Read new number of CPU following the RESTART record */ + sa_fread(ifd, &new_cpu_nr, sizeof(unsigned int), HARD_SIZE); + + if (!new_cpu_nr) { + /* CPU number cannot be zero */ + fprintf(stderr, _("Bad CPU count saved in file\n")); + close(ifd); + exit(2); + } + + /* Set new CPU count and reallocate structures */ + p = get_activity_position(act, A_CPU); + act[p]->nr = new_cpu_nr; + + for (j = 0; j < 3; j++) { + SREALLOC(act[p]->buf[j], void, act[p]->msize * act[p]->nr * act[p]->nr2); + } + + return new_cpu_nr; +} + /* *************************************************************************** * Parse sar activities options (also used by sadf). diff --git a/sar.c b/sar.c index 92c2229..db7509b 100644 --- a/sar.c +++ b/sar.c @@ -617,6 +617,7 @@ int sar_print_special(int curr, int use_tm_start, int use_tm_end, int rtype, int { char cur_time[26]; int dp = 1; + unsigned int new_cpu_nr; if (set_record_timestamp_string(curr, cur_time, 26)) return 0; @@ -628,8 +629,12 @@ int sar_print_special(int curr, int use_tm_start, int use_tm_end, int rtype, int } if (rtype == R_RESTART) { + /* Don't forget to read new number of CPU */ + new_cpu_nr = read_new_cpu_nr(ifd, act); + if (dp) { - printf("\n%-11s LINUX RESTART\n", cur_time); + printf("\n%-11s LINUX RESTART\t(%d CPU)\n", + cur_time, new_cpu_nr > 1 ? new_cpu_nr - 1 : 1); return 1; } } -- 2.40.0