]> granicus.if.org Git - sysstat/blobdiff - sar.c
sar/sadf: Add extra flexibility in case of a change of file format
[sysstat] / sar.c
diff --git a/sar.c b/sar.c
index f0db4adb2c3423501f902246e38c1cada79c7856..70ce79c1b0a94beb4a59febf5937d5575994552e 100644 (file)
--- a/sar.c
+++ b/sar.c
@@ -126,7 +126,7 @@ void usage(char *progname)
                          "[ -m { <keyword> [,...] | ALL } ] [ -n { <keyword> [,...] | ALL } ]\n"
                          "[ --dev=<dev_list> ] [ --fs=<fs_list> ] [ --iface=<iface_list> ]\n"
                          "[ --dec={ 0 | 1 | 2 } ] [ --help ] [ --human ] [ --sadc ]\n"
-                         "[ -j { ID | LABEL | PATH | UUID | ... } ]\n"
+                         "[ -j { SID | ID | LABEL | PATH | UUID | ... } ]\n"
                          "[ -f [ <filename> ] | -o [ <filename> ] | -[0-9]+ ]\n"
                          "[ -i <interval> ] [ -s [ <hh:mm[:ss]> ] ] [ -e [ <hh:mm[:ss]> ] ]\n"));
        exit(1);
@@ -427,7 +427,7 @@ void write_stats_avg(int curr, int read_from_file, unsigned int act_id)
 int write_stats(int curr, int read_from_file, long *cnt, int use_tm_start,
                int use_tm_end, int reset, unsigned int act_id, int reset_cd)
 {
-       int i;
+       int i, prev_hour;
        unsigned long long itv;
        static int cross_day = 0;
 
@@ -457,6 +457,7 @@ int write_stats(int curr, int read_from_file, long *cnt, int use_tm_start,
        if (sa_get_record_timestamp_struct(flags + S_F_LOCAL_TIME, &record_hdr[!curr],
                                           &rectime))
                return 0;
+       prev_hour = rectime.tm_hour;
        set_record_timestamp_string(flags, &record_hdr[!curr],
                                    NULL, timestamp[!curr], TIMESTAMP_LEN, &rectime);
 
@@ -467,10 +468,15 @@ int write_stats(int curr, int read_from_file, long *cnt, int use_tm_start,
        set_record_timestamp_string(flags, &record_hdr[curr],
                                    NULL, timestamp[curr], TIMESTAMP_LEN, &rectime);
 
-       /* Check if we are beginning a new day */
+       /*
+        * Check if we are beginning a new day.
+        * Use rectime.tm_hour and prev_hour instead of record_hdr[].hour for comparison
+        * to take into account the current timezone (hours displayed will depend on the
+        * TZ variable value).
+        */
        if (use_tm_start && record_hdr[!curr].ust_time &&
            (record_hdr[curr].ust_time > record_hdr[!curr].ust_time) &&
-           (record_hdr[curr].hour < record_hdr[!curr].hour)) {
+           (rectime.tm_hour < prev_hour)) {
                cross_day = 1;
        }
 
@@ -835,6 +841,12 @@ void handle_curr_act_stats(int ifd, off_t fpos, int *curr, long *cnt, int *eosaf
        }
        while (*cnt && !*eosaf && (rtype != R_RESTART));
 
+       /*
+        * At this moment, if we had a R_RESTART record, we still haven't read
+        * the number of CPU following it (nor the possible extra structures).
+        * But in this case, we always have @cnt != 0.
+        */
+
        if (davg) {
                write_stats_avg(!*curr, USE_SA_FILE, act_id);
        }
@@ -1088,9 +1100,16 @@ void read_stats_from_file(char from_file[])
                                }
                        }
                }
-
                if (!cnt) {
-                       /* Go to next Linux restart, if possible */
+                       /*
+                        * Go to next Linux restart, if possible.
+                        * Note: If we have @cnt == 0 then the last record we read was not a R_RESTART one
+                        * (else we would have had @cnt != 0, i.e. we would have stopped reading previous activity
+                        * because such a R_RESTART record would have been read, not because all the <count> lines
+                        * had been printed).
+                        * Remember @cnt is decremented only when a real line of stats have been displayed
+                        * (not when a special record has been read).
+                        */
                        do {
                                /* Read next record header */
                                eosaf = read_record_hdr(ifd, rec_hdr_tmp, &record_hdr[curr],
@@ -1317,7 +1336,7 @@ int main(int argc, char **argv)
 
                else if (!strcmp(argv[opt], "-I")) {
                        /* Parse -I option */
-                       if (parse_sar_I_opt(argv, &opt, act)) {
+                       if (parse_sar_I_opt(argv, &opt, &flags, act)) {
                                usage(argv[0]);
                        }
                }
@@ -1490,6 +1509,10 @@ int main(int argc, char **argv)
                fprintf(stderr, _("-f and -o options are mutually exclusive\n"));
                exit(1);
        }
+       if (USE_OPTION_A(flags)) {
+               /* Set -P ALL -I ALL if needed */
+               set_bitmaps(act, &flags);
+       }
        /* Use time start or option -i only when reading stats from a file */
        if ((tm_start.use || INTERVAL_SET(flags)) && !from_file[0]) {
                fprintf(stderr,
@@ -1594,7 +1617,7 @@ int main(int argc, char **argv)
 
 #ifdef TEST
                if (__unix_time) {
-                       sprintf(ltemp, "--unix_time=%llu", __unix_time);
+                       sprintf(ltemp, "--unix_time=%ld", __unix_time);
                        salloc(args_idx++, ltemp);
                }
 #endif