diff options
author | Nick Mathewson <nickm@torproject.org> | 2007-04-19 18:47:04 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2007-04-19 18:47:04 +0000 |
commit | 7392464b8805950be47fddf160efef3d52df7444 (patch) | |
tree | ca07050a3001de9ee7ed7df58b670300b4f8a452 /src/common/mempool.c | |
parent | bf4f0539cf1163c872574055fe69d67f06a5f87f (diff) | |
download | tor-7392464b8805950be47fddf160efef3d52df7444.tar.gz tor-7392464b8805950be47fddf160efef3d52df7444.zip |
r12456@catbus: nickm | 2007-04-19 14:47:01 -0400
Make dumpmemusage() dump cell pool usage information.
svn:r9991
Diffstat (limited to 'src/common/mempool.c')
-rw-r--r-- | src/common/mempool.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/common/mempool.c b/src/common/mempool.c index 91d4db07dc..9f1fd394bd 100644 --- a/src/common/mempool.c +++ b/src/common/mempool.c @@ -72,6 +72,7 @@ #define FREE(x) tor_free(x) #define ASSERT(x) tor_assert(x) #undef ALLOC_CAN_RETURN_NULL +#define TOR /* End Tor dependencies */ #else /* If you're not building this as part of Tor, you'll want to define the @@ -488,3 +489,50 @@ mp_pool_assert_ok(mp_pool_t *pool) ASSERT(pool->n_empty_chunks == n_empty); } +#ifdef TOR +/*FFFF uses Tor logging functions. */ +/**DOCDOC*/ +void +mp_pool_log_status(mp_pool_t *pool, int severity) +{ + uint64_t bytes_used = 0; + uint64_t bytes_allocated = 0; + uint64_t bu = 0, ba = 0; + mp_chunk_t *chunk; + int n_full = 0, n_used = 0; + + ASSERT(pool); + + for (chunk = pool->empty_chunks; chunk; chunk = chunk->next) { + bytes_allocated += chunk->mem_size; + } + log_fn(severity, LD_MM, U64_FORMAT" bytes in %d empty chunks", + U64_PRINTF_ARG(bytes_used), pool->n_empty_chunks); + for (chunk = pool->used_chunks; chunk; chunk = chunk->next) { + ++n_used; + bu += chunk->n_allocated * pool->item_alloc_size; + ba += chunk->mem_size; + } + log_fn(severity, LD_MM, U64_FORMAT"/"U64_FORMAT + " bytes in %d partially full chunks", + U64_PRINTF_ARG(bu), U64_PRINTF_ARG(ba), n_used); + bytes_used += bu; + bytes_allocated += bu; + bu = ba = 0; + for (chunk = pool->full_chunks; chunk; chunk = chunk->next) { + ++n_full; + bu += chunk->n_allocated * pool->item_alloc_size; + ba += chunk->mem_size; + } + log_fn(severity, LD_MM, U64_FORMAT"/"U64_FORMAT + " bytes in %d full chunks", + U64_PRINTF_ARG(bu), U64_PRINTF_ARG(ba), n_full); + bytes_used += bu; + bytes_allocated += bu; + + log_fn(severity, LD_MM, "Total: "U64_FORMAT"/"U64_FORMAT" bytes allocated " + "for cell pools are full.", + U64_PRINTF_ARG(bytes_used), U64_PRINTF_ARG(bytes_allocated)); +} +#endif + |