Fix: use allocated_count from mem.c for busy memory calculation
busy = u_get_allocated_count() - memory_pool_get_total_free_blocks()
This commit is contained in:
1 parent
348776ead4
commit
d413412f55
5 files changed
+6
-9
No files matched your search
@@ -235,3 +235,7 @@ void u_report_unfreed_blocks(void) {
|
||||
curr = *(void**)((uint8_t*)curr + NEXT_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
size_t u_get_allocated_count(void) {
|
||||
return allocated_count;
|
||||
}
|
||||
@@ -24,6 +24,7 @@ void* u_realloc_impl(void* ptr, uint32_t size, const char* location);
|
||||
void u_free_impl(void* ptr, const char* location);
|
||||
char* u_strdup_impl(const char* s, const char* location);
|
||||
void u_report_unfreed_blocks(void);
|
||||
size_t u_get_allocated_count(void);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -6,16 +6,11 @@
|
||||
#include "mem.h"
|
||||
|
||||
static size_t g_total_free = 0;
|
||||
static size_t g_total_allocated = 0;
|
||||
|
||||
size_t memory_pool_get_total_free_blocks(void) {
|
||||
return g_total_free;
|
||||
}
|
||||
|
||||
size_t memory_pool_get_total_allocated(void) {
|
||||
return g_total_allocated;
|
||||
}
|
||||
|
||||
// Инициализировать пул памяти
|
||||
struct memory_pool* memory_pool_init(size_t object_size) {
|
||||
struct memory_pool* pool = u_calloc(1, sizeof(struct memory_pool));
|
||||
@@ -48,7 +43,6 @@ void* memory_pool_alloc_impl(struct memory_pool* pool, const char* location) {
|
||||
}
|
||||
|
||||
pool->allocations++;
|
||||
g_total_allocated++;
|
||||
DEBUG_INFO(DEBUG_CATEGORY_MEMORY, "pool_alloc: %s, total_allocs=%zu", location, pool->allocations);
|
||||
return u_calloc_impl(1, pool->object_size, location); // Используем calloc для инициализации нулями
|
||||
}
|
||||
@@ -99,7 +93,6 @@ void memory_pool_destroy(struct memory_pool* pool) {
|
||||
while (obj) {
|
||||
void* next = *(void**)obj;
|
||||
g_total_free--;
|
||||
g_total_allocated--;
|
||||
u_free(obj);
|
||||
cnt++;
|
||||
obj = next;
|
||||
|
||||
@@ -29,7 +29,6 @@ void* memory_pool_alloc_impl(struct memory_pool* pool, const char* location);
|
||||
void memory_pool_free_impl(struct memory_pool* pool, void* obj, const char* location);
|
||||
void memory_pool_get_stats(struct memory_pool* pool, size_t* allocations, size_t* reuse_count);
|
||||
size_t memory_pool_get_total_free_blocks(void);
|
||||
size_t memory_pool_get_total_allocated(void);
|
||||
|
||||
#define memory_pool_alloc(pool) memory_pool_alloc_impl(pool, PLOCATION)
|
||||
#define memory_pool_free(pool, obj) memory_pool_free_impl(pool, obj, PLOCATION)
|
||||
|
||||
@@ -981,7 +981,7 @@ static void send_metrics(struct control_server* server, struct control_client* c
|
||||
rsp->etcp.active_timeouts = 0;
|
||||
}
|
||||
|
||||
rsp->etcp.busy_memory_blocks = (uint32_t)(memory_pool_get_total_allocated() - memory_pool_get_total_free_blocks());
|
||||
rsp->etcp.busy_memory_blocks = (uint32_t)(u_get_allocated_count() - memory_pool_get_total_free_blocks());
|
||||
|
||||
/* Fill TUN metrics */
|
||||
if (instance->tun) {
|
||||
|
||||
Reference in new issue
Block a user