From fc4da4bb5706f92868b54eda6e350d22653cd9bd Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Sat, 16 Jan 2021 18:53:37 +0100 Subject: [PATCH] sadf: Make 'debug' option independent from RAW output format Signed-off-by: Sebastien GODARD --- format.c | 2 +- sa.h | 28 +++++++++++++++++++++++++--- sa_common.c | 5 +++-- sadf.c | 5 +++-- sadf.h | 16 ---------------- sar.c | 7 ++++--- 6 files changed, 36 insertions(+), 27 deletions(-) diff --git a/format.c b/format.c index 7f0797c..78cd1d8 100644 --- a/format.c +++ b/format.c @@ -188,7 +188,7 @@ struct report_format *fmt[NR_FMT] = { * (RESTART and COMMENT) records. */ struct report_format sar_fmt = { - .id = 0, + .id = F_SAR_OUTPUT, .options = 0, .f_header = NULL, .f_statistics = NULL, diff --git a/sa.h b/sa.h index afdaf03..7bd7472 100644 --- a/sa.h +++ b/sa.h @@ -117,7 +117,7 @@ #define S_F_OPTION_A 0x10000000 #define S_F_OPTION_P 0x20000000 #define S_F_OPTION_I 0x40000000 -#define S_F_RAW_DEBUG_MODE 0x80000000 +#define S_F_DEBUG_MODE 0x80000000 #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) @@ -138,7 +138,7 @@ #define USE_PREFD_TIME_OUTPUT(m) (((m) & S_F_PREFD_TIME_OUTPUT) == S_F_PREFD_TIME_OUTPUT) #define SKIP_EMPTY_VIEWS(m) (((m) & S_F_SVG_SKIP) == S_F_SVG_SKIP) #define DISPLAY_ZERO_OMIT(m) (((m) & S_F_ZERO_OMIT) == S_F_ZERO_OMIT) -#define DISPLAY_DEBUG_MODE(m) (((m) & S_F_RAW_DEBUG_MODE) == S_F_RAW_DEBUG_MODE) +#define DISPLAY_DEBUG_MODE(m) (((m) & S_F_DEBUG_MODE) == S_F_DEBUG_MODE) #define AUTOSCALE_ON(m) (((m) & S_F_SVG_AUTOSCALE) == S_F_SVG_AUTOSCALE) #define DISPLAY_ONE_DAY(m) (((m) & S_F_SVG_ONE_DAY) == S_F_SVG_ONE_DAY) #define DISPLAY_IDLE(m) (((m) & S_F_SVG_SHOW_IDLE) == S_F_SVG_SHOW_IDLE) @@ -333,6 +333,28 @@ /* Type for all functions displaying statistics */ #define __print_funct_t void +/* + *************************************************************************** + * Output formats for sadf + *************************************************************************** + */ + +/* Number of output formats */ +#define NR_FMT 9 + +/* Output formats */ +#define F_SAR_OUTPUT 0 +#define F_DB_OUTPUT 1 +#define F_HEADER_OUTPUT 2 +#define F_PPC_OUTPUT 3 +#define F_XML_OUTPUT 4 +#define F_JSON_OUTPUT 5 +#define F_CONV_OUTPUT 6 +#define F_SVG_OUTPUT 7 +#define F_RAW_OUTPUT 8 +#define F_PCP_OUTPUT 9 + + /* Structure for SVG specific parameters */ struct svg_parm { unsigned long long dt; /* Interval of time for current sample */ @@ -1549,7 +1571,7 @@ __nr_t read_nr_value (int, char *, struct file_magic *, int, int, int); int read_record_hdr (int, void *, struct record_header *, struct file_header *, int, int, - int, size_t, uint64_t); + int, size_t, uint64_t, struct report_format *); void reallocate_all_buffers (struct activity *, __nr_t); void replace_nonprintable_char diff --git a/sa_common.c b/sa_common.c index f20c164..a4131e2 100644 --- a/sa_common.c +++ b/sa_common.c @@ -1456,6 +1456,7 @@ int skip_extra_struct(int ifd, int endian_mismatch, int arch_64) * sadf stop. Default behavior is to stop on unexpected EOF. * @b_size @buffer size. * @flags Flags for common options and system state. + * @ofmt Pointer on report output format structure. * * OUT: * @record_hdr Record header for current sample. @@ -1468,7 +1469,7 @@ int skip_extra_struct(int ifd, int endian_mismatch, int arch_64) */ int read_record_hdr(int ifd, void *buffer, struct record_header *record_hdr, struct file_header *file_hdr, int arch_64, int endian_mismatch, - int oneof, size_t b_size, uint64_t flags) + int oneof, size_t b_size, uint64_t flags, struct report_format *ofmt) { int rc; @@ -1489,7 +1490,7 @@ int read_record_hdr(int ifd, void *buffer, struct record_header *record_hdr, } /* Raw output in debug mode */ - if (DISPLAY_DEBUG_MODE(flags)) { + if (DISPLAY_DEBUG_MODE(flags) && (ofmt->id == F_RAW_OUTPUT)) { printf("# uptime_cs; %llu; ust_time; %llu; extra_next; %u; record_type; %d; HH:MM:SS; %02d:%02d:%02d\n", record_hdr->uptime_cs, record_hdr->ust_time, record_hdr->extra_next, record_hdr->record_type, diff --git a/sadf.c b/sadf.c index 806e32f..61fafb6 100644 --- a/sadf.c +++ b/sadf.c @@ -243,7 +243,8 @@ int read_next_sample(int ifd, int action, int curr, char *file, int *rtype, int /* Read current record */ if ((rc = read_record_hdr(ifd, rec_hdr_tmp, &record_hdr[curr], &file_hdr, - arch_64, endian_mismatch, oneof, sizeof(rec_hdr_tmp), flags)) != 0) + arch_64, endian_mismatch, oneof, sizeof(rec_hdr_tmp), flags, + fmt[f_position])) != 0) /* End of sa file */ return rc; @@ -1608,7 +1609,7 @@ int main(int argc, char **argv) flags |= S_F_SVG_SHOW_INFO; } else if (!strcmp(t, K_DEBUG)) { - flags |= S_F_RAW_DEBUG_MODE; + flags |= S_F_DEBUG_MODE; } else if (!strncmp(t, K_HEIGHT, strlen(K_HEIGHT))) { v = t + strlen(K_HEIGHT); diff --git a/sadf.h b/sadf.h index 1a2d22b..87cd341 100644 --- a/sadf.h +++ b/sadf.h @@ -27,22 +27,6 @@ *************************************************************************** */ -/* Number of output formats */ -#define NR_FMT 9 - -/* Output formats */ -#define F_DB_OUTPUT 1 -#define F_HEADER_OUTPUT 2 -#define F_PPC_OUTPUT 3 -#define F_XML_OUTPUT 4 -#define F_JSON_OUTPUT 5 -#define F_CONV_OUTPUT 6 -#define F_SVG_OUTPUT 7 -#define F_RAW_OUTPUT 8 -#define F_PCP_OUTPUT 9 - -/* Format options */ - /* * Indicate that a decimal point should be used to make output * locale independent. diff --git a/sar.c b/sar.c index 5138113..45dc1be 100644 --- a/sar.c +++ b/sar.c @@ -788,7 +788,8 @@ void handle_curr_act_stats(int ifd, off_t fpos, int *curr, long *cnt, int *eosaf * Start with reading current sample's record header. */ *eosaf = read_record_hdr(ifd, rec_hdr_tmp, &record_hdr[*curr], - &file_hdr, arch_64, endian_mismatch, UEOF_STOP, b_size, flags); + &file_hdr, arch_64, endian_mismatch, UEOF_STOP, b_size, + flags, &sar_fmt); rtype = record_hdr[*curr].record_type; if ((lines >= rows) || !lines) { @@ -1032,7 +1033,7 @@ void read_stats_from_file(char from_file[]) */ do { if (read_record_hdr(ifd, rec_hdr_tmp, &record_hdr[0], &file_hdr, - arch_64, endian_mismatch, UEOF_STOP, sizeof(rec_hdr_tmp), flags)) { + arch_64, endian_mismatch, UEOF_STOP, sizeof(rec_hdr_tmp), flags, &sar_fmt)) { /* End of sa data file */ return; } @@ -1130,7 +1131,7 @@ void read_stats_from_file(char from_file[]) do { /* Read next record header */ eosaf = read_record_hdr(ifd, rec_hdr_tmp, &record_hdr[curr], - &file_hdr, arch_64, endian_mismatch, UEOF_STOP, sizeof(rec_hdr_tmp), flags); + &file_hdr, arch_64, endian_mismatch, UEOF_STOP, sizeof(rec_hdr_tmp), flags, &sar_fmt); rtype = record_hdr[curr].record_type; if (eosaf || (rtype == R_RESTART)) -- 2.50.1