]> git.ozlabs.org Git - ccan/commitdiff
tdb2: add comparison stats
authorRusty Russell <rusty@rustcorp.com.au>
Wed, 1 Dec 2010 12:53:50 +0000 (23:23 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Wed, 1 Dec 2010 12:53:50 +0000 (23:23 +1030)
ccan/tdb2/hash.c
ccan/tdb2/tdb2.h
ccan/tdb2/tools/speed.c

index a8a701ec507d1ab13de7551a96244389c38742e3..d4d08e420d878f6e35f60fac9cac1bbbcb5a840f 100644 (file)
@@ -85,32 +85,42 @@ static bool match(struct tdb_context *tdb,
                  tdb_off_t val,
                  struct tdb_used_record *rec)
 {
                  tdb_off_t val,
                  struct tdb_used_record *rec)
 {
-       bool ret;
+       bool ret = false;
        const unsigned char *rkey;
        tdb_off_t off;
 
        const unsigned char *rkey;
        tdb_off_t off;
 
+       add_stat(tdb, compares, 1);
        /* Desired bucket must match. */
        /* 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,
 
        /* 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)
 
        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? */
 
        /* 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)
 
        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;
 }
        tdb_access_release(tdb, rkey);
        return ret;
 }
index ea298db5e6aaa6e63e3ca632d561d6e6748013ab..3cbdfbefda30f4d39374ddd10849a56e4e06583f 100644 (file)
@@ -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     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;
        uint64_t expands;
        uint64_t frees;
        uint64_t locks;
index 7a100d0adffce59468052aaa8ce9a22244d1280f..4ed8997146ea8d35613e5f21cd9250b06d3e657c 100644 (file)
@@ -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);
               (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",
        printf("expands = %llu\n",
               (unsigned long long)stats->expands);
        printf("frees = %llu\n",