diff -r a098e94cd318 src/lib/mempool-alloconly.c --- a/src/lib/mempool-alloconly.c Wed Jun 27 23:12:34 2007 +0300 +++ b/src/lib/mempool-alloconly.c Wed Jun 27 23:02:43 2007 +0300 @@ -5,6 +5,14 @@ #include "mempool.h" #include + +#ifdef DEBUG +# define DEBUG_POOL_LIST +#endif +#ifdef DEBUG_POOL_LIST +# include "ioloop.h" +# include "lib-signals.h" +#endif #ifdef HAVE_GC_GC_H # include @@ -17,6 +25,10 @@ struct alloconly_pool { struct alloconly_pool { struct pool pool; int refcount; + +#ifdef DEBUG_POOL_LIST + struct alloconly_pool *prev, *next; +#endif struct pool_block *block; #ifdef DEBUG @@ -91,6 +103,32 @@ static void check_nuls(struct pool_block } #endif +#ifdef DEBUG_POOL_LIST +static int sig_registered = FALSE; +static struct alloconly_pool *alloconly_pools; + +static void sig_print_pools(int signo __attr_unused__, + void *context __attr_unused__) +{ + struct alloconly_pool *apool; + struct pool_block *block; + unsigned int total, used, all_used = 0, all_total = 0; + + for (apool = alloconly_pools; apool != NULL; apool = apool->next) { + total = used = 0; + for (block = apool->block; block != NULL; block = block->prev) { + total += block->size; + used += block->size - block->left; + } + all_used += used; + all_total += total; + + i_info("pool %s: %u / %u bytes", apool->name, used, total); + } + i_info("pool totals: %u / %u bytes", all_used, all_total); +} +#endif + pool_t pool_alloconly_create(const char *name __attr_unused__, size_t size) { struct alloconly_pool apool, *new_apool; @@ -124,12 +162,34 @@ pool_t pool_alloconly_create(const char new_apool->block->last_alloc_size = 0; #endif +#ifdef DEBUG_POOL_LIST + if (alloconly_pools != NULL) { + new_apool->next = alloconly_pools; + alloconly_pools->prev = new_apool; + } + alloconly_pools = new_apool; + + if (current_ioloop != NULL && !sig_registered) { + sig_registered = TRUE; + lib_signals_set_handler(SIGUSR1, TRUE, sig_print_pools, NULL); + } +#endif + return &new_apool->pool; } static void pool_alloconly_destroy(struct alloconly_pool *apool) { void *block; + +#ifdef DEBUG_POOL_LIST + if (apool->next != NULL) + apool->next->prev = apool->prev; + if (apool->prev != NULL) + apool->prev->next = apool->next; + else + alloconly_pools = apool->next; +#endif /* destroy all but the last block */ pool_alloconly_clear(&apool->pool);