]> granicus.if.org Git - sysstat/commitdiff
sadc/sar: New format (part 3): Use 64-bit time fields
authorSebastien GODARD <sysstat@users.noreply.github.com>
Fri, 22 Sep 2017 07:27:01 +0000 (09:27 +0200)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Fri, 22 Sep 2017 07:27:01 +0000 (09:27 +0200)
Now use unsigned long long type for time fields (instead of
unsigned long, which are only 32-bit wide on 32-bit systems).
This is to avoid any future problems (like year 2038 integer
overflow).
Also code the year number as an integer instead of a char in datafile's
header.

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

diff --git a/sa.h b/sa.h
index 20eea8e3077d0994a38ebf83d6dd0836edf2d847..0f6b92ee782b8b61fc56214f94bf828cc9e9aaf3 100644 (file)
--- a/sa.h
+++ b/sa.h
 
 /* Structure for SVG specific parameters */
 struct svg_parm {
-       unsigned long dt;               /* Interval of time for current sample */
-       unsigned long ust_time_ref;     /* X axis start time in seconds since the epoch */
-       unsigned long ust_time_end;     /* X axis end time in seconds since the epoch */
-       unsigned long ust_time_first;   /* Time (in seconds since the epoch) for first sample */
-       int graph_no;                   /* Total number of views already displayed */
-       int restart;                    /* TRUE if we have just met a RESTART record */
-       struct file_header *file_hdr;   /* Pointer on file header structure */
+       unsigned long long dt;                  /* Interval of time for current sample */
+       unsigned long long ust_time_ref;        /* X axis start time in seconds since the epoch */
+       unsigned long long ust_time_end;        /* X axis end time in seconds since the epoch */
+       unsigned long long ust_time_first;      /* Time (in seconds since the epoch) for first sample */
+       int graph_no;                           /* Total number of views already displayed */
+       int restart;                            /* TRUE if we have just met a RESTART record */
+       struct file_header *file_hdr;           /* Pointer on file header structure */
 };
 
 /* Structure used when displaying SVG header */
@@ -410,11 +410,11 @@ struct file_header {
        /*
         * Timestamp in seconds since the epoch.
         */
-       unsigned long sa_ust_time       __attribute__ ((aligned (8)));
+       unsigned long long sa_ust_time;
        /*
         * Number of CPU items (1 .. CPU_NR + 1) for the last sample in file.
         */
-       unsigned int sa_last_cpu_nr     __attribute__ ((aligned (8)));
+       unsigned int sa_last_cpu_nr;
        /*
         * Number of activities saved in file.
         */
@@ -429,9 +429,9 @@ struct file_header {
         * No need to save DST (Daylight Saving Time) flag, since it is not taken
         * into account by the strftime() function used to print the timestamp.
         */
+       int sa_year;
        unsigned char sa_day;
        unsigned char sa_month;
-       unsigned char sa_year;
        /*
         * Size of a long integer. Useful to know the architecture on which
         * the datafile was created.
@@ -456,9 +456,9 @@ struct file_header {
 };
 
 #define FILE_HEADER_SIZE       (sizeof(struct file_header))
-#define FILE_HEADER_ULL_NR     0       /* 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       3       /* Nr of unsigned int in file_header structure */
+#define FILE_HEADER_ULL_NR     1       /* Nr of unsigned long long in file_header structure */
+#define FILE_HEADER_UL_NR      0       /* Nr of unsigned long in file_header structure */
+#define FILE_HEADER_U_NR       4       /* 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
@@ -548,11 +548,11 @@ struct record_header {
        /*
         * Timestamp (number of seconds since the epoch).
         */
-       unsigned long ust_time          __attribute__ ((aligned (8)));
+       unsigned long long ust_time;
        /*
         * Record type: R_STATS, R_RESTART,...
         */
-       unsigned char record_type       __attribute__ ((aligned (8)));
+       unsigned char record_type;
        /*
         * Timestamp: Hour (0-23), minute (0-59) and second (0-59).
         * Used to determine TRUE time (immutable, non locale dependent time).
@@ -563,8 +563,8 @@ struct record_header {
 };
 
 #define RECORD_HEADER_SIZE     (sizeof(struct record_header))
-#define RECORD_HEADER_ULL_NR   2       /* Nr of unsigned long long in record_header structure */
-#define RECORD_HEADER_UL_NR    1       /* Nr of unsigned long in record_header structure */
+#define RECORD_HEADER_ULL_NR   3       /* 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 */
 
 
index aeb20dd111a12f4250c0fec8ebaa7ca3f04dd37a..1f931728213e168a8c071fba029bc64d8c828dd7 100644 (file)
@@ -2310,7 +2310,7 @@ void set_record_timestamp_string(unsigned int l_flags, struct record_header *rec
 {
        /* Set cur_time date value */
        if (PRINT_SEC_EPOCH(l_flags) && cur_date) {
-               sprintf(cur_time, "%ld", record_hdr->ust_time);
+               sprintf(cur_time, "%llu", record_hdr->ust_time);
                strcpy(cur_date, "");
        }
        else {
diff --git a/sadc.c b/sadc.c
index c6ea98e3735cff8b7be5a2cf5e0fe5da9ea80411..2c97b05fea48ef80b1524b118a8402d77c2afbee 100644 (file)
--- a/sadc.c
+++ b/sadc.c
@@ -494,7 +494,7 @@ void setup_file_hdr(int fd)
        memset(&file_hdr, 0, FILE_HEADER_SIZE);
 
        /* Then get current date */
-       file_hdr.sa_ust_time = get_time(&rectime, 0);
+       file_hdr.sa_ust_time = (unsigned long long) get_time(&rectime, 0);
 
        /* OK, now fill the header */
        file_hdr.sa_act_nr      = get_activity_nr(act, AO_COLLECTED, COUNT_ACTIVITIES);
@@ -645,7 +645,7 @@ void write_special_record(int ofd, int rtype)
        record_hdr.record_type = rtype;
 
        /* Save time */
-       record_hdr.ust_time = get_time(&rectime, 0);
+       record_hdr.ust_time = (unsigned long long) get_time(&rectime, 0);
 
        record_hdr.hour   = rectime.tm_hour;
        record_hdr.minute = rectime.tm_min;
@@ -1112,7 +1112,7 @@ void rw_sa_stat_loop(long count, int stdfd, int ofd, char ofile[],
                reset_stats();
 
                /* Save time */
-               record_hdr.ust_time = get_time(&rectime, 0);
+               record_hdr.ust_time = (unsigned long long) get_time(&rectime, 0);
                record_hdr.hour     = rectime.tm_hour;
                record_hdr.minute   = rectime.tm_min;
                record_hdr.second   = rectime.tm_sec;
diff --git a/sadf.c b/sadf.c
index b6148710279082f9d640180d11cd9c606db472a6..3de2f701225257e193b7990fa363b50b1c7e0787 100644 (file)
--- a/sadf.c
+++ b/sadf.c
@@ -430,7 +430,7 @@ time_t get_time_ref(void)
                        return t;
        }
 
-       return record_hdr[2].ust_time;
+       return (time_t) record_hdr[2].ust_time;
 }
 
 /*
@@ -892,7 +892,7 @@ void display_curr_act_graphs(int ifd, off_t fpos, int *curr, long *cnt, int *eos
        copy_structures(act, id_seq, record_hdr, !*curr, 2);
 
        parm.graph_no = *g_nr;
-       parm.ust_time_ref = get_time_ref();
+       parm.ust_time_ref = (unsigned long long) get_time_ref();
        parm.ust_time_first = record_hdr[2].ust_time;
        parm.restart = TRUE;
        parm.file_hdr = &file_hdr;
index 3b725fc668c2fafcfb259b516c0d0b66733320a8..d89733b613f27a83b353cf845081b24bbb9ec0f6 100644 (file)
@@ -320,12 +320,13 @@ void save_svg_data(char *data, char **out, int *outsize)
  *             element in array of chars.
  ***************************************************************************
  */
-void lnappend(unsigned long timetag, double value, char **out, int *outsize, int restart)
+void lnappend(unsigned long long timetag, double value, char **out, int *outsize,
+             int restart)
 {
        char data[128];
 
        /* Prepare additional graph definition data */
-       snprintf(data, 128, " %c%lu,%.2f", restart ? 'M' : 'L', timetag, value);
+       snprintf(data, 128, " %c%llu,%.2f", restart ? 'M' : 'L', timetag, value);
        data[127] = '\0';
 
        save_svg_data(data, out, outsize);
@@ -352,13 +353,13 @@ void lnappend(unsigned long timetag, double value, char **out, int *outsize, int
  *             element in array of chars.
  ***************************************************************************
  */
-void lniappend(unsigned long timetag, unsigned long value, char **out, int *outsize,
-              int restart)
+void lniappend(unsigned long long timetag, unsigned long value, char **out,
+              int *outsize, int restart)
 {
        char data[128];
 
        /* Prepare additional graph definition data */
-       snprintf(data, 128, " %c%lu,%lu", restart ? 'M' : 'L', timetag, value);
+       snprintf(data, 128, " %c%llu,%lu", restart ? 'M' : 'L', timetag, value);
        data[127] = '\0';
 
        save_svg_data(data, out, outsize);
@@ -386,8 +387,8 @@ void lniappend(unsigned long timetag, unsigned long value, char **out, int *outs
  *             element in array of chars.
  ***************************************************************************
  */
-void brappend(unsigned long timetag, double offset, double value, char **out, int *outsize,
-             unsigned long dt)
+void brappend(unsigned long long timetag, double offset, double value, char **out,
+             int *outsize, unsigned long long dt)
 {
        char data[128];
 
@@ -396,7 +397,7 @@ void brappend(unsigned long timetag, double offset, double value, char **out, in
                /* Dont draw a flat rectangle! */
                return;
 
-       snprintf(data, 128, "<rect x=\"%lu\" y=\"%.2f\" height=\"%.2f\" width=\"%lu\"/>",
+       snprintf(data, 128, "<rect x=\"%llu\" y=\"%.2f\" height=\"%.2f\" width=\"%llu\"/>",
                 timetag - dt, MINIMUM(offset, 100.0), MINIMUM(value, (100.0 - offset)), dt);
        data[127] = '\0';
 
@@ -429,8 +430,8 @@ void brappend(unsigned long timetag, double offset, double value, char **out, in
  *             element in array of chars.
  ***************************************************************************
  */
-void cpuappend(unsigned long timetag, double *offset, double value, char **out, int *outsize,
-              unsigned long dt, double *spmin, double *spmax)
+void cpuappend(unsigned long long timetag, double *offset, double value, char **out,
+              int *outsize, unsigned long long dt, double *spmin, double *spmax)
 {
        /* Save min and max values */
        if (value < *spmin) {
@@ -472,8 +473,9 @@ void cpuappend(unsigned long timetag, double *offset, double value, char **out,
  * @spmax      Max value for this metric.
  ***************************************************************************
  */
-void recappend(unsigned long timetag, double p_value, double value, char **out, int *outsize,
-              int restart, unsigned long dt, double *spmin, double *spmax)
+void recappend(unsigned long long timetag, double p_value, double value, char **out,
+              int *outsize, int restart, unsigned long long dt,
+              double *spmin, double *spmax)
 {
        char data[128], data1[128], data2[128];
 
@@ -486,14 +488,14 @@ void recappend(unsigned long timetag, double p_value, double value, char **out,
        }
        /* Prepare additional graph definition data */
        if (restart) {
-               snprintf(data1, 128, " M%lu,%.2f", timetag - dt, p_value);
+               snprintf(data1, 128, " M%llu,%.2f", timetag - dt, p_value);
                data1[127] = '\0';
        }
        if (p_value != value) {
-               snprintf(data2, 128, " L%lu,%.2f", timetag, value);
+               snprintf(data2, 128, " L%llu,%.2f", timetag, value);
                data2[127] = '\0';
        }
-       snprintf(data, 128, "%s L%lu,%.2f%s", restart ? data1 : "", timetag, p_value,
+       snprintf(data, 128, "%s L%llu,%.2f%s", restart ? data1 : "", timetag, p_value,
                 p_value != value ? data2 : "");
        data[127] = '\0';