Commit a619466c authored by Rich Prohaska's avatar Rich Prohaska Committed by Yoni Fogel

add cache table hit and miss counters to the cachetable. closes #1483, closes #1457

git-svn-id: file:///svn/toku/tokudb@9496 c7de825b-a66e-492c-adef-691d508d4ae1
parent 360e9866
......@@ -293,20 +293,20 @@ int main (int argc, const char *argv[]) {
}
scanscan_shutdown();
#if 0 && defined TOKUDB
if (0) {
extern void print_hash_histogram (void) __attribute__((__visibility__("default")));
print_hash_histogram();
#if defined(TOKUDB)
if (1) {
extern void toku_cachetable_print_hash_histogram (void);
toku_cachetable_print_hash_histogram();
}
// if tokudb has tracing enabled (see trace_mem.h) then this will dump
// the trace data
if (1) {
if (0) {
extern void toku_print_trace_mem();
toku_print_trace_mem();
}
#endif
#if defined __linux__ && __linux__
#if defined(__linux__) && __linux__
char fname[256];
sprintf(fname, "/proc/%d/status", toku_os_getpid());
FILE *f = fopen(fname, "r");
......
......@@ -39,6 +39,11 @@ static void cachetable_reader(WORKITEM);
#define WHEN_TRACE_CT(x) ((void)0)
#endif
static u_int64_t cachetable_hit;
static u_int64_t cachetable_miss;
static u_int64_t cachetable_wait_reading;
static u_int64_t cachetable_wait;
enum ctpair_state {
CTPAIR_INVALID = 0, // invalid
CTPAIR_IDLE = 1, // in memory
......@@ -768,11 +773,13 @@ static PAIR cachetable_insert_at(CACHETABLE ct,
enum { hash_histogram_max = 100 };
static unsigned long long hash_histogram[hash_histogram_max];
void print_hash_histogram (void) {
void toku_cachetable_print_hash_histogram (void) {
int i;
for (i=0; i<hash_histogram_max; i++)
if (hash_histogram[i]) printf("%d:%llu ", i, hash_histogram[i]);
printf("\n");
printf("miss=%"PRId64" hit=%"PRId64" wait_reading=%"PRId64" wait=%"PRId64"\n",
cachetable_miss, cachetable_hit, cachetable_wait_reading, cachetable_wait);
}
static void
......@@ -830,6 +837,12 @@ int toku_cachetable_get_and_pin(CACHEFILE cachefile, CACHEKEY key, u_int32_t ful
for (p=ct->table[fullhash&(ct->table_size-1)]; p; p=p->hash_chain) {
count++;
if (p->key.b==key.b && p->cachefile==cachefile) {
if (p->rwlock.writer || p->rwlock.want_write) {
if (p->state == CTPAIR_READING)
cachetable_wait_reading++;
else
cachetable_wait++;
}
ctpair_read_lock(&p->rwlock, ct->mutex);
if (p->state == CTPAIR_INVALID) {
ctpair_read_unlock(&p->rwlock);
......@@ -841,6 +854,7 @@ int toku_cachetable_get_and_pin(CACHEFILE cachefile, CACHEKEY key, u_int32_t ful
lru_touch(ct,p);
*value = p->value;
if (sizep) *sizep = p->size;
cachetable_hit++;
note_hash_count(count);
cachetable_unlock(ct);
WHEN_TRACE_CT(printf("%s:%d cachtable_get_and_pin(%lld)--> %p\n", __FILE__, __LINE__, key, *value));
......@@ -864,6 +878,7 @@ int toku_cachetable_get_and_pin(CACHEFILE cachefile, CACHEKEY key, u_int32_t ful
*value = p->value;
if (sizep) *sizep = p->size;
cachetable_miss++;
}
r = maybe_flush_some(ct, 0);
cachetable_unlock(ct);
......
......@@ -207,7 +207,7 @@ void toku_cachefile_verify (CACHEFILE cf);
void toku_cachetable_verify (CACHETABLE t);
// Not for use in production, but useful for testing.
void print_hash_histogram (void) __attribute__((__visibility__("default")));
void toku_cachetable_print_hash_histogram (void) __attribute__((__visibility__("default")));
int toku_graceful_open(const char *db_fname, BOOL *is_dirtyp);
int toku_graceful_close(CACHEFILE cf);
......
......@@ -73,7 +73,7 @@ cachetable_debug_test (int n) {
}
toku_cachetable_verify(ct);
if (verbose) print_hash_histogram();
if (verbose) toku_cachetable_print_hash_histogram();
r = toku_cachefile_close(&f1, NULL_LOGGER, 0); assert(r == 0 && f1 == 0);
r = toku_cachetable_close(&ct); assert(r == 0 && ct == 0);
......
......@@ -30,4 +30,5 @@ EXPORTS
dlrealloc @29
dlfree @30
setup_dlmalloc @31
toku_cachetable_print_hash_histogram @32
......@@ -38,6 +38,8 @@
dlfree;
setup_dlmalloc;
toku_cachetable_print_hash_histogram;
local: *;
};
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