From 6d9075ac4697889e340f032c74ac4a9aff707fe7 Mon Sep 17 00:00:00 2001 From: morriss Date: Fri, 9 Oct 2009 21:00:00 +0000 Subject: Unify the stats output regardless of whether we're using canaries or not. Fix some math/calculation issues (including taking the guard pages into account when calculating waste). Since we've already counted the SE allocations for the distribution display, use that (instead of the canaries) to count how many allocations we've had. git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@30449 f5534014-38df-0310-8fa8-9805f1628bb7 --- epan/emem.c | 70 ++++++++++++++++++++++++------------------------------------- 1 file changed, 27 insertions(+), 43 deletions(-) (limited to 'epan/emem.c') diff --git a/epan/emem.c b/epan/emem.c index 2bdf3c5c5f..4df16d6645 100644 --- a/epan/emem.c +++ b/epan/emem.c @@ -291,7 +291,8 @@ se_init_chunk(void) } #ifdef SHOW_EMEM_STATS -static guint allocations[10] = { 0 }; +#define NUM_ALLOC_DIST 10 +static guint allocations[NUM_ALLOC_DIST] = { 0 }; static guint total_no_chunks = 0; static void @@ -303,6 +304,7 @@ print_alloc_stats() guint total_allocation = 0; guint total_free = 0; guint used_for_canaries = 0; + guint total_headers; guint i_ctr, i; emem_chunk_t *chunk; guint total_space_allocated_from_os, total_space_wasted; @@ -317,7 +319,7 @@ print_alloc_stats() printf("No memory allocated\n"); ep_stat = FALSE; } - if ((ep_debug_use_chunks)&&(ep_stat)){ + if (ep_debug_use_chunks && ep_stat) { /* Nothing interesting without chunks */ /* Only look at the used_list since those chunks are fully used. * Looking at the free list would skew our view. @@ -367,7 +369,7 @@ print_alloc_stats() } if (!se_debug_use_chunks ) - return; /* Nothing interesting without chunks & canaries?? */ + return; /* Nothing interesting without chunks?? */ /* Only look at the used_list since those chunks are fully used. * Looking at the free list would skew our view. @@ -379,7 +381,6 @@ print_alloc_stats() total_free += chunk->amount_free; if (se_debug_use_canary){ - num_allocs += chunk->canary_info->c_count; for (i_ctr = 0; i_ctr < chunk->canary_info->c_count; i_ctr++) { used_for_canaries += chunk->canary_info->cmp_len[i_ctr]; } @@ -391,60 +392,43 @@ print_alloc_stats() printf ("No fully used chunks, nothing to do\n"); return; } - if (!se_debug_use_canary){ - printf ("\n"); - printf ("\n---- Buffer space ----\n"); - printf ("\tChunk allocation size: %10u\n", EMEM_PACKET_CHUNK_SIZE); - printf ("\t* Number of chunks: %10u\n", num_chunks); - printf ("\t-------------------------------------------\n"); - printf ("\t= %u (%u including guard pages) total space used for buffers\n", - total_allocation, EMEM_PACKET_CHUNK_SIZE * num_chunks); - printf ("\t-------------------------------------------\n"); - total_space_allocated_from_os = total_allocation - + (sizeof(emem_chunk_t) + sizeof(emem_canary_t)) * num_chunks; - printf ("Total allocated from OS: %u\n\n", - total_space_allocated_from_os); - printf ("---------- Allocations from the SE pool ----------\n"); - printf (" Number of SE allocations: %10u\n", num_allocs); - printf ("Bytes used (incl. canaries): %10u\n", total_used); - printf (" Bytes used for canaries: %10u\n", used_for_canaries); - printf (" Bytes unused (wasted): %10u\n\n", - total_allocation - total_used); - printf ("---------- Statistics ----------\n"); - printf ("\nAllocation distribution (sizes include canaries):\n"); - for (i = 0; i < 9; i++) - printf ("size < %5d: %8u\n", 32< %5d: %8u\n", 32< %5d: %8u\n", 32<