]> granicus.if.org Git - sysstat/commitdiff
cifsiostat,iostat,sar: Add --pretty option
authorSebastien GODARD <sysstat@users.noreply.github.com>
Sat, 25 Jul 2020 13:15:53 +0000 (15:15 +0200)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Sat, 25 Jul 2020 13:15:53 +0000 (15:15 +0200)
This option makes the report easier to read by a human.
Please note that for sar, option -p is now equivalent to this one.
Use this option to display device names or network interface names
on the right of the report instead of the left (which can be
particularly useful for long names).

Also option -h is now equivalent to "--pretty --human".

Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
cifsiostat.c
cifsiostat.h
iostat.c
iostat.h
pr_stats.c
sa.h
sa_common.c
sadf.c
sar.c

index a5c77bce5af87c13079949866689eb75090d7100..ab404e91492544914fd2a471dd8b4d940c3e71ce 100644 (file)
@@ -293,7 +293,7 @@ void read_cifs_stat(int curr)
  */
 void write_cifs_stat_header(int *fctr)
 {
-       if (!DISPLAY_HUMAN_READ(flags)) {
+       if (!DISPLAY_PRETTY(flags)) {
                printf("Filesystem            ");
        }
        if (DISPLAY_KILOBYTES(flags)) {
@@ -309,7 +309,7 @@ void write_cifs_stat_header(int *fctr)
                *fctr = 1;
        }
        printf("    rops/s    wops/s         fo/s         fc/s         fd/s");
-       if (DISPLAY_HUMAN_READ(flags)) {
+       if (DISPLAY_PRETTY(flags)) {
                printf(" Filesystem");
        }
        printf("\n");
@@ -334,7 +334,7 @@ void write_cifs_stat(int curr, unsigned long long itv, int fctr,
 {
        double rbytes, wbytes;
 
-       if (!DISPLAY_HUMAN_READ(flags)) {
+       if (!DISPLAY_PRETTY(flags)) {
                cprintf_in(IS_STR, "%-22s", clist->name, 0);
        }
 
@@ -354,7 +354,7 @@ void write_cifs_stat(int curr, unsigned long long itv, int fctr,
                  S_VALUE(ionj->fopens, ioni->fopens, itv),
                  S_VALUE(ionj->fcloses, ioni->fcloses, itv),
                  S_VALUE(ionj->fdeletes, ioni->fdeletes, itv));
-       if (DISPLAY_HUMAN_READ(flags)) {
+       if (DISPLAY_PRETTY(flags)) {
                cprintf_in(IS_STR, " %s", clist->name, 0);
        }
        printf("\n");
@@ -515,6 +515,12 @@ int main(int argc, char **argv)
                        opt++;
                }
 
+               else if (!strcmp(argv[opt], "--pretty")) {
+                       /* Display an easy-to-read CIFS report */
+                       flags |= I_D_PRETTY;
+                       opt++;
+               }
+
                else if (!strncmp(argv[opt], "--dec=", 6) && (strlen(argv[opt]) == 7)) {
                        /* Get number of decimal places */
                        dplaces_nr = atoi(argv[opt] + 6);
@@ -530,8 +536,8 @@ int main(int argc, char **argv)
                                switch (*(argv[opt] + i)) {
 
                                case 'h':
-                                       /* Display an easy-to-read CIFS report. Also imply --human */
-                                       flags |= I_D_HUMAN_READ + I_D_UNIT;
+                                       /* Option -h is equivalent to --pretty --human */
+                                       flags |= I_D_PRETTY + I_D_UNIT;
                                        break;
 
                                case 'k':
index 891cc1de16ef6f517a5e5a679c9afcc4c2371fb3..a9409a3dd51f3120155acf82492edf9f5a224664 100644 (file)
 #define I_D_KILOBYTES          0x002
 #define I_D_MEGABYTES          0x004
 #define I_D_ISO                        0x008
-#define I_D_HUMAN_READ         0x010
+#define I_D_PRETTY             0x010
 #define I_D_DEBUG              0x020
 #define I_D_UNIT               0x040
 
-#define DISPLAY_TIMESTAMP(m)   (((m) & I_D_TIMESTAMP)     == I_D_TIMESTAMP)
-#define DISPLAY_KILOBYTES(m)   (((m) & I_D_KILOBYTES)     == I_D_KILOBYTES)
-#define DISPLAY_MEGABYTES(m)   (((m) & I_D_MEGABYTES)     == I_D_MEGABYTES)
-#define DISPLAY_ISO(m)         (((m) & I_D_ISO)           == I_D_ISO)
-#define DISPLAY_HUMAN_READ(m)  (((m) & I_D_HUMAN_READ)    == I_D_HUMAN_READ)
-#define DISPLAY_DEBUG(m)       (((m) & I_D_DEBUG)         == I_D_DEBUG)
-#define DISPLAY_UNIT(m)                (((m) & I_D_UNIT)          == I_D_UNIT)
+#define DISPLAY_TIMESTAMP(m)   (((m) & I_D_TIMESTAMP) == I_D_TIMESTAMP)
+#define DISPLAY_KILOBYTES(m)   (((m) & I_D_KILOBYTES) == I_D_KILOBYTES)
+#define DISPLAY_MEGABYTES(m)   (((m) & I_D_MEGABYTES) == I_D_MEGABYTES)
+#define DISPLAY_ISO(m)         (((m) & I_D_ISO)       == I_D_ISO)
+#define DISPLAY_PRETTY(m)      (((m) & I_D_PRETTY)    == I_D_PRETTY)
+#define DISPLAY_DEBUG(m)       (((m) & I_D_DEBUG)     == I_D_DEBUG)
+#define DISPLAY_UNIT(m)                (((m) & I_D_UNIT)      == I_D_UNIT)
 
 struct cifs_st {
        unsigned long long rd_bytes     __attribute__ ((aligned (8)));
index 211b4c29de1d5f17daec909eab656e21b4bf81c1..cc2bd65957f252b9f4306a091f2bea9c636c24f7 100644 (file)
--- a/iostat.c
+++ b/iostat.c
@@ -1069,7 +1069,7 @@ void write_disk_stat_header(int *fctr, int *tab, int hpart)
                return;
        }
 
-       if (!DISPLAY_HUMAN_READ(flags)) {
+       if (!DISPLAY_PRETTY(flags)) {
                printf("Device       ");
        }
        if (DISPLAY_EXTENDED(flags)) {
@@ -1107,7 +1107,7 @@ void write_disk_stat_header(int *fctr, int *tab, int hpart)
                               spc, units, spc, units, spc, units, spc, units, spc, units, spc, units);
                }
        }
-       if (DISPLAY_HUMAN_READ(flags)) {
+       if (DISPLAY_PRETTY(flags)) {
                printf(" Device");
        }
        printf("\n");
@@ -1143,7 +1143,7 @@ void write_plain_ext_stat(unsigned long long itv, int fctr, int hpart,
        if (d->dev_tp == T_GROUP)
                return;
 
-       if (!DISPLAY_HUMAN_READ(flags)) {
+       if (!DISPLAY_PRETTY(flags)) {
                cprintf_in(IS_STR, "%-13s", devname, 0);
        }
 
@@ -1280,7 +1280,7 @@ void write_plain_ext_stat(unsigned long long itv, int fctr, int hpart,
                }
        }
 
-       if (DISPLAY_HUMAN_READ(flags)) {
+       if (DISPLAY_PRETTY(flags)) {
                cprintf_in(IS_STR, " %s", devname, 0);
        }
        printf("\n");
@@ -1548,7 +1548,7 @@ void write_plain_basic_stat(unsigned long long itv, int fctr,
 {
        double rsectors, wsectors, dsectors;
 
-       if (!DISPLAY_HUMAN_READ(flags)) {
+       if (!DISPLAY_PRETTY(flags)) {
                cprintf_in(IS_STR, "%-13s", devname, 0);
        }
 
@@ -1592,7 +1592,7 @@ void write_plain_basic_stat(unsigned long long itv, int fctr,
                                                : (unsigned long long) dc_sec / fctr);
        }
 
-       if (DISPLAY_HUMAN_READ(flags)) {
+       if (DISPLAY_PRETTY(flags)) {
                cprintf_in(IS_STR, " %s", devname, 0);
        }
        printf("\n");
@@ -1748,7 +1748,7 @@ void write_stats(int curr, struct tm *rectime, int skip)
 
                memset(&iozero, 0, sizeof(struct io_stats));
 
-               if (DISPLAY_HUMAN_READ(flags) &&
+               if (DISPLAY_PRETTY(flags) &&
                    DISPLAY_EXTENDED(flags) &&
                    !DISPLAY_SHORT_OUTPUT(flags) &&
                    !DISPLAY_JSON_OUTPUT(flags)) {
@@ -2108,6 +2108,12 @@ int main(int argc, char **argv)
                        opt++;
                }
 
+               else if (!strcmp(argv[opt], "--pretty")) {
+                       /* Display an easy-to-read CIFS report */
+                       flags |= I_D_PRETTY;
+                       opt++;
+               }
+
 #ifdef TEST
                else if (!strncmp(argv[opt], "--getenv", 8)) {
                        __env = TRUE;
@@ -2153,11 +2159,8 @@ int main(int argc, char **argv)
                                fprintf(stderr, _("Invalid type of persistent device name\n"));
                                exit(1);
                        }
-                       /*
-                        * Persistent names are usually long: Display
-                        * them as human readable by default.
-                        */
-                       flags |= I_D_PERSIST_NAME + I_D_HUMAN_READ;
+                       /* Persistent names are usually long: Pretty display them */
+                       flags |= I_D_PERSIST_NAME + I_D_PRETTY;
                        opt++;
                }
 
@@ -2202,11 +2205,8 @@ int main(int argc, char **argv)
                                        break;
 
                                case 'h':
-                                       /*
-                                        * Display device utilization report
-                                        * in a human readable format. Also imply --human.
-                                        */
-                                       flags |= I_D_HUMAN_READ + I_D_UNIT;
+                                       /* Option -h is equivalent to --pretty --human */
+                                       flags |= I_D_PRETTY + I_D_UNIT;
                                        break;
 
                                case 'k':
index 264bc589edea89b2b1efc641ff006cf054500414..344700b558827b3d40770064a7b2d8bde58cf82f 100644 (file)
--- a/iostat.h
+++ b/iostat.h
@@ -21,7 +21,7 @@
 #define I_D_MEGABYTES          0x000200
 #define I_D_ALL_DEVICES                0x000400
 #define I_F_GROUP_DEFINED      0x000800
-#define I_D_HUMAN_READ         0x001000
+#define I_D_PRETTY             0x001000
 #define I_D_PERSIST_NAME       0x002000
 #define I_D_OMIT_SINCE_BOOT    0x004000
 #define I_D_JSON_OUTPUT                0x008000
@@ -43,7 +43,7 @@
 #define DISPLAY_UNFILTERED(m)          (((m) & I_D_UNFILTERED)       == I_D_UNFILTERED)
 #define DISPLAY_ALL_DEVICES(m)         (((m) & I_D_ALL_DEVICES)      == I_D_ALL_DEVICES)
 #define GROUP_DEFINED(m)               (((m) & I_F_GROUP_DEFINED)    == I_F_GROUP_DEFINED)
-#define DISPLAY_HUMAN_READ(m)          (((m) & I_D_HUMAN_READ)       == I_D_HUMAN_READ)
+#define DISPLAY_PRETTY(m)              (((m) & I_D_PRETTY)           == I_D_PRETTY)
 #define DISPLAY_PERSIST_NAME_I(m)      (((m) & I_D_PERSIST_NAME)     == I_D_PERSIST_NAME)
 #define DISPLAY_OMIT_SINCE_BOOT(m)     (((m) & I_D_OMIT_SINCE_BOOT)  == I_D_OMIT_SINCE_BOOT)
 #define DISPLAY_DEVMAP_NAME(m)         (((m) & I_D_DEVMAP_NAME)      == I_D_DEVMAP_NAME)
index 32b1dfaf4fb79a131de83eb4b10514b78b2470ed..e34575ece5b1c2e29ade4836d8f3fc6cbca1c7ef 100644 (file)
@@ -1022,7 +1022,7 @@ __print_funct_t print_disk_stats(struct activity *a, int prev, int curr,
        }
 
        if (dish || DISPLAY_ZERO_OMIT(flags)) {
-               print_hdr_line(timestamp[!curr], a, FIRST, DISPLAY_HUMAN_READ(flags) ? -1 : 0, 9);
+               print_hdr_line(timestamp[!curr], a, FIRST, DISPLAY_PRETTY(flags) ? -1 : 0, 9);
        }
 
        for (i = 0; i < a->nr[curr]; i++) {
@@ -1063,7 +1063,7 @@ __print_funct_t print_disk_stats(struct activity *a, int prev, int curr,
 
                printf("%-11s", timestamp[curr]);
 
-               if (!DISPLAY_HUMAN_READ(flags)) {
+               if (!DISPLAY_PRETTY(flags)) {
                        cprintf_in(IS_STR, " %9s", dev_name, 0);
                }
                cprintf_f(NO_UNIT, 1, 9, 2,
@@ -1080,7 +1080,7 @@ __print_funct_t print_disk_stats(struct activity *a, int prev, int curr,
                          xds.await);
                cprintf_pc(DISPLAY_UNIT(flags), 1, 9, 2,
                           xds.util / 10.0);
-               if (DISPLAY_HUMAN_READ(flags)) {
+               if (DISPLAY_PRETTY(flags)) {
                        cprintf_in(IS_STR, " %s", dev_name, 0);
                }
                printf("\n");
@@ -1114,7 +1114,7 @@ __print_funct_t print_net_dev_stats(struct activity *a, int prev, int curr,
        }
 
        if (dish || DISPLAY_ZERO_OMIT(flags)) {
-               print_hdr_line(timestamp[!curr], a, FIRST, DISPLAY_HUMAN_READ(flags) ? -1 : 0, 9);
+               print_hdr_line(timestamp[!curr], a, FIRST, DISPLAY_PRETTY(flags) ? -1 : 0, 9);
        }
 
        for (i = 0; i < a->nr[curr]; i++) {
@@ -1149,7 +1149,7 @@ __print_funct_t print_net_dev_stats(struct activity *a, int prev, int curr,
 
                printf("%-11s", timestamp[curr]);
 
-               if (!DISPLAY_HUMAN_READ(flags)) {
+               if (!DISPLAY_PRETTY(flags)) {
                        cprintf_in(IS_STR, " %9s", sndc->interface, 0);
                }
                rxkb = S_VALUE(sndp->rx_bytes, sndc->rx_bytes, itv);
@@ -1167,7 +1167,7 @@ __print_funct_t print_net_dev_stats(struct activity *a, int prev, int curr,
                          S_VALUE(sndp->multicast,     sndc->multicast,     itv));
                ifutil = compute_ifutil(sndc, rxkb, txkb);
                cprintf_pc(DISPLAY_UNIT(flags), 1, 9, 2, ifutil);
-               if (DISPLAY_HUMAN_READ(flags)) {
+               if (DISPLAY_PRETTY(flags)) {
                        cprintf_in(IS_STR, " %s", sndc->interface, 0);
                }
                printf("\n");
@@ -1194,7 +1194,7 @@ __print_funct_t print_net_edev_stats(struct activity *a, int prev, int curr,
        memset(&snedzero, 0, STATS_NET_EDEV_SIZE);
 
        if (dish || DISPLAY_ZERO_OMIT(flags)) {
-               print_hdr_line(timestamp[!curr], a, FIRST, DISPLAY_HUMAN_READ(flags) ? -1 : 0, 9);
+               print_hdr_line(timestamp[!curr], a, FIRST, DISPLAY_PRETTY(flags) ? -1 : 0, 9);
        }
 
        for (i = 0; i < a->nr[curr]; i++) {
@@ -1229,7 +1229,7 @@ __print_funct_t print_net_edev_stats(struct activity *a, int prev, int curr,
 
                printf("%-11s", timestamp[curr]);
 
-               if (!DISPLAY_HUMAN_READ(flags)) {
+               if (!DISPLAY_PRETTY(flags)) {
                        cprintf_in(IS_STR, " %9s", snedc->interface, 0);
                }
                cprintf_f(NO_UNIT, 9, 9, 2,
@@ -1242,7 +1242,7 @@ __print_funct_t print_net_edev_stats(struct activity *a, int prev, int curr,
                          S_VALUE(snedp->rx_frame_errors,   snedc->rx_frame_errors,   itv),
                          S_VALUE(snedp->rx_fifo_errors,    snedc->rx_fifo_errors,    itv),
                          S_VALUE(snedp->tx_fifo_errors,    snedc->tx_fifo_errors,    itv));
-               if (DISPLAY_HUMAN_READ(flags)) {
+               if (DISPLAY_PRETTY(flags)) {
                        cprintf_in(IS_STR, " %s", snedc->interface, 0);
                }
                printf("\n");
diff --git a/sa.h b/sa.h
index 3652c9479acf15fad24d3efc43ed27a26e304bd7..8b586a2101ad1149d21f1d128fecd521279fa3dc 100644 (file)
--- a/sa.h
+++ b/sa.h
@@ -88,7 +88,7 @@
 #define S_F_SINCE_BOOT         0x00000001
 #define S_F_SA_ROTAT           0x00000002      /* Only used by sadc */
 #define S_F_DEV_SID            0x00000002      /* Only used by sar/sadf */
-#define S_F_DEV_PRETTY         0x00000004
+#define S_F_PRETTY             0x00000004
 #define S_F_FORCE_FILE         0x00000008
 #define S_F_INTERVAL_SET       0x00000010
 #define S_F_TRUE_TIME          0x00000020
 #define S_F_SVG_HEIGHT         0x00200000
 #define S_F_SVG_PACKED         0x00400000
 #define S_F_SVG_SHOW_INFO      0x00800000
-#define S_F_HUMAN_READ         0x01000000
+/* Unused                      0x01000000 */
 #define S_F_ZERO_OMIT          0x02000000
 #define S_F_SVG_SHOW_TOC       0x04000000
 #define S_F_FDATASYNC          0x08000000
 #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_STABLE_ID(m)               (((m) & S_F_DEV_SID)      == S_F_DEV_SID)
-#define USE_PRETTY_OPTION(m)           (((m) & S_F_DEV_PRETTY)   == S_F_DEV_PRETTY)
+#define DISPLAY_PRETTY(m)              (((m) & S_F_PRETTY)       == S_F_PRETTY)
 #define FORCE_FILE(m)                  (((m) & S_F_FORCE_FILE)   == S_F_FORCE_FILE)
 #define INTERVAL_SET(m)                        (((m) & S_F_INTERVAL_SET) == S_F_INTERVAL_SET)
 #define PRINT_TRUE_TIME(m)             (((m) & S_F_TRUE_TIME)    == S_F_TRUE_TIME)
 #define DISPLAY_UNIT(m)                        (((m) & S_F_UNIT)         == S_F_UNIT)
 #define SET_CANVAS_HEIGHT(m)           (((m) & S_F_SVG_HEIGHT)   == S_F_SVG_HEIGHT)
 #define PACK_VIEWS(m)                  (((m) & S_F_SVG_PACKED)   == S_F_SVG_PACKED)
-#define DISPLAY_HUMAN_READ(m)          (((m) & S_F_HUMAN_READ)   == S_F_HUMAN_READ)
 #define DISPLAY_TOC(m)                 (((m) & S_F_SVG_SHOW_TOC) == S_F_SVG_SHOW_TOC)
 #define FDATASYNC(m)                   (((m) & S_F_FDATASYNC)    == S_F_FDATASYNC)
 #define USE_OPTION_A(m)                        (((m) & S_F_OPTION_A)     == S_F_OPTION_A)
index 3fbc1c751a2b07ab1f305f689e6c15a75ae33d41..d040f507632988e6d88bbc78ec711557f76cffa5 100644 (file)
@@ -2295,11 +2295,8 @@ int parse_sar_opt(char *argv[], int *opt, struct activity *act[],
                        break;
 
                case 'h':
-                       /*
-                        * Make output easier to read by a human.
-                        * Option -h implies --human and -p (pretty-print).
-                        */
-                       *flags |= S_F_HUMAN_READ + S_F_UNIT + S_F_DEV_PRETTY;
+                       /* Option -h is equivalent to --pretty --human */
+                       *flags |= S_F_PRETTY + S_F_UNIT;
                        break;
 
                case 'j':
@@ -2308,7 +2305,7 @@ int parse_sar_opt(char *argv[], int *opt, struct activity *act[],
                        }
                        (*opt)++;
                        if (!strcmp(argv[*opt], K_SID)) {
-                               *flags |= S_F_DEV_SID + S_F_DEV_PRETTY;
+                               *flags |= S_F_DEV_SID + S_F_PRETTY;
                                return 0;
                        }
 
@@ -2323,12 +2320,12 @@ int parse_sar_opt(char *argv[], int *opt, struct activity *act[],
                                return 2;
                        }
                        /* Pretty print report (option -j implies option -p) */
-                       *flags |= S_F_PERSIST_NAME + S_F_DEV_PRETTY;
+                       *flags |= S_F_PERSIST_NAME + S_F_PRETTY;
                        return 0;
                        break;
 
                case 'p':
-                       *flags |= S_F_DEV_PRETTY;
+                       *flags |= S_F_PRETTY;
                        break;
 
                case 'q':
@@ -3420,7 +3417,7 @@ char *get_sa_devname(unsigned int major, unsigned int minor, unsigned long long
                        snprintf(sid, sizeof(sid), "%#016llx%s%s", wwn[0], xsid, pn);
                        dev_name = sid;
                }
-               else if ((USE_PRETTY_OPTION(flags)) && (major == dm_major)) {
+               else if ((DISPLAY_PRETTY(flags)) && (major == dm_major)) {
                        dev_name = transform_devmapname(major, minor);
                }
 
diff --git a/sadf.c b/sadf.c
index 3a305b39971d7a43587cb2a21f633d58369dc92d..bced02ee435686e1d781a8f6270f1d9854b5ce0a 100644 (file)
--- a/sadf.c
+++ b/sadf.c
@@ -1866,7 +1866,7 @@ int main(int argc, char **argv)
                tm_end.tm_hour += 24;
        }
 
-       if (USE_PRETTY_OPTION(flags)) {
+       if (DISPLAY_PRETTY(flags)) {
                dm_major = get_devmap_major();
        }
 
diff --git a/sar.c b/sar.c
index d2b2f4f14c98e885e17584e75f6e3cbd96d972a3..f7e1ae976be4b832ab6c976e08f7a2865479f743 100644 (file)
--- a/sar.c
+++ b/sar.c
@@ -1341,6 +1341,12 @@ int main(int argc, char **argv)
                        opt++;
                }
 
+               else if (!strcmp(argv[opt], "--pretty")) {
+                       /* Display an easy-to-read report */
+                       flags |= S_F_PRETTY;
+                       opt++;
+               }
+
                else if (!strncmp(argv[opt], "--dec=", 6) && (strlen(argv[opt]) == 7)) {
                        /* Get number of decimal places */
                        dplaces_nr = atoi(argv[opt] + 6);
@@ -1563,7 +1569,7 @@ int main(int argc, char **argv)
                usage(argv[0]);
        }
 
-       if (USE_PRETTY_OPTION(flags)) {
+       if (DISPLAY_PRETTY(flags)) {
                dm_major = get_devmap_major();
        }