193a37cb24
Update the zfs module to collect statistics on average latencies, queue sizes, and keep an internal histogram of all IO latencies. Along with this, update "zpool iostat" with some new options to print out the stats: -l: Include average IO latencies stats: total_wait disk_wait syncq_wait asyncq_wait scrub read write read write read write read write wait ----- ----- ----- ----- ----- ----- ----- ----- ----- - 41ms - 2ms - 46ms - 4ms - - 5ms - 1ms - 1us - 4ms - - 5ms - 1ms - 1us - 4ms - - - - - - - - - - - 49ms - 2ms - 47ms - - - - - - - - - - - - - 2ms - 1ms - - - 1ms - ----- ----- ----- ----- ----- ----- ----- ----- ----- 1ms 1ms 1ms 413us 16us 25us - 5ms - 1ms 1ms 1ms 413us 16us 25us - 5ms - 2ms 1ms 2ms 412us 26us 25us - 5ms - - 1ms - 413us - 25us - 5ms - - 1ms - 460us - 29us - 5ms - 196us 1ms 196us 370us 7us 23us - 5ms - ----- ----- ----- ----- ----- ----- ----- ----- ----- -w: Print out latency histograms: sdb total disk sync_queue async_queue latency read write read write read write read write scrub ------- ------ ------ ------ ------ ------ ------ ------ ------ ------ 1ns 0 0 0 0 0 0 0 0 0 ... 33us 0 0 0 0 0 0 0 0 0 66us 0 0 107 2486 2 788 12 12 0 131us 2 797 359 4499 10 558 184 184 6 262us 22 801 264 1563 10 286 287 287 24 524us 87 575 71 52086 15 1063 136 136 92 1ms 152 1190 5 41292 4 1693 252 252 141 2ms 245 2018 0 50007 0 2322 371 371 220 4ms 189 7455 22 162957 0 3912 6726 6726 199 8ms 108 9461 0 102320 0 5775 2526 2526 86 17ms 23 11287 0 37142 0 8043 1813 1813 19 34ms 0 14725 0 24015 0 11732 3071 3071 0 67ms 0 23597 0 7914 0 18113 5025 5025 0 134ms 0 33798 0 254 0 25755 7326 7326 0 268ms 0 51780 0 12 0 41593 10002 10002 0 537ms 0 77808 0 0 0 64255 13120 13120 0 1s 0 105281 0 0 0 83805 20841 20841 0 2s 0 88248 0 0 0 73772 14006 14006 0 4s 0 47266 0 0 0 29783 17176 17176 0 9s 0 10460 0 0 0 4130 6295 6295 0 17s 0 0 0 0 0 0 0 0 0 34s 0 0 0 0 0 0 0 0 0 69s 0 0 0 0 0 0 0 0 0 137s 0 0 0 0 0 0 0 0 0 ------------------------------------------------------------------------------- -h: Help -H: Scripted mode. Do not display headers, and separate fields by a single tab instead of arbitrary space. -q: Include current number of entries in sync & async read/write queues, and scrub queue: syncq_read syncq_write asyncq_read asyncq_write scrubq_read pend activ pend activ pend activ pend activ pend activ ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- 0 0 0 0 78 29 0 0 0 0 0 0 0 0 78 29 0 0 0 0 0 0 0 0 0 0 0 0 0 0 - - - - - - - - - - 0 0 0 0 0 0 0 0 0 0 - - - - - - - - - - 0 0 0 0 0 0 0 0 0 0 ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- 0 0 227 394 0 19 0 0 0 0 0 0 227 394 0 19 0 0 0 0 0 0 108 98 0 19 0 0 0 0 0 0 19 98 0 0 0 0 0 0 0 0 78 98 0 0 0 0 0 0 0 0 19 88 0 0 0 0 0 0 ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -p: Display numbers in parseable (exact) values. Also, update iostat syntax to allow the user to specify specific vdevs to show statistics for. The three options for choosing pools/vdevs are: Display a list of pools: zpool iostat ... [pool ...] Display a list of vdevs from a specific pool: zpool iostat ... [pool vdev ...] Display a list of vdevs from any pools: zpool iostat ... [vdev ...] Lastly, allow zpool command "interval" value to be floating point: zpool iostat -v 0.5 Signed-off-by: Tony Hutter <hutter2@llnl.gov Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Closes #4433
159 lines
4.4 KiB
C
159 lines
4.4 KiB
C
/*
|
|
* CDDL HEADER START
|
|
*
|
|
* The contents of this file are subject to the terms of the
|
|
* Common Development and Distribution License (the "License").
|
|
* You may not use this file except in compliance with the License.
|
|
*
|
|
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
|
* or http://www.opensolaris.org/os/licensing.
|
|
* See the License for the specific language governing permissions
|
|
* and limitations under the License.
|
|
*
|
|
* When distributing Covered Code, include this CDDL HEADER in each
|
|
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
|
* If applicable, add the following below this CDDL HEADER, with the
|
|
* fields enclosed by brackets "[]" replaced with your own identifying
|
|
* information: Portions Copyright [yyyy] [name of copyright owner]
|
|
*
|
|
* CDDL HEADER END
|
|
*/
|
|
/*
|
|
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
|
*/
|
|
|
|
#include <assert.h>
|
|
#include <sys/zfs_context.h>
|
|
#include <sys/avl.h>
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <sys/spa.h>
|
|
#include <sys/fs/zfs.h>
|
|
#include <sys/refcount.h>
|
|
|
|
/*
|
|
* Routines needed by more than one client of libzpool.
|
|
*/
|
|
|
|
void
|
|
nicenum(uint64_t num, char *buf)
|
|
{
|
|
uint64_t n = num;
|
|
int index = 0;
|
|
char u;
|
|
|
|
while (n >= 1024) {
|
|
n = (n + (1024 / 2)) / 1024; /* Round up or down */
|
|
index++;
|
|
}
|
|
|
|
u = " KMGTPE"[index];
|
|
|
|
if (index == 0) {
|
|
(void) sprintf(buf, "%llu", (u_longlong_t)n);
|
|
} else if (n < 10 && (num & (num - 1)) != 0) {
|
|
(void) sprintf(buf, "%.2f%c",
|
|
(double)num / (1ULL << 10 * index), u);
|
|
} else if (n < 100 && (num & (num - 1)) != 0) {
|
|
(void) sprintf(buf, "%.1f%c",
|
|
(double)num / (1ULL << 10 * index), u);
|
|
} else {
|
|
(void) sprintf(buf, "%llu%c", (u_longlong_t)n, u);
|
|
}
|
|
}
|
|
|
|
static void
|
|
show_vdev_stats(const char *desc, const char *ctype, nvlist_t *nv, int indent)
|
|
{
|
|
vdev_stat_t *vs;
|
|
vdev_stat_t *v0 = { 0 };
|
|
uint64_t sec;
|
|
uint64_t is_log = 0;
|
|
nvlist_t **child;
|
|
uint_t c, children;
|
|
char used[6], avail[6];
|
|
char rops[6], wops[6], rbytes[6], wbytes[6], rerr[6], werr[6], cerr[6];
|
|
char *prefix = "";
|
|
|
|
v0 = umem_zalloc(sizeof (*v0), UMEM_NOFAIL);
|
|
|
|
if (indent == 0 && desc != NULL) {
|
|
(void) printf(" "
|
|
" capacity operations bandwidth ---- errors ----\n");
|
|
(void) printf("description "
|
|
"used avail read write read write read write cksum\n");
|
|
}
|
|
|
|
if (desc != NULL) {
|
|
(void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_IS_LOG, &is_log);
|
|
|
|
if (is_log)
|
|
prefix = "log ";
|
|
|
|
if (nvlist_lookup_uint64_array(nv, ZPOOL_CONFIG_VDEV_STATS,
|
|
(uint64_t **)&vs, &c) != 0)
|
|
vs = v0;
|
|
|
|
sec = MAX(1, vs->vs_timestamp / NANOSEC);
|
|
|
|
nicenum(vs->vs_alloc, used);
|
|
nicenum(vs->vs_space - vs->vs_alloc, avail);
|
|
nicenum(vs->vs_ops[ZIO_TYPE_READ] / sec, rops);
|
|
nicenum(vs->vs_ops[ZIO_TYPE_WRITE] / sec, wops);
|
|
nicenum(vs->vs_bytes[ZIO_TYPE_READ] / sec, rbytes);
|
|
nicenum(vs->vs_bytes[ZIO_TYPE_WRITE] / sec, wbytes);
|
|
nicenum(vs->vs_read_errors, rerr);
|
|
nicenum(vs->vs_write_errors, werr);
|
|
nicenum(vs->vs_checksum_errors, cerr);
|
|
|
|
(void) printf("%*s%s%*s%*s%*s %5s %5s %5s %5s %5s %5s %5s\n",
|
|
indent, "",
|
|
prefix,
|
|
(int)(indent+strlen(prefix)-25-(vs->vs_space ? 0 : 12)),
|
|
desc,
|
|
vs->vs_space ? 6 : 0, vs->vs_space ? used : "",
|
|
vs->vs_space ? 6 : 0, vs->vs_space ? avail : "",
|
|
rops, wops, rbytes, wbytes, rerr, werr, cerr);
|
|
}
|
|
free(v0);
|
|
|
|
if (nvlist_lookup_nvlist_array(nv, ctype, &child, &children) != 0)
|
|
return;
|
|
|
|
for (c = 0; c < children; c++) {
|
|
nvlist_t *cnv = child[c];
|
|
char *cname, *tname;
|
|
uint64_t np;
|
|
if (nvlist_lookup_string(cnv, ZPOOL_CONFIG_PATH, &cname) &&
|
|
nvlist_lookup_string(cnv, ZPOOL_CONFIG_TYPE, &cname))
|
|
cname = "<unknown>";
|
|
tname = calloc(1, strlen(cname) + 2);
|
|
(void) strcpy(tname, cname);
|
|
if (nvlist_lookup_uint64(cnv, ZPOOL_CONFIG_NPARITY, &np) == 0)
|
|
tname[strlen(tname)] = '0' + np;
|
|
show_vdev_stats(tname, ctype, cnv, indent + 2);
|
|
free(tname);
|
|
}
|
|
}
|
|
|
|
void
|
|
show_pool_stats(spa_t *spa)
|
|
{
|
|
nvlist_t *config, *nvroot;
|
|
char *name;
|
|
|
|
VERIFY(spa_get_stats(spa_name(spa), &config, NULL, 0) == 0);
|
|
|
|
VERIFY(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
|
|
&nvroot) == 0);
|
|
VERIFY(nvlist_lookup_string(config, ZPOOL_CONFIG_POOL_NAME,
|
|
&name) == 0);
|
|
|
|
show_vdev_stats(name, ZPOOL_CONFIG_CHILDREN, nvroot, 0);
|
|
show_vdev_stats(NULL, ZPOOL_CONFIG_L2CACHE, nvroot, 0);
|
|
show_vdev_stats(NULL, ZPOOL_CONFIG_SPARES, nvroot, 0);
|
|
|
|
nvlist_free(config);
|
|
}
|