Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Patch to add -p switch to output raw (not averaged) counters on parsable (tab-separated) lines. Also -H (no header.)
Index: cddl/contrib/opensolaris/cmd/zpool/zpool_main.c
===================================================================
--- cddl/contrib/opensolaris/cmd/zpool/zpool_main.c (revision 327490)
+++ cddl/contrib/opensolaris/cmd/zpool/zpool_main.c (working copy)
@@ -233,7 +233,7 @@
"[-R root] [-F [-n]]\n"
"\t <pool | id> [newpool]\n"));
case HELP_IOSTAT:
- return (gettext("\tiostat [-v] [-T d|u] [pool] ... [interval "
+ return (gettext("\tiostat [-Hpv] [-T d|u] [pool] ... [interval "
"[count]]\n"));
case HELP_LABELCLEAR:
return (gettext("\tlabelclear [-f] <vdev>\n"));
@@ -2324,6 +2324,8 @@
int cb_namewidth;
int cb_iteration;
zpool_list_t *cb_list;
+ boolean_t cb_literal;
+ boolean_t cb_scripted;
} iostat_cbdata_t;
static void
@@ -2331,6 +2333,9 @@
{
int i = 0;
+ if (cb->cb_scripted || cb->cb_literal)
+ return;
+
for (i = 0; i < cb->cb_namewidth; i++)
(void) printf("-");
(void) printf(" ----- ----- ----- ----- ----- -----\n");
@@ -2339,11 +2344,18 @@
static void
print_iostat_header(iostat_cbdata_t *cb)
{
- (void) printf("%*s capacity operations bandwidth\n",
- cb->cb_namewidth, "");
- (void) printf("%-*s alloc free read write read write\n",
- cb->cb_namewidth, "pool");
- print_iostat_separator(cb);
+ if (cb->cb_scripted)
+ return;
+
+ if (cb->cb_literal) {
+ (void) printf("pool/dev\talloc\tfree\trops\twops\trbytes\twbytes\n");
+ } else {
+ (void) printf("%*s capacity operations bandwidth\n",
+ cb->cb_namewidth, "");
+ (void) printf("%-*s alloc free read write read write\n",
+ cb->cb_namewidth, "pool");
+ print_iostat_separator(cb);
+ }
}
/*
@@ -2350,12 +2362,16 @@
* Display a single statistic.
*/
static void
-print_one_stat(uint64_t value)
+print_one_stat(uint64_t value, iostat_cbdata_t *cb)
{
char buf[64];
-
- zfs_nicenum(value, buf, sizeof (buf));
- (void) printf(" %5s", buf);
+
+ if (cb->cb_literal) {
+ (void) printf("\t%lu", value);
+ } else {
+ zfs_nicenum(value, buf, sizeof (buf));
+ (void) printf(" %5s", buf);
+ }
}
/*
@@ -2385,11 +2401,15 @@
verify(nvlist_lookup_uint64_array(newnv, ZPOOL_CONFIG_VDEV_STATS,
(uint64_t **)&newvs, &c) == 0);
- if (strlen(name) + depth > cb->cb_namewidth)
- (void) printf("%*s%s", depth, "", name);
- else
- (void) printf("%*s%s%*s", depth, "", name,
- (int)(cb->cb_namewidth - strlen(name) - depth), "");
+ if (cb->cb_literal) {
+ (void) printf("%.*s%s", depth, "::::::", name);
+ } else {
+ if (strlen(name) + depth > cb->cb_namewidth)
+ (void) printf("%*s%s", depth, "", name);
+ else
+ (void) printf("%*s%s%*s", depth, "", name,
+ (int)(cb->cb_namewidth - strlen(name) - depth), "");
+ }
tdelta = newvs->vs_timestamp - oldvs->vs_timestamp;
@@ -2398,25 +2418,31 @@
else
scale = (double)NANOSEC / tdelta;
+ if (cb->cb_literal)
+ scale = 1.0;
+
/* only toplevel vdevs have capacity stats */
if (newvs->vs_space == 0) {
- (void) printf(" - -");
+ if (cb->cb_literal)
+ (void) printf("\t-\t-");
+ else
+ (void) printf(" - -");
} else {
- print_one_stat(newvs->vs_alloc);
- print_one_stat(newvs->vs_space - newvs->vs_alloc);
+ print_one_stat(newvs->vs_alloc, cb);
+ print_one_stat(newvs->vs_space - newvs->vs_alloc, cb);
}
print_one_stat((uint64_t)(scale * (newvs->vs_ops[ZIO_TYPE_READ] -
- oldvs->vs_ops[ZIO_TYPE_READ])));
+ oldvs->vs_ops[ZIO_TYPE_READ])), cb);
print_one_stat((uint64_t)(scale * (newvs->vs_ops[ZIO_TYPE_WRITE] -
- oldvs->vs_ops[ZIO_TYPE_WRITE])));
+ oldvs->vs_ops[ZIO_TYPE_WRITE])), cb);
print_one_stat((uint64_t)(scale * (newvs->vs_bytes[ZIO_TYPE_READ] -
- oldvs->vs_bytes[ZIO_TYPE_READ])));
+ oldvs->vs_bytes[ZIO_TYPE_READ])), cb);
print_one_stat((uint64_t)(scale * (newvs->vs_bytes[ZIO_TYPE_WRITE] -
- oldvs->vs_bytes[ZIO_TYPE_WRITE])));
+ oldvs->vs_bytes[ZIO_TYPE_WRITE])), cb);
(void) printf("\n");
@@ -2454,9 +2480,11 @@
*/
if (num_logs(newnv) > 0) {
- (void) printf("%-*s - - - - - "
- "-\n", cb->cb_namewidth, "logs");
-
+ if (!cb->cb_scripted) {
+ (void) printf("%-*s - - -"
+ " - - -\n",
+ cb->cb_namewidth, "logs");
+ }
for (c = 0; c < children; c++) {
uint64_t islog = B_FALSE;
(void) nvlist_lookup_uint64(newchild[c],
@@ -2682,14 +2710,20 @@
unsigned long interval = 0, count = 0;
zpool_list_t *list;
boolean_t verbose = B_FALSE;
- iostat_cbdata_t cb;
+ iostat_cbdata_t cb = {0};
/* check options */
- while ((c = getopt(argc, argv, "T:v")) != -1) {
+ while ((c = getopt(argc, argv, "HT:pv")) != -1) {
switch (c) {
+ case 'H':
+ cb.cb_scripted = B_TRUE;
+ break;
case 'T':
get_timestamp_arg(*optarg);
break;
+ case 'p':
+ cb.cb_literal = B_TRUE;
+ break;
case 'v':
verbose = B_TRUE;
break;
@@ -2769,7 +2803,7 @@
if (npools > 1 && !verbose)
print_iostat_separator(&cb);
- if (verbose)
+ if (verbose && !cb.cb_scripted)
(void) printf("\n");
/*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment