]> granicus.if.org Git - sysstat/commitdiff
Add new flag to read_next_sample() function
authorSebastien GODARD <sysstat@users.noreply.github.com>
Fri, 5 Feb 2016 08:02:09 +0000 (09:02 +0100)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Fri, 5 Feb 2016 08:02:09 +0000 (09:02 +0100)
read_next_sample() function didn't fill the timestamp for special
records (COMMENT or RESTART ones) that had to be ignored.
So add a new flag (SET_TIMESTAMPS) to tell read_next_sample() function
to set the timestamps for special records when this is needed.

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

diff --git a/sadf.c b/sadf.c
index e0fa3ca51745ccc9d2e5c120db4511ef6b62d724..54e05419897cccdffdd3b884eadfbe45c10b4ab1 100644 (file)
--- a/sadf.c
+++ b/sadf.c
@@ -239,16 +239,16 @@ void xprintf(int nr_tab, const char *fmtf, ...)
 
 /*
  ***************************************************************************
- * Read next sample statistics. If it's a special record (RESTART or COMMENT)
- * then display it if requested. Also fill timestamps structures.
+ * Read next sample statistics. If it's a special record (R_RESTART or
+ * R_COMMENT) then display it if requested. Also fill timestamps structures.
  *
  * IN:
  * @ifd                File descriptor
- * @action     Flags indicating if special records should be displayed or not.
+ * @action     Flags indicating if special records should be displayed or
+ *             not.
  *
  * @curr       Index in array for current sample statistics.
  * @file       System activity data file name (name of file being read).
- * @rtype      Record type (RESTART, COMMENT, etc.)
  * @tab                Number of tabulations to print.
  * @file_actlst        List of (known or unknown) activities in file.
  * @file_magic System activity file magic header.
@@ -259,11 +259,17 @@ void xprintf(int nr_tab, const char *fmtf, ...)
  *             saved for current record.
  *
  * OUT:
- * @rectime    Structure where timestamp (expressed in local time or in UTC
- *             depending on whether options -T/-t have been used or not) has
- *             been saved for current record.
- * @loctime    Structure where timestamp (expressed in local time) has been
- *             saved for current record.
+ * @rtype       Type of record read (R_RESTART, R_COMMENT, etc.)
+ * @rectime     Structure where timestamp (expressed in local time or in UTC
+ *              depending on options used) has been saved for current record.
+ *              If current record was a special one (RESTART or COMMENT) and
+ *              noted to be ignored, then the timestamp is saved only if
+ *              explicitly told to do so with the SET_TIMESTAMPS action flag.
+ * @loctime     Structure where timestamp (expressed in local time) has been
+ *              saved for current record.
+ *              If current record was a special one (RESTART or COMMENT) and
+ *              noted to be ignored, then the timestamp is saved only if
+ *              explicitly told to do so with the SET_TIMESTAMPS action flag.
  *
  * RETURNS:
  * TRUE if end of file has been reached.
@@ -286,6 +292,10 @@ int read_next_sample(int ifd, int action, int curr, char *file, int *rtype, int
                                if (lseek(ifd, MAX_COMMENT_LEN, SEEK_CUR) < MAX_COMMENT_LEN) {
                                        perror("lseek");
                                }
+                               if (action & SET_TIMESTAMPS) {
+                                       sa_get_record_timestamp_struct(flags, &record_hdr[curr],
+                                                                      rectime, loctime);
+                               }
                        }
                        else {
                                /* Display COMMENT record */
@@ -306,6 +316,10 @@ int read_next_sample(int ifd, int action, int curr, char *file, int *rtype, int
                                        read_vol_act_structures(ifd, act, file, file_magic,
                                                                file_hdr.sa_vol_act_nr);
                                }
+                               if (action & SET_TIMESTAMPS) {
+                                       sa_get_record_timestamp_struct(flags, &record_hdr[curr],
+                                                                      rectime, loctime);
+                               }
                        }
                        else {
                                /* Display RESTART record */
diff --git a/sadf.h b/sadf.h
index b94ac09a6ebf389eee93c9651f428db1a8d4db9d..1c69fa2b64a347f329ce47a05ce4b3cd79cb6d3d 100644 (file)
--- a/sadf.h
+++ b/sadf.h
@@ -19,6 +19,7 @@
 #define IGNORE_RESTART         1
 #define DONT_READ_VOLATILE     2
 #define IGNORE_COMMENT         4
+#define SET_TIMESTAMPS         8
 
 /*
  ***************************************************************************