struct mem_stats {
size_t calls;
size_t size;
- const char *func;
- const char *file;
- int line;
- int type;
+ struct ha_caller caller;
const void *extra; // extra info specific to this call (e.g. pool ptr)
} __attribute__((aligned(sizeof(void*))));
#define calloc(x,y) ({ \
size_t __x = (x); size_t __y = (y); \
static struct mem_stats _ __attribute__((used,__section__("mem_stats"),__aligned__(sizeof(void*)))) = { \
- .file = __FILE__, .line = __LINE__, \
- .type = MEM_STATS_TYPE_CALLOC, \
- .func = __func__, \
+ .caller = { \
+ .file = __FILE__, .line = __LINE__, \
+ .what = MEM_STATS_TYPE_CALLOC, \
+ .func = __func__, \
+ }, \
}; \
HA_WEAK("__start_mem_stats"); \
HA_WEAK("__stop_mem_stats"); \
#define will_free(x, y) ({ \
void *__x = (x); size_t __y = (y); \
static struct mem_stats _ __attribute__((used,__section__("mem_stats"),__aligned__(sizeof(void*)))) = { \
- .file = __FILE__, .line = __LINE__, \
- .type = MEM_STATS_TYPE_FREE, \
- .func = __func__, \
+ .caller = { \
+ .file = __FILE__, .line = __LINE__, \
+ .what = MEM_STATS_TYPE_FREE, \
+ .func = __func__, \
+ }, \
}; \
HA_WEAK("__start_mem_stats"); \
HA_WEAK("__stop_mem_stats"); \
#define ha_free(x) ({ \
typeof(x) __x = (x); \
static struct mem_stats _ __attribute__((used,__section__("mem_stats"),__aligned__(sizeof(void*)))) = { \
- .file = __FILE__, .line = __LINE__, \
- .type = MEM_STATS_TYPE_FREE, \
- .func = __func__, \
+ .caller = { \
+ .file = __FILE__, .line = __LINE__, \
+ .what = MEM_STATS_TYPE_FREE, \
+ .func = __func__, \
+ }, \
}; \
HA_WEAK("__start_mem_stats"); \
HA_WEAK("__stop_mem_stats"); \
#define malloc(x) ({ \
size_t __x = (x); \
static struct mem_stats _ __attribute__((used,__section__("mem_stats"),__aligned__(sizeof(void*)))) = { \
- .file = __FILE__, .line = __LINE__, \
- .type = MEM_STATS_TYPE_MALLOC, \
- .func = __func__, \
+ .caller = { \
+ .file = __FILE__, .line = __LINE__, \
+ .what = MEM_STATS_TYPE_MALLOC, \
+ .func = __func__, \
+ }, \
}; \
HA_WEAK("__start_mem_stats"); \
HA_WEAK("__stop_mem_stats"); \
#define realloc(x,y) ({ \
void *__x = (x); size_t __y = (y); \
static struct mem_stats _ __attribute__((used,__section__("mem_stats"),__aligned__(sizeof(void*)))) = { \
- .file = __FILE__, .line = __LINE__, \
- .type = MEM_STATS_TYPE_REALLOC, \
- .func = __func__, \
+ .caller = { \
+ .file = __FILE__, .line = __LINE__, \
+ .what = MEM_STATS_TYPE_REALLOC, \
+ .func = __func__, \
+ }, \
}; \
HA_WEAK("__start_mem_stats"); \
HA_WEAK("__stop_mem_stats"); \
#define strdup(x) ({ \
const char *__x = (x); size_t __y = strlen(__x); \
static struct mem_stats _ __attribute__((used,__section__("mem_stats"),__aligned__(sizeof(void*)))) = { \
- .file = __FILE__, .line = __LINE__, \
- .type = MEM_STATS_TYPE_STRDUP, \
- .func = __func__, \
+ .caller = { \
+ .file = __FILE__, .line = __LINE__, \
+ .what = MEM_STATS_TYPE_STRDUP, \
+ .func = __func__, \
+ }, \
}; \
HA_WEAK("__start_mem_stats"); \
HA_WEAK("__stop_mem_stats"); \
struct pool_head *__pool = (pool); \
typeof(ptr) __ptr = (ptr); \
static struct mem_stats _ __attribute__((used,__section__("mem_stats"),__aligned__(sizeof(void*)))) = { \
- .file = __FILE__, .line = __LINE__, \
- .type = MEM_STATS_TYPE_P_FREE, \
- .func = __func__, \
+ .caller = { \
+ .file = __FILE__, .line = __LINE__, \
+ .what = MEM_STATS_TYPE_P_FREE, \
+ .func = __func__, \
+ }, \
}; \
_.extra = __pool; \
HA_WEAK("__start_mem_stats"); \
struct pool_head *__pool = (pool); \
size_t __x = __pool->size; \
static struct mem_stats _ __attribute__((used,__section__("mem_stats"),__aligned__(sizeof(void*)))) = { \
- .file = __FILE__, .line = __LINE__, \
- .type = MEM_STATS_TYPE_P_ALLOC, \
- .func = __func__, \
+ .caller = { \
+ .file = __FILE__, .line = __LINE__, \
+ .what = MEM_STATS_TYPE_P_ALLOC, \
+ .func = __func__, \
+ }, \
}; \
_.extra = __pool; \
HA_WEAK("__start_mem_stats"); \
struct pool_head *__pool = (pool); \
size_t __x = __pool->size; \
static struct mem_stats _ __attribute__((used,__section__("mem_stats"),__aligned__(sizeof(void*)))) = { \
- .file = __FILE__, .line = __LINE__, \
- .type = MEM_STATS_TYPE_P_ALLOC, \
- .func = __func__, \
+ .caller = { \
+ .file = __FILE__, .line = __LINE__, \
+ .what = MEM_STATS_TYPE_P_ALLOC, \
+ .func = __func__, \
+ }, \
}; \
_.extra = __pool; \
HA_WEAK("__start_mem_stats"); \
if (!ptr->size && !ptr->calls && !ctx->show_all)
continue;
- for (p = name = ptr->file; *p; p++) {
+ for (p = name = ptr->caller.file; *p; p++) {
if (*p == '/')
name = p + 1;
}
if (ctx->show_all)
- w = snprintf(&tmp, 0, "%s(%s:%d) ", ptr->func, name, ptr->line);
+ w = snprintf(&tmp, 0, "%s(%s:%d) ", ptr->caller.func, name, ptr->caller.line);
else
- w = snprintf(&tmp, 0, "%s:%d ", name, ptr->line);
+ w = snprintf(&tmp, 0, "%s:%d ", name, ptr->caller.line);
if (w > ctx->width)
ctx->width = w;
continue;
/* basename only */
- for (p = name = ptr->file; *p; p++) {
+ for (p = name = ptr->caller.file; *p; p++) {
if (*p == '/')
name = p + 1;
}
- func = ptr->func;
+ func = ptr->caller.func;
- switch (ptr->type) {
+ switch (ptr->caller.what) {
case MEM_STATS_TYPE_CALLOC: type = "CALLOC"; break;
case MEM_STATS_TYPE_FREE: type = "FREE"; break;
case MEM_STATS_TYPE_MALLOC: type = "MALLOC"; break;
if (ctx->show_all)
chunk_appendf(&trash, "%s(", func);
- chunk_appendf(&trash, "%s:%d", name, ptr->line);
+ chunk_appendf(&trash, "%s:%d", name, ptr->caller.line);
if (ctx->show_all)
chunk_appendf(&trash, ")");