summaryrefslogtreecommitdiffstats
path: root/cddl/contrib/opensolaris/cmd
diff options
context:
space:
mode:
authormm <mm@FreeBSD.org>2013-04-06 17:18:48 +0000
committermm <mm@FreeBSD.org>2013-04-06 17:18:48 +0000
commitb78a61d3ba357224efe924479da868d65e0fcb9d (patch)
treed15145188cec4da6f7bf2dff1082b670f7055623 /cddl/contrib/opensolaris/cmd
parent9c031f1fcf371d39b79161408056863b701e9dd4 (diff)
downloadFreeBSD-src-b78a61d3ba357224efe924479da868d65e0fcb9d.zip
FreeBSD-src-b78a61d3ba357224efe924479da868d65e0fcb9d.tar.gz
MFV r249185:
Allow zdb to output a histogram of compressed block sizes. Illumos ZFS issues: 3641 want a histogram of compressed block sizes MFC after: 3 weeks
Diffstat (limited to 'cddl/contrib/opensolaris/cmd')
-rw-r--r--cddl/contrib/opensolaris/cmd/zdb/zdb.c89
1 files changed, 65 insertions, 24 deletions
diff --git a/cddl/contrib/opensolaris/cmd/zdb/zdb.c b/cddl/contrib/opensolaris/cmd/zdb/zdb.c
index 1d56407..c265c99 100644
--- a/cddl/contrib/opensolaris/cmd/zdb/zdb.c
+++ b/cddl/contrib/opensolaris/cmd/zdb/zdb.c
@@ -21,10 +21,11 @@
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2012 by Delphix. All rights reserved.
+ * Copyright (c) 2013 by Delphix. All rights reserved.
*/
#include <stdio.h>
+#include <unistd.h>
#include <stdio_ext.h>
#include <stdlib.h>
#include <ctype.h>
@@ -237,18 +238,18 @@ zdb_nicenum(uint64_t num, char *buf)
nicenum(num, buf);
}
-const char dump_zap_stars[] = "****************************************";
-const int dump_zap_width = sizeof (dump_zap_stars) - 1;
+const char histo_stars[] = "****************************************";
+const int histo_width = sizeof (histo_stars) - 1;
static void
-dump_zap_histogram(uint64_t histo[ZAP_HISTOGRAM_SIZE])
+dump_histogram(const uint64_t *histo, int size)
{
int i;
- int minidx = ZAP_HISTOGRAM_SIZE - 1;
+ int minidx = size - 1;
int maxidx = 0;
uint64_t max = 0;
- for (i = 0; i < ZAP_HISTOGRAM_SIZE; i++) {
+ for (i = 0; i < size; i++) {
if (histo[i] > max)
max = histo[i];
if (histo[i] > 0 && i > maxidx)
@@ -257,12 +258,14 @@ dump_zap_histogram(uint64_t histo[ZAP_HISTOGRAM_SIZE])
minidx = i;
}
- if (max < dump_zap_width)
- max = dump_zap_width;
+ if (max < histo_width)
+ max = histo_width;
- for (i = minidx; i <= maxidx; i++)
- (void) printf("\t\t\t%u: %6llu %s\n", i, (u_longlong_t)histo[i],
- &dump_zap_stars[(max - histo[i]) * dump_zap_width / max]);
+ for (i = minidx; i <= maxidx; i++) {
+ (void) printf("\t\t\t%3u: %6llu %s\n",
+ i, (u_longlong_t)histo[i],
+ &histo_stars[(max - histo[i]) * histo_width / max]);
+ }
}
static void
@@ -313,19 +316,19 @@ dump_zap_stats(objset_t *os, uint64_t object)
(u_longlong_t)zs.zs_salt);
(void) printf("\t\tLeafs with 2^n pointers:\n");
- dump_zap_histogram(zs.zs_leafs_with_2n_pointers);
+ dump_histogram(zs.zs_leafs_with_2n_pointers, ZAP_HISTOGRAM_SIZE);
(void) printf("\t\tBlocks with n*5 entries:\n");
- dump_zap_histogram(zs.zs_blocks_with_n5_entries);
+ dump_histogram(zs.zs_blocks_with_n5_entries, ZAP_HISTOGRAM_SIZE);
(void) printf("\t\tBlocks n/10 full:\n");
- dump_zap_histogram(zs.zs_blocks_n_tenths_full);
+ dump_histogram(zs.zs_blocks_n_tenths_full, ZAP_HISTOGRAM_SIZE);
(void) printf("\t\tEntries with n chunks:\n");
- dump_zap_histogram(zs.zs_entries_using_n_chunks);
+ dump_histogram(zs.zs_entries_using_n_chunks, ZAP_HISTOGRAM_SIZE);
(void) printf("\t\tBuckets with n entries:\n");
- dump_zap_histogram(zs.zs_buckets_with_n_entries);
+ dump_histogram(zs.zs_buckets_with_n_entries, ZAP_HISTOGRAM_SIZE);
}
/*ARGSUSED*/
@@ -947,7 +950,7 @@ sprintf_blkptr_compact(char *blkbuf, const blkptr_t *bp)
const dva_t *dva = bp->blk_dva;
int ndvas = dump_opt['d'] > 5 ? BP_GET_NDVAS(bp) : 1;
- if (dump_opt['b'] >= 5) {
+ if (dump_opt['b'] >= 6) {
sprintf_blkptr(blkbuf, bp);
return;
}
@@ -1986,11 +1989,13 @@ dump_one_dir(const char *dsname, void *arg)
/*
* Block statistics.
*/
+#define PSIZE_HISTO_SIZE (SPA_MAXBLOCKSIZE / SPA_MINBLOCKSIZE + 1)
typedef struct zdb_blkstats {
- uint64_t zb_asize;
- uint64_t zb_lsize;
- uint64_t zb_psize;
- uint64_t zb_count;
+ uint64_t zb_asize;
+ uint64_t zb_lsize;
+ uint64_t zb_psize;
+ uint64_t zb_count;
+ uint64_t zb_psize_histogram[PSIZE_HISTO_SIZE];
} zdb_blkstats_t;
/*
@@ -2014,6 +2019,9 @@ typedef struct zdb_cb {
zdb_blkstats_t zcb_type[ZB_TOTAL + 1][ZDB_OT_TOTAL + 1];
uint64_t zcb_dedup_asize;
uint64_t zcb_dedup_blocks;
+ uint64_t zcb_start;
+ uint64_t zcb_lastprint;
+ uint64_t zcb_totalasize;
uint64_t zcb_errors[256];
int zcb_readfails;
int zcb_haderrors;
@@ -2040,6 +2048,7 @@ zdb_count_block(zdb_cb_t *zcb, zilog_t *zilog, const blkptr_t *bp,
zb->zb_lsize += BP_GET_LSIZE(bp);
zb->zb_psize += BP_GET_PSIZE(bp);
zb->zb_count++;
+ zb->zb_psize_histogram[BP_GET_PSIZE(bp) >> SPA_MINBLOCKSHIFT]++;
}
if (dump_opt['L'])
@@ -2126,7 +2135,7 @@ zdb_blkptr_cb(spa_t *spa, zilog_t *zilog, const blkptr_t *bp,
zcb->zcb_readfails = 0;
- if (dump_opt['b'] >= 4) {
+ if (dump_opt['b'] >= 5) {
sprintf_blkptr(blkbuf, bp);
(void) printf("objset %llu object %llu "
"level %lld offset 0x%llx %s\n",
@@ -2137,6 +2146,28 @@ zdb_blkptr_cb(spa_t *spa, zilog_t *zilog, const blkptr_t *bp,
blkbuf);
}
+ if (dump_opt['b'] < 5 && isatty(STDERR_FILENO) &&
+ gethrtime() > zcb->zcb_lastprint + NANOSEC) {
+ uint64_t now = gethrtime();
+ char buf[10];
+ uint64_t bytes = zcb->zcb_type[ZB_TOTAL][ZDB_OT_TOTAL].zb_asize;
+ int kb_per_sec =
+ 1 + bytes / (1 + ((now - zcb->zcb_start) / 1000 / 1000));
+ int sec_remaining =
+ (zcb->zcb_totalasize - bytes) / 1024 / kb_per_sec;
+
+ zfs_nicenum(bytes, buf, sizeof (buf));
+ (void) fprintf(stderr,
+ "\r%5s completed (%4dMB/s) "
+ "estimated time remaining: %uhr %02umin %02usec ",
+ buf, kb_per_sec / 1024,
+ sec_remaining / 60 / 60,
+ sec_remaining / 60 % 60,
+ sec_remaining % 60);
+
+ zcb->zcb_lastprint = now;
+ }
+
return (0);
}
@@ -2268,7 +2299,7 @@ count_block_cb(void *arg, const blkptr_t *bp, dmu_tx_t *tx)
{
zdb_cb_t *zcb = arg;
- if (dump_opt['b'] >= 4) {
+ if (dump_opt['b'] >= 5) {
char blkbuf[BP_SPRINTF_LEN];
sprintf_blkptr(blkbuf, bp);
(void) printf("[%s] %s\n",
@@ -2287,7 +2318,7 @@ dump_block_stats(spa_t *spa)
int flags = TRAVERSE_PRE | TRAVERSE_PREFETCH_METADATA | TRAVERSE_HARD;
int leaks = 0;
- (void) printf("\nTraversing all blocks %s%s%s%s%s...\n",
+ (void) printf("\nTraversing all blocks %s%s%s%s%s...\n\n",
(dump_opt['c'] || !dump_opt['L']) ? "to verify " : "",
(dump_opt['c'] == 1) ? "metadata " : "",
dump_opt['c'] ? "checksums " : "",
@@ -2323,6 +2354,8 @@ dump_block_stats(spa_t *spa)
if (dump_opt['c'] > 1)
flags |= TRAVERSE_PREFETCH_DATA;
+ zcb.zcb_totalasize = metaslab_class_get_alloc(spa_normal_class(spa));
+ zcb.zcb_start = zcb.zcb_lastprint = gethrtime();
zcb.zcb_haderrors |= traverse_pool(spa, 0, flags, zdb_blkptr_cb, &zcb);
if (zcb.zcb_haderrors) {
@@ -2450,6 +2483,14 @@ dump_block_stats(spa_t *spa)
else
(void) printf(" L%d %s\n",
level, typename);
+
+ if (dump_opt['b'] >= 4) {
+ (void) printf("psize "
+ "(in 512-byte sectors): "
+ "number of blocks\n");
+ dump_histogram(zb->zb_psize_histogram,
+ PSIZE_HISTO_SIZE);
+ }
}
}
}
OpenPOWER on IntegriCloud