Skip to content

Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.

revert(diagnostics): take the allocation profiler out of the build

Martin Vogel375d11e3e42b
diff --git a/Makefile.cbm b/Makefile.cbm
index 8a05379ad..66c438ba9 100644
--- a/Makefile.cbm
+++ b/Makefile.cbm
@@ -133,7 +133,7 @@ endif
# and redirecting malloc into mimalloc underneath ASan's own interception mixes
# two allocators on the same pointers. Windows keeps its wrap flags everywhere,
# because there the shim is what makes mimalloc own the allocations at all.
-LDFLAGS = -lm -lstdc++ -lpthread -lz $(WIN32_LIBS) $(STATIC_FLAGS) $(MIMALLOC_WRAP_FLAGS) $(MIMALLOC_WRAP_FLAGS_POSIX)
+LDFLAGS = -lm -lstdc++ -lpthread -lz $(WIN32_LIBS) $(STATIC_FLAGS) $(MIMALLOC_WRAP_FLAGS)
LDFLAGS_TEST = -lm -lstdc++ -lpthread -lz $(SANITIZE) $(WIN32_LIBS) $(MIMALLOC_WRAP_FLAGS)
LDFLAGS_TSAN = -lm -lstdc++ -lpthread -lz $(TSAN_SANITIZE) $(WIN32_LIBS) $(MIMALLOC_WRAP_FLAGS)
@@ -155,8 +155,6 @@ FOUNDATION_SRCS = \
src/foundation/compat_fs.c \
src/foundation/compat_regex.c \
src/foundation/mem.c \
- src/foundation/mem_profile.c \
- src/foundation/mem_override_posix.c \
src/foundation/diagnostics.c \
src/foundation/profile.c \
src/foundation/dump_verify.c \
diff --git a/internal/cbm/cbm.c b/internal/cbm/cbm.c
index aae578540..ee1749cdb 100644
--- a/internal/cbm/cbm.c
+++ b/internal/cbm/cbm.c
@@ -21,7 +21,6 @@
#include "foundation/constants.h"
#include "mimalloc.h" // mi_malloc/mi_calloc/mi_realloc/mi_free/mi_usable_size — bind 3rd-party allocators (#424)
#if defined(CBM_BIND_TS_ALLOCATOR) && CBM_BIND_TS_ALLOCATOR
-#include "foundation/mem_profile.h"
#include "sqlite3.h" // sqlite3_mem_methods, sqlite3_config, SQLITE_CONFIG_MALLOC — bind sqlite to mimalloc
#endif
#include <stdint.h> // uint32_t, uint64_t, int64_t
@@ -269,19 +268,14 @@ static TSParser *get_thread_parser(const TSLanguage *ts_lang, CBMLanguage lang)
* (#581). */
static void *cbm_sqlite_malloc(int n) {
void *block = mi_malloc((size_t)n);
- cbm_mem_profile_alloc_at(block, (size_t)n, __builtin_return_address(0));
return block;
}
static void cbm_sqlite_free(void *p) {
- cbm_mem_profile_free(p);
mi_free(p);
}
static void *cbm_sqlite_realloc(void *p, int n) {
- if (p) {
- cbm_mem_profile_free(p);
- }
+ if (p) {}
void *grown = mi_realloc(p, (size_t)n);
- cbm_mem_profile_alloc_at(grown, (size_t)n, __builtin_return_address(0));
return grown;
}
static int cbm_sqlite_size(void *p) {
@@ -294,24 +288,18 @@ static int cbm_sqlite_roundup(int n) {
* through these, and they too skip the interposer. */
static void *cbm_ts_malloc(size_t n) {
void *block = mi_malloc(n);
- cbm_mem_profile_alloc_at(block, n, __builtin_return_address(0));
return block;
}
static void *cbm_ts_calloc(size_t count, size_t size) {
void *block = mi_calloc(count, size);
- cbm_mem_profile_alloc_at(block, count * size, __builtin_return_address(0));
return block;
}
static void *cbm_ts_realloc(void *p, size_t n) {
- if (p) {
- cbm_mem_profile_free(p);
- }
+ if (p) {}
void *grown = mi_realloc(p, n);
- cbm_mem_profile_alloc_at(grown, n, __builtin_return_address(0));
return grown;
}
static void cbm_ts_free(void *p) {
- cbm_mem_profile_free(p);
mi_free(p);
}
diff --git a/src/foundation/mem.c b/src/foundation/mem.c
index fddae7755..2979a471c 100644
--- a/src/foundation/mem.c
+++ b/src/foundation/mem.c
@@ -11,7 +11,6 @@
#include "log.h"
#include "compat_fs.h"
#include "compat_thread.h"
-#include "mem_profile.h"
#include "foundation/constants.h"
@@ -351,16 +350,6 @@ void cbm_mem_init_with_cap(double ram_fraction, size_t hard_cap_bytes) {
char ram_mb[CBM_SZ_32];
snprintf(budget_mb, sizeof(budget_mb), "%zu", g_budget / MB_DIVISOR);
snprintf(ram_mb, sizeof(ram_mb), "%zu", info.total_ram / MB_DIVISOR);
- {
- /* Report the profiler gate once. Without this, "no records" cannot be
- * told apart from "never enabled" — and that ambiguity already cost
- * three measurement rounds. */
- char profile_threshold[CBM_SZ_32];
- (void)snprintf(profile_threshold, sizeof(profile_threshold), "%zu",
- cbm_mem_profile_threshold());
- cbm_log_info("mem.profile.gate", "enabled", cbm_mem_profile_enabled() ? "true" : "false",
- "threshold", profile_threshold);
- }
cbm_log_info("mem.init", "budget_mb", budget_mb, "total_ram_mb", ram_mb, "source",
resolved.source);
}
@@ -903,8 +892,6 @@ void cbm_mem_census_log(const char *tag) {
/* Attribution alongside the pool totals: the census says which pool holds
* the memory, the profile says which call sites put it there. Emitting
* both from one place keeps the two views on the same sample. */
- cbm_mem_profile_totals_t profile;
- cbm_mem_profile_totals(&profile);
/* The allocator's OWN view, next to the OS view. If mimalloc's committed
* area tracks the process's private commit, the memory is the allocator's
* and it is holding pages against tiny live data; if it stays flat while
@@ -916,26 +903,12 @@ void cbm_mem_census_log(const char *tag) {
char map_area_kb[CBM_SZ_32];
(void)snprintf(map_live_kb, sizeof(map_live_kb), "%zu", map.live_bytes / CBM_SZ_1K);
(void)snprintf(map_area_kb, sizeof(map_area_kb), "%zu", map.area_committed_bytes / CBM_SZ_1K);
- char prof_live_kb[CBM_SZ_32];
- char prof_sites[CBM_SZ_32];
- char prof_lost[CBM_SZ_32];
- char prof_total_kb[CBM_SZ_32];
- (void)snprintf(prof_live_kb, sizeof(prof_live_kb), "%zu", profile.live_bytes / CBM_SZ_1K);
- (void)snprintf(prof_sites, sizeof(prof_sites), "%zu", profile.sites);
- (void)snprintf(prof_total_kb, sizeof(prof_total_kb), "%zu", profile.total_bytes / CBM_SZ_1K);
- (void)snprintf(prof_lost, sizeof(prof_lost), "%zu",
- profile.site_table_full + profile.pointer_table_full + profile.capture_failed);
- char profile_path[CBM_SZ_1K];
- if (cbm_safe_getenv("CBM_MEM_PROFILE_OUT", profile_path, sizeof(profile_path), NULL) != NULL) {
- (void)cbm_mem_profile_dump(profile_path, tag ? tag : "?");
- }
- cbm_log_info("mem.census", "at", tag ? tag : "?", "prof_live_kb", prof_live_kb, "mi_area_kb",
- map_area_kb, "mi_live_kb", map_live_kb, "prof_sites", prof_sites, "prof_total_kb",
- prof_total_kb, "prof_lost", prof_lost, "priv_kb", priv_kb, "crt_kb", crt_kb,
- "crt_busy_kb", busy_kb, "mapped_kb", mapped_kb, "rss_kb", rss_kb, "biggest_kb",
- biggest_kb, "regions", regions, "big_regions", big_regions, "heaps", heaps,
- "biggest_base", base, "priv_small_kb", psmall, "priv_med_kb", pmed,
- "priv_large_kb", plarge, "priv_counts", pcounts, "large_map", large_map);
+ cbm_log_info("mem.census", "at", tag ? tag : "?", "mi_area_kb", map_area_kb, "mi_live_kb",
+ map_live_kb, "priv_kb", priv_kb, "crt_kb", crt_kb, "crt_busy_kb", busy_kb,
+ "mapped_kb", mapped_kb, "rss_kb", rss_kb, "biggest_kb", biggest_kb, "regions",
+ regions, "big_regions", big_regions, "heaps", heaps, "biggest_base", base,
+ "priv_small_kb", psmall, "priv_med_kb", pmed, "priv_large_kb", plarge,
+ "priv_counts", pcounts, "large_map", large_map);
/* The phase table answers WHICH bracketed path the committed bytes stayed
* in. Emitted once at the end rather than per request: it is cumulative,
* so only the final table carries the verdict. */
diff --git a/src/foundation/mem_override_win.c b/src/foundation/mem_override_win.c
index 43b845dfb..8b51cb690 100644
--- a/src/foundation/mem_override_win.c
+++ b/src/foundation/mem_override_win.c
@@ -42,7 +42,6 @@
* mimalloc is always safe.
*/
#include "foundation/mem.h"
-#include "foundation/mem_profile.h"
#include <mimalloc.h>
#include <stddef.h>
@@ -70,15 +69,11 @@ static inline bool mem_override_is_ours(const void *block) {
}
void *__wrap_malloc(size_t size) {
- void *block = mi_malloc(size);
- cbm_mem_profile_alloc_at(block, size, __builtin_return_address(0));
- return block;
+ return mi_malloc(size);
}
void *__wrap_calloc(size_t count, size_t size) {
- void *block = mi_calloc(count, size);
- cbm_mem_profile_alloc_at(block, count * size, __builtin_return_address(0));
- return block;
+ return mi_calloc(count, size);
}
char *__wrap_strdup(const char *text) {
@@ -100,7 +95,6 @@ void __wrap_free(void *block) {
return;
}
if (mem_override_is_ours(block)) {
- cbm_mem_profile_free(block);
mi_free(block);
return;
}
@@ -126,9 +120,7 @@ void *__wrap_realloc(void *block, size_t size) {
return mi_malloc(size);
}
if (mem_override_is_ours(block)) {
- cbm_mem_profile_free(block);
void *grown = mi_realloc(block, size);
- cbm_mem_profile_alloc_at(grown, size, __builtin_return_address(0));
return grown;
}
/* A CRT block cannot be handed to mi_realloc, and the CRT's realloc must