]> granicus.if.org Git - sysstat/commitdiff
sadf: Make 'debug' option independent from RAW output format
authorSebastien GODARD <sysstat@users.noreply.github.com>
Sat, 16 Jan 2021 17:53:37 +0000 (18:53 +0100)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Sat, 16 Jan 2021 17:53:37 +0000 (18:53 +0100)
Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
format.c
sa.h
sa_common.c
sadf.c
sadf.h
sar.c

index 7f0797c62c8917434fa71a0c32360be6cf5f3584..78cd1d89544509a82bb32643ecef52f1f928a679 100644 (file)
--- 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 afdaf03ddb50f5816eeeeb9e97c019cec167b9d6..7bd747222915fae496ebc7d614d93be27e706964 100644 (file)
--- a/sa.h
+++ b/sa.h
 #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)
 #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)
 /* 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
index f20c164744a0b3c351d81f7760aa811816f48ce3..a4131e23665f8c8e1dc447d26313f52c066669ec 100644 (file)
@@ -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 806e32f884251d2cdb3381e5b50699673e71ce22..61fafb65a5a34627b3a5b0f8552a1d97a9f38453 100644 (file)
--- 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 1a2d22be565c777b21ae33399c5f211bf9b78674..87cd3414103a8ea44ca8e6ee7e26df112213c6ec 100644 (file)
--- a/sadf.h
+++ b/sadf.h
  ***************************************************************************
  */
 
-/* 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 5138113981c79f6c087624805da94a7958a43d68..45dc1beedf8605f7801d8019dab2e64787d2cdbf 100644 (file)
--- 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))