+
    Bi+                     b   ^ RI t ^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RI Ht ^ RIH	t	 ^ RIH
t
HtHt ^ RIHt  ! R R4      t ! R	 R
4      t]	P                   ! 4        ! R R]]4      4       t]	P                   ! 4        ! R R]]]4      4       t]	P                   ! 4        ! R R]]4      4       t]	P                   ! 4        ! R R]]4      4       t]	P                   ! 4        ! R R]4      4       t ! R R4      t]	P                   ! 4        ! R R]]4      4       t]R8X  d   ]P2                  ! 4        R# R# )    N)contextmanager)
monitoring)threading_helper)Thread_PyRLockBarrier)TestCasec                   P   a  ] tR t^t o ^
t^2t^tR tR tR t	R t
R tR tRtV tR# )	!InstrumentationMultiThreadedMixinc                    R # N selfs   &?/usr/lib/python3.14/test/test_free_threading/test_monitoring.pyafter_threads/InstrumentationMultiThreadedMixin.after_threads           c                    R # r   r   r   s   &r   during_threads0InstrumentationMultiThreadedMixin.during_threads   r   r   c                    V F
  pV! 4        K  	  V^8  d   V# V P                  V^,
          V4      V P                  V^,
          V4      ,           # )   )work)r   nfuncsfuncs   &&& r   r   &InstrumentationMultiThreadedMixin.work   sF    DF q5HyyQ&1q5%)@@@r   c                T    \         P                  ! R 4       V P                  W4       R# )g?N)timesleepr   )r   r   r   s   &&&r   
start_work,InstrumentationMultiThreadedMixin.start_work&   s     	

3		!r   c                    R # r   r   r   s   &r   
after_test,InstrumentationMultiThreadedMixin.after_test,   r   r   c                &   . p\        V P                  4       F)  p/ p\        R V4       VP                  VR,          4       K+  	  . p\        V P                  4       FP  p\        V P                  V P                  \        V4      3R7      pVP                  4        VP                  V4       KR  	  V P                  4         RpV F  pVP                  4       '       g   K  Rp M	  V'       g   MV P                  4        KA  V P                  4        R# )zdef f(): passftargetargsTFN)range
func_countexecappendthread_countr   r#   fibliststartr   is_aliver   r&   )r   r   ixthreadst	any_alives   &      r   test_instrumentation6InstrumentationMultiThreadedMixin.test_instrumentation0   s    t'AA!$LL3  (
 t(()AdooTXXtE{4KLAGGINN1	 * 	I::<< $I 
 !r   r   N)__name__
__module____qualname____firstlineno__r1   r.   r2   r   r   r   r#   r&   r;   __static_attributes____classdictcell____classdict__s   @r   r   r      s8     LJ
CA r   r   c                   ,   a  ] tR t^Pt o R tR tRtV tR# )MonitoringTestMixinc                    \        ^4       FN  p\        P                  ! V4      e   K  Wn        \        P                  ! WP
                  P                  4        R# 	  R# )   N)r-   r   get_tooltool_iduse_tool_id	__class__r=   )r   r6   s   & r   setUpMonitoringTestMixin.setUpQ   sA    qA""1%- &&q..*A*AB	 r   c                F    \         P                  ! V P                  4       R # r   )r   free_tool_idrJ   r   s   &r   tearDownMonitoringTestMixin.tearDownX   s    -r   )rJ   N)r=   r>   r?   r@   rM   rQ   rA   rB   rC   s   @r   rF   rF   P   s     . .r   rF   c                   D   a a ] tR t^\t oV 3R ltR tR tR tRtVt	V ;t
# )SetPreTraceMultiThreadedc                2   < \         SV `  4        R V n        R# FN)superrM   calledr   rL   s   &r   rM   SetPreTraceMultiThreaded.setUp`   s    r   c                <    V P                  V P                  4       R # r   
assertTruerX   r   s   &r   r&   #SetPreTraceMultiThreaded.after_testd       $r   c                (    R V n         V P                  # TrX   
trace_funcr   frameeventargs   &&&&r   rc   #SetPreTraceMultiThreaded.trace_funcg       r   c                F    \         P                  ! V P                  4       R # r   )syssettracerc   r   s   &r   r   &SetPreTraceMultiThreaded.after_threadsk   s    T__%r   rX   )r=   r>   r?   r@   rM   r&   rc   r   rA   rB   __classcell__rL   rD   s   @@r   rT   rT   \   s     %& &r   rT   c                   P   a a ] tR t^ot oV 3R ltV 3R ltR tR tR tRt	Vt
V ;t# )MonitoringMultiThreadedc                   < \         SV `  4        R V n        R V n        \        P
                  ! V P                  \        P                  P                  V P                  4       R# rV   )
rW   rM   setrX   r   register_callbackrJ   eventsLINEcallbackrY   s   &r   rM   MonitoringMultiThreaded.setUpu   sC    $$LL*++00$--	
r   c                f   < \         P                  ! V P                  ^ 4       \        SV `  4        R# r   N)r   
set_eventsrJ   rW   rQ   rY   s   &r   rQ    MonitoringMultiThreaded.tearDown}   s"    dllA.r   c                    R V n         R# )TNrn   )r   r,   s   &*r   rx    MonitoringMultiThreaded.callback   s	    r   c                <    V P                  V P                  4       R # r   r\   r   s   &r   r&   "MonitoringMultiThreaded.after_test   r_   r   c                J   V P                   '       dZ   \        P                  ! V P                  \        P                  P
                  \        P                  P                  ,          4       M!\        P                  ! V P                  ^ 4       V P                   '       * V n         R# r{   )rt   r   r|   rJ   rv   CALLrw   r   s   &r   r   &MonitoringMultiThreaded.during_threads   sb    888!!j//44z7H7H7M7MM !!$,,2xx<r   rX   rt   )r=   r>   r?   r@   rM   rQ   rx   r&   r   rA   rB   ro   rp   s   @@r   rr   rr   o   s#     
%   r   rr   c                   >   a  ] tR t^t o R tR tR tR tR tRt	V t
R# )SetTraceMultiThreadedc                "    R V n         R V n        R# rV   rt   rX   r   s   &r   rM   SetTraceMultiThreaded.setUp       r   c                <    V P                  V P                  4       R # r   r\   r   s   &r   r&    SetTraceMultiThreaded.after_test   r_   r   c                2    \         P                  ! R 4       R # r   rk   rl   r   s   &r   rQ   SetTraceMultiThreaded.tearDown   s    Tr   c                (    R V n         V P                  # ra   rb   rd   s   &&&&r   rc    SetTraceMultiThreaded.trace_func   ri   r   c                    V P                   '       d"   \        P                  ! V P                  4       M\        P                  ! R 4       V P                   '       * V n         R # r   )rt   rk   rl   rc   r   s   &r   r   $SetTraceMultiThreaded.during_threads   s4    888LL)LLxx<r   r   Nr=   r>   r?   r@   rM   r&   rQ   rc   r   rA   rB   rC   s   @r   r   r      s#     %   r   r   c                   >   a  ] tR t^t o R tR tR tR tR tRt	V t
R# )SetProfileMultiThreadedc                "    R V n         R V n        R# rV   r   r   s   &r   rM   SetProfileMultiThreaded.setUp   r   r   c                <    V P                  V P                  4       R # r   r\   r   s   &r   r&   "SetProfileMultiThreaded.after_test   r_   r   c                2    \         P                  ! R 4       R # r   rk   
setprofiler   s   &r   rQ    SetProfileMultiThreaded.tearDown   s    tr   c                (    R V n         V P                  # ra   rb   rd   s   &&&&r   rc   "SetProfileMultiThreaded.trace_func   ri   r   c                    V P                   '       d"   \        P                  ! V P                  4       M\        P                  ! R 4       V P                   '       * V n         R # r   )rt   rk   r   rc   r   s   &r   r   &SetProfileMultiThreaded.during_threads   s4    888NN4??+NN4 xx<r   r   Nr   rC   s   @r   r   r      s#     %   r   r   c                   &   a  ] tR t^t o R tRtV tR# )SetProfileAllMultiThreadedc                  aa \         P                  ! 4       oR  oVV3R lpR p. p\        ^
4       F;  p\         P                  ! VR7      pVP	                  4        VP                  V4       K=  	  \        ^d4       F/  p\         P                  ! V4       \         P                  ! R4       K1  	  SP                  4        V F  pVP                  4        K  	  R# )c                      R # r   r   r   r   r   r   ASetProfileAllMultiThreaded.test_profile_all_threads.<locals>.func       r   c                  ~   < S P                  4       '       g&   S! 4        S! 4        S! 4        S! 4        S! 4        K;  R # r   )is_set)doner   s   r   	bg_threadFSetProfileAllMultiThreaded.test_profile_all_threads.<locals>.bg_thread   s,    kkmm $r   c                     R # r   r   )re   rf   rg   s   &&&r   
my_profileGSetProfileAllMultiThreaded.test_profile_all_threads.<locals>.my_profile   s    r   r+   N)		threadingEventr-   r   r4   r0   setprofile_all_threadsrt   join)r   r   r   
bg_threadsr6   r9   r   r   s   &     @@r   test_profile_all_threads3SetProfileAllMultiThreaded.test_profile_all_threads   s     			 
rA  	2AGGIa  
 sA,,Z8,,T2  	
AFFH r   r   N)r=   r>   r?   r@   r   rA   rB   rC   s   @r   r   r      s      r   r   c                   ,   a  ] tR t^t o R tR tRtV tR# )TraceBufc                H    . V n         \        P                  ! 4       V n        R # r   )tracesr   Locktraces_lockr   s   &r   __init__TraceBuf.__init__   s    $>>+r   c                    V P                   ;_uu_ 4        V P                  P                  V4       R R R 4       R #   + '       g   i     R # ; ir   )r   r   r0   )r   traces   &&r   r0   TraceBuf.append   s/    KKu% s	   ;A	)r   r   N)r=   r>   r?   r@   r   r0   rA   rB   rC   s   @r   r   r      s     ,& &r   r   c                   P   a  ] tR t^t o R tR tR tR tR tR t	R t
R tR	tV tR
# )MonitoringMiscc                "   VP                  4        R  p\        ^4       F=  p\        P                  ! V P                  \        P
                  P                  V4       K?  	  V P                  P                  \        P                  ! V4      4       R# )c                      R # r   r   )r,   s   *r   rx   2MonitoringMisc.register_callback.<locals>.callback   r   r   N)waitr-   r   ru   rJ   rv   rw   refsr0   weakrefref)r   barrierrx   r6   s   &&  r   ru    MonitoringMisc.register_callback   s_    	 sA((z7H7H7M7MxX  			X./r   c                   . V n         . p\        ^4      p\        ^4       F<  p\        V P                  V3R7      pVP                  4        VP                  V4       K>  	  V F  pVP                  4        K  	  \        P                  ! V P                  \        P                  P                  R4       V P                    F  pV P                  V! 4       R4       K  	  R# )   r*   N)r   r   r-   r   ru   r4   r0   r   r   rJ   rv   rw   assertEqual)r   r8   r   r6   r9   threadr   s   &      r   test_register_callback%MonitoringMisc.test_register_callback   s    	!*qAd44G:FAGGINN1 
 FKKM  	$$T\\:3D3D3I3I4P99CSUD) r   c                  aaa V3R  loRo\         P                  ! S4        \        4       oVV3R lp\        VR7      pVP	                  4        \        S4       F  pS;_uu_ 4         RRR4       K  	  VP                  4        \         P                  ! R4       R#   + '       g   i     KT  ; i  \         P                  ! R4       i ; i)c                    < R V n         S# ra   )f_trace_opcodes)re   rf   rg   r   s   &&&r   r   :MonitoringMisc.test_set_local_trace_opcodes.<locals>.trace  s    $(E!Lr   i  c                  |   < \        S4       F  p S;_uu_ 4         R R R 4       K  	  R #   + '       g   i     K.  ; ir   )r-   )r6   lloopss    r   r)   6MonitoringMisc.test_set_local_trace_opcodes.<locals>.f  s(    uA  &s   *;r   N)rk   rl   r   r   r4   r-   r   )r   r)   r9   r6   r   r   r   s   &   @@@r   test_set_local_trace_opcodes+MonitoringMisc.test_set_local_trace_opcodes  s    	 U	
A
 a AGGI5\Q Q " FFHLL	 QQ LLs$   AB2 (B*B2 B/)	B2 2C
c           	       aaaa . oV3R  loV3R loR o\         P                  ! S4        S! ^^4       \         P                  ! R4       SP                  4        VV3R lp\        VR
R7      pVP	                  4        VP                  4        RRRR\        3RR\        3RRR	R\         P                  3.pV P                  SV4       R#   \         P                  ! R4       i ; i)c                 V   < SP                  V P                  P                  W34       R # r   r0   f_codeco_name)re   rf   rg   r   s   &&&r   profilerEMonitoringMisc.test_toggle_setprofile_no_new_events.<locals>.profiler-  s    MM5<<//<=r   c                    < S! W4      # r   r   )r7   ybs   &&r   a>MonitoringMisc.test_toggle_setprofile_no_new_events.<locals>.a0  s    Q7Nr   c                     \        W4      # r   )max)r7   r   s   &&r   r   >MonitoringMisc.test_toggle_setprofile_no_new_events.<locals>.b3  s    q9r   Nc                    < \         P                  ! S4        S! W4       \         P                  ! R 4       R #   \         P                  ! R 4       i ; ir   r   )r7   r   r   r   s   &&r   thread_mainHMonitoringMisc.test_toggle_setprofile_no_new_events.<locals>.thread_main=  s4    NN8$%!t$t$s	   9 Ar*   r   c_callc_returnr   )d      )r   callN)r   r   N)r   returnr   )r   r   r   )rk   r   clearr   r4   r   r   r   )r   r   r9   expectedr   r   r   r   s   &   @@@@r   $test_toggle_setprofile_no_new_events3MonitoringMisc.test_toggle_setprofile_no_new_events'  s     	>		 	x 	!aGNN4 	% +J7			  (C *c"  Hcnn5
 	*- NN4 s   	C C$c                  aa	a
a R  o
V
V3R lo	R oV	VV3R lp^p\        V4      p. p\        V4       F2  p\        W5V3R7      pVP                  4        VP	                  V4       K4  	  V F  pVP                  4        K  	  \        V4       FA  pV P                  RRV3VP                  4       V P                  RRV3VP                  4       KC  	  R# )	c                     V # r   r   idents   &r   in_child0MonitoringMisc.observe_threads.<locals>.in_childS      Lr   c                 p   < S! 4       ;_uu_ 4        S! V 4       R R R 4       R #   + '       g   i     R # ; ir   r   )r   r   observers   &r   child-MonitoringMisc.observe_threads.<locals>.childV  s     s   	$5	c                     V # r   r   r   s   &r   	in_parent1MonitoringMisc.observe_threads.<locals>.in_parentZ  r  r   c                    < V P                  4        S! 4       ;_uu_ 4        \        SV3R 7      pVP                  4        VP                  4        S! V4       RRR4       R#   + '       g   i     R# ; i)r*   N)r   r   r4   r   )r   r   r9   r  r  r  s   && r   parent.MonitoringMisc.observe_threads.<locals>.parent]  sG    LLN%uh7	% 	 s   7A""A3	r*   r  r   r   N)r   r-   r   r4   r0   r   assertInr   )r   r  bufr  num_threadsr   r8   r6   r9   r  r   r  s   &f&      @@@r   observe_threadsMonitoringMisc.observe_threadsR  s    		 		! +&{#AfQ<8AGGINN1 $ AFFH  {#AMM;!4cjjAMM:x3SZZ@ $r   c                l   aa \        4       oV3R  lo\        V3R l4       pV P                  VS4       R# )c                 V   < SP                  V P                  P                  W34       R # r   r   )re   rf   rg   r  s   &&&r   r   5MonitoringMisc.test_profile_threads.<locals>.profilerv  s    JJ,,e9:r   c               3      <"   \         P                  ! S 4        R x  \         P                  ! R 4       R #   \         P                  ! R 4       i ; i5ir   r   )r   s   r   profile4MonitoringMisc.test_profile_threads.<locals>.profiley  s2     NN8$%t$t$   A7 AAANr   r   r  )r   r  r  r   s   & @@r   test_profile_threads#MonitoringMisc.test_profile_threadss  s5    j	; 
	% 
	% 	Wc*r   c                n   aa \        4       oVV3R  lo\        V3R l4       pV P                  VS4       R# )c                 V   < SP                  V P                  P                  W34       S# r   r   )re   rf   rg   r  tracers   &&&r   r  1MonitoringMisc.test_trace_threads.<locals>.tracer  s#    JJ,,e9:Mr   c               3      <"   \         P                  ! S 4        R x  \         P                  ! R 4       R #   \         P                  ! R 4       i ; i5ir   r   )r  s   r   r   0MonitoringMisc.test_trace_threads.<locals>.trace  s2     LL #T"T"r  Nr  )r   r   r  r  s   & @@r   test_trace_threads!MonitoringMisc.test_trace_threads  s5    j	 
	# 
	# 	UC(r   c                J  a \        4       oV3R  lp\        P                  ! V P                  \        P                  P
                  V4       \        P                  ! V P                  \        P                  P
                  4       \        R 4       pV P                  VS4       R# )c                 D   < SP                  V P                  R V34       R# )r   N)r0   r   )codeoffretvalr  s   &&&r   monitor_py_return>MonitoringMisc.test_monitor_threads.<locals>.monitor_py_return  s    JJh78r   c               3      "   R x  R # 5ir   r   r   r   r   noop1MonitoringMisc.test_monitor_threads.<locals>.noop  s     s   	N)	r   r   ru   rJ   rv   	PY_RETURNr|   r   r  )r   r)  r,  r  s   &  @r   test_monitor_threads#MonitoringMisc.test_monitor_threads  s    j	9 	$$LL*++557H	
 	LL*++55	
 
	 
	 	T3'r   )r   N)r=   r>   r?   r@   ru   r   r   r   r  r  r"  r/  rA   rB   rC   s   @r   r   r      s5     	0* 2)+VAB+ )"( (r   r   __main__)rk   r   r!   unittestr   
contextlibr   r   test.supportr   r   r   r   r	   r   rF   requires_working_threadingrT   rr   r   r   r   r   r   r=   mainr   r   r   <module>r7     sO        %  ) / / < <~	. 	. ,,.&@( & /&$ ,,. :H  / B ,,. =x   / 2 ,,. ?   / 2 ,,.  /B& & ,,.t((( t( /t(n zMMO r   