From a3e4ebff2eb9dc2e386160b8acf77d70236f4def Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 31 Aug 2011 15:31:08 +0930 Subject: [PATCH] tdb2: add stats to tdb1 backend. It's actually quite a good fit; we use compare_wrong_bucket for dead records, which is kind of correct (they should be in the free list). --- ccan/tdb2/tdb1_freelist.c | 8 ++++++++ ccan/tdb2/tdb1_io.c | 1 + ccan/tdb2/tdb1_tdb.c | 17 ++++++++++++----- ccan/tdb2/tdb1_transaction.c | 5 +++++ 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/ccan/tdb2/tdb1_freelist.c b/ccan/tdb2/tdb1_freelist.c index 37f19ab2..af012937 100644 --- a/ccan/tdb2/tdb1_freelist.c +++ b/ccan/tdb2/tdb1_freelist.c @@ -83,6 +83,7 @@ int tdb1_free(struct tdb_context *tdb, tdb1_off_t offset, struct tdb1_record *re goto fail; } + tdb->stats.alloc_coalesce_tried++; /* Look left */ if (offset - sizeof(tdb1_off_t) > TDB1_DATA_START(tdb->tdb1.header.hash_size)) { tdb1_off_t left = offset - sizeof(tdb1_off_t); @@ -131,6 +132,9 @@ int tdb1_free(struct tdb_context *tdb, tdb1_off_t offset, struct tdb1_record *re "tdb1_free: update_tailer failed at %u", offset); goto fail; } + tdb->stats.alloc_coalesce_succeeded++; + tdb->stats.alloc_coalesce_num_merged++; + tdb->stats.frees++; tdb1_unlock(tdb, -1, F_WRLCK); return 0; } @@ -151,6 +155,7 @@ update: } /* And we're done. */ + tdb->stats.frees++; tdb1_unlock(tdb, -1, F_WRLCK); return 0; @@ -188,6 +193,7 @@ static tdb1_off_t tdb1_allocate_ofs(struct tdb_context *tdb, if (tdb1_rec_write(tdb, rec_ptr, rec) == -1) { return 0; } + tdb->stats.allocs++; return rec_ptr; } @@ -215,6 +221,8 @@ static tdb1_off_t tdb1_allocate_ofs(struct tdb_context *tdb, return 0; } + tdb->stats.allocs++; + tdb->stats.alloc_leftover++; return rec_ptr; } diff --git a/ccan/tdb2/tdb1_io.c b/ccan/tdb2/tdb1_io.c index 8219e930..ba6deeef 100644 --- a/ccan/tdb2/tdb1_io.c +++ b/ccan/tdb2/tdb1_io.c @@ -307,6 +307,7 @@ static int tdb1_expand_file(struct tdb_context *tdb, tdb1_off_t size, tdb1_off_t addition -= written; size += written; } + tdb->stats.expands++; return 0; } diff --git a/ccan/tdb2/tdb1_tdb.c b/ccan/tdb2/tdb1_tdb.c index 98f830cc..9730dcef 100644 --- a/ccan/tdb2/tdb1_tdb.c +++ b/ccan/tdb2/tdb1_tdb.c @@ -89,11 +89,18 @@ static tdb1_off_t tdb1_find(struct tdb_context *tdb, TDB_DATA key, uint32_t hash if (tdb1_rec_read(tdb, rec_ptr, r) == -1) return 0; - if (!TDB1_DEAD(r) && hash==r->full_hash - && key.dsize==r->key_len - && tdb1_parse_data(tdb, key, rec_ptr + sizeof(*r), - r->key_len, tdb1_key_compare, - NULL) == 0) { + tdb->stats.compares++; + if (TDB1_DEAD(r)) { + tdb->stats.compare_wrong_bucket++; + } else if (key.dsize != r->key_len) { + tdb->stats.compare_wrong_keylen++; + } else if (hash != r->full_hash) { + tdb->stats.compare_wrong_rechash++; + } else if (tdb1_parse_data(tdb, key, rec_ptr + sizeof(*r), + r->key_len, tdb1_key_compare, + NULL) != 0) { + tdb->stats.compare_wrong_keycmp++; + } else { return rec_ptr; } /* detect tight infinite loop */ diff --git a/ccan/tdb2/tdb1_transaction.c b/ccan/tdb2/tdb1_transaction.c index ecd7d262..126f7684 100644 --- a/ccan/tdb2/tdb1_transaction.c +++ b/ccan/tdb2/tdb1_transaction.c @@ -432,6 +432,7 @@ static int _tdb1_transaction_start(struct tdb_context *tdb) tdb->last_error = TDB_ERR_EINVAL; return -1; } + tdb->stats.transaction_nest++; tdb->tdb1.transaction->nesting++; return 0; } @@ -511,6 +512,7 @@ static int _tdb1_transaction_start(struct tdb_context *tdb) tdb->tdb1.transaction->io_methods = tdb->tdb1.io; tdb->tdb1.io = &transaction1_methods; + tdb->stats.transactions++; return 0; fail: @@ -621,6 +623,7 @@ static int _tdb1_transaction_cancel(struct tdb_context *tdb) */ int tdb1_transaction_cancel(struct tdb_context *tdb) { + tdb->stats.transaction_cancel++; return _tdb1_transaction_cancel(tdb); } @@ -739,6 +742,7 @@ static int tdb1_recovery_allocate(struct tdb_context *tdb, " failed to create recovery area"); return -1; } + tdb->stats.transaction_expand_file++; /* remap the file (if using mmap) */ methods->tdb1_oob(tdb, tdb->file->map_size + 1, 1); @@ -1000,6 +1004,7 @@ static int _tdb1_transaction_prepare_commit(struct tdb_context *tdb) " expansion failed"); return -1; } + tdb->stats.transaction_expand_file++; tdb->file->map_size = tdb->tdb1.transaction->old_map_size; methods->tdb1_oob(tdb, tdb->file->map_size + 1, 1); } -- 2.39.2