dovecot-2.2: lib: add rudementary statistics gathering to data-s...

dovecot at dovecot.org dovecot at dovecot.org
Mon Jul 28 13:54:27 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/d3914e9ffba3
changeset: 17637:d3914e9ffba3
user:      Phil Carmody <phil at dovecot.fi>
date:      Mon Jul 28 16:45:33 2014 +0300
description:
lib: add rudementary statistics gathering to data-stack debugging
These currently just enhance the overly-large alloc_size warning
message in t_malloc_real() to show what the history of allocations
is. New warnings look like this:
 Warning: Growing data stack by 32768 as 'test_run_funcs' reaches 16416 bytes from 202 allocations.

Future possible directions:
t_malloc_real() could be further modified to identify badly-behaved
regions of code that allocate lots of smaller blocks as it happens
(which might be noisy). t_pop() could be modified to detect such code
after it exits its block (so just one warning per instance of
misbehaviour).

Signed-off-by: Phil Carmody <phil at dovecot.fi>

diffstat:

 src/lib/data-stack.c |  16 ++++++++++++++--
 1 files changed, 14 insertions(+), 2 deletions(-)

diffs (48 lines):

diff -r 9251b51dda54 -r d3914e9ffba3 src/lib/data-stack.c
--- a/src/lib/data-stack.c	Mon Jul 28 16:45:33 2014 +0300
+++ b/src/lib/data-stack.c	Mon Jul 28 16:45:33 2014 +0300
@@ -56,6 +56,9 @@
 	size_t last_alloc_size[BLOCK_FRAME_COUNT];
 #ifdef DEBUG
 	const char *marker[BLOCK_FRAME_COUNT];
+	/* Fairly arbitrary profiling data */
+	unsigned long long alloc_bytes[BLOCK_FRAME_COUNT];
+	unsigned int alloc_count[BLOCK_FRAME_COUNT];
 #endif
 };
 
@@ -158,6 +161,8 @@
         current_frame_block->last_alloc_size[frame_pos] = 0;
 #ifdef DEBUG
 	current_frame_block->marker[frame_pos] = marker;
+	current_frame_block->alloc_bytes[frame_pos] = 0ULL;
+	current_frame_block->alloc_count[frame_pos] = 0;
 #else
 	(void)marker; /* only used for debugging */
 #endif
@@ -359,6 +364,10 @@
 	alloc_size = MEM_ALIGN(size);
 #else
 	alloc_size = MEM_ALIGN(sizeof(size)) + MEM_ALIGN(size + SENTRY_COUNT);
+	if(permanent) {
+		current_frame_block->alloc_bytes[frame_pos] += alloc_size;
+		current_frame_block->alloc_count[frame_pos]++;
+	}
 #endif
 	data_stack_last_buffer_reset(TRUE);
 
@@ -404,9 +413,12 @@
 		if (warn && getenv("DEBUG_SILENT") == NULL) {
 			/* warn after allocation, so if i_warning() wants to
 			   allocate more memory we don't go to infinite loop */
-			i_warning("Growing data stack[%s] with: %"PRIuSIZE_T,
+			i_warning("Growing data stack by %"PRIuSIZE_T" as "
+				  "'%s' reaches %llu bytes from %u allocations.",
+				  block->size,
 				  current_frame_block->marker[frame_pos],
-				  block->size);
+				  current_frame_block->alloc_bytes[frame_pos],
+				  current_frame_block->alloc_count[frame_pos]);
 		}
 #endif
 	}


More information about the dovecot-cvs mailing list