From: Marko Kreen Date: Fri, 11 Jan 2008 22:36:01 +0000 (+0000) Subject: SHOW MEM cmd to describe slab usage X-Git-Tag: pgbouncer_1_2_rc2~60 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d490f5bf6c3b9c92ebdc793b8bc8040e2d0a82eb;p=pgbouncer SHOW MEM cmd to describe slab usage --- diff --git a/include/slab.h b/include/slab.h index 738effe..276523a 100644 --- a/include/slab.h +++ b/include/slab.h @@ -15,4 +15,8 @@ int objcache_total_count(ObjectCache *cache); int objcache_free_count(ObjectCache *cache); int objcache_active_count(ObjectCache *cache); +typedef void (*slab_stat_fn)(void *arg, const char *slab_name, + unsigned size, unsigned free, + unsigned total); +void objcache_stats(slab_stat_fn fn, void *arg); diff --git a/src/admin.c b/src/admin.c index 3a9b85c..0c940fa 100644 --- a/src/admin.c +++ b/src/admin.c @@ -704,6 +704,33 @@ static bool admin_show_pools(PgSocket *admin, const char *arg) return true; } +static void slab_stat_cb(void *arg, const char *slab_name, + unsigned size, unsigned free, + unsigned total) +{ + PktBuf *buf = arg; + unsigned alloc = total * size; + pktbuf_write_DataRow(buf, "siiii", slab_name, + size, total - free, free, alloc); +} + +/* Command: SHOW MEM */ +static bool admin_show_mem(PgSocket *admin, const char *arg) +{ + PktBuf *buf; + + buf = pktbuf_dynamic(256); + if (!buf) { + admin_error(admin, "no mem"); + return true; + } + pktbuf_write_RowDescription(buf, "siiii", "name", + "size", "used", "free", "memtotal"); + objcache_stats(slab_stat_cb, buf); + admin_flush(admin, buf, "SHOW"); + return true; +} + /* Command: SHOW CONFIG */ static bool admin_show_config(PgSocket *admin, const char *arg) { @@ -895,9 +922,9 @@ static bool admin_show_help(PgSocket *admin, const char *arg) SEND_generic(res, admin, 'N', "sssss", "SNOTICE", "C00000", "MConsole usage", - "D\n\tSHOW [HELP|CONFIG|DATABASES" - "|POOLS|CLIENTS|SERVERS|VERSION]\n" - "\tSHOW [FDS|SOCKETS|ACTIVE_SOCKETS|LISTS]\n" + "D\n\tSHOW HELP|CONFIG|DATABASES" + "|POOLS|CLIENTS|SERVERS|VERSION\n" + "\tSHOW FDS|SOCKETS|ACTIVE_SOCKETS|LISTS|MEM\n" "\tSET key = arg\n" "\tRELOAD\n" "\tPAUSE []\n" @@ -946,6 +973,7 @@ static struct cmd_lookup show_map [] = { {"users", admin_show_users}, {"version", admin_show_version}, {"totals", admin_show_totals}, + {"mem", admin_show_mem}, {NULL, NULL} }; diff --git a/src/slab.c b/src/slab.c index c33904c..8f6170b 100644 --- a/src/slab.c +++ b/src/slab.c @@ -205,3 +205,20 @@ int objcache_active_count(ObjectCache *cache) return objcache_total_count(cache) - objcache_free_count(cache); } +static void run_slab_stats(ObjectCache *cache, slab_stat_fn fn, void *arg) +{ + unsigned free = statlist_count(&cache->freelist); + fn(arg, cache->name, cache->final_size, free, cache->total_count); +} + +void objcache_stats(slab_stat_fn fn, void *arg) +{ + ObjectCache *cache; + List *item; + + statlist_for_each(item, &objcache_list) { + cache = container_of(item, ObjectCache, head); + run_slab_stats(cache, fn, arg); + } +} +