Skip to content

Commit 409d6ec

Browse files
benpeartdscho
authored andcommitted
mem_pool: add GIT_TRACE_MEMPOOL support
Add tracing around initializing and discarding mempools. In discard report on the amount of memory unused in the current block to help tune setting the initial_size. Signed-off-by: Ben Peart <[email protected]>
1 parent c27092b commit 409d6ec

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

mem-pool.c

+10
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
#include "git-compat-util.h"
88
#include "mem-pool.h"
99
#include "gettext.h"
10+
#include "trace.h"
1011

12+
static struct trace_key trace_mem_pool = TRACE_KEY_INIT(MEMPOOL);
1113
#define BLOCK_GROWTH_SIZE (1024 * 1024 - sizeof(struct mp_block))
1214

1315
/*
@@ -65,12 +67,20 @@ void mem_pool_init(struct mem_pool *pool, size_t initial_size)
6567

6668
if (initial_size > 0)
6769
mem_pool_alloc_block(pool, initial_size, NULL);
70+
71+
trace_printf_key(&trace_mem_pool,
72+
"mem_pool (%p): init (%"PRIuMAX") initial size\n",
73+
(void *)pool, (uintmax_t)initial_size);
6874
}
6975

7076
void mem_pool_discard(struct mem_pool *pool, int invalidate_memory)
7177
{
7278
struct mp_block *block, *block_to_free;
7379

80+
trace_printf_key(&trace_mem_pool,
81+
"mem_pool (%p): discard (%"PRIuMAX") unused\n",
82+
(void *)pool,
83+
(uintmax_t)(pool->mp_block->end - pool->mp_block->next_free));
7484
block = pool->mp_block;
7585
while (block)
7686
{

0 commit comments

Comments
 (0)