
    sh?/                        S r SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKJ	r
  SSKJrJr  SSKJr  SSKJrJr   " S S\R&                  5      r\" / S	Q5      rS
 r " S S5      r\" \5      rS rS rS r " S S\R<                  5      r " S S\5      r  " S S\5      r!\S 5       r"\S 5       r#\S 5       r$SS jr%S S jr&\SS j5       r'S\!4S jr(S r)\RT                  (       a  \)" 5         gg)!ag  
The ``numba.core.event`` module provides a simple event system for applications
to register callbacks to listen to specific compiler events.

The following events are built in:

- ``"numba:compile"`` is broadcast when a dispatcher is compiling. Events of
  this kind have ``data`` defined to be a ``dict`` with the following
  key-values:

  - ``"dispatcher"``: the dispatcher object that is compiling.
  - ``"args"``: the argument types.
  - ``"return_type"``: the return type.

- ``"numba:compiler_lock"`` is broadcast when the internal compiler-lock is
  acquired. This is mostly used internally to measure time spent with the lock
  acquired.

- ``"numba:llvm_lock"`` is broadcast when the internal LLVM-lock is acquired.
  This is used internally to measure time spent with the lock acquired.

- ``"numba:run_pass"`` is broadcast when a compiler pass is running.

    - ``"name"``: pass name.
    - ``"qualname"``: qualified name of the function being compiled.
    - ``"module"``: module name of the function being compiled.
    - ``"flags"``: compilation flags.
    - ``"args"``: argument types.
    - ``"return_type"`` return type.

Applications can register callbacks that are listening for specific events using
``register(kind: str, listener: Listener)``, where ``listener`` is an instance
of ``Listener`` that defines custom actions on occurrence of the specific event.
    N)default_timer)contextmanager	ExitStack)defaultdict)configutilsc                   \    \ rS rSrSr\R                  " 5       r\R                  " 5       rSr	g)EventStatus2   zStatus of an event.
     N)
__name__
__module____qualname____firstlineno____doc__enumautoSTARTEND__static_attributes__r       d/Users/tiagomarins/Projetos/claudeai/copy_bank/venv/lib/python3.13/site-packages/numba/core/event.pyr
   r
   2   s    IIKE
))+Cr   r
   )znumba:compiler_lockznumba:compileznumba:llvm_locknumba:run_passc                 f    U R                  S5      (       a  U [        ;  a  U  S3n[        U5      eU $ )a  Guard to ensure that an event kind is valid.

All event kinds with a "numba:" prefix must be defined in the pre-defined
``numba.core.event._builtin_kinds``.
Custom event kinds are allowed by not using the above prefix.

Parameters
----------
kind : str

Return
------
res : str
znumba:zG is not a valid event kind, it starts with the reserved prefix 'numba:')
startswith_builtin_kinds
ValueError)kindmsgs     r   _guard_kindr    B   s:     x  T%? = =oKr   c                       \ rS rSrSrSS jr\S 5       r\S 5       r\S 5       r	\S 5       r
\S	 5       r\S
 5       rS r\rSrg)EventX   zAn event.

Parameters
----------
kind : str
status : EventStatus
data : any; optional
    Additional data for the event.
exc_details : 3-tuple; optional
    Same 3-tuple for ``__exit__``.
Nc                 l    [        U5      U l        X l        X0l        Ub  US   c  S U l        g UU l        g Nr   )r    _kind_status_data_exc_details)selfr   statusdataexc_detailss        r   __init__Event.__init__d   s<     &

 + 3{1~7M ""- 	r   c                     U R                   $ )z&Event kind

Returns
-------
res : str
)r&   r*   s    r   r   
Event.kindl        zzr   c                     U R                   $ )z0Event status

Returns
-------
res : EventStatus
)r'   r1   s    r   r+   Event.statusv   s     ||r   c                     U R                   $ )z)Event data

Returns
-------
res : object
)r(   r1   s    r   r,   
Event.data   r3   r   c                 <    U R                   [        R                  :H  $ )z3Is it a *START* event?

Returns
-------
res : bool
)r'   r
   r   r1   s    r   is_startEvent.is_start   s     ||{0000r   c                 <    U R                   [        R                  :H  $ )z2Is it an *END* event?

Returns
-------
res : bool
)r'   r
   r   r1   s    r   is_endEvent.is_end   s     ||{..r   c                     U R                   SL $ )zIs the event carrying an exception?

This is used for *END* event. This method will never return ``True``
in a *START* event.

Returns
-------
res : bool
N)r)   r1   s    r   	is_failedEvent.is_failed   s       D((r   c                     U R                   b   [        U R                   5      R                   OSnSU R                   SU R                   SU S3$ )NNonezEvent(z, z, data: ))r,   typer   r&   r'   )r*   r,   s     r   __str__Event.__str__   sM    99( 		?//0.4 	

|2dll^8D6CCr   )r(   r)   r&   r'   NN)r   r   r   r   r   r.   propertyr   r+   r,   r9   r<   r?   rE   __repr__r   r   r   r   r"   r"   X   s    
/       1 1 / / 
) 
)D
 Hr   r"   c                 x    [        U[        5      (       d   e[        U 5      n [        U    R	                  U5        g)zbRegister a listener for a given event kind.

Parameters
----------
kind : str
listener : Listener
N)
isinstanceListenerr    _registeredappendr   listeners     r   registerrQ      s4     h))))tDX&r   c                 |    [        U[        5      (       d   e[        U 5      n [        U    nUR	                  U5        g)zdUnregister a listener for a given event kind.

Parameters
----------
kind : str
listener : Listener
N)rK   rL   r    rM   remove)r   rP   lsts      r   
unregisterrU      s7     h))))tD
d
CJJxr   c                 Z    [         U R                      H  nUR                  U 5        M     g)zUBroadcast an event to all registered listeners.

Parameters
----------
event : Event
N)rM   r   notify)eventrP   s     r   	broadcastrY      s#      

+ ,r   c                   f    \ rS rSrSr\R                  S 5       r\R                  S 5       rS r	Sr
g)rL      z(Base class for all event listeners.
    c                     g)zKCalled when there is a *START* event.

Parameters
----------
event : Event
Nr   r*   rX   s     r   on_startListener.on_start        	r   c                     g)zICalled when there is a *END* event.

Parameters
----------
event : Event
Nr   r]   s     r   on_endListener.on_end   r`   r   c                     UR                   (       a  U R                  U5        gUR                  (       a  U R                  U5        g[	        S5      e)zPNotify this Listener with the given Event.

Parameters
----------
event : Event
unreachableN)r9   r^   r<   rb   AssertionErrorr]   s     r   rW   Listener.notify   s5     >>MM% \\KK //r   r   N)r   r   r   r   r   abcabstractmethodr^   rb   rW   r   r   r   r   rL   rL      s>      	 0r   rL   c                   J    \ rS rSrSrS rS rS r\S 5       r	\S 5       r
Srg	)
TimingListeneri  zxA listener that measures the total time spent between *START* and
*END* events during the time this listener is active.
c                     SU l         g r%   )_depthr1   s    r   r.   TimingListener.__init__  s	    r   c                 l    U R                   S:X  a  [        5       U l        U =R                   S-  sl         g )Nr      )rm   timer_tsr]   s     r   r^   TimingListener.on_start	  s%    ;;!wDHqr   c                     U =R                   S-  sl         U R                   S:X  a-  [        U SS5      n[        5       U R                  -
  U-   U l        g g )Nrp   r   	_duration)rm   getattrrq   rr   ru   )r*   rX   lasts      r   rb   TimingListener.on_end  sF    q;;!4a0D#g0D8DN r   c                     [        U S5      $ )zReturns a ``bool`` indicating whether a measurement has been made.

When this returns ``False``, the matching event has never fired.
If and only if this returns ``True``, ``.duration`` can be read without
error.
ru   )hasattrr1   s    r   doneTimingListener.done  s     t[))r   c                     U R                   $ )zReturns the measured duration.

This may raise ``AttributeError``. Users can use ``.done`` to check
that a measurement has been made.
)ru   r1   s    r   durationTimingListener.duration  s     ~~r   )rm   ru   rr   N)r   r   r   r   r   r.   r^   rb   rH   r{   r~   r   r   r   r   rk   rk     s>    
9 * *  r   rk   c                   *    \ rS rSrSrS rS rS rSrg)RecordingListeneri(  zA listener that records all events and stores them in the ``.buffer``
attribute as a list of 2-tuple ``(float, Event)``, where the first element
is the time the event occurred as returned by ``time.time()`` and the second
element is the event.
c                     / U l         g Nbufferr1   s    r   r.   RecordingListener.__init__.  s	    r   c                 d    U R                   R                  [        R                  " 5       U45        g r   r   rN   timer]   s     r   r^   RecordingListener.on_start1      DIIK/0r   c                 d    U R                   R                  [        R                  " 5       U45        g r   r   r]   s     r   rb   RecordingListener.on_end4  r   r   r   N)	r   r   r   r   r   r.   r^   rb   r   r   r   r   r   r   (  s    
11r   r   c              #   b   #    [        X5         Uv   [        X5        g! [        X5        f = f7f)aU  Install a listener for event "kind" temporarily within the duration of
the context.

Returns
-------
res : Listener
    The *listener* provided.

Examples
--------

>>> with install_listener("numba:compile", listener):
>>>     some_code()  # listener will be active here.
>>> other_code()     # listener will be unregistered by this point.

N)rQ   rU   rO   s     r   install_listenerr   8  s)     $ T#4"
4"s   / /,/c              #      #    [        5       n[        X5         Uv   SSS5        UR                  (       a  U" UR                  5        gg! , (       d  f       N3= f7f)a  Install a TimingListener temporarily to measure the duration of
an event.

If the context completes successfully, the *callback* function is executed.
The *callback* function is expected to take a float argument for the
duration in seconds.

Returns
-------
res : TimingListener

Examples
--------

This is equivalent to:

>>> with install_listener(kind, TimingListener()) as res:
>>>    ...
N)rk   r   r{   r~   )r   callbacktls      r   install_timerr   Q  sC     * 
	B	$	# 
$ 
ww  
$	#s   AA
-A

AAc              #   r   #    [        5       n[        X5         Uv   SSS5        g! , (       d  f       g= f7f)aB  Install a RecordingListener temporarily to record all events.

Once the context is closed, users can use ``RecordingListener.buffer``
to access the recorded events.

Returns
-------
res : RecordingListener

Examples
--------

This is equivalent to:

>>> with install_listener(kind, RecordingListener()) as res:
>>>    ...
N)r   r   )r   rls     r   install_recorderr   n  s'     & 
	B	$	# 
$	#	#s   7&	7
47c                 L    [        U [        R                  US9n[        U5        g)zTrigger the start of an event of *kind* with *data*.

Parameters
----------
kind : str
    Event kind.
data : any; optional
    Extra event data.
)r   r+   r,   N)r"   r
   r   rY   )r   r,   evts      r   start_eventr     s     T+"3"3$
?CcNr   c                 L    [        U [        R                  XS9n[        U5        g)zTrigger the end of an event of *kind*, *exc_details*.

Parameters
----------
kind : str
    Event kind.
data : any; optional
    Extra event data.
exc_details : 3-tuple; optional
    Same 3-tuple for ``__exit__``. Or, ``None`` if no error.
)r   r+   r,   r-   N)r"   r
   r   rY   )r   r,   r-   r   s       r   	end_eventr     s"     +//C cNr   c              #      ^ ^#    [        5        nUR                  UU 4S j5       n[        T TS9  Sv   SSS5        g! , (       d  f       g= f7f)a  A context manager to trigger the start and end events of *kind* with
*data*. The start event is triggered when entering the context.
The end event is triggered when exiting the context.

Parameters
----------
kind : str
    Event kind.
data : any; optional
    Extra event data.
c                     > [        TTU S9  g )N)r,   r-   )r   )r-   r,   r   s    r   on_exittrigger_event.<locals>.on_exit  s    d;?r   )r,   N)r   pushr   )r   r,   scoper   s   ``  r   trigger_eventr     s?      
		@ 
	@ 	Dt$ 
s   A%=	A
AArP   c                 F   [         R                  " 5       n[        R                  " 5       n/ nU R                   Hd  u  pEUR
                  n[        UR                  5      nUS-  nUR                  (       a  SOSn	US   n
Un[        XqX(XUS9nUR                  U5        Mf     U$ )zGPrepare events in `listener` for serializing as chrome trace data.
    i@B BEname)catpidtidtsphr   args)osgetpid	threadingget_native_idr   r,   strr   r9   dictrN   )rP   r   r   evsr   recr,   r   	ts_scaledr   r   r   evs                r   _prepare_chrome_trace_datar     s     ))+C

!
!
#C
C??xx#((mN	LLScF|#
 	

2 # Jr   c                     ^^ [        5       m[        ST5        [        R                  m[        R                  UU4S j5       n g)zTSetup a RecordingListener and an exit handler to write the captured
events to file.
r   c                     > [        T5      n [        TS5       n[        R                  " X[        R
                  S9  S S S 5        g ! , (       d  f       g = f)Nw)cls)r   openjsondumpr   _LazyJSONEncoder)r   outfilenamerP   s     r   _write_chrome_trace=_setup_chrome_trace_exit_handler.<locals>._write_chrome_trace  s;     )2(C CIIcE$:$:; !  s   $A
AN)r   rQ   r   CHROME_TRACEatexit)r   r   rP   s    @@r    _setup_chrome_trace_exit_handlerr     s9     !"Hx(""H__< <r   r   rG   )+r   r   r   r   rh   r   r   r   timeitr   rq   
contextlibr   r   collectionsr   
numba.corer   r   Enumr
   	frozensetr   r    r"   listrM   rQ   rU   rY   ABCrL   rk   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>r      s(  !F 
   
    ) 0 # $$))    ,X Xv $
'#0sww #0L#X #L1 1  # #0  8  .$  *): 0<  
$& r   