@@ -45,8 +45,6 @@ static struct {
4545 int use_domain ;
4646} tracemalloc_config = {TRACEMALLOC_NOT_INITIALIZED , 0 , 1 , 1 };
4747
48- int tracemalloc_debug = 0 ;
49-
5048#if defined(TRACE_RAW_MALLOC ) && defined(WITH_THREAD )
5149/* This lock is needed because tracemalloc_free() is called without
5250 the GIL held from PyMem_RawFree(). It cannot acquire the lock because it
@@ -898,35 +896,23 @@ tracemalloc_clear_traces(void)
898896 _Py_hashtable_clear (tracemalloc_filenames );
899897}
900898
901- #define DEBUG (MSG ) \
902- if (tracemalloc_debug) { fprintf(stderr, "[pid %li, tid %li, reentrant key %i] " MSG "\n", (long)getpid(), PyThread_get_thread_ident(), tracemalloc_reentrant_key); fflush(stderr); }
903-
904899
905900static int
906901tracemalloc_init (void )
907902{
908- DEBUG ("tracemalloc_init()" );
909-
910- #ifdef WITH_THREAD
911- assert (PyGILState_Check ());
912- #endif
913-
914903 if (tracemalloc_config .initialized == TRACEMALLOC_FINALIZED ) {
915904 PyErr_SetString (PyExc_RuntimeError ,
916905 "the tracemalloc module has been unloaded" );
917906 return -1 ;
918907 }
919908
920- if (tracemalloc_config .initialized == TRACEMALLOC_INITIALIZED ) {
921- DEBUG ("tracemalloc_init(): exit (already initialized)" );
909+ if (tracemalloc_config .initialized == TRACEMALLOC_INITIALIZED )
922910 return 0 ;
923- }
924911
925912 PyMem_GetAllocator (PYMEM_DOMAIN_RAW , & allocators .raw );
926913
927914#ifdef REENTRANT_THREADLOCAL
928915 tracemalloc_reentrant_key = PyThread_create_key ();
929- fprintf (stderr , "[pid %li, tid %li] PyThread_create_key() -> %i\n" , (long )getpid (), PyThread_get_thread_ident (), tracemalloc_reentrant_key ); fflush (stderr );
930916 if (tracemalloc_reentrant_key == -1 ) {
931917#ifdef MS_WINDOWS
932918 PyErr_SetFromWindowsErr (0 );
@@ -988,24 +974,18 @@ fprintf(stderr, "[pid %li, tid %li] PyThread_create_key() -> %i\n", (long)getpid
988974 /* Disable tracing allocations until hooks are installed. Set
989975 also the reentrant flag to detect bugs: fail with an assertion error
990976 if set_reentrant(1) is called while tracing is disabled. */
991- DEBUG ("tracemalloc_init(): set_reentrant(1)" );
992977 set_reentrant (1 );
993978
994979 tracemalloc_config .initialized = TRACEMALLOC_INITIALIZED ;
995- DEBUG ("tracemalloc_init(): done" );
996- assert (get_reentrant ());
997980 return 0 ;
998981}
999982
1000983
1001984static void
1002985tracemalloc_deinit (void )
1003986{
1004- DEBUG ("tracemalloc_deinit()" );
1005- if (tracemalloc_config .initialized != TRACEMALLOC_INITIALIZED ) {
1006- DEBUG ("tracemalloc_deinit(): exit (not initialized)" );
987+ if (tracemalloc_config .initialized != TRACEMALLOC_INITIALIZED )
1007988 return ;
1008- }
1009989 tracemalloc_config .initialized = TRACEMALLOC_FINALIZED ;
1010990
1011991 tracemalloc_stop ();
@@ -1022,15 +1002,12 @@ DEBUG("tracemalloc_deinit(): exit (not initialized)");
10221002 }
10231003#endif
10241004
1025- DEBUG ("tracemalloc_deinit(): delete reentrant key" );
10261005#ifdef REENTRANT_THREADLOCAL
1027- fprintf (stderr , "[pid %li, tid %li] PyThread_delete_key(%i)\n" , (long )getpid (), PyThread_get_thread_ident (), tracemalloc_reentrant_key ); fflush (stderr );
10281006 PyThread_delete_key (tracemalloc_reentrant_key );
10291007 tracemalloc_reentrant_key = -1 ;
10301008#endif
10311009
10321010 Py_XDECREF (unknown_filename );
1033- DEBUG ("tracemalloc_deinit(): done" );
10341011}
10351012
10361013
@@ -1040,24 +1017,13 @@ tracemalloc_start(int max_nframe)
10401017 PyMemAllocatorEx alloc ;
10411018 size_t size ;
10421019
1043- DEBUG ("tracemalloc_start()" );
1044-
1045- #ifdef WITH_THREAD
1046- assert (PyGILState_Check ());
1047- #endif
1048-
1049- if (tracemalloc_init () < 0 ) {
1050- DEBUG ("tracemalloc_start(): ERROR! init failed!" );
1020+ if (tracemalloc_init () < 0 )
10511021 return -1 ;
1052- }
10531022
10541023 if (tracemalloc_config .tracing ) {
10551024 /* hook already installed: do nothing */
1056- DEBUG ("tracemalloc_start(): exit (already tracing)" );
1057- assert (!get_reentrant ());
10581025 return 0 ;
10591026 }
1060- assert (get_reentrant ());
10611027
10621028 assert (1 <= max_nframe && max_nframe <= MAX_NFRAME );
10631029 tracemalloc_config .max_nframe = max_nframe ;
@@ -1097,38 +1063,23 @@ assert(get_reentrant());
10971063
10981064 /* everything is ready: start tracing Python memory allocations */
10991065 tracemalloc_config .tracing = 1 ;
1100-
1101- DEBUG ("tracemalloc_start(): set_reentrant(0)" );
11021066 set_reentrant (0 );
11031067
1104- DEBUG ("tracemalloc_start(): done" );
1105- assert (!get_reentrant ());
11061068 return 0 ;
11071069}
11081070
11091071
11101072static void
11111073tracemalloc_stop (void )
11121074{
1113- DEBUG ("tracemalloc_stop()" );
1114-
1115- #ifdef WITH_THREAD
1116- assert (PyGILState_Check ());
1117- #endif
1118-
1119- if (!tracemalloc_config .tracing ) {
1120- DEBUG ("tracemalloc_stop(): exit (not tracing)" );
1121- assert (get_reentrant ());
1075+ if (!tracemalloc_config .tracing )
11221076 return ;
1123- }
1124- assert (!get_reentrant ());
11251077
11261078 /* stop tracing Python memory allocations */
11271079 tracemalloc_config .tracing = 0 ;
11281080
11291081 /* set the reentrant flag to detect bugs: fail with an assertion error if
11301082 set_reentrant(1) is called while tracing is disabled. */
1131- DEBUG ("tracemalloc_stop(): set_reentrant(1)" );
11321083 set_reentrant (1 );
11331084
11341085 /* unregister the hook on memory allocators */
@@ -1143,8 +1094,6 @@ DEBUG("tracemalloc_stop(): set_reentrant(1)");
11431094 /* release memory */
11441095 raw_free (tracemalloc_traceback );
11451096 tracemalloc_traceback = NULL ;
1146- DEBUG ("tracemalloc_stop(): done" );
1147- assert (get_reentrant ());
11481097}
11491098
11501099PyDoc_STRVAR (tracemalloc_is_tracing_doc ,
@@ -1512,11 +1461,8 @@ py_tracemalloc_start(PyObject *self, PyObject *args)
15121461 }
15131462 nframe_int = Py_SAFE_DOWNCAST (nframe , Py_ssize_t , int );
15141463
1515- if (tracemalloc_start (nframe_int ) < 0 ) {
1516- DEBUG ("start(): ERROR!" );
1464+ if (tracemalloc_start (nframe_int ) < 0 )
15171465 return NULL ;
1518- }
1519- DEBUG ("start(): done" );
15201466
15211467 Py_RETURN_NONE ;
15221468}
@@ -1642,17 +1588,12 @@ PyMODINIT_FUNC
16421588PyInit__tracemalloc (void )
16431589{
16441590 PyObject * m ;
1645-
1646- fprintf (stderr , "[pid %li, tid %li] PyInit__tracemalloc\n" , (long )getpid (), PyThread_get_thread_ident ()); fflush (stderr );
1647-
16481591 m = PyModule_Create (& module_def );
16491592 if (m == NULL )
16501593 return NULL ;
16511594
1652- #if 0
16531595 if (tracemalloc_init () < 0 )
16541596 return NULL ;
1655- #endif
16561597
16571598 return m ;
16581599}
0 commit comments