summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2011-09-14 08:10:13 +0930
committerRusty Russell <rusty@rustcorp.com.au>2011-09-14 08:10:13 +0930
commit26f3587d4bf60fe3c82084a7661c4f856534725f (patch)
tree4268149def9655420fc296e01dc98e9102039685 /lib
parentb30bb0ed903a49a9a81d0418211e4f985eca20ab (diff)
downloadsamba-26f3587d4bf60fe3c82084a7661c4f856534725f.tar.gz
samba-26f3587d4bf60fe3c82084a7661c4f856534725f.tar.bz2
samba-26f3587d4bf60fe3c82084a7661c4f856534725f.zip
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). Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (Imported from CCAN commit a3e4ebff2eb9dc2e386160b8acf77d70236f4def)
Diffstat (limited to 'lib')
-rw-r--r--lib/tdb2/tdb1_freelist.c8
-rw-r--r--lib/tdb2/tdb1_io.c1
-rw-r--r--lib/tdb2/tdb1_tdb.c17
-rw-r--r--lib/tdb2/tdb1_transaction.c5
4 files changed, 26 insertions, 5 deletions
diff --git a/lib/tdb2/tdb1_freelist.c b/lib/tdb2/tdb1_freelist.c
index 37f19ab28b..af01293721 100644
--- a/lib/tdb2/tdb1_freelist.c
+++ b/lib/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/lib/tdb2/tdb1_io.c b/lib/tdb2/tdb1_io.c
index 8219e93046..ba6deeef20 100644
--- a/lib/tdb2/tdb1_io.c
+++ b/lib/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/lib/tdb2/tdb1_tdb.c b/lib/tdb2/tdb1_tdb.c
index 98f830cc9a..9730dceffc 100644
--- a/lib/tdb2/tdb1_tdb.c
+++ b/lib/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/lib/tdb2/tdb1_transaction.c b/lib/tdb2/tdb1_transaction.c
index ecd7d2628e..126f768468 100644
--- a/lib/tdb2/tdb1_transaction.c
+++ b/lib/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);
}