DBusMemPool: add usage stats

Reviewed-by: Cosimo Alfarano <cosimo.alfarano@collabora.co.uk>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=34040
This commit is contained in:
Simon McVittie 2011-02-08 12:29:52 +00:00
parent 206fff7ee6
commit 82bc508785
2 changed files with 48 additions and 0 deletions

View file

@ -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

View file

@ -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 */