X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Ftdb2%2Ftools%2Fspeed.c;h=06dc45f6327890f3688a74655ff66c8146b06deb;hb=788c3a4f3469afa00c7414451a5f93e584ce0187;hp=7a100d0adffce59468052aaa8ce9a22244d1280f;hpb=fe55330a60e4e14ea6cac2ff40d50eddca4cf140;p=ccan diff --git a/ccan/tdb2/tools/speed.c b/ccan/tdb2/tools/speed.c index 7a100d0a..06dc45f6 100644 --- a/ccan/tdb2/tools/speed.c +++ b/ccan/tdb2/tools/speed.c @@ -49,6 +49,8 @@ static void dump_and_clear_stats(struct tdb_attribute_stats *stats) (unsigned long long)stats->allocs); printf(" alloc_subhash = %llu\n", (unsigned long long)stats->alloc_subhash); + printf(" alloc_chain = %llu\n", + (unsigned long long)stats->alloc_chain); printf(" alloc_bucket_exact = %llu\n", (unsigned long long)stats->alloc_bucket_exact); printf(" alloc_bucket_max = %llu\n", @@ -65,6 +67,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", @@ -89,6 +103,7 @@ int main(int argc, char *argv[]) struct tdb_context *tdb; struct timeval start, stop; union tdb_attribute seed, stats; + enum TDB_ERROR ecode; /* Try to keep benchmarks even. */ seed.base.attr = TDB_ATTRIBUTE_SEED; @@ -137,19 +152,19 @@ int main(int argc, char *argv[]) argc--; } - if (transaction && tdb_transaction_start(tdb)) - errx(1, "starting transaction: %s", tdb_errorstr(tdb)); + if (transaction && (ecode = tdb_transaction_start(tdb))) + errx(1, "starting transaction: %s", tdb_errorstr(ecode)); /* Add 1000 records. */ printf("Adding %u records: ", num); fflush(stdout); gettimeofday(&start, NULL); for (i = 0; i < num; i++) - if (tdb_store(tdb, key, data, TDB_INSERT) != 0) + if ((ecode = tdb_store(tdb, key, data, TDB_INSERT)) != 0) errx(1, "Inserting key %u in tdb: %s", - i, tdb_errorstr(tdb)); + i, tdb_errorstr(ecode)); gettimeofday(&stop, NULL); - if (transaction && tdb_transaction_commit(tdb)) - errx(1, "committing transaction: %s", tdb_errorstr(tdb)); + if (transaction && (ecode = tdb_transaction_commit(tdb))) + errx(1, "committing transaction: %s", tdb_errorstr(ecode)); printf(" %zu ns (%zu bytes)\n", normalize(&start, &stop, num), file_size()); @@ -158,22 +173,23 @@ int main(int argc, char *argv[]) if (++stage == stopat) exit(0); - if (transaction && tdb_transaction_start(tdb)) - errx(1, "starting transaction: %s", tdb_errorstr(tdb)); + if (transaction && (ecode = tdb_transaction_start(tdb))) + errx(1, "starting transaction: %s", tdb_errorstr(ecode)); /* Finding 1000 records. */ printf("Finding %u records: ", num); fflush(stdout); gettimeofday(&start, NULL); for (i = 0; i < num; i++) { - int *dptr; - dptr = (int *)tdb_fetch(tdb, key).dptr; - if (!dptr || *dptr != i) + struct tdb_data dbuf; + if ((ecode = tdb_fetch(tdb, key, &dbuf)) != TDB_SUCCESS + || *(int *)dbuf.dptr != i) { errx(1, "Fetching key %u in tdb gave %u", - i, dptr ? *dptr : -1); + i, ecode ? ecode : *(int *)dbuf.dptr); + } } gettimeofday(&stop, NULL); - if (transaction && tdb_transaction_commit(tdb)) - errx(1, "committing transaction: %s", tdb_errorstr(tdb)); + if (transaction && (ecode = tdb_transaction_commit(tdb))) + errx(1, "committing transaction: %s", tdb_errorstr(ecode)); printf(" %zu ns (%zu bytes)\n", normalize(&start, &stop, num), file_size()); if (seed.base.next) @@ -181,21 +197,22 @@ int main(int argc, char *argv[]) if (++stage == stopat) exit(0); - if (transaction && tdb_transaction_start(tdb)) - errx(1, "starting transaction: %s", tdb_errorstr(tdb)); + if (transaction && (ecode = tdb_transaction_start(tdb))) + errx(1, "starting transaction: %s", tdb_errorstr(ecode)); /* Missing 1000 records. */ printf("Missing %u records: ", num); fflush(stdout); gettimeofday(&start, NULL); for (i = num; i < num*2; i++) { - int *dptr; - dptr = (int *)tdb_fetch(tdb, key).dptr; - if (dptr) - errx(1, "Fetching key %u in tdb gave %u", i, *dptr); + struct tdb_data dbuf; + ecode = tdb_fetch(tdb, key, &dbuf); + if (ecode != TDB_ERR_NOEXIST) + errx(1, "Fetching key %u in tdb gave %s", + i, tdb_errorstr(ecode)); } gettimeofday(&stop, NULL); - if (transaction && tdb_transaction_commit(tdb)) - errx(1, "committing transaction: %s", tdb_errorstr(tdb)); + if (transaction && (ecode = tdb_transaction_commit(tdb))) + errx(1, "committing transaction: %s", tdb_errorstr(ecode)); printf(" %zu ns (%zu bytes)\n", normalize(&start, &stop, num), file_size()); if (seed.base.next) @@ -203,8 +220,8 @@ int main(int argc, char *argv[]) if (++stage == stopat) exit(0); - if (transaction && tdb_transaction_start(tdb)) - errx(1, "starting transaction: %s", tdb_errorstr(tdb)); + if (transaction && (ecode = tdb_transaction_start(tdb))) + errx(1, "starting transaction: %s", tdb_errorstr(ecode)); /* Traverse 1000 records. */ printf("Traversing %u records: ", num); fflush(stdout); @@ -215,8 +232,8 @@ int main(int argc, char *argv[]) if (i != (num - 1) * (num / 2)) errx(1, "Traverse tallied to %u", i); gettimeofday(&stop, NULL); - if (transaction && tdb_transaction_commit(tdb)) - errx(1, "committing transaction: %s", tdb_errorstr(tdb)); + if (transaction && (ecode = tdb_transaction_commit(tdb))) + errx(1, "committing transaction: %s", tdb_errorstr(ecode)); printf(" %zu ns (%zu bytes)\n", normalize(&start, &stop, num), file_size()); if (seed.base.next) @@ -224,21 +241,21 @@ int main(int argc, char *argv[]) if (++stage == stopat) exit(0); - if (transaction && tdb_transaction_start(tdb)) - errx(1, "starting transaction: %s", tdb_errorstr(tdb)); + if (transaction && (ecode = tdb_transaction_start(tdb))) + errx(1, "starting transaction: %s", tdb_errorstr(ecode)); /* Delete 1000 records (not in order). */ printf("Deleting %u records: ", num); fflush(stdout); gettimeofday(&start, NULL); for (j = 0; j < num; j++) { i = (j + 100003) % num; - if (tdb_delete(tdb, key) != 0) + if ((ecode = tdb_delete(tdb, key)) != TDB_SUCCESS) errx(1, "Deleting key %u in tdb: %s", - i, tdb_errorstr(tdb)); + i, tdb_errorstr(ecode)); } gettimeofday(&stop, NULL); - if (transaction && tdb_transaction_commit(tdb)) - errx(1, "committing transaction: %s", tdb_errorstr(tdb)); + if (transaction && (ecode = tdb_transaction_commit(tdb))) + errx(1, "committing transaction: %s", tdb_errorstr(ecode)); printf(" %zu ns (%zu bytes)\n", normalize(&start, &stop, num), file_size()); if (seed.base.next) @@ -246,21 +263,21 @@ int main(int argc, char *argv[]) if (++stage == stopat) exit(0); - if (transaction && tdb_transaction_start(tdb)) - errx(1, "starting transaction: %s", tdb_errorstr(tdb)); + if (transaction && (ecode = tdb_transaction_start(tdb))) + errx(1, "starting transaction: %s", tdb_errorstr(ecode)); /* Re-add 1000 records (not in order). */ printf("Re-adding %u records: ", num); fflush(stdout); gettimeofday(&start, NULL); for (j = 0; j < num; j++) { i = (j + 100003) % num; - if (tdb_store(tdb, key, data, TDB_INSERT) != 0) + if ((ecode = tdb_store(tdb, key, data, TDB_INSERT)) != 0) errx(1, "Inserting key %u in tdb: %s", - i, tdb_errorstr(tdb)); + i, tdb_errorstr(ecode)); } gettimeofday(&stop, NULL); - if (transaction && tdb_transaction_commit(tdb)) - errx(1, "committing transaction: %s", tdb_errorstr(tdb)); + if (transaction && (ecode = tdb_transaction_commit(tdb))) + errx(1, "committing transaction: %s", tdb_errorstr(ecode)); printf(" %zu ns (%zu bytes)\n", normalize(&start, &stop, num), file_size()); if (seed.base.next) @@ -268,43 +285,43 @@ int main(int argc, char *argv[]) if (++stage == stopat) exit(0); - if (transaction && tdb_transaction_start(tdb)) - errx(1, "starting transaction: %s", tdb_errorstr(tdb)); + if (transaction && (ecode = tdb_transaction_start(tdb))) + errx(1, "starting transaction: %s", tdb_errorstr(ecode)); /* Append 1000 records. */ printf("Appending %u records: ", num); fflush(stdout); gettimeofday(&start, NULL); for (i = 0; i < num; i++) - if (tdb_append(tdb, key, data) != 0) + if ((ecode = tdb_append(tdb, key, data)) != TDB_SUCCESS) errx(1, "Appending key %u in tdb: %s", - i, tdb_errorstr(tdb)); + i, tdb_errorstr(ecode)); gettimeofday(&stop, NULL); - if (transaction && tdb_transaction_commit(tdb)) - errx(1, "committing transaction: %s", tdb_errorstr(tdb)); + if (transaction && (ecode = tdb_transaction_commit(tdb))) + errx(1, "committing transaction: %s", tdb_errorstr(ecode)); printf(" %zu ns (%zu bytes)\n", normalize(&start, &stop, num), file_size()); if (++stage == stopat) exit(0); - if (transaction && tdb_transaction_start(tdb)) - errx(1, "starting transaction: %s", tdb_errorstr(tdb)); + if (transaction && (ecode = tdb_transaction_start(tdb))) + errx(1, "starting transaction: %s", tdb_errorstr(ecode)); /* Churn 1000 records: not in order! */ printf("Churning %u records: ", num); fflush(stdout); gettimeofday(&start, NULL); for (j = 0; j < num; j++) { i = (j + 1000019) % num; - if (tdb_delete(tdb, key) != 0) + if ((ecode = tdb_delete(tdb, key)) != TDB_SUCCESS) errx(1, "Deleting key %u in tdb: %s", - i, tdb_errorstr(tdb)); + i, tdb_errorstr(ecode)); i += num; - if (tdb_store(tdb, key, data, TDB_INSERT) != 0) + if ((ecode = tdb_store(tdb, key, data, TDB_INSERT)) != 0) errx(1, "Inserting key %u in tdb: %s", - i, tdb_errorstr(tdb)); + i, tdb_errorstr(ecode)); } gettimeofday(&stop, NULL); - if (transaction && tdb_transaction_commit(tdb)) - errx(1, "committing transaction: %s", tdb_errorstr(tdb)); + if (transaction && (ecode = tdb_transaction_commit(tdb))) + errx(1, "committing transaction: %s", tdb_errorstr(ecode)); printf(" %zu ns (%zu bytes)\n", normalize(&start, &stop, num), file_size());