]> granicus.if.org Git - zfs/commitdiff
Dashes for zero latency values in zpool iostat -p
authorTony Hutter <hutter2@llnl.gov>
Thu, 22 Jun 2017 16:39:01 +0000 (09:39 -0700)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Thu, 22 Jun 2017 16:39:01 +0000 (09:39 -0700)
This prints dashes instead of zeros for zero latency values in
'zpool iostat -p'.  You'll get zero latencies reported when the
disk is idle, but technically a zero latency is invalid, since you
can't measure the latency of doing nothing.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: George Melikov <mail@gmelikov.ru>
Reviewed-by: Giuseppe Di Natale <dinatale2@llnl.gov>
Signed-off-by: Tony Hutter <hutter2@llnl.gov>
Closes #6210

cmd/zpool/zpool_main.c
include/libzfs.h
lib/libzfs/libzfs_util.c

index 5fccd754b4fb8928a223ac8b06e223af9479e2db..2a68fe66f8b2abdfacd3940300e91f1bdd42d069 100644 (file)
@@ -3460,7 +3460,7 @@ print_iostat_latency(iostat_cbdata_t *cb, nvlist_t *oldnv,
        nva = calc_and_alloc_stats_ex(names, ARRAY_SIZE(names), oldnv, newnv);
 
        if (cb->cb_literal)
-               format = ZFS_NICENUM_RAW;
+               format = ZFS_NICENUM_RAWTIME;
        else
                format = ZFS_NICENUM_TIME;
 
index c634ccd863bdc33744fd06268afc25b113da37b7..62a61406ad0d0fa891875a77cd094516991caf3f 100644 (file)
@@ -775,11 +775,21 @@ extern int zfs_unshareall(zfs_handle_t *);
 extern int zfs_deleg_share_nfs(libzfs_handle_t *, char *, char *, char *,
     void *, void *, int, zfs_share_op_t);
 
+/*
+ * Formats for iostat numbers.  Examples: "12K", "30ms", "4B", "2321234", "-".
+ *
+ * ZFS_NICENUM_1024:   Print kilo, mega, tera, peta, exa..
+ * ZFS_NICENUM_BYTES:  Print single bytes ("13B"), kilo, mega, tera...
+ * ZFS_NICENUM_TIME:   Print nanosecs, microsecs, millisecs, seconds...
+ * ZFS_NICENUM_RAW:    Print the raw number without any formatting
+ * ZFS_NICENUM_RAWTIME:        Same as RAW, but print dashes ('-') for zero.
+ */
 enum zfs_nicenum_format {
        ZFS_NICENUM_1024 = 0,
        ZFS_NICENUM_BYTES = 1,
        ZFS_NICENUM_TIME = 2,
-       ZFS_NICENUM_RAW = 3
+       ZFS_NICENUM_RAW = 3,
+       ZFS_NICENUM_RAWTIME = 4
 };
 
 /*
index c281f9eb3239cdf35efc150bc0b14e672d270fa6..1fb7b5ee50e59c8e1d12f9556cb4fb65dcc0ab4d 100644 (file)
@@ -623,9 +623,14 @@ zfs_nicenum_format(uint64_t num, char *buf, size_t buflen,
        if (format == ZFS_NICENUM_RAW) {
                snprintf(buf, buflen, "%llu", (u_longlong_t)num);
                return;
+       } else if (format == ZFS_NICENUM_RAWTIME && num > 0) {
+               snprintf(buf, buflen, "%llu", (u_longlong_t)num);
+               return;
+       } else if (format == ZFS_NICENUM_RAWTIME && num == 0) {
+               snprintf(buf, buflen, "%s", "-");
+               return;
        }
 
-
        while (n >= k_unit[format] && index < units_len[format]) {
                n /= k_unit[format];
                index++;
@@ -633,7 +638,7 @@ zfs_nicenum_format(uint64_t num, char *buf, size_t buflen,
 
        u = units[format][index];
 
-       /* Don't print 0ns times */
+       /* Don't print zero latencies since they're invalid */
        if ((format == ZFS_NICENUM_TIME) && (num == 0)) {
                (void) snprintf(buf, buflen, "-");
        } else if ((index == 0) || ((num %