]> granicus.if.org Git - sysstat/commitdiff
sar/sadc: Get rid of volatile activities
authorSebastien GODARD <sysstat@users.noreply.github.com>
Fri, 17 Nov 2017 13:37:09 +0000 (14:37 +0100)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Fri, 17 Nov 2017 13:37:09 +0000 (14:37 +0100)
So called "volatile activities" were activities for which the number of
items could vary and corresponding structures were reallocated
accordingly.
In fact only A_CPU activity (CPU statistics) was volatile, to take into
account a possible restart of a VM machine including more CPU than when
the datafile was created.
The goal is now to allocate dynamically all the structures used by
activities, so we no longer have to distinguish between activities which
are volatile or not.

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

index da30a5cb80bcd67044e524376d9816ea89f17a6a..b9acfba42b0c9ae2cd8d1f45913281880b204df5 100644 (file)
@@ -71,7 +71,7 @@ struct act_bitmap irq_bitmap = {
  */
 struct activity cpu_act = {
        .id             = A_CPU,
-       .options        = AO_COLLECTED + AO_VOLATILE + AO_MULTIPLE_OUTPUTS +
+       .options        = AO_COLLECTED + AO_MULTIPLE_OUTPUTS +
                          AO_GRAPH_PER_ITEM,
        .magic          = ACTIVITY_MAGIC_BASE,
        .group          = G_DEFAULT,
@@ -1215,7 +1215,7 @@ struct activity net_udp6_act = {
 /* CPU frequency */
 struct activity pwr_cpufreq_act = {
        .id             = A_PWR_CPUFREQ,
-       .options        = AO_VOLATILE + AO_GRAPH_PER_ITEM,
+       .options        = AO_GRAPH_PER_ITEM,
        .magic          = ACTIVITY_MAGIC_BASE,
        .group          = G_POWER,
 #ifdef SOURCE_SADC
@@ -1410,7 +1410,7 @@ struct activity huge_act = {
 /* CPU weighted frequency */
 struct activity pwr_wghfreq_act = {
        .id             = A_PWR_WGHFREQ,
-       .options        = AO_VOLATILE + AO_MATRIX,
+       .options        = AO_MATRIX,
        .magic          = ACTIVITY_MAGIC_BASE,
        .group          = G_POWER,
 #ifdef SOURCE_SADC
diff --git a/sa.h b/sa.h
index 44d4b7252e14d7ff90dc1e78165aa35e992398a1..740d6dcc2ff19291d19fb178dc1a76bef06b56f8 100644 (file)
--- a/sa.h
+++ b/sa.h
@@ -339,16 +339,21 @@ struct svg_hdr_parm {
  *     |                             |
  *     | record_header structure     |
  *     |                             |
+ *     |--                         --|
+ *     |(__nr_t)       * 0+          |
  *     |--                           | * <count>
  *     |                             |
- *     | Statistics structures...(*) |
+ *     | Statistics structures...    |
  *     |                             |
  *     |--                         --|
  *
- * (*)Note: If it's a special record, we may find a comment instead of
- * statistics (R_COMMENT record type) or, if it's a R_RESTART record type,
- * <sa_nr_vol_act> structures (of type file_activity) for the volatile
- * activities.
+ * Note: A record_header structure is followed by 0+ __nr_t values giving
+ * the number of statistics structures for activities whose number of items
+ * may vary (ie. activities having a positive f_count_index value).
+ * If the record header's type is R_COMMENT then we find only a comment
+ * following the record_header structure.
+ * If the record_header's type is R_RESTART then we find only the number of CPU
+ * (of type __nr_t) of the machine following the record_header structure.
  ***************************************************************************
  */
 
@@ -430,26 +435,17 @@ struct file_header {
         * Number of jiffies per second.
         */
        unsigned long sa_hz             __attribute__ ((aligned (8)));
-       /*
-        * 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;
+       unsigned int sa_cpu_nr          __attribute__ ((aligned (8)));
        /*
         * Number of activities saved in file.
         */
        unsigned int sa_act_nr;
-       /*
-        * Number of volatile activities in file. This is the number of
-        * file_activity structures saved after each restart mark in file.
-        */
-       unsigned int sa_vol_act_nr;
        /*
         * Current year.
         */
@@ -498,7 +494,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       13      /* Nr of [unsigned] int in file_header structure */
+#define FILE_HEADER_U_NR       11      /* 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
@@ -623,15 +619,7 @@ struct record_header {
  */
 #define AO_SELECTED            0x02
 /*
- * When appending data to a file, the number of items (for every activity)
- * is forced to that of the file (number of network interfaces, serial lines,
- * etc.) Exceptions are volatile activities (like A_CPU) whose number of items
- * is related to the number of CPUs: If current machine has a different number
- * of CPU than that of the file (but is equal to sa_last_cpu_nr) then data
- * will be appended with a number of items equal to that of the machine.
- */
-#define AO_VOLATILE            0x04
-/*
+ * 0x04: Unused.
  * 0x08: Unused.
  */
 /*
@@ -660,7 +648,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 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)
@@ -1238,12 +1225,10 @@ int print_special_record
         struct file_header *, struct activity * [], struct report_format *, int, int);
 void read_file_stat_bunch
        (struct activity * [], int, int, int, struct file_activity *, int, int);
+__nr_t read_new_cpu_nr
+       (int, char *, struct file_magic *, int, int);
 int read_record_hdr
        (int, void *, struct record_header *, struct file_header *, int, int);
-__nr_t read_vol_act_structures
-       (int, struct activity * [], char *, struct file_magic *, unsigned int, int, int);
-int reallocate_vol_act_structures
-       (struct activity * [], unsigned int, unsigned int);
 void remap_struct
        (unsigned int [], unsigned int [], void *, unsigned int);
 void replace_nonprintable_char
index 4e30f28784d901f5e26651823fa4167d71599985..c0c01437173e3dcf535175492af8970082adec1d 100644 (file)
@@ -53,6 +53,7 @@ extern struct act_bitmap cpu_bitmap;
 unsigned int hdr_types_nr[] = {FILE_HEADER_ULL_NR, FILE_HEADER_UL_NR, FILE_HEADER_U_NR};
 unsigned int act_types_nr[] = {FILE_ACTIVITY_ULL_NR, FILE_ACTIVITY_UL_NR, FILE_ACTIVITY_U_NR};
 unsigned int rec_types_nr[] = {RECORD_HEADER_ULL_NR, RECORD_HEADER_UL_NR, RECORD_HEADER_U_NR};
+unsigned int nr_types_nr[]  = {0, 0, 1};
 
 /*
  ***************************************************************************
@@ -1590,16 +1591,7 @@ void check_file_actlst(int *ifd, char *dfile, struct activity *act[],
                if (fal->size > act[p]->msize) {
                        act[p]->msize = fal->size;
                }
-               /*
-                * NOTA BENE:
-                * If current activity is a volatile one then fal->nr is the
-                * number of items (CPU at the present time as only CPU related
-                * activities are volatile today) for the statistics located
-                * between the start of the data file and the first restart mark.
-                * Volatile activities have a number of items which can vary
-                * in file. In this case, a RESTART record is followed by the
-                * volatile activity structures.
-                */
+
                act[p]->nr    = fal->nr;
                act[p]->nr2   = fal->nr2;
                act[p]->fsize = fal->size;
@@ -1652,95 +1644,39 @@ format_error:
 
 /*
  ***************************************************************************
- * Set number of items for current volatile activity and reallocate its
- * structures accordingly.
- * NB: As only activities related to CPU can be volatile, the number of
- * items corresponds in fact to the number of CPU.
- *
- * IN:
- * @act                Array of activities.
- * @act_nr     Number of items for current volatile activity.
- * @act_id     Activity identification for current volatile activity.
- *
- * RETURN:
- * -1 if unknown activity and 0 otherwise.
- ***************************************************************************
- */
-int reallocate_vol_act_structures(struct activity *act[], unsigned int act_nr,
-                                  unsigned int act_id)
-{
-       int j, p;
-
-       if ((p = get_activity_position(act, act_id, RESUME_IF_NOT_FOUND)) < 0)
-               /* Ignore unknown activity */
-               return -1;
-
-       act[p]->nr = act_nr;
-
-       for (j = 0; j < 3; j++) {
-               SREALLOC(act[p]->buf[j], void,
-                        (size_t) act[p]->msize * (size_t) act[p]->nr * (size_t) act[p]->nr2);
-       }
-
-       return 0;
-}
-
-/*
- ***************************************************************************
- * Read the volatile activities structures following a RESTART record.
- * Then set number of items for each corresponding activity and reallocate
- * structures.
+ * Read the new number of CPU saved after a RESTART record.
  *
  * IN:
  * @ifd                Input file descriptor.
- * @act                Array of activities.
  * @file       Name of file being read.
  * @file_magic file_magic structure filled with file magic header data.
- * @vol_act_nr Number of volatile activities structures to read.
  * @endian_mismatch
  *             TRUE if file's data don't match current machine's endianness.
  * @arch_64    TRUE if file's data come from a 64 bit machine.
  *
  * RETURNS:
- * New number of items.
- *
- * NB: As only activities related to CPU can be volatile, the new number of
- * items corresponds in fact to the new number of CPU.
+ * New number of CPU.
  ***************************************************************************
  */
-__nr_t read_vol_act_structures(int ifd, struct activity *act[], char *file,
-                              struct file_magic *file_magic,
-                              unsigned int vol_act_nr, int endian_mismatch,
-                              int arch_64)
+__nr_t read_new_cpu_nr(int ifd, char *file, struct file_magic *file_magic,
+                      int endian_mismatch, int arch_64)
 {
-       struct file_activity file_act;
-       int item_nr = 0;
-       int i, rc;
-
-       for (i = 0; i < vol_act_nr; i++) {
+       __nr_t cpu_nr;
 
-               sa_fread(ifd, &file_act, FILE_ACTIVITY_SIZE, HARD_SIZE);
+       sa_fread(ifd, &cpu_nr, sizeof(__nr_t), HARD_SIZE);
 
-               /* Normalize endianness for file_activity structures */
-               if (endian_mismatch) {
-                       swap_struct(act_types_nr, &file_act, arch_64);
-               }
-
-               if (file_act.id) {
-                       rc = reallocate_vol_act_structures(act, file_act.nr, file_act.id);
-                       if ((rc == 0) && !item_nr) {
-                               item_nr = file_act.nr;
-                       }
-               }
-               /* else ignore empty structures that may exist */
+       /* Normalize endianness for file_activity structures */
+       if (endian_mismatch) {
+               nr_types_nr[2] = 1;
+               swap_struct(nr_types_nr, &cpu_nr, arch_64);
        }
 
-       if (!item_nr) {
-               /* All volatile activities structures cannot be empty */
+       if (!cpu_nr) {
+               /* CPU number cannot be zero */
                handle_invalid_sa_file(&ifd, file_magic, file, 0);
        }
 
-       return item_nr;
+       return cpu_nr;
 }
 
 /*
@@ -2464,9 +2400,8 @@ int print_special_record(struct record_header *record_hdr, unsigned int l_flags,
 
        if (rtype == R_RESTART) {
                /* 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);
+               file_hdr->sa_cpu_nr = read_new_cpu_nr(ifd, file, file_magic,
+                                                     endian_mismatch, arch_64);
 
                if (!dp)
                        return 0;
index f22f7682a2b387334969edf25e460510789d9f55..36187dbd4c2b9145816bdd827f95dfe317febab6 100644 (file)
--- a/sa_conv.c
+++ b/sa_conv.c
@@ -137,8 +137,8 @@ void upgrade_file_header(void *buffer, struct file_header *file_hdr)
        strncpy(file_hdr->sa_machine, f_hdr->sa_machine, UTSNAME_LEN);
        file_hdr->sa_machine[UTSNAME_LEN - 1] = '\0';
        /* The last two values below will be updated later */
-       file_hdr->sa_vol_act_nr = 0;
-       file_hdr->sa_last_cpu_nr = 0;
+//     file_hdr->sa_vol_act_nr = 0;
+//     file_hdr->sa_last_cpu_nr = 0;
 }
 
 /*
@@ -442,7 +442,7 @@ int upgrade_header_section(char dfile[], int fd, int stdfd,
                           struct file_header *file_hdr, int previous_format,
                           struct file_activity **file_actlst, unsigned int vol_id_seq[])
 {
-       int i, j, n, p;
+       int i, n, p;
        unsigned int a_cpu = FALSE;
        void *buffer = NULL;
        struct file_activity *fal;
@@ -480,7 +480,7 @@ int upgrade_header_section(char dfile[], int fd, int stdfd,
        SREALLOC(*file_actlst, struct file_activity, FILE_ACTIVITY_SIZE * file_hdr->sa_act_nr);
        fal = *file_actlst;
 
-       j = 0;
+//     j = 0;
        for (i = 0; i < file_hdr->sa_act_nr; i++, fal++) {
 
                sa_fread(fd, fal, FILE_ACTIVITY_SIZE, HARD_SIZE);
@@ -495,7 +495,7 @@ int upgrade_header_section(char dfile[], int fd, int stdfd,
                if ((p = get_activity_position(act, fal->id, RESUME_IF_NOT_FOUND)) >= 0) {
                        /* This is a known activity, maybe with an unknown format */
 
-                       if (IS_VOLATILE(act[p]->options) && previous_format) {
+//                     if (IS_VOLATILE(act[p]->options) && previous_format) {
                                /*
                                 * Current activity is known by current version
                                 * as a volatile one: So increment the number of
@@ -503,7 +503,7 @@ int upgrade_header_section(char dfile[], int fd, int stdfd,
                                 * for old format data files, since up-to-date
                                 * format data files already have the right value here).
                                 */
-                               file_hdr->sa_vol_act_nr += 1;
+//                             file_hdr->sa_vol_act_nr += 1;
 
                                /*
                                 * Create the sequence of volatile activities.
@@ -512,8 +512,8 @@ int upgrade_header_section(char dfile[], int fd, int stdfd,
                                 * since this sequence already exists following
                                 * the RESTART record.
                                 */
-                               vol_id_seq[j++] = act[p]->id;
-                       }
+//                             vol_id_seq[j++] = act[p]->id;
+//                     }
 
                        if (fal->id == A_CPU) {
                                /*
@@ -521,9 +521,9 @@ int upgrade_header_section(char dfile[], int fd, int stdfd,
                                 * activities. The number of CPU is a constant
                                 * all along the file.
                                 */
-                               if (previous_format) {
-                                       file_hdr->sa_last_cpu_nr = fal->nr;
-                               }
+//                             if (previous_format) {
+//                                     file_hdr->sa_last_cpu_nr = fal->nr;
+//                             }
                                a_cpu = TRUE;
                        }
 
@@ -688,6 +688,7 @@ int upgrade_restart_record(int fd, int stdfd, struct activity *act[],
                           struct file_header *file_hdr, int previous_format,
                           unsigned int vol_id_seq[])
 {
+#if 0
        int i, p;
        struct file_activity file_act;
 
@@ -722,7 +723,7 @@ int upgrade_restart_record(int fd, int stdfd, struct activity *act[],
        }
 
        fprintf(stderr, "R");
-
+#endif
        return 0;
 }
 
diff --git a/sadc.c b/sadc.c
index f4f5893227951b741b100c83628354d7de6878c3..14c2a90b719e5fdb66b17909c0f4c58e42b7dcf0 100644 (file)
--- a/sadc.c
+++ b/sadc.c
@@ -70,7 +70,6 @@ struct record_header record_hdr;
 char comment[MAX_COMMENT_LEN];
 
 unsigned int id_seq[NR_ACT];
-unsigned int vol_id_seq[NR_ACT];
 
 extern unsigned int hdr_types_nr[];
 extern unsigned int act_types_nr[];
@@ -507,8 +506,6 @@ void setup_file_hdr(int fd)
 
        /* OK, now fill the header */
        file_hdr.sa_act_nr      = get_activity_nr(act, AO_COLLECTED, COUNT_ACTIVITIES);
-       file_hdr.sa_vol_act_nr  = get_activity_nr(act, AO_COLLECTED + AO_VOLATILE,
-                                                 COUNT_ACTIVITIES);
        file_hdr.sa_day         = rectime.tm_mday;
        file_hdr.sa_month       = rectime.tm_mon;
        file_hdr.sa_year        = rectime.tm_year;
@@ -522,13 +519,6 @@ void setup_file_hdr(int fd)
        file_hdr.act_size = FILE_ACTIVITY_SIZE;
        file_hdr.rec_size = RECORD_HEADER_SIZE;
 
-       /*
-        * This is a new file (or stdout): Field sa_last_cpu_nr is set to the number
-        * of CPU items of the machine (1 .. CPU_NR + 1).
-        * A_CPU activity is always collected, hence its number of items is
-        * 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
@@ -578,11 +568,6 @@ void setup_file_hdr(int fd)
                        if (write_all(fd, &file_act, FILE_ACTIVITY_SIZE)
                            != FILE_ACTIVITY_SIZE)
                                goto write_error;
-
-                       /* Create sequence of volatile activities */
-                       if (IS_VOLATILE(act[p]->options)) {
-                               vol_id_seq[i] = act[p]->id;
-                       }
                }
        }
 
@@ -597,47 +582,22 @@ write_error:
 
 /*
  ***************************************************************************
- * Write the volatile activity structures following each restart mark.
- * sa_vol_act_nr structures have to be written.
- * Note that volatile activities written after the restart marks may be
- * different within the same file if different versions of sysstat have been
- * used to create the file and then to append data to it.
+ * Write the new number of CPU after the RESTART record in file.
  *
  * IN:
  * @ofd                Output file descriptor.
  ***************************************************************************
  */
-void write_vol_act_structures(int ofd)
+void write_new_cpu_nr(int ofd)
 {
-       struct file_activity file_act;
-       int i, p;
-
-       memset(&file_act, 0, FILE_ACTIVITY_SIZE);
+       int p;
+       __nr_t cpu_nr;
 
-       for (i = 0; i < file_hdr.sa_vol_act_nr; i++) {
-
-               if (!vol_id_seq[i]) {
-                       /*
-                        * Write an empty structure when current sysstat
-                        * version knows fewer volatile activities than
-                        * the number saved in file's header.
-                        */
-                       file_act.id = file_act.nr = 0;
-               }
-               else {
-                       p = get_activity_position(act, vol_id_seq[i], EXIT_IF_NOT_FOUND);
-
-                       /*
-                        * All the fields in file_activity structure are not used.
-                        * In particular, act[p]->nr2 is left unmodified.
-                        */
-                       file_act.id = act[p]->id;
-                       file_act.nr = act[p]->nr;
-               }
+       p = get_activity_position(act, A_CPU, EXIT_IF_NOT_FOUND);
+       cpu_nr = act[p]->nr;
 
-               if (write_all(ofd, &file_act, FILE_ACTIVITY_SIZE) != FILE_ACTIVITY_SIZE) {
-                       p_write_error();
-               }
+       if (write_all(ofd, &cpu_nr, sizeof(__nr_t)) != sizeof(__nr_t)) {
+               p_write_error();
        }
 }
 
@@ -682,8 +642,8 @@ void write_special_record(int ofd, int rtype)
        }
 
        if (rtype == R_RESTART) {
-               /* Also write the volatile activities structures */
-               write_vol_act_structures(ofd);
+               /* Also write the new number of CPU */
+               write_new_cpu_nr(ofd);
        }
        else if (rtype == R_COMMENT) {
                /* Also write the comment */
@@ -737,41 +697,6 @@ void write_stats(int ofd)
        }
 }
 
-/*
- ***************************************************************************
- * Rewrite file's header. Done when number of CPU has changed.
- *
- * IN:
- * @ofd                Output file descriptor.
- * @fpos       Position in file where header structure has to be written.
- * @file_magic File magic structure.
- ***************************************************************************
- */
-void rewrite_file_hdr(int *ofd, off_t fpos, struct file_magic *file_magic)
-{
-       /* Remove O_APPEND status flag */
-       if (fcntl(*ofd, F_SETFL, 0) < 0) {
-               perror("fcntl");
-               exit(2);
-       }
-
-       /* Now rewrite file's header with its new CPU number value */
-       if (lseek(*ofd, fpos, SEEK_SET) < fpos) {
-               perror("lseek");
-               exit(2);
-       }
-
-       if (write_all(*ofd, &file_hdr, FILE_HEADER_SIZE) != FILE_HEADER_SIZE) {
-               p_write_error();
-       }
-
-       /* Restore O_APPEND status flag */
-       if (fcntl(*ofd, F_SETFL, O_APPEND) < 0) {
-               perror("fcntl");
-               exit(2);
-       }
-}
-
 /*
  ***************************************************************************
  * Create a system activity daily data file.
@@ -851,8 +776,7 @@ void open_ofile(int *ofd, char ofile[], int restart_mark)
        struct file_activity file_act[NR_ACT];
        struct tm rectime = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL};
        ssize_t sz;
-       off_t fpos;
-       int i, j, p;
+       int i, p;
 
        if (!ofile[0])
                return;
@@ -895,15 +819,6 @@ void open_ofile(int *ofd, char ofile[], int restart_mark)
                handle_invalid_sa_file(ofd, &file_magic, ofile, sz);
        }
 
-       /*
-        * Save current file position.
-        * Needed later to update sa_last_cpu_nr.
-        */
-       if ((fpos = lseek(*ofd, 0, SEEK_CUR)) < 0) {
-               perror("lseek");
-               exit(2);
-       }
-
        /* Read file standard header */
        if ((sz = read(*ofd, &file_hdr, FILE_HEADER_SIZE)) != FILE_HEADER_SIZE)
                goto append_error;
@@ -924,11 +839,9 @@ void open_ofile(int *ofd, char ofile[], int restart_mark)
        }
 
        /* OK: It's a true system activity file */
-       if (!file_hdr.sa_act_nr || (file_hdr.sa_act_nr > NR_ACT) ||
-           (file_hdr.sa_vol_act_nr > NR_ACT))
+       if (!file_hdr.sa_act_nr || (file_hdr.sa_act_nr > NR_ACT))
                /*
-                * No activities at all or at least one unknown activity,
-                * or too many volatile activities:
+                * No activities at all or at least one unknown activity:
                 * Cannot append data to such a file.
                 */
                goto append_error;
@@ -990,8 +903,6 @@ void open_ofile(int *ofd, char ofile[], int restart_mark)
                id_seq[i] = 0;
        }
 
-       j = 0;
-
        for (i = 0; i < file_hdr.sa_act_nr; i++) {
 
                p = get_activity_position(act, file_act[i].id, EXIT_IF_NOT_FOUND);
@@ -999,18 +910,8 @@ void open_ofile(int *ofd, char ofile[], int restart_mark)
                /*
                 * Force number of items (serial lines, network interfaces...)
                 * and sub-items to that of the file, and reallocate structures.
-                * Exceptions are volatile activities, for which number of items
-                * is kept unmodified unless its value was zero (in this case,
-                * it is also forced to the value of the file).
-                * Also keep in mind that the file cannot contain more than
-                * sa_vol_act_nr volatile activities.
                 */
-               if (!IS_VOLATILE(act[p]->options) || !act[p]->nr || (j >= file_hdr.sa_vol_act_nr)) {
-                       act[p]->nr  = file_act[i].nr;
-               }
-               else {
-                       vol_id_seq[j++] = file_act[i].id;
-               }
+               act[p]->nr  = file_act[i].nr;
                act[p]->nr2 = file_act[i].nr2;
                SREALLOC(act[p]->_buf0, void,
                         (size_t) act[p]->msize * (size_t) act[p]->nr * (size_t) act[p]->nr2);
@@ -1020,35 +921,6 @@ void open_ofile(int *ofd, char ofile[], int restart_mark)
                act[p]->options |= AO_COLLECTED;
        }
 
-       while (j < file_hdr.sa_vol_act_nr) {
-               vol_id_seq[j++] = 0;
-       }
-
-       p = get_activity_position(act, A_CPU, EXIT_IF_NOT_FOUND);
-       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) {
-                       /*
-                        * We are inserting a restart mark, and current machine
-                        * has a different number of CPU than that saved in file,
-                        * so update sa_last_cpu_nr in file's header and rewrite it.
-                        */
-                       file_hdr.sa_last_cpu_nr = act[p]->nr;
-                       rewrite_file_hdr(ofd, fpos, &file_magic);
-               }
-               else {
-                       /*
-                        * Current number of cpu items (for current system)
-                        * doesn't match number of cpu items of the last sample
-                        * saved in file.
-                        */
-                       goto append_error;
-               }
-       }
-
        return;
 
 append_error:
diff --git a/sadf.c b/sadf.c
index 7e1d6e208d6ac58f1660462f7cdfb1529fc0fb03..39082d19c6f1cb3afb893c92caa3c300a9a2435e 100644 (file)
--- a/sadf.c
+++ b/sadf.c
@@ -191,43 +191,6 @@ void check_format_options(void)
        }
 }
 
-/*
- ***************************************************************************
- * Save or restore number of items for all known activities.
- *
- * IN:
- * @save_act_nr        Array containing number of items to restore for each
- *             activity.
- * @action     DO_SAVE to save number of items, or DO_RESTORE to restore.
- *
- * OUT:
- * @save_act_nr        Array containing number of items saved for each activity.
- ***************************************************************************
- */
-void sr_act_nr(__nr_t save_act_nr[], int action)
-{
-       int i;
-
-       if (action == DO_SAVE) {
-               /* Save number of items for all activities */
-               for (i = 0; i < NR_ACT; i++) {
-                       save_act_nr[i] = act[i]->nr;
-               }
-       }
-       else if (action == DO_RESTORE) {
-               /*
-                * Restore number of items for all activities
-                * and reallocate structures accordingly.
-                */
-               for (i = 0; i < NR_ACT; i++) {
-                       if (save_act_nr[i] > 0) {
-                               reallocate_vol_act_structures(act, save_act_nr[i],
-                                                             act[i]->id);
-                       }
-               }
-       }
-}
-
 /*
  ***************************************************************************
  * Read next sample statistics. If it's a special record (R_RESTART or
@@ -301,14 +264,12 @@ int read_next_sample(int ifd, int action, int curr, char *file, int *rtype, int
                        if (action & IGNORE_RESTART) {
                                /*
                                 * Ignore RESTART record (don't display it)
-                                * but anyway we have to reallocate volatile
-                                * activities structures (unless we don't want to
-                                * do it now).
+                                * but anyway we have to read the CPU number that follows it
+                                * (unless we don't want to do it now).
                                 */
-                               if (!(action & DONT_READ_VOLATILE)) {
-                                       read_vol_act_structures(ifd, act, file, file_magic,
-                                                               file_hdr.sa_vol_act_nr,
-                                                               endian_mismatch, arch_64);
+                               if (!(action & DONT_READ_CPU_NR)) {
+                                       file_hdr.sa_cpu_nr = read_new_cpu_nr(ifd, file, file_magic,
+                                                                            endian_mismatch, arch_64);
                                }
                                if (action & SET_TIMESTAMPS) {
                                        sa_get_record_timestamp_struct(flags, &record_hdr[curr],
@@ -434,10 +395,10 @@ time_t get_time_ref(void)
  ***************************************************************************
  * Compute the number of rows that will contain SVG views. Usually only one
  * view is displayed on a row, unless the "packed" option has been entered.
- * Each activity selected may have several views. Moreover we have to take
- * into account volatile activities (eg. CPU) for which the number of views
- * will depend on the highest number of items (eg. maximum number of CPU)
- * saved in the file.
+ * Each activity selected may have several views. Moreover some activities
+ * may have a number of items that vary within the file: In this case,
+ * the number of views will depend on the highest number of items saved in
+ * the file.
  *
  * IN:
  * @ifd                        File descriptor of input file.
@@ -466,14 +427,12 @@ int get_svg_graph_nr(int ifd, char *file, struct file_magic *file_magic,
        int i, n, p, eosaf;
        int rtype, new_tot_g_nr, tot_g_nr = 0;
        off_t fpos;
-       __nr_t save_act_nr[NR_ACT] = {0};
 
-       /* Save current file position and items number */
+       /* Save current file position */
        if ((fpos = lseek(ifd, 0, SEEK_CUR)) < 0) {
                perror("lseek");
                exit(2);
        }
-       sr_act_nr(save_act_nr, DO_SAVE);
 
        /* Init total number of views for each activity */
        for (i = 0; i < NR_ACT; i++) {
@@ -548,20 +507,18 @@ int get_svg_graph_nr(int ifd, char *file, struct file_magic *file_magic,
                        break;
 
        /*
-        * If we have found a RESTART record then we have also read the list of volatile
-        * activities following it, reallocated the structures and changed the number of
-        * items (act[p]->nr) for those volatile activities. So loop again to compute
-        * the new total number of graphs.
+        * If we have found a RESTART record then we have also read the new number of
+        * CPU that follows and saved it in file_header's sa_cpu_nr field.
+        * FIXME: Loop again to compute the new total number of graphs.
         */
        }
        while (rtype == R_RESTART);
 
-       /* Rewind file and restore items number */
+       /* Rewind file */
        if (lseek(ifd, fpos, SEEK_SET) < fpos) {
                perror("lseek");
                exit(2);
        }
-       sr_act_nr(save_act_nr, DO_RESTORE);
 
        if (*views_per_row > MAX_VIEWS_ON_A_ROW) {
                *views_per_row = MAX_VIEWS_ON_A_ROW;
@@ -793,7 +750,7 @@ void rw_curr_act_stats(int ifd, off_t fpos, int *curr, long *cnt, int *eosaf,
 
        do {
                /* Display <count> lines of stats */
-               *eosaf = read_next_sample(ifd, IGNORE_RESTART | DONT_READ_VOLATILE,
+               *eosaf = read_next_sample(ifd, IGNORE_RESTART | DONT_READ_CPU_NR,
                                          *curr, file, &rtype, 0, file_magic,
                                          file_actlst, rectime, loctime);
 
@@ -839,8 +796,6 @@ void rw_curr_act_stats(int ifd, off_t fpos, int *curr, long *cnt, int *eosaf,
  *             saved for current record.
  * @file       Name of file being read.
  * @file_magic file_magic structure filled with file magic header data.
- * @save_act_nr        Array where the number of volatile activities are saved
- *             for current position in file.
  * @g_nr       Number of graphs already displayed (for all activities).
  *
  * OUT:
@@ -854,23 +809,17 @@ void rw_curr_act_stats(int ifd, off_t fpos, int *curr, long *cnt, int *eosaf,
 void display_curr_act_graphs(int ifd, off_t fpos, int *curr, long *cnt, int *eosaf,
                             int p, int *reset, struct file_activity *file_actlst,
                             struct tm *rectime, struct tm *loctime,
-                            char *file, struct file_magic *file_magic,
-                            __nr_t save_act_nr[], int *g_nr)
+                            char *file, struct file_magic *file_magic, int *g_nr)
 {
        struct svg_parm parm;
        int rtype;
        int next, reset_cd;
 
-       /* Rewind file... */
+       /* Rewind file */
        if (lseek(ifd, fpos, SEEK_SET) < fpos) {
                perror("lseek");
                exit(2);
        }
-       /*
-        * ... and restore number of items for volatile activities
-        * for this position in file.
-        */
-       sr_act_nr(save_act_nr, DO_RESTORE);
 
        /*
         * Restore the first stats collected.
@@ -970,7 +919,6 @@ void logic1_display_loop(int ifd, struct file_activity *file_actlst, char *file,
 {
        int curr, tab = 0, rtype;
        int eosaf, next, reset = FALSE;
-       __nr_t save_act_nr[NR_ACT] = {0};
        long cnt = 1;
        off_t fpos;
 
@@ -984,8 +932,6 @@ void logic1_display_loop(int ifd, struct file_activity *file_actlst, char *file,
                perror("lseek");
                exit(2);
        }
-       /* Save number of activities items for current file position */
-       sr_act_nr(save_act_nr, DO_SAVE);
 
        /* Print header (eg. XML file header) */
        if (*fmt[f_position]->f_header) {
@@ -1064,16 +1010,11 @@ void logic1_display_loop(int ifd, struct file_activity *file_actlst, char *file,
                (*fmt[f_position]->f_statistics)(&tab, F_END);
        }
 
-       /* Rewind file... */
+       /* Rewind file */
        if (lseek(ifd, fpos, SEEK_SET) < fpos) {
                perror("lseek");
                exit(2);
        }
-       /*
-        * ... and restore number of items for volatile activities
-        * for this position in file.
-        */
-       sr_act_nr(save_act_nr, DO_RESTORE);
 
        /* Process now RESTART entries to display restart messages */
        if (*fmt[f_position]->f_restart) {
@@ -1092,16 +1033,11 @@ void logic1_display_loop(int ifd, struct file_activity *file_actlst, char *file,
                (*fmt[f_position]->f_restart)(&tab, F_END, NULL, NULL, FALSE, &file_hdr);
        }
 
-       /* Rewind file... */
+       /* Rewind file */
        if (lseek(ifd, fpos, SEEK_SET) < fpos) {
                perror("lseek");
                exit(2);
        }
-       /*
-        * ... and restore number of items for volatile activities
-        * for this position in file.
-        */
-       sr_act_nr(save_act_nr, DO_RESTORE);
 
        /* Last, process COMMENT entries to display comments */
        if (DISPLAY_COMMENT(flags)) {
@@ -1237,7 +1173,7 @@ void logic2_display_loop(int ifd, struct file_activity *file_actlst,
                if (!cnt) {
                        /* Go to next Linux restart, if possible */
                        do {
-                               eosaf = read_next_sample(ifd, IGNORE_RESTART | DONT_READ_VOLATILE,
+                               eosaf = read_next_sample(ifd, IGNORE_RESTART | DONT_READ_CPU_NR,
                                                         curr, file, &rtype, 0, file_magic,
                                                         file_actlst, rectime, loctime);
                        }
@@ -1288,7 +1224,6 @@ void logic3_display_loop(int ifd, struct file_activity *file_actlst,
        long cnt = 1;
        off_t fpos;
        int graph_nr = 0;
-       __nr_t save_act_nr[NR_ACT] = {0};
 
        /* Use a decimal point to make SVG code locale independent */
        setlocale(LC_NUMERIC, "C");
@@ -1344,8 +1279,6 @@ void logic3_display_loop(int ifd, struct file_activity *file_actlst,
                perror("lseek");
                exit(2);
        }
-       /* Save number of activities items for current file position */
-       sr_act_nr(save_act_nr, DO_SAVE);
 
        /* For each requested activity, display graphs */
        for (i = 0; i < NR_ACT; i++) {
@@ -1361,7 +1294,7 @@ void logic3_display_loop(int ifd, struct file_activity *file_actlst,
                        display_curr_act_graphs(ifd, fpos, &curr, &cnt, &eosaf,
                                                p, &reset, file_actlst,
                                                rectime, loctime, file,
-                                               file_magic, save_act_nr, &g_nr);
+                                               file_magic, &g_nr);
                }
                else {
                        unsigned int optf, msk;
@@ -1374,7 +1307,7 @@ void logic3_display_loop(int ifd, struct file_activity *file_actlst,
                                        display_curr_act_graphs(ifd, fpos, &curr, &cnt, &eosaf,
                                                                p, &reset, file_actlst,
                                                                rectime, loctime, file,
-                                                               file_magic, save_act_nr, &g_nr);
+                                                               file_magic, &g_nr);
                                        act[p]->opt_flags = optf;
                                }
                        }
diff --git a/sadf.h b/sadf.h
index cef63b6e768b48918e57ce7c116411eaa81a7871..7be036dc72ee73ef883a1fd7fd08005ac389f323 100644 (file)
--- a/sadf.h
+++ b/sadf.h
@@ -17,7 +17,7 @@
 
 #define IGNORE_NOTHING         0
 #define IGNORE_RESTART         1
-#define DONT_READ_VOLATILE     2
+#define DONT_READ_CPU_NR       2
 #define IGNORE_COMMENT         4
 #define SET_TIMESTAMPS         8
 
index d830fb77d9da3ecb4f836a51951f730c7f728df2..6ab536a7da62985fd8adbeb3d3fd0d9e09f0044a 100644 (file)
@@ -840,9 +840,6 @@ __printf_funct_t print_hdr_header(void *parm, int action, char *dfile,
                                 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"),
-                      file_hdr->sa_last_cpu_nr > 1 ? file_hdr->sa_last_cpu_nr - 1 : 1);
-
                /* Fill file timestmap structure (rectime) */
                get_file_timestamp_struct(flags, &rectime, file_hdr);
                strftime(cur_time, sizeof(cur_time), "%Y-%m-%d", &rectime);
@@ -857,9 +854,9 @@ __printf_funct_t print_hdr_header(void *parm, int action, char *dfile,
                printf(_("Size of a long int: %d\n"), file_hdr->sa_sizeof_long);
                printf("HZ = %lu\n", file_hdr->sa_hz);
 
-               /* Number of activities (number of volatile activities) in file */
-               printf("sa_act_nr (sa_vol_act_nr): %u (%u)\n",
-                      file_hdr->sa_act_nr, file_hdr->sa_vol_act_nr);
+               /* Number of activities in file */
+               printf("sa_act_nr: %u\n",
+                      file_hdr->sa_act_nr);
 
                printf(_("List of activities:\n"));