diff --git a/src/server/simple-cache.c b/src/server/simple-cache.c index 1023cf9c1f09c669e18bdb9c5a6b84d47776ece8..140deaf339a2952405c806ef0135554af9cdf6cc 100644 --- a/src/server/simple-cache.c +++ b/src/server/simple-cache.c @@ -386,6 +386,7 @@ cached_get_person_stat( Pers_no person ) if ( node->ptr != NULL ) { pers_set_mru( person ); + ++pers_mcb->hits; return node->ptr; } @@ -393,11 +394,13 @@ cached_get_person_stat( Pers_no person ) { node->ptr = copy_person (node->snap_shot); pers_set_mru (person); + ++pers_mcb->hits; return node->ptr; } node->ptr = read_person(file_a, node->pos, node->size); + ++pers_mcb->misses; pers_set_mru (person); return node->ptr; } @@ -406,6 +409,34 @@ cached_get_person_stat( Pers_no person ) /* * Conference-related calls */ + + +static int no_of_allocated_small_confs = 0; + +static void +free_small_conf (Small_conf *sc) +{ + if ( sc != NULL ) + { + --no_of_allocated_small_confs; + s_clear ( &sc->name ); + sfree (sc); + } +} + + +static Small_conf * +alloc_small_conf(void) +{ + Small_conf *s; + s = smalloc(sizeof(Small_conf)); + *s = EMPTY_SMALL_CONF; + ++no_of_allocated_small_confs; + + return s; +} + + extern Conf_no /* Also cache the name */ cached_create_conf (String name) { @@ -569,6 +600,7 @@ cached_get_conf_stat (Conf_no conf_no) if ( node->ptr != NULL ) { conf_set_mru (conf_no); + ++conf_mcb->hits; return node->ptr; } @@ -576,10 +608,12 @@ cached_get_conf_stat (Conf_no conf_no) { node->ptr = copy_conf (node->snap_shot); conf_set_mru (conf_no); + ++conf_mcb->hits; return node->ptr; } node->ptr = read_conference(file_a, node->pos, node->size); + ++conf_mcb->misses; conf_set_mru (conf_no); return node->ptr; @@ -666,6 +700,7 @@ cached_get_text_stat( Text_no text ) { TRACE1("Found in ptr.\n"); text_set_mru( text ); + ++text_mcb->hits; return node->ptr; } @@ -674,6 +709,7 @@ cached_get_text_stat( Text_no text ) TRACE1("Found in snap_shot\n"); node->ptr = copy_text_stat(node->snap_shot); text_set_mru (text); + ++text_mcb->hits; return node->ptr; } @@ -681,6 +717,7 @@ cached_get_text_stat( Text_no text ) node->ptr = read_text_stat(file_a, node->pos, node->size); text_set_mru (text); + ++text_mcb->misses; return node->ptr; } @@ -1552,15 +1589,6 @@ sync_part(void) return FALSE; } -static Small_conf * -alloc_small_conf(void) -{ - Small_conf *s; - s = smalloc(sizeof(Small_conf)); - *s = EMPTY_SMALL_CONF; - - return s; -} static void setup_small_conf(Conf_no conf_no, @@ -1772,7 +1800,11 @@ free_all_cache (void) destruct_cache_node (pers_mcb, i); - s_clear ( &small_conf_arr[i]->name ); + if ( small_conf_arr[i] != NULL ) + { + free_small_conf (small_conf_arr[i]); + small_conf_arr[i] = NULL; + } } for ( i = 0; i < next_text_num; i++ ) @@ -1920,7 +1952,7 @@ limit_text_stat() /* * Limit the number of 'clean' cache entries. */ -void +EXPORT void cache_limit_size(void) { limit_pers(); @@ -1928,4 +1960,37 @@ cache_limit_size(void) limit_text_stat(); } - +EXPORT void +dump_cache_mem_usage(FILE *fp) +{ + fprintf(fp, "---simple-cache.c:\n" + "\tSmall_confs: %d\n", + no_of_allocated_small_confs); +} + + +EXPORT void +dump_cache_stats(FILE *fp) +{ + fprintf(fp, "---simple-cache.c:\n"); + fprintf(fp, + "\tPersons:\n" + "\t hits: %lu\n" + "\t miss: %lu\n", + pers_mcb->hits, + pers_mcb->misses); + fprintf(fp, + "\tConferences:\n" + "\t hits: %lu\n" + "\t miss: %lu\n", + conf_mcb->hits, + conf_mcb->misses); + fprintf(fp, + "\tText_stats:\n" + "\t hits: %lu\n" + "\t miss: %lu\n", + text_mcb->hits, + text_mcb->misses); +} + +