X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Ftdb%2Fsummary.c;h=cb6dd6ee127bf20e1af36361bb0670930007e91b;hb=0a97f2dc1df96702dd88d4be169f43dd186c2bfa;hp=b8f7f97624ce69d22533688282410b30d9cf953b;hpb=43d881a232a4999e0d23db8e4335604dd5f3474a;p=ccan-lca-2011.git diff --git a/ccan/tdb/summary.c b/ccan/tdb/summary.c index b8f7f97..cb6dd6e 100644 --- a/ccan/tdb/summary.c +++ b/ccan/tdb/summary.c @@ -19,7 +19,7 @@ #include #define SUMMARY_FORMAT \ - "Size of file/data: %zu/%zu\n" \ + "Size of file/data: %u/%zu\n" \ "Number of records: %zu\n" \ "Smallest/average/largest keys: %zu/%zu/%zu\n%s" \ "Smallest/average/largest data: %zu/%zu/%zu\n%s" \ @@ -37,21 +37,6 @@ #define HISTO_WIDTH 70 #define HISTO_HEIGHT 20 -/* Slow, but should be very rare. */ -static size_t dead_space(struct tdb_context *tdb, tdb_off_t off) -{ - size_t len; - - for (len = 0; off + len < tdb->map_size; len++) { - char c; - if (tdb->methods->tdb_read(tdb, off, &c, 1, 0)) - return 0; - if (c != 0 && c != 0x42) - break; - } - return len; -} - static size_t get_hash_length(struct tdb_context *tdb, unsigned int i) { tdb_off_t rec_ptr; @@ -81,6 +66,8 @@ char *tdb_summary(struct tdb_context *tdb, enum tdb_summary_flags flags) bool locked; size_t len, unc = 0; + freeg = keysg = datag = deadg = extrag = hashg = uncoalg = NULL; + /* Read-only databases use no locking at all: it's best-effort. * We may have a write lock already, so skip that case too. */ if (tdb->read_only || tdb->allrecord_lock.count != 0) { @@ -124,7 +111,7 @@ char *tdb_summary(struct tdb_context *tdb, enum tdb_summary_flags flags) case TDB_RECOVERY_INVALID_MAGIC: case 0x42424242: unc++; - rec.rec_len = dead_space(tdb, off) - sizeof(rec); + rec.rec_len = tdb_dead_space(tdb, off) - sizeof(rec); /* Fall through */ case TDB_DEAD_MAGIC: tally_add(dead, rec.rec_len); @@ -156,8 +143,6 @@ char *tdb_summary(struct tdb_context *tdb, enum tdb_summary_flags flags) extrag = tally_histogram(extra, HISTO_WIDTH, HISTO_HEIGHT); hashg = tally_histogram(hash, HISTO_WIDTH, HISTO_HEIGHT); uncoalg = tally_histogram(uncoal, HISTO_WIDTH, HISTO_HEIGHT); - } else { - freeg = keysg = datag = deadg = extrag = hashg = NULL; } /* 20 is max length of a %zu. */