From: Willy Tarreau Date: Wed, 17 Aug 2022 07:35:16 +0000 (+0200) Subject: MINOR: pools/memprof: store and report the pool's name in each bin X-Git-Tag: v2.7-dev4~35 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=42b180dcdb0fd51467ce69882d48649b160bcdf4;p=thirdparty%2Fhaproxy.git MINOR: pools/memprof: store and report the pool's name in each bin Storing the pointer to the pool along with the stats is quite useful as it allows to report the name. That's what we're doing here. We could store it in place of another field but that's not convenient as it would require to change all functions that manipulate counters. Thus here we store one extra field, as well as some padding because the struct turns 56 bytes long, thus better go to 64 directly. Example of output from "show profiling memory": 2 0 48 0| 0x4bfb2c ha_quic_set_encryption_secrets+0xcc/0xb5e p_alloc(24) [pool=quic_tls_iv] 0 55252 0 10608384| 0x4bed32 main+0x2beb2 free(-192) 15 0 2760 0| 0x4be855 main+0x2b9d5 p_alloc(184) [pool=quic_frame] 1 0 1048 0| 0x4be266 ha_quic_add_handshake_data+0x2b6/0x66d p_alloc(1048) [pool=quic_crypto] 3 0 552 0| 0x4be142 ha_quic_add_handshake_data+0x192/0x66d p_alloc(184) [pool=quic_frame] 31276 0 6755616 0| 0x4bb8f9 quic_sock_fd_iocb+0x689/0x69b p_alloc(216) [pool=quic_dgram] 0 31424 0 6787584| 0x4bb7f3 quic_sock_fd_iocb+0x583/0x69b p_free(-216) [pool=quic_dgram] 152 0 32832 0| 0x4bb4d9 quic_sock_fd_iocb+0x269/0x69b p_alloc(216) [pool=quic_dgram] --- diff --git a/include/haproxy/activity-t.h b/include/haproxy/activity-t.h index 0f5210f69e..24e9f79ac3 100644 --- a/include/haproxy/activity-t.h +++ b/include/haproxy/activity-t.h @@ -69,6 +69,8 @@ struct memprof_stats { unsigned long long free_calls; unsigned long long alloc_tot; unsigned long long free_tot; + void *info; // for pools, ptr to the pool + void *pad; // pad to 64 }; #endif diff --git a/src/activity.c b/src/activity.c index ee5577102e..41beb4d81f 100644 --- a/src/activity.c +++ b/src/activity.c @@ -726,6 +726,12 @@ static int cli_io_handler_show_profiling(struct appctx *appctx) chunk_appendf(&trash," [delta=%lld]", (long long)(entry->alloc_tot - entry->free_tot)); } + if (entry->info) { + /* that's a pool name */ + const struct pool_head *pool = entry->info; + chunk_appendf(&trash," [pool=%s]", pool->name); + } + chunk_appendf(&trash, "\n"); if (applet_putchk(appctx, &trash) == -1) diff --git a/src/pool.c b/src/pool.c index 6f3e41971d..57dc079aa3 100644 --- a/src/pool.c +++ b/src/pool.c @@ -734,6 +734,7 @@ void *__pool_alloc(struct pool_head *pool, unsigned int flags) bin = memprof_get_bin(__builtin_return_address(0), MEMPROF_METH_P_ALLOC); _HA_ATOMIC_ADD(&bin->alloc_calls, 1); _HA_ATOMIC_ADD(&bin->alloc_tot, pool->size); + _HA_ATOMIC_STORE(&bin->info, pool); } #endif if (unlikely(flags & POOL_F_MUST_ZERO)) @@ -763,6 +764,7 @@ void __pool_free(struct pool_head *pool, void *ptr) bin = memprof_get_bin(__builtin_return_address(0), MEMPROF_METH_P_FREE); _HA_ATOMIC_ADD(&bin->free_calls, 1); _HA_ATOMIC_ADD(&bin->free_tot, pool->size); + _HA_ATOMIC_STORE(&bin->info, pool); } #endif