mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-23 06:41:32 +02:00
MINOR: cli/pools: store "show pools" results into a temporary array
This will permit sorting and filtering that are currently not possible.
This commit is contained in:
parent
ace3da8dd4
commit
224adf2bfb
67
src/pool.c
67
src/pool.c
@ -82,6 +82,17 @@ static const struct {
|
|||||||
{ 0 /* end */ }
|
{ 0 /* end */ }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* describes a snapshot of a pool line about to be dumped by "show pools" */
|
||||||
|
struct pool_dump_info {
|
||||||
|
const struct pool_head *entry;
|
||||||
|
ulong alloc_items;
|
||||||
|
ulong alloc_bytes;
|
||||||
|
ulong used_items;
|
||||||
|
ulong cached_items;
|
||||||
|
ulong need_avg;
|
||||||
|
ulong failed_items;
|
||||||
|
};
|
||||||
|
|
||||||
static int mem_fail_rate __read_mostly = 0;
|
static int mem_fail_rate __read_mostly = 0;
|
||||||
static int using_default_allocator __read_mostly = 1;
|
static int using_default_allocator __read_mostly = 1;
|
||||||
static int disable_trim __read_mostly = 0;
|
static int disable_trim __read_mostly = 0;
|
||||||
@ -868,38 +879,62 @@ void pool_destroy_all()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* will not dump more than this number of entries. Anything beyond this will
|
||||||
|
* likely not fit into a regular output buffer anyway.
|
||||||
|
*/
|
||||||
|
#define POOLS_MAX_DUMPED_ENTRIES 1024
|
||||||
|
|
||||||
/* This function dumps memory usage information into the trash buffer. */
|
/* This function dumps memory usage information into the trash buffer. */
|
||||||
void dump_pools_to_trash()
|
void dump_pools_to_trash()
|
||||||
{
|
{
|
||||||
|
struct pool_dump_info pool_info[POOLS_MAX_DUMPED_ENTRIES];
|
||||||
struct pool_head *entry;
|
struct pool_head *entry;
|
||||||
unsigned long long allocated, used;
|
unsigned long long allocated, used;
|
||||||
int nbpools;
|
int nbpools, i;
|
||||||
unsigned long long cached_bytes = 0;
|
unsigned long long cached_bytes = 0;
|
||||||
uint cached = 0;
|
uint cached = 0;
|
||||||
|
|
||||||
allocated = used = nbpools = 0;
|
allocated = used = nbpools = 0;
|
||||||
chunk_printf(&trash, "Dumping pools usage. Use SIGQUIT to flush them.\n");
|
|
||||||
list_for_each_entry(entry, &pools, list) {
|
list_for_each_entry(entry, &pools, list) {
|
||||||
|
if (nbpools >= POOLS_MAX_DUMPED_ENTRIES)
|
||||||
|
break;
|
||||||
|
|
||||||
if (!(pool_debugging & POOL_DBG_NO_CACHE)) {
|
if (!(pool_debugging & POOL_DBG_NO_CACHE)) {
|
||||||
int i;
|
|
||||||
for (cached = i = 0; i < global.nbthread; i++)
|
for (cached = i = 0; i < global.nbthread; i++)
|
||||||
cached += entry->cache[i].count;
|
cached += entry->cache[i].count;
|
||||||
cached_bytes += cached * (ullong)entry->size;
|
|
||||||
}
|
}
|
||||||
chunk_appendf(&trash, " - Pool %s (%u bytes) : %u allocated (%llu bytes), %u used"
|
pool_info[nbpools].entry = entry;
|
||||||
" (~%u by thread caches)"
|
pool_info[nbpools].alloc_items = entry->allocated;
|
||||||
", needed_avg %u, %u failures, %u users, @%p%s\n",
|
pool_info[nbpools].alloc_bytes = (ulong)entry->size * entry->allocated;
|
||||||
entry->name, entry->size, entry->allocated,
|
pool_info[nbpools].used_items = entry->used;
|
||||||
(ullong)entry->size * entry->allocated, entry->used,
|
pool_info[nbpools].cached_items = cached;
|
||||||
cached,
|
pool_info[nbpools].need_avg = swrate_avg(entry->needed_avg, POOL_AVG_SAMPLES);
|
||||||
swrate_avg(entry->needed_avg, POOL_AVG_SAMPLES), entry->failed,
|
pool_info[nbpools].failed_items = entry->failed;
|
||||||
entry->users, entry,
|
|
||||||
(entry->flags & MEM_F_SHARED) ? " [SHARED]" : "");
|
|
||||||
|
|
||||||
allocated += entry->allocated * (ullong)entry->size;
|
|
||||||
used += entry->used * (ullong)entry->size;
|
|
||||||
nbpools++;
|
nbpools++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
chunk_printf(&trash, "Dumping pools usage");
|
||||||
|
if (nbpools >= POOLS_MAX_DUMPED_ENTRIES)
|
||||||
|
chunk_appendf(&trash, " (limited to the first %u entries)", POOLS_MAX_DUMPED_ENTRIES);
|
||||||
|
chunk_appendf(&trash, ". Use SIGQUIT to flush them.\n");
|
||||||
|
|
||||||
|
for (i = 0; i < nbpools && i < POOLS_MAX_DUMPED_ENTRIES; i++) {
|
||||||
|
chunk_appendf(&trash, " - Pool %s (%lu bytes) : %lu allocated (%lu bytes), %lu used"
|
||||||
|
" (~%lu by thread caches)"
|
||||||
|
", needed_avg %lu, %lu failures, %u users, @%p%s\n",
|
||||||
|
pool_info[i].entry->name, (ulong)pool_info[i].entry->size,
|
||||||
|
pool_info[i].alloc_items, pool_info[i].alloc_bytes,
|
||||||
|
pool_info[i].used_items, pool_info[i].cached_items,
|
||||||
|
pool_info[i].need_avg, pool_info[i].failed_items,
|
||||||
|
pool_info[i].entry->users, pool_info[i].entry,
|
||||||
|
(pool_info[i].entry->flags & MEM_F_SHARED) ? " [SHARED]" : "");
|
||||||
|
|
||||||
|
cached_bytes += pool_info[i].cached_items * (ulong)pool_info[i].entry->size;
|
||||||
|
allocated += pool_info[i].alloc_items * (ulong)pool_info[i].entry->size;
|
||||||
|
used += pool_info[i].used_items * (ulong)pool_info[i].entry->size;
|
||||||
|
}
|
||||||
|
|
||||||
chunk_appendf(&trash, "Total: %d pools, %llu bytes allocated, %llu used"
|
chunk_appendf(&trash, "Total: %d pools, %llu bytes allocated, %llu used"
|
||||||
" (~%llu by thread caches)"
|
" (~%llu by thread caches)"
|
||||||
".\n",
|
".\n",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user