]> granicus.if.org Git - sysstat/commitdiff
cifsiostat: Display values in human readable format
authorSebastien GODARD <sysstat@users.noreply.github.com>
Thu, 17 Nov 2016 11:26:41 +0000 (12:26 +0100)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Thu, 17 Nov 2016 11:26:41 +0000 (12:26 +0100)
Add new "--human" option to display sizes in human readable format.

Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
cifsiostat.c
cifsiostat.h

index 17714be16d3f98f88696f108d1cc16c8c98b6a31..86d9ec3424470ae06236b9f1cc824de2cc2797cb 100644 (file)
@@ -72,10 +72,10 @@ void usage(char *progname)
 
 #ifdef DEBUG
        fprintf(stderr, _("Options are:\n"
-                         "[ -h ] [ -k | -m ] [ -t ] [ -V ] [ --debuginfo ]\n"));
+                         "[ --human ] [ -h ] [ -k | -m ] [ -t ] [ -V ] [ --debuginfo ]\n"));
 #else
        fprintf(stderr, _("Options are:\n"
-                         "[ -h ] [ -k | -m ] [ -t ] [ -V ]\n"));
+                         "[ --human ] [ -h ] [ -k | -m ] [ -t ] [ -V ]\n"));
 #endif
        exit(1);
 }
@@ -429,6 +429,8 @@ void write_cifs_stat(int curr, unsigned long long itv, int fctr,
                     struct io_hdr_stats *shi, struct cifs_stats *ioni,
                     struct cifs_stats *ionj)
 {
+       double rbytes, wbytes;
+
        if (DISPLAY_HUMAN_READ(flags)) {
                cprintf_in(IS_STR, "%-22s\n", shi->name, 0);
                printf("%22s", "");
@@ -438,9 +440,14 @@ void write_cifs_stat(int curr, unsigned long long itv, int fctr,
        }
 
        /*       rB/s   wB/s   fo/s   fc/s   fd/s*/
-       cprintf_f(-1, 2, 12, 2,
-                 S_VALUE(ionj->rd_bytes, ioni->rd_bytes, itv) / fctr,
-                 S_VALUE(ionj->wr_bytes, ioni->wr_bytes, itv) / fctr);
+       rbytes = S_VALUE(ionj->rd_bytes, ioni->rd_bytes, itv);
+       wbytes = S_VALUE(ionj->wr_bytes, ioni->wr_bytes, itv);
+       if (!DISPLAY_UNIT(flags)) {
+               rbytes /= fctr;
+               wbytes /= fctr;
+       }
+       cprintf_f(DISPLAY_UNIT(flags) ? 1 : -1, 2, 12, 2,
+                 rbytes, wbytes);
        cprintf_f(-1, 2, 9, 2,
                  S_VALUE(ionj->rd_ops, ioni->rd_ops, itv),
                  S_VALUE(ionj->wr_ops, ioni->wr_ops, itv));
@@ -596,14 +603,20 @@ int main(int argc, char **argv)
                        opt++;
                } else
 #endif
-               if (!strncmp(argv[opt], "-", 1)) {
+
+               if (!strcmp(argv[opt], "--human")) {
+                       flags |= I_D_UNIT;
+                       opt++;
+               }
+
+               else if (!strncmp(argv[opt], "-", 1)) {
                        for (i = 1; *(argv[opt] + i); i++) {
 
                                switch (*(argv[opt] + i)) {
 
                                case 'h':
-                                       /* Display an easy-to-read CIFS report */
-                                       flags |= I_D_HUMAN_READ;
+                                       /* Display an easy-to-read CIFS report. Also imply --human */
+                                       flags |= I_D_HUMAN_READ + I_D_UNIT;
                                        break;
 
                                case 'k':
index cd5960a34dd7fdd91cdac48265c1872b3b9db9c5..98eb93e512bf2c64609bc19c85a74865db64a3c4 100644 (file)
@@ -18,6 +18,7 @@
 #define I_D_ISO                        0x008
 #define I_D_HUMAN_READ         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)
@@ -25,6 +26,7 @@
 #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)
 
 /* Preallocation constants */
 #define NR_CIFS_PREALLOC       2