sar and sadf had the same functions with almost the same features.
Merge them.
Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
#define S_F_COMMENT 0x00001000
#define S_F_PERSIST_NAME 0x00002000
#define S_F_LOCAL_TIME 0x00004000
+#define S_F_PREFD_TIME_OUTPUT 0x00008000
#define WANT_SINCE_BOOT(m) (((m) & S_F_SINCE_BOOT) == S_F_SINCE_BOOT)
#define WANT_SA_ROTAT(m) (((m) & S_F_SA_ROTAT) == S_F_SA_ROTAT)
#define DISPLAY_COMMENT(m) (((m) & S_F_COMMENT) == S_F_COMMENT)
#define DISPLAY_PERSIST_NAME_S(m) (((m) & S_F_PERSIST_NAME) == S_F_PERSIST_NAME)
#define PRINT_LOCAL_TIME(m) (((m) & S_F_LOCAL_TIME) == S_F_LOCAL_TIME)
+#define USE_PREFD_TIME_OUTPUT(m) (((m) & S_F_PREFD_TIME_OUTPUT) == S_F_PREFD_TIME_OUTPUT)
#define AO_F_NULL 0x00000000
set_default_file(char *, int, int);
extern void
set_hdr_rectime(unsigned int, struct tm *, struct file_header *);
+extern void
+ set_record_timestamp_string(unsigned int, struct record_header *,
+ char *, char *, int, struct tm *);
#endif /* _SA_H */
return rc;
}
+
+/*
+ ***************************************************************************
+ * Set current record's timestamp strings (date and time) using the time
+ * data saved in @rectime structure. The string may be the number of seconds
+ * since the epoch if flag S_F_SEC_EPOCH has been set.
+ *
+ * IN:
+ * @l_flags Flags indicating the type of time expected by the user.
+ * S_F_SEC_EPOCH means the time should be expressed in seconds
+ * since the epoch (01/01/1970).
+ * @record_hdr Record header containing the number of seconds since the
+ * epoch.
+ * @cur_date String where timestamp's date will be saved. May be NULL.
+ * @cur_time String where timestamp's time will be saved.
+ * @len Maximum length of timestamp strings.
+ * @rectime Structure with current timestamp (expressed in local time or
+ * in UTC depending on whether options -T or -t have been used
+ * or not) that should be broken down in date and time strings.
+ *
+ * OUT:
+ * @cur_date Timestamp's date string (if expected).
+ * @cur_time Timestamp's time string. May contain the number of seconds
+ * since the epoch (01-01-1970) if corresponding option has
+ * been used.
+ ***************************************************************************
+*/
+void set_record_timestamp_string(unsigned int l_flags, struct record_header *record_hdr,
+ char *cur_date, char *cur_time, int len, struct tm *rectime)
+{
+ /* Set cur_time date value */
+ if (PRINT_SEC_EPOCH(l_flags) && cur_date) {
+ sprintf(cur_time, "%ld", record_hdr->ust_time);
+ strcpy(cur_date, "");
+ }
+ else {
+ /*
+ * If options -T or -t have been used then cur_time is
+ * expressed in local time. Else it is expressed in UTC.
+ */
+ if (cur_date) {
+ strftime(cur_date, len, "%Y-%m-%d", rectime);
+ }
+ if (USE_PREFD_TIME_OUTPUT(l_flags)) {
+ strftime(cur_time, len, "%X", rectime);
+ }
+ else {
+ strftime(cur_time, len, "%H:%M:%S", rectime);
+ }
+ }
+}
}
}
-/*
- ***************************************************************************
- * Set current record's timestamp strings (date and time). This timestamp is
- * expressed in UTC or in local time, depending on whether options -T or -t
- * have been used or not.
- *
- * IN:
- * @curr Index in array for current sample statistics.
- * @cur_date String where timestamp's date will be saved.
- * @cur_time String where timestamp's time will be saved.
- * @len Maximum length of timestamp strings.
- * @rectime Structure with current timestamp (expressed in local time or
- * in UTC depending on whether options -T or -t have been used
- * or not) that should be broken down in date and time strings.
- *
- * OUT:
- * @cur_date Timestamp's date string.
- * @cur_time Timestamp's time string. May contain the number of seconds
- * since the epoch (01-01-1970) if option -U has been used.
- ***************************************************************************
-*/
-void set_record_timestamp_string(int curr, char *cur_date, char *cur_time, int len,
- struct tm *rectime)
-{
- /* Set cur_time date value */
- if (PRINT_SEC_EPOCH(flags)) {
- sprintf(cur_time, "%ld", record_hdr[curr].ust_time);
- strcpy(cur_date, "");
- }
- else {
- /*
- * If options -T or -t have been used then cur_time is
- * expressed in local time. Else it is expressed in UTC.
- */
- strftime(cur_date, len, "%Y-%m-%d", rectime);
- strftime(cur_time, len, "%H:%M:%S", rectime);
- }
-}
-
/*
***************************************************************************
* Print tabulations
}
else {
/* Set date and time strings to be displayed for current record */
- set_record_timestamp_string(curr, cur_date, cur_time, 32, rectime);
+ set_record_timestamp_string(flags, &record_hdr[curr],
+ cur_date, cur_time, 32, rectime);
}
if (rtype == R_RESTART) {
}
/* Set current timestamp string */
- set_record_timestamp_string(curr, cur_date, cur_time, 32, rectime);
+ set_record_timestamp_string(flags, &record_hdr[curr],
+ cur_date, cur_time, 32, rectime);
write_mech_stats(curr, dt, itv, g_itv, cur_date, cur_time, act_id);
}
/* Set date and time strings for current record */
- set_record_timestamp_string(curr, cur_date, cur_time, 32, rectime);
+ set_record_timestamp_string(flags, &record_hdr[curr],
+ cur_date, cur_time, 32, rectime);
if (*fmt[f_position]->f_timestamp) {
(*fmt[f_position]->f_timestamp)(&tab, F_BEGIN, cur_date, cur_time,
return rc;
}
-/*
- ***************************************************************************
- * Set current record's timestamp string.
- *
- * IN:
- * @curr Index in array for current sample statistics.
- * @len Maximum length of timestamp string.
- *
- * OUT:
- * @cur_time Timestamp string.
- *
- * RETURNS:
- * 1 if an error was detected, or 0 otherwise.
- ***************************************************************************
-*/
-int set_record_timestamp_string(int curr, char *cur_time, int len)
-{
- /* Fill timestamp structure */
- if (sa_get_record_timestamp_struct(flags + S_F_LOCAL_TIME, &record_hdr[curr],
- &rectime, NULL))
- /* Error detected */
- return 1;
-
- /* Set cur_time date value */
- strftime(cur_time, len, "%X", &rectime);
-
- return 0;
-}
-
/*
***************************************************************************
* Print statistics average.
return 0;
}
- /* Set previous timestamp */
- if (set_record_timestamp_string(!curr, timestamp[!curr], 16))
+ /* Get then set previous timestamp */
+ if (sa_get_record_timestamp_struct(flags + S_F_LOCAL_TIME, &record_hdr[!curr],
+ &rectime, NULL))
return 0;
- /* Set current timestamp */
- if (set_record_timestamp_string(curr, timestamp[curr], 16))
+ set_record_timestamp_string(S_F_PREFD_TIME_OUTPUT, &record_hdr[!curr],
+ NULL, timestamp[!curr], 16, &rectime);
+
+ /* Get then set current timestamp */
+ if (sa_get_record_timestamp_struct(flags + S_F_LOCAL_TIME, &record_hdr[curr],
+ &rectime, NULL))
return 0;
+ set_record_timestamp_string(S_F_PREFD_TIME_OUTPUT, &record_hdr[curr],
+ NULL, timestamp[curr], 16, &rectime);
/* Check if we are beginning a new day */
if (use_tm_start && record_hdr[!curr].ust_time &&
int dp = 1;
unsigned int new_cpu_nr;
- if (set_record_timestamp_string(curr, cur_time, 26))
+ if (sa_get_record_timestamp_struct(flags + S_F_LOCAL_TIME, &record_hdr[curr],
+ &rectime, NULL))
return 0;
+ set_record_timestamp_string(S_F_PREFD_TIME_OUTPUT, &record_hdr[curr],
+ NULL, cur_time, 26, &rectime);
/* The record must be in the interval specified by -s/-e options */
if ((use_tm_start && (datecmp(&rectime, &tm_start) < 0)) ||