§
    1@Äj$1  ã                   ó  — d Z ddlZddlZddlZddlZddlZddlZddlZddlm	Z
 ddlmZmZ ddlmZ ddlmZmZ  G d„ dej        ¦  «        Z eg d	¢¦  «        Zd
„ Z G d„ d¦  «        Z ee¦  «        Zd„ Zd„ Zd„ Z G d„ dej        ¦  «        Z G d„ de¦  «        Z  G d„ de¦  «        Z!ed„ ¦   «         Z"ed„ ¦   «         Z#ed„ ¦   «         Z$dd„Z%d d„Z&edd„¦   «         Z'de!fd„Z(d„ Z)ej*        r e)¦   «          dS dS )!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                   óN   — e Zd ZdZ ej        ¦   «         Z ej        ¦   «         ZdS )ÚEventStatuszStatus of an event.
    N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚenumÚautoÚSTARTÚEND© ó    úAC:\Projects\Historical\venv\Lib\site-packages\numba/core/event.pyr
   r
   2   s2   € € € € € ðð àˆDŒI‰KŒK€EØ
ˆ$Œ)‰+Œ+€C€C€Cr   r
   )znumba:compiler_lockznumba:compileznumba:llvm_lockúnumba:run_passc                 ój   — |                       d¦  «        r| t          vr| › d�}t          |¦  «        ‚| S )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   sG   € ð ‡‚�xÑ Ô ð  TµÐ%?Ð%?Øð =ð =ð =ˆå˜‰oŒoÐØ€Kr   c                   ó¨   — e Zd ZdZdd„Zed„ ¦   «         Zed„ ¦   «         Zed„ ¦   «         Zed„ ¦   «         Z	ed„ ¦   «         Z
ed	„ ¦   «         Zd
„ ZeZdS )ÚEventzàAn 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                 óp   — t          |¦  «        | _        || _        || _        |�|d         €d n|| _        d S ©Nr   )r   Ú_kindÚ_statusÚ_dataÚ_exc_details)Úselfr   ÚstatusÚdataÚexc_detailss        r   Ú__init__zEvent.__init__d   sF   € Ý  Ñ&Ô&ˆŒ
ØˆŒØˆŒ
à +Ð 3°{À1´~Ð7Mð "˜Tà"-ð 	ÔÐÐr   c                 ó   — | j         S )zFEvent kind

        Returns
        -------
        res : str
        )r"   ©r&   s    r   r   z
Event.kindl   ó   € ð ŒzÐr   c                 ó   — | j         S )zPEvent status

        Returns
        -------
        res : EventStatus
        )r#   r,   s    r   r'   zEvent.statusv   s   € ð Œ|Ðr   c                 ó   — | j         S )zIEvent data

        Returns
        -------
        res : object
        )r$   r,   s    r   r(   z
Event.data€   r-   r   c                 ó,   — | j         t          j        k    S )zSIs it a *START* event?

        Returns
        -------
        res : bool
        )r#   r
   r   r,   s    r   Úis_startzEvent.is_startŠ   s   € ð Œ|�{Ô0Ò0Ð0r   c                 ó,   — | j         t          j        k    S )zRIs it an *END* event?

        Returns
        -------
        res : bool
        )r#   r
   r   r,   s    r   Úis_endzEvent.is_end”   s   € ð Œ|�{œÒ.Ð.r   c                 ó   — | j         du S )zÊIs 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%   r,   s    r   Ú	is_failedzEvent.is_failedž   s   € ð Ô  DÐ(Ð(r   c                 ót   — | j         �t          | j         ¦  «        j        › nd}d| j        › d| j        › d|› d�S )NÚNonezEvent(z, z, data: ú))r(   Útyper   r"   r#   )r&   r(   s     r   Ú__str__zEvent.__str__«   sM   € à”9Ð(õ ˜œ	‘?”?Ô/Ð1Ð1Ø.4ð 	àC˜œ
ÐCÐC d¤lÐCÐC¸DÐCÐCÐCÐCr   ©NN)r   r   r   r   r*   Úpropertyr   r'   r(   r1   r3   r5   r:   Ú__repr__r   r   r   r   r   X   sç   € € € € € ð
ð 
ð/ð /ð /ð /ð ðð ñ „Xðð ðð ñ „Xðð ðð ñ „Xðð ð1ð 1ñ „Xð1ð ð/ð /ñ „Xð/ð ð
)ð 
)ñ „Xð
)ðDð Dð Dð
 €H€H€Hr   r   c                 ó’   — t          |t          ¦  «        sJ ‚t          | ¦  «        } t          |                               |¦  «         dS )zvRegister a listener for a given event kind.

    Parameters
    ----------
    kind : str
    listener : Listener
    N)Ú
isinstanceÚListenerr   Ú_registeredÚappend©r   Úlisteners     r   ÚregisterrE   ¶   sF   € õ �h¥Ñ)Ô)Ð)Ð)Ð)Ý�tÑÔ€DÝ�Ô×Ò˜XÑ&Ô&Ð&Ð&Ð&r   c                 ó–   — t          |t          ¦  «        sJ ‚t          | ¦  «        } t          |          }|                     |¦  «         dS )zxUnregister a listener for a given event kind.

    Parameters
    ----------
    kind : str
    listener : Listener
    N)r?   r@   r   rA   Úremove)r   rD   Úlsts      r   Ú
unregisterrI   Ã   sI   € õ �h¥Ñ)Ô)Ð)Ð)Ð)Ý�tÑÔ€DÝ
�dÔ
€CØ‡J‚JˆxÑÔÐÐÐr   c                 óZ   — t           | j                 D ]}|                     | ¦  «         ŒdS )zeBroadcast an event to all registered listeners.

    Parameters
    ----------
    event : Event
    N)rA   r   Únotify)ÚeventrD   s     r   Ú	broadcastrM   Ñ   s9   € õ   ¤
Ô+ð ð ˆØ�Š˜ÑÔÐÐðð r   c                   óX   — e Zd ZdZej        d„ ¦   «         Zej        d„ ¦   «         Zd„ ZdS )r@   z(Base class for all event listeners.
    c                 ó   — dS )zkCalled when there is a *START* event.

        Parameters
        ----------
        event : Event
        Nr   ©r&   rL   s     r   Úon_startzListener.on_startß   ó	   € ð 	ˆr   c                 ó   — dS )ziCalled when there is a *END* event.

        Parameters
        ----------
        event : Event
        Nr   rP   s     r   Úon_endzListener.on_endé   rR   r   c                 ó˜   — |j         r|                      |¦  «         dS |j        r|                      |¦  «         dS t	          d¦  «        ‚)zpNotify this Listener with the given Event.

        Parameters
        ----------
        event : Event
        ÚunreachableN)r1   rQ   r3   rT   ÚAssertionErrorrP   s     r   rK   zListener.notifyó   sV   € ð Œ>ð 	0Ø�MŠM˜%Ñ Ô Ð Ð Ð ØŒ\ð 	0Ø�KŠK˜ÑÔÐÐÐå  Ñ/Ô/Ð/r   N)	r   r   r   r   ÚabcÚabstractmethodrQ   rT   rK   r   r   r   r@   r@   Ü   si   € € € € € ðð àÔðð ñ Ôðð 	Ôðð ñ Ôðð0ð 0ð 0ð 0ð 0r   r@   c                   óP   — e Zd ZdZd„ Zd„ Zd„ Zed„ ¦   «         Zed„ ¦   «         Z	dS )ÚTimingListenerz€A listener that measures the total time spent between *START* and
    *END* events during the time this listener is active.
    c                 ó   — d| _         d S r!   )Ú_depthr,   s    r   r*   zTimingListener.__init__  s   € ØˆŒˆˆr   c                 ób   — | j         dk    rt          ¦   «         | _        | xj         dz  c_         d S )Nr   é   )r]   ÚtimerÚ_tsrP   s     r   rQ   zTimingListener.on_start	  s.   € ØŒ;˜!ÒÐÝ‘w”wˆDŒHØˆŒ�qÑˆŒˆˆr   c                 óž   — | xj         dz  c_         | j         dk    r1t          | dd¦  «        }t          ¦   «         | j        z
  |z   | _        d S d S )Nr_   r   Ú	_duration)r]   Úgetattrr`   ra   rc   )r&   rL   Úlasts      r   rT   zTimingListener.on_end  sS   € ØˆŒ�qÑˆŒØŒ;˜!ÒÐÝ˜4 ¨aÑ0Ô0ˆDÝ#™gœg¨¬Ñ0°DÑ8ˆDŒNˆNˆNð Ðr   c                 ó"   — t          | d¦  «        S )zôReturns 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.
        rc   )Úhasattrr,   s    r   ÚdonezTimingListener.done  s   € õ �t˜[Ñ)Ô)Ð)r   c                 ó   — | j         S )zžReturns the measured duration.

        This may raise ``AttributeError``. Users can use ``.done`` to check
        that a measurement has been made.
        )rc   r,   s    r   ÚdurationzTimingListener.duration  s   € ð Œ~Ðr   N)
r   r   r   r   r*   rQ   rT   r<   rh   rj   r   r   r   r[   r[     s�   € € € € € ðð ðð ð ðð ð ð
9ð 9ð 9ð ð*ð *ñ „Xð*ð ðð ñ „Xðð ð r   r[   c                   ó$   — e Zd ZdZd„ Zd„ Zd„ ZdS )ÚRecordingListenera  A 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                 ó   — g | _         d S ©N)Úbufferr,   s    r   r*   zRecordingListener.__init__.  s   € ØˆŒˆˆr   c                 ó`   — | j                              t          j        ¦   «         |f¦  «         d S rn   ©ro   rB   ÚtimerP   s     r   rQ   zRecordingListener.on_start1  ó)   € ØŒ×Ò�DœI™KœK¨Ð/Ñ0Ô0Ð0Ð0Ð0r   c                 ó`   — | j                              t          j        ¦   «         |f¦  «         d S rn   rq   rP   s     r   rT   zRecordingListener.on_end4  rs   r   N)r   r   r   r   r*   rQ   rT   r   r   r   rl   rl   (  sK   € € € € € ðð ð
ð ð ð1ð 1ð 1ð1ð 1ð 1ð 1ð 1r   rl   c              #   ó~   K  — t          | |¦  «         	 |V — t          | |¦  «         dS # t          | |¦  «         w xY w)a�  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)rE   rI   rC   s     r   Úinstall_listenerrv   8  sR   è è € õ$ ˆT�8ÑÔÐð#Øˆˆˆå�4˜Ñ"Ô"Ð"Ð"Ð"ø�
�4˜Ñ"Ô"Ð"Ð"øøøs   ”* ª<c              #   ó°   K  — t          ¦   «         }t          | |¦  «        5  |V — ddd¦  «         n# 1 swxY w Y   |j        r ||j        ¦  «         dS dS )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)r[   rv   rh   rj   )r   ÚcallbackÚtls      r   Úinstall_timerrz   Q  s¯   è è € õ* 
Ñ	Ô	€BÝ	˜$ Ñ	#Ô	#ð ð Øˆˆˆðð ð ñ ô ð ð ð ð ð ð øøøð ð ð ð ð 
„wð Øˆ�”ÑÔÐÐÐðð s   ¡2²6¹6c              #   ó€   K  — t          ¦   «         }t          | |¦  «        5  |V — ddd¦  «         dS # 1 swxY w Y   dS )an  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)rl   rv   )r   Úrls     r   Úinstall_recorderr}   n  s�   è è € õ& 
Ñ	Ô	€BÝ	˜$ Ñ	#Ô	#ð ð Øˆˆˆðð ð ñ ô ð ð ð ð ð ð ð øøøð ð ð ð ð ð s   ¡3³7º7c                 ó\   — t          | t          j        |¬¦  «        }t          |¦  «         dS )z®Trigger 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   rM   )r   r(   Úevts      r   Ústart_eventr€   †  s*   € õ �T¥+Ô"3¸$Ð
?Ñ
?Ô
?€CÝˆc�N„N€N€N€Nr   c                 ó^   — t          | t          j        ||¬¦  «        }t          |¦  «         dS )a  Trigger 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   rM   )r   r(   r)   r   s       r   Ú	end_eventr‚   ”  s4   € õ Ø�+œ/°À+ðñ ô €Cõ ˆc�N„N€N€N€Nr   c              #   ó¬   ‡ ‡K  — t          ¦   «         5 }|j        ˆˆ fd„¦   «         }t          ‰ ‰¬¦  «         dV — ddd¦  «         dS # 1 swxY w Y   dS )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          ‰‰| ¬¦  «         d S )N)r(   r)   )r‚   )r)   r(   r   s    €€r   Úon_exitztrigger_event.<locals>.on_exit´  s   ø€ å�d °;Ð?Ñ?Ô?Ð?Ð?Ð?r   )r(   N)r   Úpushr€   )r   r(   Úscoper…   s   ``  r   Útrigger_eventrˆ   ¦  sÃ   øøè è € õ 
‰Œð ˜Ø	Œð	@ð 	@ð 	@ð 	@ð 	@ñ 
Œð	@õ 	�D˜tÐ$Ñ$Ô$Ð$Øˆˆˆðð ð ñ ô ð ð ð ð ð ð ð øøøð ð ð ð ð ð s   “)A	Á	AÁArD   c           
      ó0  — t          j        ¦   «         }t          j        ¦   «         }g }| j        D ]e\  }}|j        }t          |j        ¦  «        }|dz  }|j        rdnd}	|d         }
|}t          |||||	|
|¬¦  «        }| 
                    |¦  «         Œf|S )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_idro   r(   Ústrr   r1   ÚdictrB   )rD   rŽ   r�   Úevsr�   Úrecr(   r�   Ú	ts_scaledr‘   rŒ   r’   Úevs                r   Ú_prepare_chrome_trace_datar�   ¼  s®   € õ Œ)‰+Œ+€CÝ
Ô
!Ñ
#Ô
#€CØ
€CØ”?ð ð ‰ˆˆCØŒxˆÝ�#”(‰mŒmˆØ˜‘Nˆ	Ø”LÐ)ˆSˆS cˆØ�FŒ|ˆØˆÝØ˜ #¨)¸ÀØð
ñ 
ô 
ˆð 	�
Š
�2‰ŒˆˆØ€Jr   c                  óŽ   ‡‡— t          ¦   «         Št          d‰¦  «         t          j        Št          j        ˆˆfd„¦   «         } dS )z\Setup a RecordingListener and an exit handler to write the captured
    events to file.
    r   c                  óº   •— t          ‰¦  «        } t          ‰d¦  «        5 }t          j        | |t          j        ¬¦  «         d d d ¦  «         d S # 1 swxY w Y   d S )NÚw)Úcls)r�   ÚopenÚjsonÚdumpr   Ú_LazyJSONEncoder)r™   ÚoutÚfilenamerD   s     €€r   Ú_write_chrome_tracez=_setup_chrome_trace_exit_handler.<locals>._write_chrome_traceÜ  s�   ø€ õ )¨Ñ2Ô2ˆÝ�(˜CÑ Ô ð 	< CÝŒI�c˜3¥EÔ$:Ð;Ñ;Ô;Ð;ð	<ð 	<ð 	<ñ 	<ô 	<ð 	<ð 	<ð 	<ð 	<ð 	<ð 	<ð 	<øøøð 	<ð 	<ð 	<ð 	<ð 	<ð 	<s   ¡"AÁAÁAN)rl   rE   r   ÚCHROME_TRACEÚatexit)r¨   r§   rD   s    @@r   Ú _setup_chrome_trace_exit_handlerr«   Ô  s^   øø€ õ !Ñ"Ô"€HÝÐ˜xÑ(Ô(Ð(ÝÔ"€Hå„_ð<ð <ð <ð <ð <ñ „_ð<ð <ð <r   rn   r;   )+r   r“   r£   rª   rX   r   rr   r•   Útimeitr   r`   Ú
contextlibr   r   Úcollectionsr   Ú
numba.corer   r   ÚEnumr
   Ú	frozensetr   r   r   ÚlistrA   rE   rI   rM   ÚABCr@   r[   rl   rv   rz   r}   r€   r‚   rˆ   r�   r«   r©   r   r   r   ú<module>r´      sæ  ðð!ð !ðF 
€	€	€	Ø €€€Ø €€€Ø 
€
€
€
Ø €€€Ø €€€Ø Ð Ð Ð Ø )Ð )Ð )Ð )Ð )Ð )Ø 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0Ø #Ð #Ð #Ð #Ð #Ð #à $Ð $Ð $Ð $Ð $Ð $Ð $Ð $ðð ð ð ð �$”)ñ ô ð ð �ð ð ð ñ ô €ðð ð ð,Xð Xð Xð Xð Xñ Xô Xð Xðv ˆk˜$ÑÔ€ð
'ð 
'ð 
'ðð ð ðð ð ð#0ð #0ð #0ð #0ð #0ˆsŒwñ #0ô #0ð #0ðL#ð #ð #ð #ð #�Xñ #ô #ð #ðL1ð 1ð 1ð 1ð 1˜ñ 1ô 1ð 1ð  ð#ð #ñ „ð#ð0 ðð ñ „ðð8 ðð ñ „ðð.ð ð ð ðð ð ð ð$ ðð ð ñ „ðð*Ð):ð ð ð ð ð0<ð <ð <ð  
Ôð 'Ø$Ð$Ñ&Ô&Ð&Ð&Ð&ð'ð 'r   