]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: debug: also store the function name in struct mem_stats
authorWilly Tarreau <w@1wt.eu>
Tue, 9 Aug 2022 06:40:08 +0000 (08:40 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 9 Aug 2022 06:42:42 +0000 (08:42 +0200)
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 :-(

include/haproxy/bug.h
include/haproxy/pool.h
src/debug.c

index 1ca15a641f565aee2dfbc84c7792382c3930e57b..f4cc71b4bab29d1ff5c7bd2dc40ed9c8ea295867 100644 (file)
@@ -242,6 +242,7 @@ enum {
 struct mem_stats {
        size_t calls;
        size_t size;
+       const char *func;
        const char *file;
        int line;
        int type;
@@ -254,6 +255,7 @@ struct mem_stats {
        static struct mem_stats _ __attribute__((used,__section__("mem_stats"),__aligned__(sizeof(void*)))) = { \
                .file = __FILE__, .line = __LINE__,                     \
                .type = MEM_STATS_TYPE_CALLOC,                          \
+               .func = __func__,                                       \
        };                                                              \
        HA_WEAK("__start_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*)))) = { \
                .file = __FILE__, .line = __LINE__,                     \
                .type = MEM_STATS_TYPE_FREE,                            \
+               .func = __func__,                                       \
        };                                                              \
        HA_WEAK("__start_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*)))) = { \
                .file = __FILE__, .line = __LINE__,                     \
                .type = MEM_STATS_TYPE_FREE,                            \
+               .func = __func__,                                       \
        };                                                              \
        HA_WEAK("__start_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*)))) = { \
                .file = __FILE__, .line = __LINE__,                     \
                .type = MEM_STATS_TYPE_MALLOC,                          \
+               .func = __func__,                                       \
        };                                                              \
        HA_WEAK("__start_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*)))) = { \
                .file = __FILE__, .line = __LINE__,                     \
                .type = MEM_STATS_TYPE_REALLOC,                         \
+               .func = __func__,                                       \
        };                                                              \
        HA_WEAK("__start_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*)))) = { \
                .file = __FILE__, .line = __LINE__,                     \
                .type = MEM_STATS_TYPE_STRDUP,                          \
+               .func = __func__,                                       \
        };                                                              \
        HA_WEAK("__start_mem_stats");                                   \
        HA_WEAK("__stop_mem_stats");                                    \
index 579b53cb89543d7b5dcae6dda6f67ca96c1dcc55..ec974d1b1bc51bf9d1f6b2156599cb16e08663c7 100644 (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*)))) = { \
                .file = __FILE__, .line = __LINE__,                     \
                .type = MEM_STATS_TYPE_P_FREE,                          \
+               .func = __func__,                                       \
        };                                                              \
        _.extra = __pool;                                               \
        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*)))) = { \
                .file = __FILE__, .line = __LINE__,                     \
                .type = MEM_STATS_TYPE_P_ALLOC,                         \
+               .func = __func__,                                       \
        };                                                              \
        _.extra = __pool;                                               \
        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*)))) = { \
                .file = __FILE__, .line = __LINE__,                     \
                .type = MEM_STATS_TYPE_P_ALLOC,                         \
+               .func = __func__,                                       \
        };                                                              \
        _.extra = __pool;                                               \
        HA_WEAK("__start_mem_stats");                                   \
index 074af81179aa2e2bf7b9bc10f2a3b2b1e3f51ae2..0431306885c5aa2ea050a0edb4363c86af7f57d7 100644 (file)
@@ -1279,8 +1279,6 @@ static int debug_iohandler_memstats(struct appctx *appctx)
        if (unlikely(sc_ic(sc)->flags & (CF_WRITE_ERROR|CF_SHUTW)))
                goto end;
 
-       chunk_reset(&trash);
-
        /* we have two inner loops here, one for the proxy, the other one for
         * the buffer.
         */
@@ -1289,6 +1287,7 @@ static int debug_iohandler_memstats(struct appctx *appctx)
                const char *name;
                const char *p;
                const char *info = NULL;
+               const char *func = NULL;
 
                if (!ptr->size && !ptr->calls && !ctx->show_all)
                        continue;
@@ -1299,6 +1298,8 @@ static int debug_iohandler_memstats(struct appctx *appctx)
                                name = p + 1;
                }
 
+               func = ptr->func;
+
                switch (ptr->type) {
                case MEM_STATS_TYPE_CALLOC:  type = "CALLOC";  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->calls ? (ptr->size / ptr->calls) : 0));
 
-               chunk_printf(&trash, "%s:%d", name, ptr->line);
-               while (trash.data < 25)
+               chunk_reset(&trash);
+               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++] = ' ';
+
                chunk_appendf(&trash, "%7s  size: %12lu  calls: %9lu  size/call: %6lu %s\n",
                             type,
                             (unsigned long)ptr->size, (unsigned long)ptr->calls,