From c5b6a07414258e2b0fe478b0a1eb1222f38a53ac Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 8 Feb 2011 12:29:52 +0000 Subject: [PATCH 04/10] DBusMemPool: add usage stats Bug: https://bugs.freedesktop.org/show_bug.cgi?id=34040 --- dbus/dbus-mempool.c | 42 ++++++++++++++++++++++++++++++++++++++++++ dbus/dbus-mempool.h | 6 ++++++ 2 files changed, 48 insertions(+), 0 deletions(-) diff --git a/dbus/dbus-mempool.c b/dbus/dbus-mempool.c index 680586b..563bffc 100644 --- a/dbus/dbus-mempool.c +++ b/dbus/dbus-mempool.c @@ -390,6 +390,48 @@ _dbus_mem_pool_dealloc (DBusMemPool *pool, } } +#ifdef DBUS_ENABLE_STATS +void +_dbus_mem_pool_get_stats (DBusMemPool *pool, + dbus_uint32_t *in_use_p, + dbus_uint32_t *in_free_list_p, + dbus_uint32_t *allocated_p) +{ + DBusMemBlock *block; + DBusFreedElement *freed; + dbus_uint32_t in_use = 0; + dbus_uint32_t in_free_list = 0; + dbus_uint32_t allocated = 0; + + if (pool != NULL) + { + in_use = pool->element_size * pool->allocated_elements; + + for (freed = pool->free_elements; freed != NULL; freed = freed->next) + { + in_free_list += pool->element_size; + } + + for (block = pool->blocks; block != NULL; block = block->next) + { + if (block == pool->blocks) + allocated += pool->block_size; + else + allocated += block->used_so_far; + } + } + + if (in_use_p != NULL) + *in_use_p = in_use; + + if (in_free_list_p != NULL) + *in_free_list_p = in_free_list; + + if (allocated_p != NULL) + *allocated_p = allocated; +} +#endif /* DBUS_ENABLE_STATS */ + /** @} */ #ifdef DBUS_BUILD_TESTS diff --git a/dbus/dbus-mempool.h b/dbus/dbus-mempool.h index afe5247..6693eeb 100644 --- a/dbus/dbus-mempool.h +++ b/dbus/dbus-mempool.h @@ -39,6 +39,12 @@ void* _dbus_mem_pool_alloc (DBusMemPool *pool); dbus_bool_t _dbus_mem_pool_dealloc (DBusMemPool *pool, void *element); +/* if DBUS_ENABLE_STATS */ +void _dbus_mem_pool_get_stats (DBusMemPool *pool, + dbus_uint32_t *in_use_p, + dbus_uint32_t *in_free_list_p, + dbus_uint32_t *allocated_p); + DBUS_END_DECLS #endif /* DBUS_MEMPOOL_H */ -- 1.7.2.3