|
54 | 54 | #define DEBUG_ENABLED 0 |
55 | 55 | #endif |
56 | 56 |
|
| 57 | +/* Set this variable to 1 in order to debug garbage collection data |
| 58 | +* and threading flow for improving the debug of memory leaks and async bugs. |
| 59 | +* Set it to 0 in order to remove all the noise. |
| 60 | +*/ |
| 61 | +#define DEBUG_PRINT_ENABLED 1 |
| 62 | + |
57 | 63 | typedef struct loader_impl_py_function_type |
58 | 64 | { |
59 | 65 | PyObject *func; |
@@ -160,7 +166,7 @@ static value py_loader_impl_error_value(loader_impl_py py_impl); |
160 | 166 |
|
161 | 167 | static value py_loader_impl_error_value_from_exception(loader_impl_py py_impl, PyObject *type_obj, PyObject *value_obj, PyObject *traceback_obj); |
162 | 168 |
|
163 | | -#if DEBUG_ENABLED |
| 169 | +#if DEBUG_ENABLED && DEBUG_PRINT_ENABLED |
164 | 170 | #if (defined(__ADDRESS_SANITIZER__) || defined(__MEMORY_SANITIZER__)) |
165 | 171 | static void py_loader_impl_gc_print(loader_impl_py py_impl); |
166 | 172 | #endif |
@@ -2221,7 +2227,7 @@ int py_loader_impl_initialize_traceback(loader_impl impl, loader_impl_py py_impl |
2221 | 2227 | return 1; |
2222 | 2228 | } |
2223 | 2229 |
|
2224 | | -#if DEBUG_ENABLED |
| 2230 | +#if DEBUG_ENABLED && DEBUG_PRINT_ENABLED |
2225 | 2231 | int py_loader_impl_initialize_gc(loader_impl_py py_impl) |
2226 | 2232 | { |
2227 | 2233 | PyObject *flags; |
@@ -2396,10 +2402,10 @@ int py_loader_impl_initialize_thread_background_module(loader_impl_py py_impl) |
2396 | 2402 | "import asyncio\n" |
2397 | 2403 | "import threading\n" |
2398 | 2404 | "import sys\n" |
2399 | | -#if DEBUG_ENABLED |
| 2405 | +#if DEBUG_ENABLED && DEBUG_PRINT_ENABLED |
2400 | 2406 | "def trace_calls(frame, event, arg):\n" |
2401 | 2407 | " t = threading.current_thread()\n" |
2402 | | - " print(f\"[{t.native_id}] {t.name}: {event} {frame.f_code.co_name}\")\n" |
| 2408 | + " print(f\"[{t.native_id}] {t.name}: {event} {frame.f_code.co_name}\", flush=True)\n" |
2403 | 2409 | "threading.settrace(trace_calls)\n" |
2404 | 2410 | "sys.settrace(trace_calls)\n" |
2405 | 2411 | #endif |
@@ -2686,7 +2692,7 @@ loader_impl_data py_loader_impl_initialize(loader_impl impl, configuration confi |
2686 | 2692 |
|
2687 | 2693 | loader_impl_py py_impl = malloc(sizeof(struct loader_impl_py_type)); |
2688 | 2694 | int traceback_initialized = 1; |
2689 | | -#if DEBUG_ENABLED |
| 2695 | +#if DEBUG_ENABLED && DEBUG_PRINT_ENABLED |
2690 | 2696 | int gc_initialized = 1; |
2691 | 2697 | #endif |
2692 | 2698 | int gil_release; |
@@ -2762,7 +2768,7 @@ loader_impl_data py_loader_impl_initialize(loader_impl impl, configuration confi |
2762 | 2768 | traceback_initialized = 0; |
2763 | 2769 | } |
2764 | 2770 |
|
2765 | | -#if DEBUG_ENABLED |
| 2771 | +#if DEBUG_ENABLED && DEBUG_PRINT_ENABLED |
2766 | 2772 | /* Initialize GC module */ |
2767 | 2773 | { |
2768 | 2774 | gc_initialized = py_loader_impl_initialize_gc(py_impl); |
@@ -2862,7 +2868,7 @@ loader_impl_data py_loader_impl_initialize(loader_impl impl, configuration confi |
2862 | 2868 | Py_DecRef(py_impl->traceback_format_exception); |
2863 | 2869 | Py_DecRef(py_impl->traceback_module); |
2864 | 2870 | } |
2865 | | -#if DEBUG_ENABLED |
| 2871 | +#if DEBUG_ENABLED && DEBUG_PRINT_ENABLED |
2866 | 2872 | if (gc_initialized == 0) |
2867 | 2873 | { |
2868 | 2874 | Py_DecRef(py_impl->gc_set_debug); |
@@ -2917,7 +2923,7 @@ int py_loader_impl_execution_path(loader_impl impl, const loader_path path) |
2917 | 2923 | goto clear_current_path; |
2918 | 2924 | } |
2919 | 2925 |
|
2920 | | -#if DEBUG_ENABLED |
| 2926 | +#if DEBUG_ENABLED && DEBUG_PRINT_ENABLED |
2921 | 2927 | py_loader_impl_sys_path_print(system_paths); |
2922 | 2928 | #endif |
2923 | 2929 |
|
@@ -4199,7 +4205,7 @@ value py_loader_impl_error_value_from_exception(loader_impl_py py_impl, PyObject |
4199 | 4205 | return ret; |
4200 | 4206 | } |
4201 | 4207 |
|
4202 | | -#if DEBUG_ENABLED |
| 4208 | +#if DEBUG_ENABLED && DEBUG_PRINT_ENABLED |
4203 | 4209 | #if (defined(__ADDRESS_SANITIZER__) || defined(__MEMORY_SANITIZER__)) |
4204 | 4210 | void py_loader_impl_gc_print(loader_impl_py py_impl) |
4205 | 4211 | { |
@@ -4355,7 +4361,7 @@ int py_loader_impl_destroy(loader_impl impl) |
4355 | 4361 | Py_DecRef(py_impl->thread_background_stop); |
4356 | 4362 | Py_DecRef(py_impl->thread_background_register_atexit); |
4357 | 4363 |
|
4358 | | -#if DEBUG_ENABLED |
| 4364 | +#if DEBUG_ENABLED && DEBUG_PRINT_ENABLED |
4359 | 4365 | { |
4360 | 4366 | #if (defined(__ADDRESS_SANITIZER__) || defined(__MEMORY_SANITIZER__)) |
4361 | 4367 | py_loader_impl_gc_print(py_impl); |
|
0 commit comments