Commit f2c286c9 authored by Rusty Russell's avatar Rusty Russell

tdb2: add comparison stats

parent 4e185ad8
......@@ -85,32 +85,42 @@ static bool match(struct tdb_context *tdb,
tdb_off_t val,
struct tdb_used_record *rec)
{
bool ret;
bool ret = false;
const unsigned char *rkey;
tdb_off_t off;
add_stat(tdb, compares, 1);
/* Desired bucket must match. */
if (h->home_bucket != (val & TDB_OFF_HASH_GROUP_MASK))
return false;
if (h->home_bucket != (val & TDB_OFF_HASH_GROUP_MASK)) {
add_stat(tdb, compare_wrong_bucket, 1);
return ret;
}
/* Top bits of offset == next bits of hash. */
if (bits(val, TDB_OFF_HASH_EXTRA_BIT, TDB_OFF_UPPER_STEAL_EXTRA)
!= bits(h->h, 64 - h->hash_used - TDB_OFF_UPPER_STEAL_EXTRA,
TDB_OFF_UPPER_STEAL_EXTRA))
return false;
TDB_OFF_UPPER_STEAL_EXTRA)) {
add_stat(tdb, compare_wrong_offsetbits, 1);
return ret;
}
off = val & TDB_OFF_MASK;
if (tdb_read_convert(tdb, off, rec, sizeof(*rec)) == -1)
return false;
return ret;
/* FIXME: check extra bits in header? */
if (rec_key_length(rec) != key->dsize)
return false;
if (rec_key_length(rec) != key->dsize) {
add_stat(tdb, compare_wrong_keylen, 1);
return ret;
}
rkey = tdb_access_read(tdb, off + sizeof(*rec), key->dsize, false);
if (!rkey)
return false;
ret = (memcmp(rkey, key->dptr, key->dsize) == 0);
return ret;
if (memcmp(rkey, key->dptr, key->dsize) == 0)
ret = true;
else
add_stat(tdb, compare_wrong_keycmp, 1);
tdb_access_release(tdb, rkey);
return ret;
}
......
......@@ -126,6 +126,12 @@ struct tdb_attribute_stats {
uint64_t alloc_coalesce_race;
uint64_t alloc_coalesce_succeeded;
uint64_t alloc_coalesce_num_merged;
uint64_t compares;
uint64_t compare_wrong_bucket;
uint64_t compare_wrong_offsetbits;
uint64_t compare_wrong_keylen;
uint64_t compare_wrong_rechash;
uint64_t compare_wrong_keycmp;
uint64_t expands;
uint64_t frees;
uint64_t locks;
......
......@@ -65,6 +65,18 @@ static void dump_and_clear_stats(struct tdb_attribute_stats *stats)
(unsigned long long)stats->alloc_coalesce_succeeded);
printf(" alloc_coalesce_num_merged = %llu\n",
(unsigned long long)stats->alloc_coalesce_num_merged);
printf("compares = %llu\n",
(unsigned long long)stats->compares);
printf(" compare_wrong_bucket = %llu\n",
(unsigned long long)stats->compare_wrong_bucket);
printf(" compare_wrong_offsetbits = %llu\n",
(unsigned long long)stats->compare_wrong_offsetbits);
printf(" compare_wrong_keylen = %llu\n",
(unsigned long long)stats->compare_wrong_keylen);
printf(" compare_wrong_rechash = %llu\n",
(unsigned long long)stats->compare_wrong_rechash);
printf(" compare_wrong_keycmp = %llu\n",
(unsigned long long)stats->compare_wrong_keycmp);
printf("expands = %llu\n",
(unsigned long long)stats->expands);
printf("frees = %llu\n",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment