diff --git a/include/haproxy/activity-t.h b/include/haproxy/activity-t.h index 63779ff9a..f21f8057c 100644 --- a/include/haproxy/activity-t.h +++ b/include/haproxy/activity-t.h @@ -34,6 +34,42 @@ #define HA_PROF_MEMORY 0x00000004 /* memory profiling */ + +#ifdef USE_MEMORY_PROFILING +/* Elements used by memory profiling. This determines the number of buckets to + * store stats. + */ +#define MEMPROF_HASH_BITS 10 +#define MEMPROF_HASH_BUCKETS (1U << MEMPROF_HASH_BITS) + +enum memprof_method { + MEMPROF_METH_UNKNOWN = 0, + MEMPROF_METH_MALLOC, + MEMPROF_METH_CALLOC, + MEMPROF_METH_REALLOC, + MEMPROF_METH_FREE, + MEMPROF_METH_METHODS /* count, must be last */ +}; + +/* stats: + * - malloc increases alloc + * - free increases free (if non null) + * - realloc increases either depending on the size change. + * when the real size is known (malloc_usable_size()), it's used in free_tot + * and alloc_tot, otherwise the requested size is reported in alloc_tot and + * zero in free_tot. + */ +struct memprof_stats { + const void *caller; + enum memprof_method method; + /* 4-7 bytes hole here */ + unsigned long long alloc_calls; + unsigned long long free_calls; + unsigned long long alloc_tot; + unsigned long long free_tot; +}; +#endif + /* per-thread activity reports. It's important that it's aligned on cache lines * because some elements will be updated very often. Most counters are OK on * 32-bit since this will be used during debugging sessions for troubleshooting diff --git a/include/haproxy/activity.h b/include/haproxy/activity.h index 0c5727ba9..383e1ee09 100644 --- a/include/haproxy/activity.h +++ b/include/haproxy/activity.h @@ -33,6 +33,10 @@ void report_stolen_time(uint64_t stolen); void activity_count_runtime(uint32_t run_time); struct sched_activity *sched_activity_entry(struct sched_activity *array, const void *func); +#ifdef USE_MEMORY_PROFILING +struct memprof_stats *memprof_get_bin(const void *ra, enum memprof_method meth); +#endif + #endif /* _HAPROXY_ACTIVITY_H */ /* diff --git a/src/activity.c b/src/activity.c index ff9effbde..c020f24d2 100644 --- a/src/activity.c +++ b/src/activity.c @@ -51,41 +51,11 @@ struct sched_activity sched_activity[256] __attribute__((aligned(64))) = { }; #ifdef USE_MEMORY_PROFILING -/* determine the number of buckets to store stats */ -#define MEMPROF_HASH_BITS 10 -#define MEMPROF_HASH_BUCKETS (1U << MEMPROF_HASH_BITS) - -enum memprof_method { - MEMPROF_METH_UNKNOWN = 0, - MEMPROF_METH_MALLOC, - MEMPROF_METH_CALLOC, - MEMPROF_METH_REALLOC, - MEMPROF_METH_FREE, - MEMPROF_METH_METHODS /* count, must be last */ -}; static const char *const memprof_methods[MEMPROF_METH_METHODS] = { "unknown", "malloc", "calloc", "realloc", "free", }; -/* stats: - * - malloc increases alloc - * - free increases free (if non null) - * - realloc increases either depending on the size change. - * when the real size is known (malloc_usable_size()), it's used in free_tot - * and alloc_tot, otherwise the requested size is reported in alloc_tot and - * zero in free_tot. - */ -struct memprof_stats { - const void *caller; - enum memprof_method method; - /* 4-7 bytes hole here */ - unsigned long long alloc_calls; - unsigned long long free_calls; - unsigned long long alloc_tot; - unsigned long long free_tot; -}; - /* last one is for hash collisions ("others") and has no caller address */ struct memprof_stats memprof_stats[MEMPROF_HASH_BUCKETS + 1] = { }; @@ -210,7 +180,7 @@ static void memprof_free_initial_handler(void *ptr) * case, returns a default bin). The caller address is atomically set except * for the default one which is never set. */ -static struct memprof_stats *memprof_get_bin(const void *ra, enum memprof_method meth) +struct memprof_stats *memprof_get_bin(const void *ra, enum memprof_method meth) { int retries = 16; // up to 16 consecutive entries may be tested. const void *old;