]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: pools/memprof: store and report the pool's name in each bin
authorWilly Tarreau <w@1wt.eu>
Wed, 17 Aug 2022 07:35:16 +0000 (09:35 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 17 Aug 2022 08:34:00 +0000 (10:34 +0200)
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]

include/haproxy/activity-t.h
src/activity.c
src/pool.c

index 0f5210f69edd439de44ea91d4ed8991433ea9be4..24e9f79ac35d74b447cca5478037e99ef368d98a 100644 (file)
@@ -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
 
index ee5577102efef1ce89cac0722ed02c38b897d555..41beb4d81f69449743ad864a0b054af3f67a08ba 100644 (file)
@@ -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)
index 6f3e41971de6fca98e391f7515c3c3fce4faca03..57dc079aa303635837d81610c989b142d1ab077a 100644 (file)
@@ -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