From f2b0fb963a10edbcd1654dfd7d3c889dd4484e58 Mon Sep 17 00:00:00 2001 From: Taegyun Kim Date: Mon, 18 Aug 2025 14:33:39 -0400 Subject: [PATCH 1/4] [do not merge]: build memalloc with debug --- setup.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 2b678310ebe..6dad5453ec6 100644 --- a/setup.py +++ b/setup.py @@ -873,6 +873,7 @@ def get_exts_for(name): else: debug_compile_args = [] +memalloc_debug_compile_args = ["-g"] if not IS_PYSTON: ext_modules: t.List[t.Union[Extension, Cython.Distutils.Extension, RustExtension]] = [ @@ -886,12 +887,12 @@ def get_exts_for(name): "ddtrace/profiling/collector/_memalloc_heap_map.c", ], extra_compile_args=( - debug_compile_args + memalloc_debug_compile_args # If NDEBUG is set, assert statements are compiled out. Make # sure we explicitly set this for normal builds, and explicitly # _unset_ it for debug builds in case the CFLAGS from sysconfig # include -DNDEBUG - + (["-DNDEBUG"] if not debug_compile_args else ["-UNDEBUG"]) + + (["-DNDEBUG"] if not memalloc_debug_compile_args else ["-UNDEBUG"]) + ["-D_POSIX_C_SOURCE=200809L", "-std=c11"] + fast_build_args if CURRENT_OS != "Windows" From 77de67f7fed616008e4eb00e12a262e87d6deffd Mon Sep 17 00:00:00 2001 From: Taegyun Kim Date: Mon, 18 Aug 2025 14:40:41 -0400 Subject: [PATCH 2/4] break build cache --- ddtrace/profiling/collector/_memalloc_debug.h | 9 --------- 1 file changed, 9 deletions(-) diff --git a/ddtrace/profiling/collector/_memalloc_debug.h b/ddtrace/profiling/collector/_memalloc_debug.h index 25dd5235225..cc6d77f6aae 100644 --- a/ddtrace/profiling/collector/_memalloc_debug.h +++ b/ddtrace/profiling/collector/_memalloc_debug.h @@ -11,10 +11,8 @@ static inline void memalloc_debug_gil_release(void) { -#ifndef NDEBUG Py_BEGIN_ALLOW_THREADS; Py_END_ALLOW_THREADS; -#endif } typedef struct @@ -28,7 +26,6 @@ memalloc_gil_debug_check_init(memalloc_gil_debug_check_t* c) c->acquired = false; } -#ifndef NDEBUG /* Annotate that we are beginning a critical section where we don't want other * memalloc code to run. If compiled assertions enabled, this will check that the * GIL is held and that the guard has not already been acquired elsewhere. @@ -53,11 +50,5 @@ memalloc_gil_debug_check_init(memalloc_gil_debug_check_t* c) assert(p->acquired); \ p->acquired = false; \ } while (0) -#else - -#define MEMALLOC_GIL_DEBUG_CHECK_ACQUIRE(c) -#define MEMALLOC_GIL_DEBUG_CHECK_RELEASE(c) - -#endif #endif From 37bfa85c9d0d80c7e52667d7c462853c71194bf4 Mon Sep 17 00:00:00 2001 From: Taegyun Kim Date: Tue, 19 Aug 2025 03:51:43 +0900 Subject: [PATCH 3/4] Discard changes to ddtrace/profiling/collector/_memalloc_debug.h --- ddtrace/profiling/collector/_memalloc_debug.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ddtrace/profiling/collector/_memalloc_debug.h b/ddtrace/profiling/collector/_memalloc_debug.h index cc6d77f6aae..25dd5235225 100644 --- a/ddtrace/profiling/collector/_memalloc_debug.h +++ b/ddtrace/profiling/collector/_memalloc_debug.h @@ -11,8 +11,10 @@ static inline void memalloc_debug_gil_release(void) { +#ifndef NDEBUG Py_BEGIN_ALLOW_THREADS; Py_END_ALLOW_THREADS; +#endif } typedef struct @@ -26,6 +28,7 @@ memalloc_gil_debug_check_init(memalloc_gil_debug_check_t* c) c->acquired = false; } +#ifndef NDEBUG /* Annotate that we are beginning a critical section where we don't want other * memalloc code to run. If compiled assertions enabled, this will check that the * GIL is held and that the guard has not already been acquired elsewhere. @@ -50,5 +53,11 @@ memalloc_gil_debug_check_init(memalloc_gil_debug_check_t* c) assert(p->acquired); \ p->acquired = false; \ } while (0) +#else + +#define MEMALLOC_GIL_DEBUG_CHECK_ACQUIRE(c) +#define MEMALLOC_GIL_DEBUG_CHECK_RELEASE(c) + +#endif #endif From 1a88cf48fcd2e6f7c8545c902176710ddd469c02 Mon Sep 17 00:00:00 2001 From: Taegyun Kim Date: Mon, 18 Aug 2025 14:52:18 -0400 Subject: [PATCH 4/4] break build cache by editing a source file --- ddtrace/profiling/collector/_memalloc_heap.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ddtrace/profiling/collector/_memalloc_heap.c b/ddtrace/profiling/collector/_memalloc_heap.c index 2939087820e..f3ea835c4be 100644 --- a/ddtrace/profiling/collector/_memalloc_heap.c +++ b/ddtrace/profiling/collector/_memalloc_heap.c @@ -11,6 +11,8 @@ /* How heap profiler sampling works: + to break build cache + This is mostly derived from https://github.com/google/tcmalloc/blob/master/docs/sampling.md#detailed-treatment-of-weighting-weighting