int main(int argc, char *argv[]) { unsigned int i, j; struct tdb_context *tdb; int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP, TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT, TDB_NOMMAP|TDB_CONVERT, TDB_INTERNAL|TDB_VERSION1, TDB_VERSION1, TDB_NOMMAP|TDB_VERSION1, TDB_INTERNAL|TDB_CONVERT|TDB_VERSION1, TDB_CONVERT|TDB_VERSION1, TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 }; struct tdb_data key = { (unsigned char *)&j, sizeof(j) }; struct tdb_data data = { (unsigned char *)&j, sizeof(j) }; char *summary; plan_tests(sizeof(flags) / sizeof(flags[0]) * (1 + 2 * 5) + 1); for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) { tdb = tdb_open("run-summary.tdb", flags[i], O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr); ok1(tdb); if (!tdb) continue; /* Put some stuff in there. */ for (j = 0; j < 500; j++) { /* Make sure padding varies to we get some graphs! */ data.dsize = j % (sizeof(j) + 1); if (tdb_store(tdb, key, data, TDB_REPLACE) != 0) fail("Storing in tdb"); } for (j = 0; j <= TDB_SUMMARY_HISTOGRAMS; j += TDB_SUMMARY_HISTOGRAMS) { ok1(tdb_summary(tdb, j, &summary) == TDB_SUCCESS); ok1(strstr(summary, "Number of records: 500\n")); ok1(strstr(summary, "Smallest/average/largest keys: 4/4/4\n")); ok1(strstr(summary, "Smallest/average/largest data: 0/2/4\n")); if (!(flags[i] & TDB_VERSION1) && j == TDB_SUMMARY_HISTOGRAMS) { ok1(strstr(summary, "|") && strstr(summary, "*")); } else { ok1(!strstr(summary, "|") && !strstr(summary, "*")); } free(summary); } tdb_close(tdb); } ok1(tap_log_messages == 0); return exit_status(); }
static void info_tdb(void) { char *summary = tdb_summary(tdb); if (!summary) { printf("Error = %s\n", tdb_errorstr(tdb)); } else { printf("%s", summary); free(summary); } }
static void info_tdb(void) { enum TDB_ERROR ecode; char *summary; ecode = tdb_summary(tdb, TDB_SUMMARY_HISTOGRAMS, &summary); if (ecode) { terror(ecode, "Getting summary"); } else { printf("%s", summary); free(summary); } }
int main(int argc, char *argv[]) { unsigned int i, j; struct tdb_context *tdb; int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP, TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT, TDB_NOMMAP|TDB_CONVERT }; TDB_DATA key = { (unsigned char *)&j, sizeof(j) }; TDB_DATA data = { (unsigned char *)&j, sizeof(j) }; char *summary; plan_tests(sizeof(flags) / sizeof(flags[0]) * 14); for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) { tdb = tdb_open("run-summary.tdb", 131, flags[i], O_RDWR|O_CREAT|O_TRUNC, 0600); ok1(tdb); if (!tdb) continue; /* Put some stuff in there. */ for (j = 0; j < 500; j++) { /* Make sure padding varies to we get some graphs! */ data.dsize = j % (sizeof(j) + 1); if (tdb_store(tdb, key, data, TDB_REPLACE) != 0) fail("Storing in tdb"); } summary = tdb_summary(tdb); diag("%s", summary); ok1(strstr(summary, "Size of file/data: ")); ok1(strstr(summary, "Number of records: 500\n")); ok1(strstr(summary, "Smallest/average/largest keys: 4/4/4\n")); ok1(strstr(summary, "Smallest/average/largest data: 0/2/4\n")); ok1(strstr(summary, "Smallest/average/largest padding: ")); ok1(strstr(summary, "Number of dead records: 0\n")); ok1(strstr(summary, "Number of free records: 1\n")); ok1(strstr(summary, "Smallest/average/largest free records: ")); ok1(strstr(summary, "Number of hash chains: 131\n")); ok1(strstr(summary, "Smallest/average/largest hash chains: ")); ok1(strstr(summary, "Number of uncoalesced records: 0\n")); ok1(strstr(summary, "Smallest/average/largest uncoalesced runs: 0/0/0\n")); ok1(strstr(summary, "Percentage keys/data/padding/free/dead/rechdrs&tailers/hashes: ")); free(summary); tdb_close(tdb); } return exit_status(); }
int main(int argc, char *argv[]) { unsigned int i, j, num = 1000, stage = 0, stopat = -1; int flags = TDB_DEFAULT; bool transaction = false, summary = false; TDB_DATA key, data; struct tdb_context *tdb; struct timeval start, stop; union tdb_attribute seed, log; bool do_stats = false; enum TDB_ERROR ecode; /* Try to keep benchmarks even. */ seed.base.attr = TDB_ATTRIBUTE_SEED; seed.base.next = NULL; seed.seed.seed = 0; log.base.attr = TDB_ATTRIBUTE_LOG; log.base.next = &seed; log.log.fn = tdb_log; if (argv[1] && strcmp(argv[1], "--internal") == 0) { flags = TDB_INTERNAL; argc--; argv++; } if (argv[1] && strcmp(argv[1], "--transaction") == 0) { transaction = true; argc--; argv++; } if (argv[1] && strcmp(argv[1], "--no-sync") == 0) { flags |= TDB_NOSYNC; argc--; argv++; } if (argv[1] && strcmp(argv[1], "--summary") == 0) { summary = true; argc--; argv++; } if (argv[1] && strcmp(argv[1], "--stats") == 0) { do_stats = true; argc--; argv++; } tdb = tdb_open("/tmp/speed.tdb", flags, O_RDWR|O_CREAT|O_TRUNC, 0600, &log); if (!tdb) err(1, "Opening /tmp/speed.tdb"); key.dptr = (void *)&i; key.dsize = sizeof(i); data = key; if (argv[1]) { num = atoi(argv[1]); argv++; argc--; } if (argv[1]) { stopat = atoi(argv[1]); argv++; argc--; } /* Add 1000 records. */ printf("Adding %u records: ", num); fflush(stdout); if (transaction && (ecode = tdb_transaction_start(tdb))) errx(1, "starting transaction: %s", tdb_errorstr(ecode)); gettimeofday(&start, NULL); for (i = 0; i < num; i++) if ((ecode = tdb_store(tdb, key, data, TDB_INSERT)) != 0) errx(1, "Inserting key %u in tdb: %s", i, tdb_errorstr(ecode)); gettimeofday(&stop, NULL); 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 (tdb_check(tdb, NULL, NULL)) errx(1, "tdb_check failed!"); if (summary) { char *sumstr = NULL; tdb_summary(tdb, TDB_SUMMARY_HISTOGRAMS, &sumstr); printf("%s\n", sumstr); free(sumstr); } if (do_stats) dump_and_clear_stats(&tdb, flags, &log); if (++stage == stopat) exit(0); /* Finding 1000 records. */ printf("Finding %u records: ", num); fflush(stdout); if (transaction && (ecode = tdb_transaction_start(tdb))) errx(1, "starting transaction: %s", tdb_errorstr(ecode)); gettimeofday(&start, NULL); for (i = 0; i < num; 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, ecode ? ecode : *(int *)dbuf.dptr); } } gettimeofday(&stop, NULL); 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 (tdb_check(tdb, NULL, NULL)) errx(1, "tdb_check failed!"); if (summary) { char *sumstr = NULL; tdb_summary(tdb, TDB_SUMMARY_HISTOGRAMS, &sumstr); printf("%s\n", sumstr); free(sumstr); } if (do_stats) dump_and_clear_stats(&tdb, flags, &log); if (++stage == stopat) exit(0); /* Missing 1000 records. */ printf("Missing %u records: ", num); fflush(stdout); if (transaction && (ecode = tdb_transaction_start(tdb))) errx(1, "starting transaction: %s", tdb_errorstr(ecode)); gettimeofday(&start, NULL); for (i = num; i < num*2; i++) { 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 && (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 (tdb_check(tdb, NULL, NULL)) errx(1, "tdb_check failed!"); if (summary) { char *sumstr = NULL; tdb_summary(tdb, TDB_SUMMARY_HISTOGRAMS, &sumstr); printf("%s\n", sumstr); free(sumstr); } if (do_stats) dump_and_clear_stats(&tdb, flags, &log); if (++stage == stopat) exit(0); /* Traverse 1000 records. */ printf("Traversing %u records: ", num); fflush(stdout); if (transaction && (ecode = tdb_transaction_start(tdb))) errx(1, "starting transaction: %s", tdb_errorstr(ecode)); i = 0; gettimeofday(&start, NULL); if (tdb_traverse(tdb, count_record, &i) != num) errx(1, "Traverse returned wrong number of records"); if (i != (num - 1) * (num / 2)) errx(1, "Traverse tallied to %u", i); gettimeofday(&stop, NULL); 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 (tdb_check(tdb, NULL, NULL)) errx(1, "tdb_check failed!"); if (summary) { char *sumstr = NULL; tdb_summary(tdb, TDB_SUMMARY_HISTOGRAMS, &sumstr); printf("%s\n", sumstr); free(sumstr); } if (do_stats) dump_and_clear_stats(&tdb, flags, &log); if (++stage == stopat) exit(0); /* Delete 1000 records (not in order). */ printf("Deleting %u records: ", num); fflush(stdout); if (transaction && (ecode = tdb_transaction_start(tdb))) errx(1, "starting transaction: %s", tdb_errorstr(ecode)); gettimeofday(&start, NULL); for (j = 0; j < num; j++) { i = (j + 100003) % num; if ((ecode = tdb_delete(tdb, key)) != TDB_SUCCESS) errx(1, "Deleting key %u in tdb: %s", i, tdb_errorstr(ecode)); } gettimeofday(&stop, NULL); 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 (tdb_check(tdb, NULL, NULL)) errx(1, "tdb_check failed!"); if (summary) { char *sumstr = NULL; tdb_summary(tdb, TDB_SUMMARY_HISTOGRAMS, &sumstr); printf("%s\n", sumstr); free(sumstr); } if (do_stats) dump_and_clear_stats(&tdb, flags, &log); if (++stage == stopat) exit(0); /* Re-add 1000 records (not in order). */ printf("Re-adding %u records: ", num); fflush(stdout); if (transaction && (ecode = tdb_transaction_start(tdb))) errx(1, "starting transaction: %s", tdb_errorstr(ecode)); gettimeofday(&start, NULL); for (j = 0; j < num; j++) { i = (j + 100003) % num; if ((ecode = tdb_store(tdb, key, data, TDB_INSERT)) != 0) errx(1, "Inserting key %u in tdb: %s", i, tdb_errorstr(ecode)); } gettimeofday(&stop, NULL); 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 (tdb_check(tdb, NULL, NULL)) errx(1, "tdb_check failed!"); if (summary) { char *sumstr = NULL; tdb_summary(tdb, TDB_SUMMARY_HISTOGRAMS, &sumstr); printf("%s\n", sumstr); free(sumstr); } if (do_stats) dump_and_clear_stats(&tdb, flags, &log); if (++stage == stopat) exit(0); /* Append 1000 records. */ if (transaction && (ecode = tdb_transaction_start(tdb))) errx(1, "starting transaction: %s", tdb_errorstr(ecode)); printf("Appending %u records: ", num); fflush(stdout); gettimeofday(&start, NULL); for (i = 0; i < num; i++) if ((ecode = tdb_append(tdb, key, data)) != TDB_SUCCESS) errx(1, "Appending key %u in tdb: %s", i, tdb_errorstr(ecode)); gettimeofday(&stop, NULL); 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 (tdb_check(tdb, NULL, NULL)) errx(1, "tdb_check failed!"); if (summary) { char *sumstr = NULL; tdb_summary(tdb, TDB_SUMMARY_HISTOGRAMS, &sumstr); printf("%s\n", sumstr); free(sumstr); } if (++stage == stopat) exit(0); /* Churn 1000 records: not in order! */ if (transaction && (ecode = tdb_transaction_start(tdb))) errx(1, "starting transaction: %s", tdb_errorstr(ecode)); printf("Churning %u records: ", num); fflush(stdout); gettimeofday(&start, NULL); for (j = 0; j < num; j++) { i = (j + 1000019) % num; if ((ecode = tdb_delete(tdb, key)) != TDB_SUCCESS) errx(1, "Deleting key %u in tdb: %s", i, tdb_errorstr(ecode)); i += num; if ((ecode = tdb_store(tdb, key, data, TDB_INSERT)) != 0) errx(1, "Inserting key %u in tdb: %s", i, tdb_errorstr(ecode)); } gettimeofday(&stop, NULL); 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 (tdb_check(tdb, NULL, NULL)) errx(1, "tdb_check failed!"); if (summary) { char *sumstr = NULL; tdb_summary(tdb, TDB_SUMMARY_HISTOGRAMS, &sumstr); printf("%s\n", sumstr); free(sumstr); } if (do_stats) dump_and_clear_stats(&tdb, flags, &log); if (++stage == stopat) exit(0); return 0; }