]> granicus.if.org Git - sysstat/commitdiff
sar/sadc: Don't assume CPU statistics are always recorded in file
authorSebastien GODARD <sysstat@users.noreply.github.com>
Fri, 17 Nov 2017 08:33:50 +0000 (09:33 +0100)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Fri, 17 Nov 2017 08:33:50 +0000 (09:33 +0100)
CPU statistics were always collected and saved when a saDD datafile was
created. Those statistics were in particular used to compute time
interval in jiffies, and to give the number of processors of the machine
(which was displayed in the report header).

We no longer use CPU jiffies to compute time interval (which is now
expressed in 1/100th of a second and calculated using the /proc/uptime
file). So CPU statistics are no longer compulsory: They may not be
collected and available in file.
Since we always need a way to know the number of CPU of the machine
where the data file has been created, we add a new field (sa_cpu_nr) in
the file_header structure.

Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
sa.h
sa_common.c
sadc.c
sadf.c
sadf.h
sadf_misc.c
sar.c

diff --git a/sa.h b/sa.h
index 971462bb0c15ed812dedd2475849cda570153749..44d4b7252e14d7ff90dc1e78165aa35e992398a1 100644 (file)
--- a/sa.h
+++ b/sa.h
@@ -434,6 +434,13 @@ struct file_header {
         * Number of CPU items (1 .. CPU_NR + 1) for the last sample in file.
         */
        unsigned int sa_last_cpu_nr     __attribute__ ((aligned (8)));
+       /*
+        * Number of [online or offline] CPU (1 .. CPU_NR + 1)
+        * when the datafile has been created.
+        * When reading a datafile, this value is updated whenever
+        * a RESTART record is found.
+        */
+       unsigned int sa_cpu_nr;
        /*
         * Number of activities saved in file.
         */
@@ -491,7 +498,7 @@ struct file_header {
 #define FILE_HEADER_SIZE       (sizeof(struct file_header))
 #define FILE_HEADER_ULL_NR     1       /* Nr of unsigned long long in file_header structure */
 #define FILE_HEADER_UL_NR      1       /* Nr of unsigned long in file_header structure */
-#define FILE_HEADER_U_NR       12      /* Nr of [unsigned] int in file_header structure */
+#define FILE_HEADER_U_NR       13      /* Nr of [unsigned] int in file_header structure */
 /* The values below are used for sanity check */
 #define MIN_FILE_HEADER_SIZE   0
 #define MAX_FILE_HEADER_SIZE   8192
@@ -919,7 +926,7 @@ struct report_format {
         * (data displayed once at the beginning of the report).
         */
        __printf_funct_t (*f_header) (void *, int, char *, struct file_magic *, struct file_header *,
-                                     __nr_t, struct activity * [], unsigned int []);
+                                     struct activity * [], unsigned int []);
        /*
         * This function defines the statistics part of the report.
         * Used only with textual (XML-like) reports.
@@ -934,8 +941,7 @@ struct report_format {
        /*
         * This function displays the restart messages.
         */
-       __printf_funct_t (*f_restart) (int *, int, char *, char *, int, struct file_header *,
-                                      unsigned int);
+       __printf_funct_t (*f_restart) (int *, int, char *, char *, int, struct file_header *);
        /*
         * This function displays the comments.
         */
@@ -1221,11 +1227,11 @@ int parse_sar_n_opt
 int parse_timestamp
        (char * [], int *, struct tstamp *, const char *);
 void print_report_hdr
-       (unsigned int, struct tm *, struct file_header *, int);
+       (unsigned int, struct tm *, struct file_header *);
 void print_sar_comment
        (int *, int, char *, char *, int, char *, struct file_header *);
-void print_sar_restart
-       (int *, int, char *, char *, int, struct file_header *, unsigned int);
+__printf_funct_t print_sar_restart
+       (int *, int, char *, char *, int, struct file_header *);
 int print_special_record
        (struct record_header *, unsigned int, struct tstamp *, struct tstamp *,
         int, int, struct tm *, struct tm *, char *, int, struct file_magic *,
index 69ad81c06fb68d19ab81c91866d26a8cfe2927e2..4e30f28784d901f5e26651823fa4167d71599985 100644 (file)
@@ -566,26 +566,27 @@ void get_file_timestamp_struct(unsigned int flags, struct tm *rectime,
  * IN:
  * @flags      Flags for common options and system state.
  * @file_hdr   System activity file standard header.
- * @cpu_nr     Number of CPU (value in [1, NR_CPUS + 1]).
- *             1 means that there is only one proc and non SMP kernel.
- *             2 means one proc and SMP kernel.
- *             Etc.
  *
  * OUT:
  * @rectime    Date and time from file header.
  ***************************************************************************
  */
 void print_report_hdr(unsigned int flags, struct tm *rectime,
-                     struct file_header *file_hdr, int cpu_nr)
+                     struct file_header *file_hdr)
 {
 
        /* Get date of file creation */
        get_file_timestamp_struct(flags, rectime, file_hdr);
 
-       /* Display the header */
+       /*
+        * Display the header.
+        * NB: Number of CPU (value in [1, NR_CPUS + 1]).
+        *      1 means that there is only one proc and non SMP kernel.
+        *      2 means one proc and SMP kernel. Etc.
+        */
        print_gal_header(rectime, file_hdr->sa_sysname, file_hdr->sa_release,
                         file_hdr->sa_nodename, file_hdr->sa_machine,
-                        cpu_nr > 1 ? cpu_nr - 1 : 1,
+                        file_hdr->sa_cpu_nr > 1 ? file_hdr->sa_cpu_nr - 1 : 1,
                         PLAIN_OUTPUT);
 }
 
@@ -956,8 +957,8 @@ void select_default_activity(struct activity *act[])
        /* Default is CPU activity... */
        if (!get_activity_nr(act, AO_SELECTED, COUNT_ACTIVITIES)) {
                /*
-                * Still OK even when reading stats from a file
-                * since A_CPU activity is always recorded.
+                * Yet A_CPU activity may not be available in file
+                * since the user can choose not to collect it.
                 */
                act[p]->options |= AO_SELECTED;
        }
@@ -1458,7 +1459,6 @@ void check_file_actlst(int *ifd, char *dfile, struct activity *act[],
                       int ignore, int *endian_mismatch, int *arch_64)
 {
        int i, j, k, p;
-       unsigned int a_cpu = FALSE;
        struct file_activity *fal;
        void *buffer = NULL;
 
@@ -1587,10 +1587,6 @@ void check_file_actlst(int *ifd, char *dfile, struct activity *act[],
                        act[p]->ftypes_nr[k] = fal->types_nr[k];
                }
 
-               if (fal->id == A_CPU) {
-                       a_cpu = TRUE;
-               }
-
                if (fal->size > act[p]->msize) {
                        act[p]->msize = fal->size;
                }
@@ -1615,13 +1611,6 @@ void check_file_actlst(int *ifd, char *dfile, struct activity *act[],
                id_seq[j++] = fal->id;
        }
 
-       if (!a_cpu)
-               /*
-                * CPU activity should always be in file
-                * and have a known format (expected magical number).
-                */
-               goto format_error;
-
        while (j < NR_ACT) {
                id_seq[j++] = 0;
        }
@@ -2451,7 +2440,6 @@ int print_special_record(struct record_header *record_hdr, unsigned int l_flags,
 {
        char cur_date[TIMESTAMP_LEN], cur_time[TIMESTAMP_LEN];
        int dp = 1;
-       unsigned int new_cpu_nr;
 
        /* Fill timestamp structure (rectime) for current record */
        if (sa_get_record_timestamp_struct(l_flags, record_hdr, rectime, loctime))
@@ -2475,10 +2463,10 @@ int print_special_record(struct record_header *record_hdr, unsigned int l_flags,
        }
 
        if (rtype == R_RESTART) {
-               /* Don't forget to read the volatile activities structures */
-               new_cpu_nr = read_vol_act_structures(ifd, act, file, file_magic,
-                                                    file_hdr->sa_vol_act_nr,
-                                                    endian_mismatch, arch_64);
+               /* Read new cpu number following RESTART record */
+               file_hdr->sa_cpu_nr = read_vol_act_structures(ifd, act, file, file_magic,
+                                                             file_hdr->sa_vol_act_nr,
+                                                             endian_mismatch, arch_64);
 
                if (!dp)
                        return 0;
@@ -2486,8 +2474,7 @@ int print_special_record(struct record_header *record_hdr, unsigned int l_flags,
                if (*ofmt->f_restart) {
                        (*ofmt->f_restart)(&tab, F_MAIN, cur_date, cur_time,
                                           !PRINT_LOCAL_TIME(l_flags) &&
-                                          !PRINT_TRUE_TIME(l_flags), file_hdr,
-                                          new_cpu_nr);
+                                          !PRINT_TRUE_TIME(l_flags), file_hdr);
                }
        }
        else if (rtype == R_COMMENT) {
diff --git a/sadc.c b/sadc.c
index 9cabc0dc951733a13db8f19911ef4aa75c7f39b3..f4f5893227951b741b100c83628354d7de6878c3 100644 (file)
--- a/sadc.c
+++ b/sadc.c
@@ -185,7 +185,7 @@ void parse_sadc_S_option(char *argv[], int opt)
                        /*
                         * Although undocumented, option -S followed by a numerical value
                         * enables the user to select each activity that should be
-                        * collected. "-S 0" unselects all activities but CPU.
+                        * collected. "-S 0" unselects all activities.
                         * A value greater than 255 enables the user to select groups
                         * of activities.
                         */
@@ -204,11 +204,10 @@ void parse_sadc_S_option(char *argv[], int opt)
                                usage(argv[0]);
                        }
                        else if (!act_id) {
-                               /* Unselect all activities but CPU */
+                               /* Unselect all activities */
                                for (i = 0; i < NR_ACT; i++) {
                                        act[i]->options &= ~AO_COLLECTED;
                                }
-                               COLLECT_ACTIVITY(A_CPU);
                        }
                        else {
                                /* Select chosen activity */
@@ -530,6 +529,14 @@ void setup_file_hdr(int fd)
         * always counted (in sa_sys_init()).
         */
        file_hdr.sa_last_cpu_nr = act[get_activity_position(act, A_CPU, EXIT_IF_NOT_FOUND)]->nr;
+       /*
+        * This is a new file (or stdout): Set sa_cpu_nr field to the number
+        * of CPU of the machine (1 .. CPU_NR + 1). This is the number of CPU, whether
+        * online or offline, at the time of the first collected sample.
+        * All activities (including A_CPU) are counted in sa_sys_init(), even
+        * if they are not collected.
+        */
+       file_hdr.sa_cpu_nr = act[get_activity_position(act, A_CPU, EXIT_IF_NOT_FOUND)]->nr;
 
        /* Get system name, release number, hostname and machine architecture */
        uname(&header);
@@ -1018,10 +1025,9 @@ void open_ofile(int *ofd, char ofile[], int restart_mark)
        }
 
        p = get_activity_position(act, A_CPU, EXIT_IF_NOT_FOUND);
-       if (!IS_COLLECTED(act[p]->options)) {
-               /* A_CPU activity should always exist in file */
-               goto append_error;
-       }
+       if (!IS_COLLECTED(act[p]->options))
+               /* A_CPU activity may not exist in file */
+               return;
 
        if (act[p]->nr != file_hdr.sa_last_cpu_nr) {
                if (restart_mark) {
@@ -1335,6 +1341,11 @@ int main(int argc, char **argv)
                }
        }
 
+       /* At least one activity must be collected (default is A_CPU) */
+       if (!get_activity_nr(act, AO_COLLECTED, COUNT_ACTIVITIES)) {
+               COLLECT_ACTIVITY(A_CPU);
+       }
+
        /* Process file entered on the command line */
        if (WANT_SA_ROTAT(flags)) {
                /* File name set to '-' */
diff --git a/sadf.c b/sadf.c
index fb32e2c9d4da07b02a893c84f0994b7408ae90ae..7e1d6e208d6ac58f1660462f7cdfb1529fc0fb03 100644 (file)
--- a/sadf.c
+++ b/sadf.c
@@ -957,7 +957,6 @@ void display_curr_act_graphs(int ifd, off_t fpos, int *curr, long *cnt, int *eos
  * @file_actlst        List of (known or unknown) activities in file.
  * @file       System activity data file name (name of file being read).
  * @file_magic System activity file magic header.
- * @cpu_nr     Number of processors for current activity data file.
  * @rectime    Structure where timestamp (expressed in local time or in UTC
  *             depending on whether options -T/-t have been used or not) can
  *             be saved for current record.
@@ -966,7 +965,7 @@ void display_curr_act_graphs(int ifd, off_t fpos, int *curr, long *cnt, int *eos
  ***************************************************************************
  */
 void logic1_display_loop(int ifd, struct file_activity *file_actlst, char *file,
-                        struct file_magic *file_magic, __nr_t cpu_nr,
+                        struct file_magic *file_magic,
                         struct tm *rectime, struct tm *loctime)
 {
        int curr, tab = 0, rtype;
@@ -991,7 +990,7 @@ void logic1_display_loop(int ifd, struct file_activity *file_actlst, char *file,
        /* Print header (eg. XML file header) */
        if (*fmt[f_position]->f_header) {
                (*fmt[f_position]->f_header)(&tab, F_BEGIN, file, file_magic,
-                                            &file_hdr, cpu_nr, act, id_seq);
+                                            &file_hdr, act, id_seq);
        }
 
        /* Process activities */
@@ -1079,7 +1078,7 @@ void logic1_display_loop(int ifd, struct file_activity *file_actlst, char *file,
        /* Process now RESTART entries to display restart messages */
        if (*fmt[f_position]->f_restart) {
                (*fmt[f_position]->f_restart)(&tab, F_BEGIN, NULL, NULL, FALSE,
-                                             &file_hdr, 0);
+                                             &file_hdr);
        }
 
        do {
@@ -1090,7 +1089,7 @@ void logic1_display_loop(int ifd, struct file_activity *file_actlst, char *file,
        while (!eosaf);
 
        if (*fmt[f_position]->f_restart) {
-               (*fmt[f_position]->f_restart)(&tab, F_END, NULL, NULL, FALSE, &file_hdr, 0);
+               (*fmt[f_position]->f_restart)(&tab, F_END, NULL, NULL, FALSE, &file_hdr);
        }
 
        /* Rewind file... */
@@ -1126,7 +1125,7 @@ void logic1_display_loop(int ifd, struct file_activity *file_actlst, char *file,
        /* Print header trailer */
        if (*fmt[f_position]->f_header) {
                (*fmt[f_position]->f_header)(&tab, F_END, file, file_magic,
-                                            &file_hdr, cpu_nr, act, id_seq);
+                                            &file_hdr, act, id_seq);
        }
 }
 
@@ -1269,7 +1268,6 @@ void logic2_display_loop(int ifd, struct file_activity *file_actlst,
  * IN:
  * @ifd                File descriptor of input file.
  * @file_actlst        List of (known or unknown) activities in file.
- * @cpu_nr     Number of processors for current activity data file.
  * @rectime    Structure where timestamp (expressed in local time or in UTC
  *             depending on whether options -T/-t have been used or not) can
  *             be saved for current record.
@@ -1279,7 +1277,7 @@ void logic2_display_loop(int ifd, struct file_activity *file_actlst,
  * @file_magic file_magic structure filled with file magic header data.
  ***************************************************************************
  */
-void logic3_display_loop(int ifd, struct file_activity *file_actlst, __nr_t cpu_nr,
+void logic3_display_loop(int ifd, struct file_activity *file_actlst,
                         struct tm *rectime, struct tm *loctime, char *file,
                         struct file_magic *file_magic)
 {
@@ -1317,7 +1315,7 @@ void logic3_display_loop(int ifd, struct file_activity *file_actlst, __nr_t cpu_
        /* Print SVG header */
        if (*fmt[f_position]->f_header) {
                (*fmt[f_position]->f_header)(&parm, F_BEGIN + F_MAIN, file, file_magic,
-                                            &file_hdr, cpu_nr, act, id_seq);
+                                            &file_hdr, act, id_seq);
        }
 
        /*
@@ -1390,7 +1388,7 @@ close_svg:
        /* Print SVG trailer */
        if (*fmt[f_position]->f_header) {
                (*fmt[f_position]->f_header)(&parm, F_END, file, file_magic,
-                                            &file_hdr, cpu_nr, act, id_seq);
+                                            &file_hdr, act, id_seq);
        }
 }
 
@@ -1410,21 +1408,17 @@ void read_stats_from_file(char dfile[])
        struct file_activity *file_actlst = NULL;
        struct tm rectime, loctime;
        int ifd, ignore, tab = 0;
-       __nr_t cpu_nr;
 
        /* Prepare file for reading and read its headers */
        ignore = ACCEPT_BAD_FILE_FORMAT(fmt[f_position]->options);
        check_file_actlst(&ifd, dfile, act, &file_magic, &file_hdr,
                          &file_actlst, id_seq, ignore, &endian_mismatch, &arch_64);
 
-       /* Now pick up number of proc for this file */
-       cpu_nr = act[get_activity_position(act, A_CPU, EXIT_IF_NOT_FOUND)]->nr;
-
        if (DISPLAY_HDR_ONLY(flags)) {
                if (*fmt[f_position]->f_header) {
                        /* Display only data file header then exit */
                        (*fmt[f_position]->f_header)(&tab, F_BEGIN + F_END, dfile, &file_magic,
-                                                    &file_hdr, cpu_nr, act, id_seq);
+                                                    &file_hdr, act, id_seq);
                }
                exit(0);
        }
@@ -1434,7 +1428,7 @@ void read_stats_from_file(char dfile[])
 
        /* Call function corresponding to selected output format */
        if (format == F_SVG_OUTPUT) {
-               logic3_display_loop(ifd, file_actlst, cpu_nr,
+               logic3_display_loop(ifd, file_actlst,
                                    &rectime, &loctime, dfile, &file_magic);
        }
        else if (DISPLAY_GROUPED_STATS(fmt[f_position]->options)) {
@@ -1443,7 +1437,7 @@ void read_stats_from_file(char dfile[])
        }
        else {
                logic1_display_loop(ifd, file_actlst, dfile,
-                                   &file_magic, cpu_nr, &rectime, &loctime);
+                                   &file_magic, &rectime, &loctime);
        }
 
        close(ifd);
diff --git a/sadf.h b/sadf.h
index 0b5d17ea619b9f0f51353ed49179c44e931ccb26..cef63b6e768b48918e57ce7c116411eaa81a7871 100644 (file)
--- a/sadf.h
+++ b/sadf.h
@@ -130,17 +130,15 @@ void convert_file
  * Prototypes used to display restart messages
  */
 __printf_funct_t print_db_restart
-       (int *, int, char *, char *, int, struct file_header *, unsigned int);
+       (int *, int, char *, char *, int, struct file_header *);
 __printf_funct_t print_ppc_restart
-       (int *, int, char *, char *, int, struct file_header *, unsigned int);
+       (int *, int, char *, char *, int, struct file_header *);
 __printf_funct_t print_xml_restart
-       (int *, int, char *, char *, int, struct file_header *, unsigned int);
+       (int *, int, char *, char *, int, struct file_header *);
 __printf_funct_t print_json_restart
-       (int *, int, char *, char *, int, struct file_header *, unsigned int);
-__printf_funct_t print_sar_restart
-       (int *, int, char *, char *, int, struct file_header *, unsigned int);
+       (int *, int, char *, char *, int, struct file_header *);
 __printf_funct_t print_raw_restart
-       (int *, int, char *, char *, int, struct file_header *, unsigned int);
+       (int *, int, char *, char *, int, struct file_header *);
 
 /*
  * Prototypes used to display comments
@@ -185,15 +183,15 @@ __tm_funct_t print_raw_timestamp
  */
 __printf_funct_t print_xml_header
        (void *, int, char *, struct file_magic *, struct file_header *,
-        __nr_t, struct activity * [], unsigned int []);
+        struct activity * [], unsigned int []);
 __printf_funct_t print_json_header
        (void *, int, char *, struct file_magic *, struct file_header *,
-        __nr_t, struct activity * [], unsigned int []);
+        struct activity * [], unsigned int []);
 __printf_funct_t print_hdr_header
        (void *, int, char *, struct file_magic *, struct file_header *,
-        __nr_t, struct activity * [], unsigned int []);
+        struct activity * [], unsigned int []);
 __printf_funct_t print_svg_header
        (void *, int, char *, struct file_magic *, struct file_header *,
-        __nr_t, struct activity * [], unsigned int []);
+        struct activity * [], unsigned int []);
 
 #endif  /* _SADF_H */
index b1ec39577e513072cdbf1241aee7b3ae809d396d..d830fb77d9da3ecb4f836a51951f730c7f728df2 100644 (file)
@@ -46,11 +46,10 @@ extern char *seps[];
  * @utc                True if @cur_time is expressed in UTC.
  * @sep                Character used as separator.
  * @file_hdr   System activity file standard header.
- * @cpu_nr     CPU count associated with restart mark.
  ***************************************************************************
  */
 void print_dbppc_restart(char *cur_date, char *cur_time, int utc, char sep,
-                        struct file_header *file_hdr, unsigned int cpu_nr)
+                        struct file_header *file_hdr)
 {
        printf("%s%c-1%c", file_hdr->sa_nodename, sep, sep);
        if (strlen(cur_date)) {
@@ -61,7 +60,7 @@ void print_dbppc_restart(char *cur_date, char *cur_time, int utc, char sep,
                printf(" UTC");
        }
        printf("%cLINUX-RESTART\t(%d CPU)\n",
-              sep, cpu_nr > 1 ? cpu_nr - 1 : 1);
+              sep, file_hdr->sa_cpu_nr > 1 ? file_hdr->sa_cpu_nr - 1 : 1);
 }
 
 /*
@@ -75,16 +74,14 @@ void print_dbppc_restart(char *cur_date, char *cur_time, int utc, char sep,
  * @cur_time   Time string of current restart message.
  * @utc                True if @cur_time is expressed in UTC.
  * @file_hdr   System activity file standard header.
- * @cpu_nr     CPU count associated with restart mark.
  ***************************************************************************
  */
 __printf_funct_t print_db_restart(int *tab, int action, char *cur_date,
-                                 char *cur_time, int utc, struct file_header *file_hdr,
-                                 unsigned int cpu_nr)
+                                 char *cur_time, int utc, struct file_header *file_hdr)
 {
        /* Actions F_BEGIN and F_END ignored */
        if (action == F_MAIN) {
-               print_dbppc_restart(cur_date, cur_time, utc, ';', file_hdr, cpu_nr);
+               print_dbppc_restart(cur_date, cur_time, utc, ';', file_hdr);
        }
 }
 
@@ -99,16 +96,14 @@ __printf_funct_t print_db_restart(int *tab, int action, char *cur_date,
  * @cur_time   Time string of current restart message.
  * @utc                True if @cur_time is expressed in UTC.
  * @file_hdr   System activity file standard header.
- * @cpu_nr     CPU count associated with restart mark.
  ***************************************************************************
  */
 __printf_funct_t print_ppc_restart(int *tab, int action, char *cur_date,
-                                  char *cur_time, int utc, struct file_header *file_hdr,
-                                  unsigned int cpu_nr)
+                                  char *cur_time, int utc, struct file_header *file_hdr)
 {
        /* Actions F_BEGIN and F_END ignored */
        if (action == F_MAIN) {
-               print_dbppc_restart(cur_date, cur_time, utc, '\t', file_hdr, cpu_nr);
+               print_dbppc_restart(cur_date, cur_time, utc, '\t', file_hdr);
        }
 }
 
@@ -123,22 +118,21 @@ __printf_funct_t print_ppc_restart(int *tab, int action, char *cur_date,
  * @cur_time   Time string of current restart message.
  * @utc                True if @cur_time is expressed in UTC.
  * @file_hdr   System activity file standard header (unused here).
- * @cpu_nr     CPU count associated with restart mark.
  *
  * OUT:
  * @tab                Number of tabulations.
  ***************************************************************************
  */
 __printf_funct_t print_xml_restart(int *tab, int action, char *cur_date,
-                                  char *cur_time, int utc, struct file_header *file_hdr,
-                                  unsigned int cpu_nr)
+                                  char *cur_time, int utc, struct file_header *file_hdr)
 {
        if (action & F_BEGIN) {
                xprintf((*tab)++, "<restarts>");
        }
        if (action & F_MAIN) {
                xprintf(*tab, "<boot date=\"%s\" time=\"%s\" utc=\"%d\" cpu_count=\"%d\"/>",
-                       cur_date, cur_time, utc ? 1 : 0, cpu_nr > 1 ? cpu_nr - 1 : 1);
+                       cur_date, cur_time, utc ? 1 : 0,
+                       file_hdr->sa_cpu_nr > 1 ? file_hdr->sa_cpu_nr - 1 : 1);
        }
        if (action & F_END) {
                xprintf(--(*tab), "</restarts>");
@@ -156,15 +150,13 @@ __printf_funct_t print_xml_restart(int *tab, int action, char *cur_date,
  * @cur_time   Time string of current restart message.
  * @utc                True if @cur_time is expressed in UTC.
  * @file_hdr   System activity file standard header (unused here).
- * @cpu_nr     CPU count associated with restart mark.
  *
  * OUT:
  * @tab                Number of tabulations.
  ***************************************************************************
  */
 __printf_funct_t print_json_restart(int *tab, int action, char *cur_date,
-                                   char *cur_time, int utc, struct file_header *file_hdr,
-                                   unsigned int cpu_nr)
+                                   char *cur_time, int utc, struct file_header *file_hdr)
 {
        static int sep = FALSE;
 
@@ -178,7 +170,8 @@ __printf_funct_t print_json_restart(int *tab, int action, char *cur_date,
                }
                xprintf((*tab)++, "{");
                xprintf(*tab, "\"boot\": {\"date\": \"%s\", \"time\": \"%s\", \"utc\": %d, \"cpu_count\": %d}",
-                       cur_date, cur_time, utc ? 1 : 0, cpu_nr > 1 ? cpu_nr - 1 : 1);
+                       cur_date, cur_time, utc ? 1 : 0,
+                       file_hdr->sa_cpu_nr > 1 ? file_hdr->sa_cpu_nr - 1 : 1);
                xprintf0(--(*tab), "}");
                sep = TRUE;
        }
@@ -202,12 +195,10 @@ __printf_funct_t print_json_restart(int *tab, int action, char *cur_date,
  * @cur_time   Time string of current restart message.
  * @utc                True if @cur_time is expressed in UTC.
  * @file_hdr   System activity file standard header (unused here).
- * @cpu_nr     CPU count associated with restart mark.
  ***************************************************************************
  */
 __printf_funct_t print_raw_restart(int *tab, int action, char *cur_date,
-                                  char *cur_time, int utc, struct file_header *file_hdr,
-                                  unsigned int cpu_nr)
+                                  char *cur_time, int utc, struct file_header *file_hdr)
 {
        /* Actions F_BEGIN and F_END ignored */
        if (action == F_MAIN) {
@@ -215,7 +206,8 @@ __printf_funct_t print_raw_restart(int *tab, int action, char *cur_date,
                if (strlen(cur_date) && utc) {
                        printf(" UTC");
                }
-               printf("\tLINUX-RESTART\t(%d CPU)\n", cpu_nr > 1 ? cpu_nr - 1 : 1);
+               printf("\tLINUX-RESTART\t(%d CPU)\n",
+                      file_hdr->sa_cpu_nr > 1 ? file_hdr->sa_cpu_nr - 1 : 1);
        }
 }
 
@@ -688,7 +680,6 @@ __tm_funct_t print_raw_timestamp(void *parm, int action, char *cur_date,
  * @dfile      Name of system activity data file.
  * @file_magic System activity file magic header.
  * @file_hdr   System activity file standard header.
- * @cpu_nr     Number of processors for current daily data file.
  * @act                Array of activities (unused here).
  * @id_seq     Activity sequence (unused here).
  *
@@ -698,7 +689,7 @@ __tm_funct_t print_raw_timestamp(void *parm, int action, char *cur_date,
  */
 __printf_funct_t print_xml_header(void *parm, int action, char *dfile,
                                  struct file_magic *file_magic,
-                                 struct file_header *file_hdr, __nr_t cpu_nr,
+                                 struct file_header *file_hdr,
                                  struct activity *act[], unsigned int id_seq[])
 {
        struct tm rectime, *loc_t;
@@ -726,7 +717,7 @@ __printf_funct_t print_xml_header(void *parm, int action, char *dfile,
 
                xprintf(*tab, "<machine>%s</machine>", file_hdr->sa_machine);
                xprintf(*tab, "<number-of-cpus>%d</number-of-cpus>",
-                       cpu_nr > 1 ? cpu_nr - 1 : 1);
+                       file_hdr->sa_cpu_nr > 1 ? file_hdr->sa_cpu_nr - 1 : 1);
 
                /* Fill file timestmap structure (rectime) */
                get_file_timestamp_struct(flags, &rectime, file_hdr);
@@ -755,7 +746,6 @@ __printf_funct_t print_xml_header(void *parm, int action, char *dfile,
  * @dfile      Name of system activity data file.
  * @file_magic System activity file magic header.
  * @file_hdr   System activity file standard header.
- * @cpu_nr     Number of processors for current daily data file.
  * @act                Array of activities (unused here).
  * @id_seq     Activity sequence (unused here).
  *
@@ -765,7 +755,7 @@ __printf_funct_t print_xml_header(void *parm, int action, char *dfile,
  */
 __printf_funct_t print_json_header(void *parm, int action, char *dfile,
                                   struct file_magic *file_magic,
-                                  struct file_header *file_hdr, __nr_t cpu_nr,
+                                  struct file_header *file_hdr,
                                   struct activity *act[], unsigned int id_seq[])
 {
        struct tm rectime, *loc_t;
@@ -783,7 +773,7 @@ __printf_funct_t print_json_header(void *parm, int action, char *dfile,
 
                xprintf(*tab, "\"machine\": \"%s\",", file_hdr->sa_machine);
                xprintf(*tab, "\"number-of-cpus\": %d,",
-                       cpu_nr > 1 ? cpu_nr - 1 : 1);
+                       file_hdr->sa_cpu_nr > 1 ? file_hdr->sa_cpu_nr - 1 : 1);
 
                /* Fill file timestmap structure (rectime) */
                get_file_timestamp_struct(flags, &rectime, file_hdr);
@@ -815,14 +805,13 @@ __printf_funct_t print_json_header(void *parm, int action, char *dfile,
  * @dfile      Name of system activity data file.
  * @file_magic System activity file magic header.
  * @file_hdr   System activity file standard header.
- * @cpu_nr     Number of processors for current daily data file.
  * @act                Array of activities.
  * @id_seq     Activity sequence.
  ***************************************************************************
  */
 __printf_funct_t print_hdr_header(void *parm, int action, char *dfile,
                                  struct file_magic *file_magic,
-                                 struct file_header *file_hdr, __nr_t cpu_nr,
+                                 struct file_header *file_hdr,
                                  struct activity *act[], unsigned int id_seq[])
 {
        int i, p;
@@ -848,7 +837,7 @@ __printf_funct_t print_hdr_header(void *parm, int action, char *dfile,
                print_gal_header(localtime((const time_t *) &(file_hdr->sa_ust_time)),
                                 file_hdr->sa_sysname, file_hdr->sa_release,
                                 file_hdr->sa_nodename, file_hdr->sa_machine,
-                                cpu_nr > 1 ? cpu_nr - 1 : 1,
+                                file_hdr->sa_cpu_nr > 1 ? file_hdr->sa_cpu_nr - 1 : 1,
                                 PLAIN_OUTPUT);
 
                printf(_("Number of CPU for last samples in file: %u\n"),
@@ -904,14 +893,13 @@ __printf_funct_t print_hdr_header(void *parm, int action, char *dfile,
  * @dfile      Name of system activity data file (unused here).
  * @file_magic System activity file magic header (unused here).
  * @file_hdr   System activity file standard header.
- * @cpu_nr     Number of processors for current daily data file.
  * @act                Array of activities (unused here).
  * @id_seq     Activity sequence (unused here).
  ***************************************************************************
  */
 __printf_funct_t print_svg_header(void *parm, int action, char *dfile,
                                  struct file_magic *file_magic,
-                                 struct file_header *file_hdr, __nr_t cpu_nr,
+                                 struct file_header *file_hdr,
                                  struct activity *act[], unsigned int id_seq[])
 {
        struct svg_hdr_parm *hdr_parm = (struct svg_hdr_parm *) parm;
@@ -936,7 +924,7 @@ __printf_funct_t print_svg_header(void *parm, int action, char *dfile,
                print_gal_header(localtime((const time_t *) &(file_hdr->sa_ust_time)),
                                 file_hdr->sa_sysname, file_hdr->sa_release,
                                 file_hdr->sa_nodename, file_hdr->sa_machine,
-                                cpu_nr > 1 ? cpu_nr - 1 : 1,
+                                file_hdr->sa_cpu_nr > 1 ? file_hdr->sa_cpu_nr - 1 : 1,
                                 PLAIN_OUTPUT);
                printf("</text>\n");
        }
diff --git a/sar.c b/sar.c
index 6af0979be3f384c2916ad7d25d569a0370e94462..9f42c71cbdfff3c6fc7c66ddbbe93bc357f8f4e3 100644 (file)
--- a/sar.c
+++ b/sar.c
@@ -583,17 +583,16 @@ int sa_read(void *buffer, int size)
  * @cur_time   Time string of current restart message.
  * @utc                True if @cur_time is expressed in UTC (unused here).
  * @file_hdr   System activity file standard header (unused here).
- * @cpu_nr     CPU count associated with restart mark.
  ***************************************************************************
  */
-__print_funct_t print_sar_restart(int *tab, int action, char *cur_date, char *cur_time, int utc,
-                                 struct file_header *file_hdr, unsigned int cpu_nr)
+__printf_funct_t print_sar_restart(int *tab, int action, char *cur_date, char *cur_time,
+                                 int utc, struct file_header *file_hdr)
 {
        char restart[64];
 
        printf("\n%-11s", cur_time);
        sprintf(restart, "  LINUX RESTART\t(%d CPU)\n",
-               cpu_nr > 1 ? cpu_nr - 1 : 1);
+               file_hdr->sa_cpu_nr > 1 ? file_hdr->sa_cpu_nr - 1 : 1);
        cprintf_s(IS_RESTART, "%s", restart);
 
 }
@@ -906,8 +905,7 @@ void read_stats_from_file(char from_file[])
        allocate_structures(act);
 
        /* Print report header */
-       print_report_hdr(flags, &rectime, &file_hdr,
-                        act[get_activity_position(act, A_CPU, EXIT_IF_NOT_FOUND)]->nr);
+       print_report_hdr(flags, &rectime, &file_hdr);
 
        /* Read system statistics from file */
        do {
@@ -1071,8 +1069,7 @@ void read_stats(void)
        allocate_structures(act);
 
        /* Print report header */
-       print_report_hdr(flags, &rectime, &file_hdr,
-                        act[get_activity_position(act, A_CPU, EXIT_IF_NOT_FOUND)]->nr);
+       print_report_hdr(flags, &rectime, &file_hdr);
 
        /* Read system statistics sent by the data collector */
        read_sadc_stat_bunch(0);