]> granicus.if.org Git - sysstat/commitdiff
sar: Fix sar -s/-e output on datafile spanning two days
authorSebastien GODARD <sysstat@users.noreply.github.com>
Tue, 13 Aug 2019 07:14:45 +0000 (09:14 +0200)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Tue, 13 Aug 2019 07:14:45 +0000 (09:14 +0200)
This patch fixes the output of the following command:

TZ=GMT ./sar -f tests/data-cd -s 23:59:58
Linux 1.2.3-TEST (SYSSTAT.TEST)  05/01/2019  _x86_64_ (8 CPU)

11:59:58 PM     CPU     %user     %nice   %system   %iowait    %steal     %idle
11:59:59 PM     all      2.28      0.00      1.93      0.50      0.00     95.29
12:00:00 AM     all      2.66     23.20      2.27      0.16      0.00     71.71
12:00:01 AM     all      6.53      9.63      4.42      0.54      0.00     78.89
Average:        all      4.01     13.45      3.02      0.39      0.00     79.13

Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
sar.c

diff --git a/sar.c b/sar.c
index 276b177221dbe7cf71f3df7f45143d94af768168..0b3848f64c04778aa92480a9421492561ffbabd9 100644 (file)
--- a/sar.c
+++ b/sar.c
@@ -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;
        }