mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 05:31:20 +00:00 
			
		
		
		
	bpo-43760: Add PyThreadState_EnterTracing() (GH-28542)
Add PyThreadState_EnterTracing() and PyThreadState_LeaveTracing() functions to the limited C API to suspend and resume tracing and profiling. Add an unit test on the PyThreadState C API to _testcapi. Add also internal _PyThreadState_DisableTracing() and _PyThreadState_ResetTracing().
This commit is contained in:
		
							parent
							
								
									354c35220d
								
							
						
					
					
						commit
						547d26aa08
					
				
					 9 changed files with 146 additions and 25 deletions
				
			
		|  | @ -256,8 +256,7 @@ sys_audit_tstate(PyThreadState *ts, const char *event, | |||
|         } | ||||
| 
 | ||||
|         /* Disallow tracing in hooks unless explicitly enabled */ | ||||
|         ts->tracing++; | ||||
|         ts->cframe->use_tracing = 0; | ||||
|         PyThreadState_EnterTracing(ts); | ||||
|         while ((hook = PyIter_Next(hooks)) != NULL) { | ||||
|             _Py_IDENTIFIER(__cantrace__); | ||||
|             PyObject *o; | ||||
|  | @ -270,14 +269,12 @@ sys_audit_tstate(PyThreadState *ts, const char *event, | |||
|                 break; | ||||
|             } | ||||
|             if (canTrace) { | ||||
|                 ts->cframe->use_tracing = (ts->c_tracefunc || ts->c_profilefunc) ? 255 : 0; | ||||
|                 ts->tracing--; | ||||
|                 PyThreadState_LeaveTracing(ts); | ||||
|             } | ||||
|             PyObject* args[2] = {eventName, eventArgs}; | ||||
|             o = _PyObject_FastCallTstate(ts, hook, args, 2); | ||||
|             if (canTrace) { | ||||
|                 ts->tracing++; | ||||
|                 ts->cframe->use_tracing = 0; | ||||
|                 PyThreadState_EnterTracing(ts); | ||||
|             } | ||||
|             if (!o) { | ||||
|                 break; | ||||
|  | @ -285,8 +282,7 @@ sys_audit_tstate(PyThreadState *ts, const char *event, | |||
|             Py_DECREF(o); | ||||
|             Py_CLEAR(hook); | ||||
|         } | ||||
|         ts->cframe->use_tracing = (ts->c_tracefunc || ts->c_profilefunc) ? 255 : 0; | ||||
|         ts->tracing--; | ||||
|         PyThreadState_LeaveTracing(ts); | ||||
|         if (_PyErr_Occurred(ts)) { | ||||
|             goto exit; | ||||
|         } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Victor Stinner
						Victor Stinner