MINOR: debug: also store the function name in struct mem_stats

The calling function name is now stored in the structure, and it's
reported when the "all" argument is passed. The first column is
significantly enlarged because some names are really wide :-(
This commit is contained in:
Willy Tarreau 2022-08-09 08:40:08 +02:00
parent 55c950baa9
commit 17200dd1f3
3 changed files with 24 additions and 4 deletions

View File

@ -242,6 +242,7 @@ enum {
struct mem_stats { struct mem_stats {
size_t calls; size_t calls;
size_t size; size_t size;
const char *func;
const char *file; const char *file;
int line; int line;
int type; int type;
@ -254,6 +255,7 @@ struct mem_stats {
static struct mem_stats _ __attribute__((used,__section__("mem_stats"),__aligned__(sizeof(void*)))) = { \ static struct mem_stats _ __attribute__((used,__section__("mem_stats"),__aligned__(sizeof(void*)))) = { \
.file = __FILE__, .line = __LINE__, \ .file = __FILE__, .line = __LINE__, \
.type = MEM_STATS_TYPE_CALLOC, \ .type = MEM_STATS_TYPE_CALLOC, \
.func = __func__, \
}; \ }; \
HA_WEAK("__start_mem_stats"); \ HA_WEAK("__start_mem_stats"); \
HA_WEAK("__stop_mem_stats"); \ HA_WEAK("__stop_mem_stats"); \
@ -271,6 +273,7 @@ struct mem_stats {
static struct mem_stats _ __attribute__((used,__section__("mem_stats"),__aligned__(sizeof(void*)))) = { \ static struct mem_stats _ __attribute__((used,__section__("mem_stats"),__aligned__(sizeof(void*)))) = { \
.file = __FILE__, .line = __LINE__, \ .file = __FILE__, .line = __LINE__, \
.type = MEM_STATS_TYPE_FREE, \ .type = MEM_STATS_TYPE_FREE, \
.func = __func__, \
}; \ }; \
HA_WEAK("__start_mem_stats"); \ HA_WEAK("__start_mem_stats"); \
HA_WEAK("__stop_mem_stats"); \ HA_WEAK("__stop_mem_stats"); \
@ -285,6 +288,7 @@ struct mem_stats {
static struct mem_stats _ __attribute__((used,__section__("mem_stats"),__aligned__(sizeof(void*)))) = { \ static struct mem_stats _ __attribute__((used,__section__("mem_stats"),__aligned__(sizeof(void*)))) = { \
.file = __FILE__, .line = __LINE__, \ .file = __FILE__, .line = __LINE__, \
.type = MEM_STATS_TYPE_FREE, \ .type = MEM_STATS_TYPE_FREE, \
.func = __func__, \
}; \ }; \
HA_WEAK("__start_mem_stats"); \ HA_WEAK("__start_mem_stats"); \
HA_WEAK("__stop_mem_stats"); \ HA_WEAK("__stop_mem_stats"); \
@ -303,6 +307,7 @@ struct mem_stats {
static struct mem_stats _ __attribute__((used,__section__("mem_stats"),__aligned__(sizeof(void*)))) = { \ static struct mem_stats _ __attribute__((used,__section__("mem_stats"),__aligned__(sizeof(void*)))) = { \
.file = __FILE__, .line = __LINE__, \ .file = __FILE__, .line = __LINE__, \
.type = MEM_STATS_TYPE_MALLOC, \ .type = MEM_STATS_TYPE_MALLOC, \
.func = __func__, \
}; \ }; \
HA_WEAK("__start_mem_stats"); \ HA_WEAK("__start_mem_stats"); \
HA_WEAK("__stop_mem_stats"); \ HA_WEAK("__stop_mem_stats"); \
@ -317,6 +322,7 @@ struct mem_stats {
static struct mem_stats _ __attribute__((used,__section__("mem_stats"),__aligned__(sizeof(void*)))) = { \ static struct mem_stats _ __attribute__((used,__section__("mem_stats"),__aligned__(sizeof(void*)))) = { \
.file = __FILE__, .line = __LINE__, \ .file = __FILE__, .line = __LINE__, \
.type = MEM_STATS_TYPE_REALLOC, \ .type = MEM_STATS_TYPE_REALLOC, \
.func = __func__, \
}; \ }; \
HA_WEAK("__start_mem_stats"); \ HA_WEAK("__start_mem_stats"); \
HA_WEAK("__stop_mem_stats"); \ HA_WEAK("__stop_mem_stats"); \
@ -331,6 +337,7 @@ struct mem_stats {
static struct mem_stats _ __attribute__((used,__section__("mem_stats"),__aligned__(sizeof(void*)))) = { \ static struct mem_stats _ __attribute__((used,__section__("mem_stats"),__aligned__(sizeof(void*)))) = { \
.file = __FILE__, .line = __LINE__, \ .file = __FILE__, .line = __LINE__, \
.type = MEM_STATS_TYPE_STRDUP, \ .type = MEM_STATS_TYPE_STRDUP, \
.func = __func__, \
}; \ }; \
HA_WEAK("__start_mem_stats"); \ HA_WEAK("__start_mem_stats"); \
HA_WEAK("__stop_mem_stats"); \ HA_WEAK("__stop_mem_stats"); \

View File

@ -258,6 +258,7 @@ static inline void *pool_get_from_cache(struct pool_head *pool, const void *call
static struct mem_stats _ __attribute__((used,__section__("mem_stats"),__aligned__(sizeof(void*)))) = { \ static struct mem_stats _ __attribute__((used,__section__("mem_stats"),__aligned__(sizeof(void*)))) = { \
.file = __FILE__, .line = __LINE__, \ .file = __FILE__, .line = __LINE__, \
.type = MEM_STATS_TYPE_P_FREE, \ .type = MEM_STATS_TYPE_P_FREE, \
.func = __func__, \
}; \ }; \
_.extra = __pool; \ _.extra = __pool; \
HA_WEAK("__start_mem_stats"); \ HA_WEAK("__start_mem_stats"); \
@ -275,6 +276,7 @@ static inline void *pool_get_from_cache(struct pool_head *pool, const void *call
static struct mem_stats _ __attribute__((used,__section__("mem_stats"),__aligned__(sizeof(void*)))) = { \ static struct mem_stats _ __attribute__((used,__section__("mem_stats"),__aligned__(sizeof(void*)))) = { \
.file = __FILE__, .line = __LINE__, \ .file = __FILE__, .line = __LINE__, \
.type = MEM_STATS_TYPE_P_ALLOC, \ .type = MEM_STATS_TYPE_P_ALLOC, \
.func = __func__, \
}; \ }; \
_.extra = __pool; \ _.extra = __pool; \
HA_WEAK("__start_mem_stats"); \ HA_WEAK("__start_mem_stats"); \
@ -290,6 +292,7 @@ static inline void *pool_get_from_cache(struct pool_head *pool, const void *call
static struct mem_stats _ __attribute__((used,__section__("mem_stats"),__aligned__(sizeof(void*)))) = { \ static struct mem_stats _ __attribute__((used,__section__("mem_stats"),__aligned__(sizeof(void*)))) = { \
.file = __FILE__, .line = __LINE__, \ .file = __FILE__, .line = __LINE__, \
.type = MEM_STATS_TYPE_P_ALLOC, \ .type = MEM_STATS_TYPE_P_ALLOC, \
.func = __func__, \
}; \ }; \
_.extra = __pool; \ _.extra = __pool; \
HA_WEAK("__start_mem_stats"); \ HA_WEAK("__start_mem_stats"); \

View File

@ -1279,8 +1279,6 @@ static int debug_iohandler_memstats(struct appctx *appctx)
if (unlikely(sc_ic(sc)->flags & (CF_WRITE_ERROR|CF_SHUTW))) if (unlikely(sc_ic(sc)->flags & (CF_WRITE_ERROR|CF_SHUTW)))
goto end; goto end;
chunk_reset(&trash);
/* we have two inner loops here, one for the proxy, the other one for /* we have two inner loops here, one for the proxy, the other one for
* the buffer. * the buffer.
*/ */
@ -1289,6 +1287,7 @@ static int debug_iohandler_memstats(struct appctx *appctx)
const char *name; const char *name;
const char *p; const char *p;
const char *info = NULL; const char *info = NULL;
const char *func = NULL;
if (!ptr->size && !ptr->calls && !ctx->show_all) if (!ptr->size && !ptr->calls && !ctx->show_all)
continue; continue;
@ -1299,6 +1298,8 @@ static int debug_iohandler_memstats(struct appctx *appctx)
name = p + 1; name = p + 1;
} }
func = ptr->func;
switch (ptr->type) { switch (ptr->type) {
case MEM_STATS_TYPE_CALLOC: type = "CALLOC"; break; case MEM_STATS_TYPE_CALLOC: type = "CALLOC"; break;
case MEM_STATS_TYPE_FREE: type = "FREE"; break; case MEM_STATS_TYPE_FREE: type = "FREE"; break;
@ -1316,9 +1317,18 @@ static int debug_iohandler_memstats(struct appctx *appctx)
// (unsigned long)ptr->size, (unsigned long)ptr->calls, // (unsigned long)ptr->size, (unsigned long)ptr->calls,
// (unsigned long)(ptr->calls ? (ptr->size / ptr->calls) : 0)); // (unsigned long)(ptr->calls ? (ptr->size / ptr->calls) : 0));
chunk_printf(&trash, "%s:%d", name, ptr->line); chunk_reset(&trash);
while (trash.data < 25) if (ctx->show_all)
chunk_appendf(&trash, "%s(", func);
chunk_appendf(&trash, "%s:%d", name, ptr->line);
if (ctx->show_all)
chunk_appendf(&trash, ")");
while (trash.data < (ctx->show_all ? 45 : 25))
trash.area[trash.data++] = ' '; trash.area[trash.data++] = ' ';
chunk_appendf(&trash, "%7s size: %12lu calls: %9lu size/call: %6lu %s\n", chunk_appendf(&trash, "%7s size: %12lu calls: %9lu size/call: %6lu %s\n",
type, type,
(unsigned long)ptr->size, (unsigned long)ptr->calls, (unsigned long)ptr->size, (unsigned long)ptr->calls,