From 969d736be6b980a6c9dde099e5fa66f618d2d52a Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Mon, 30 Sep 2019 14:21:34 +0200 Subject: [PATCH] sadf: Enhance raw format ouput Now also display records header contents in debug mode. Signed-off-by: Sebastien GODARD --- sa.h | 5 ++--- sa_common.c | 11 ++++++++++- sadf.c | 4 ++-- sar.c | 6 +++--- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/sa.h b/sa.h index 33ea525..37da7a9 100644 --- a/sa.h +++ b/sa.h @@ -99,8 +99,6 @@ #define S_F_LOCAL_TIME 0x00004000 #define S_F_PREFD_TIME_OUTPUT 0x00008000 #define S_F_SVG_SKIP 0x00010000 -/* Same value as S_F_SVG_SKIP above. Used for a different output format */ -#define S_F_RAW_DEBUG_MODE 0x00010000 #define S_F_SVG_AUTOSCALE 0x00020000 #define S_F_SVG_ONE_DAY 0x00040000 #define S_F_SVG_SHOW_IDLE 0x00080000 @@ -115,6 +113,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 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) @@ -1505,7 +1504,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); + int, size_t, unsigned int); void reallocate_all_buffers (struct activity *, __nr_t); void replace_nonprintable_char diff --git a/sa_common.c b/sa_common.c index 8bbe3a6..969c236 100644 --- a/sa_common.c +++ b/sa_common.c @@ -1526,6 +1526,7 @@ int skip_extra_struct(int ifd, int endian_mismatch, int arch_64) * @oneof Set to EOF_CONT if an unexpected end of file should not make * sadf stop. Default behavior is to stop on unexpected EOF. * @b_size @buffer size. + * @flags Flags for common options and system state. * * OUT: * @record_hdr Record header for current sample. @@ -1538,7 +1539,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) + int oneof, size_t b_size, unsigned int flags) { int rc; @@ -1558,6 +1559,14 @@ int read_record_hdr(int ifd, void *buffer, struct record_header *record_hdr, swap_struct(rec_types_nr, record_hdr, arch_64); } + /* Raw output in debug mode */ + if (DISPLAY_DEBUG_MODE(flags)) { + 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, + record_hdr->hour, record_hdr->minute, record_hdr->second); + } + /* * Skip unknown extra structures if present. * This will be done later for R_COMMENT and R_RESTART records, as extra structures diff --git a/sadf.c b/sadf.c index 496665c..619d3d1 100644 --- a/sadf.c +++ b/sadf.c @@ -240,7 +240,7 @@ 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))) != 0) + arch_64, endian_mismatch, oneof, sizeof(rec_hdr_tmp), flags)) != 0) /* End of sa file */ return rc; @@ -749,7 +749,7 @@ int generic_write_stats(int curr, int use_tm_start, int use_tm_end, int reset, else if (format == F_RAW_OUTPUT) { /* Raw output */ if (DISPLAY_DEBUG_MODE(flags)) { - printf("# %s: %d/%d (%d)\n", act[i]->name, + printf("# name; %s; nr_curr; %d; nr_alloc; %d; nr_ini; %d\n", act[i]->name, act[i]->nr[curr], act[i]->nr_allocated, act[i]->nr_ini); } diff --git a/sar.c b/sar.c index 70ce79c..964accf 100644 --- a/sar.c +++ b/sar.c @@ -780,7 +780,7 @@ 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); + &file_hdr, arch_64, endian_mismatch, UEOF_STOP, b_size, flags); rtype = record_hdr[*curr].record_type; if (!*eosaf && (rtype != R_RESTART) && (rtype != R_COMMENT)) { @@ -1015,7 +1015,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))) { + arch_64, endian_mismatch, UEOF_STOP, sizeof(rec_hdr_tmp), flags)) { /* End of sa data file */ return; } @@ -1113,7 +1113,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)); + &file_hdr, arch_64, endian_mismatch, UEOF_STOP, sizeof(rec_hdr_tmp), flags); rtype = record_hdr[curr].record_type; if (!eosaf && (rtype != R_RESTART) && (rtype != R_COMMENT)) { -- 2.40.0