Dashes for zero latency values in zpool iostat -p

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 
This commit is contained in:
Tony Hutter 2017-06-22 09:39:01 -07:00 committed by Brian Behlendorf
parent d9ad3fea3b
commit 29eb494285
3 changed files with 19 additions and 4 deletions
cmd/zpool
include
lib/libzfs

View 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;

View 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
};
/*

View 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 %