FreeBSD/cddl/contrib/opensolaris/cmd/zpool/zpool_main.c
/*
 * Print out all the statistics for the given vdev.  This can either be the
 * toplevel configuration, or called recursively.  If 'name' is NULL, then this
 * is a verbose output, and we don't want to display the toplevel pool stats.
 */
Print out all the statistics for the given vdev.  This can either be the
toplevel configuration, or called recursively.  If 'name' is NULL, then this
is a verbose output, and we don't want to display the toplevel pool stats.
Print out all the statistics for the given vdev . This can either be the toplevel configuration or called recursively . If ' name ' is NULL then this is a verbose output and we don ' t want to display the toplevel pool stats .
void
print_vdev_stats(zpool_handle_t *zhp, const char *name, nvlist_t *oldnv,
    nvlist_t *newnv, iostat_cbdata_t *cb, int depth)
{
	nvlist_t **oldchild, **newchild;
	uint_t c, children;
	vdev_stat_t *oldvs, *newvs;
	vdev_stat_t zerovs = { 0 };
	uint64_t tdelta;
	double scale;
	char *vname;
	if (oldnv != NULL) {
		verify(nvlist_lookup_uint64_array(oldnv,
		    ZPOOL_CONFIG_VDEV_STATS, (uint64_t **)&oldvs, &c) == 0);
	} else {
		oldvs = &zerovs;
	}
	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), "");
	tdelta = newvs->vs_timestamp - oldvs->vs_timestamp;
	if (tdelta == 0)
		scale = 1.0;
	else
		scale = (double)NANOSEC / tdelta;
	if (newvs->vs_space == 0) {
		(void) printf("      -      -");
	} else {
		print_one_stat(newvs->vs_alloc);
		print_one_stat(newvs->vs_space - newvs->vs_alloc);
	}
	print_one_stat((uint64_t)(scale * (newvs->vs_ops[ZIO_TYPE_READ] -
	    oldvs->vs_ops[ZIO_TYPE_READ])));
	print_one_stat((uint64_t)(scale * (newvs->vs_ops[ZIO_TYPE_WRITE] -
	    oldvs->vs_ops[ZIO_TYPE_WRITE])));
	print_one_stat((uint64_t)(scale * (newvs->vs_bytes[ZIO_TYPE_READ] -
	    oldvs->vs_bytes[ZIO_TYPE_READ])));
	print_one_stat((uint64_t)(scale * (newvs->vs_bytes[ZIO_TYPE_WRITE] -
	    oldvs->vs_bytes[ZIO_TYPE_WRITE])));
	(void) printf("\n");
	if (!cb->cb_verbose)
		return;
	if (nvlist_lookup_nvlist_array(newnv, ZPOOL_CONFIG_CHILDREN,
	    &newchild, &children) != 0)
		return;
	if (oldnv && nvlist_lookup_nvlist_array(oldnv, ZPOOL_CONFIG_CHILDREN,
	    &oldchild, &c) != 0)
		return;
	for (c = 0; c < children; c++) {
		uint64_t ishole = B_FALSE, islog = B_FALSE;
		(void) nvlist_lookup_uint64(newchild[c], ZPOOL_CONFIG_IS_HOLE,
		    &ishole);
		(void) nvlist_lookup_uint64(newchild[c], ZPOOL_CONFIG_IS_LOG,
		    &islog);
		if (ishole || islog)
			continue;
		vname = zpool_vdev_name(g_zfs, zhp, newchild[c], B_FALSE);
		print_vdev_stats(zhp, vname, oldnv ? oldchild[c] : NULL,
		    newchild[c], cb, depth + 2);
		free(vname);
	}
	if (num_logs(newnv) > 0) {
		(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],
			    ZPOOL_CONFIG_IS_LOG, &islog);
			if (islog) {
				vname = zpool_vdev_name(g_zfs, zhp, newchild[c],
				    B_FALSE);
				print_vdev_stats(zhp, vname, oldnv ?
				    oldchild[c] : NULL, newchild[c],
				    cb, depth + 2);
				free(vname);
			}
		}
	}
	if (nvlist_lookup_nvlist_array(newnv, ZPOOL_CONFIG_L2CACHE,
	    &newchild, &children) != 0)
		return;
	if (oldnv && nvlist_lookup_nvlist_array(oldnv, ZPOOL_CONFIG_L2CACHE,
	    &oldchild, &c) != 0)
		return;
	if (children > 0) {
		(void) printf("%-*s      -      -      -      -      -      "
		    "-\n", cb->cb_namewidth, "cache");
		for (c = 0; c < children; c++) {
			vname = zpool_vdev_name(g_zfs, zhp, newchild[c],
			    B_FALSE);
			print_vdev_stats(zhp, vname, oldnv ? oldchild[c] : NULL,
			    newchild[c], cb, depth + 2);
			free(vname);
		}
	}
}
void print_vdev_stats ( zpool_handle_t * zhp , const char * name , nvlist_t * oldnv , nvlist_t * newnv , iostat_cbdata_t * cb , int depth ) { nvlist_t * * oldchild , * * newchild ; uint_t c , children ; vdev_stat_t * oldvs , * newvs ; vdev_stat_t zerovs = { 0 } ; uint64_t tdelta ; double scale ; char * vname ; if ( oldnv != NULL ) { verify ( nvlist_lookup_uint64_array ( oldnv , ZPOOL_CONFIG_VDEV_STATS , ( uint64_t * * ) & oldvs , & c ) == 0 ) ; } else { oldvs = & zerovs ; } verify ( nvlist_lookup_uint64_array ( newnv , ZPOOL_CONFIG_VDEV_STATS , ( uint64_t * * ) & newvs , & c ) == 0 ) ; if ( strlen ( name ) + depth > cb -> cb_namewidth ) ( void ) printf ( " " , depth , " " , name ) ; else ( void ) printf ( " " , depth , " " , name , ( int ) ( cb -> cb_namewidth - strlen ( name ) - depth ) , " " ) ; tdelta = newvs -> vs_timestamp - oldvs -> vs_timestamp ; if ( tdelta == 0 ) scale = 1.0 ; else scale = ( double ) NANOSEC / tdelta ; if ( newvs -> vs_space == 0 ) { ( void ) printf ( " " ) ; } else { print_one_stat ( newvs -> vs_alloc ) ; print_one_stat ( newvs -> vs_space - newvs -> vs_alloc ) ; } print_one_stat ( ( uint64_t ) ( scale * ( newvs -> vs_ops [ ZIO_TYPE_READ ] - oldvs -> vs_ops [ ZIO_TYPE_READ ] ) ) ) ; print_one_stat ( ( uint64_t ) ( scale * ( newvs -> vs_ops [ ZIO_TYPE_WRITE ] - oldvs -> vs_ops [ ZIO_TYPE_WRITE ] ) ) ) ; print_one_stat ( ( uint64_t ) ( scale * ( newvs -> vs_bytes [ ZIO_TYPE_READ ] - oldvs -> vs_bytes [ ZIO_TYPE_READ ] ) ) ) ; print_one_stat ( ( uint64_t ) ( scale * ( newvs -> vs_bytes [ ZIO_TYPE_WRITE ] - oldvs -> vs_bytes [ ZIO_TYPE_WRITE ] ) ) ) ; ( void ) printf ( " \n " ) ; if ( ! cb -> cb_verbose ) return ; if ( nvlist_lookup_nvlist_array ( newnv , ZPOOL_CONFIG_CHILDREN , & newchild , & children ) != 0 ) return ; if ( oldnv && nvlist_lookup_nvlist_array ( oldnv , ZPOOL_CONFIG_CHILDREN , & oldchild , & c ) != 0 ) return ; for ( c = 0 ; c < children ; c ++ ) { uint64_t ishole = B_FALSE , islog = B_FALSE ; ( void ) nvlist_lookup_uint64 ( newchild [ c ] , ZPOOL_CONFIG_IS_HOLE , & ishole ) ; ( void ) nvlist_lookup_uint64 ( newchild [ c ] , ZPOOL_CONFIG_IS_LOG , & islog ) ; if ( ishole || islog ) continue ; vname = zpool_vdev_name ( g_zfs , zhp , newchild [ c ] , B_FALSE ) ; print_vdev_stats ( zhp , vname , oldnv ? oldchild [ c ] : NULL , newchild [ c ] , cb , depth + 2 ) ; free ( vname ) ; } if ( num_logs ( newnv ) > 0 ) { ( void ) printf ( " " " \n " , cb -> cb_namewidth , " " ) ; for ( c = 0 ; c < children ; c ++ ) { uint64_t islog = B_FALSE ; ( void ) nvlist_lookup_uint64 ( newchild [ c ] , ZPOOL_CONFIG_IS_LOG , & islog ) ; if ( islog ) { vname = zpool_vdev_name ( g_zfs , zhp , newchild [ c ] , B_FALSE ) ; print_vdev_stats ( zhp , vname , oldnv ? oldchild [ c ] : NULL , newchild [ c ] , cb , depth + 2 ) ; free ( vname ) ; } } } if ( nvlist_lookup_nvlist_array ( newnv , ZPOOL_CONFIG_L2CACHE , & newchild , & children ) != 0 ) return ; if ( oldnv && nvlist_lookup_nvlist_array ( oldnv , ZPOOL_CONFIG_L2CACHE , & oldchild , & c ) != 0 ) return ; if ( children > 0 ) { ( void ) printf ( " " " \n " , cb -> cb_namewidth , " " ) ; for ( c = 0 ; c < children ; c ++ ) { vname = zpool_vdev_name ( g_zfs , zhp , newchild [ c ] , B_FALSE ) ; print_vdev_stats ( zhp , vname , oldnv ? oldchild [ c ] : NULL , newchild [ c ] , cb , depth + 2 ) ; free ( vname ) ; } } }
Print out all the statistics for the given vdev.
Print out all the statistics for the given vdev .
/* only toplevel vdevs have capacity stats */ /*
	 * Log device section
	 */ /*
	 * Include level 2 ARC devices in iostat output
	 */