
    Iri              	       D   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
  e j                    Zeeef         Z G d d          Z G d	 d
e          Zdddedeeeef                  dee         fdZddddee         deeeef                  dee         fdZdS )    Nwraps)OptionalUnion   )flags)protonc                   b    e Zd ZdZddedeeeef                  ddfdZd Z	d Z
d	 Zd
 Zd ZdS )scopea  
    A context manager and decorator for entering and exiting a scope.

    Usage:
        context manager:
        ```python
        with proton.scope("test0", {metric_name: metric_value}):
            foo[1,](x, y)
        ```

        decorator:
        ```python
        @proton.scope("test0", {metric_name: metric_value})
        def foo(x, y):
            ...
        ```

    Args:
        name (str): The name of the scope.
        metrics (dict[str, float], optional): The metrics of the scope. Default is None.
    Nnamemetricsreturnc                 0    || _         || _        d | _        d S Nr   r   id)selfr   r   s      m/var/www/html/bestrading.cuttalo.com/models/btc_v9/venv/lib/python3.11/site-packages/triton/profiler/scope.py__init__zscope.__init__%   s    	    c                     t           j        sd S t          j                    | _        t          j        | j        | j                   | j        r!t          j        | j        | j                   d S d S r   )	r   profiling_on	libprotonrecord_scoper   enter_scoper   r   add_metricsr   s    r   _enter_scopezscope._enter_scope*   sj    ! 	F(**dgty111< 	9!$'4<88888	9 	9r   c                 n    t           j        r| j        d S t          j        | j        | j                   d S r   )r   r   r   r   
exit_scoper   r   s    r   _exit_scopezscope._exit_scope2   s5    ! 	TW_FTWdi00000r   c                 .    |                                   | S r   )r   r   s    r   	__enter__zscope.__enter__7   s    r   c                 .    |                                   d S r   )r!   )r   exc_type	exc_value	tracebacks       r   __exit__zscope.__exit__;   s    r   c                 @     t                     fd            }|S )Nc                                                        	  | i |                                 S #                                  w xY wr   )r   r!   )argskwargsfuncr   s     r   wrapperzscope.__call__.<locals>.wrapper@   sY    #tT,V,,  """"  """"s	   3 A	r   )r   r-   r.   s   `` r   __call__zscope.__call__>   s9    	t	# 	# 	# 	# 	# 
	# r   r   )__name__
__module____qualname____doc__strr   dictMetricValueTyper   r   r!   r#   r(   r/    r   r   r   r      s         , S 8Do9M4N+O [_    
9 9 91 1 1
    
 
 
 
 
r   r   c                   b     e Zd ZdZd	dedeeeef                  ddf fdZ fdZ	 fdZ
 xZS )
cpu_timed_scopez
    A scope that measures elapsed time (cpu_time).

    Args:
        name (str): The name of the scope.
        metrics (dict[str, float], optional): Additional metrics to add. Default is None.
    Nr   r   r   c                     t                                          ||           d | _        |rd|v rt          d          d S d S )Ncpu_timez'The metric name 'cpu_time' is reserved.)superr   
start_time
ValueError)r   r   r   	__class__s      r   r   zcpu_timed_scope.__init__T   sX    w''' 	HzW,,FGGG	H 	H,,r   c                     t           j        sd S t          j                    | _        t                                                       d S r   )r   r   timetime_nsr=   r<   r   )r   r?   s    r   r   zcpu_timed_scope._enter_scopeZ   s<    ! 	F,..r   c                     t           j        sd S t                                                       | j        9t          j                    | j        z
  }t          j        | j	        d|i           d S d S )Nzcpu_time (ns)(exc))
r   r   r<   r!   r=   rA   rB   r   r   r   )r   r;   r?   s     r   r!   zcpu_timed_scope._exit_scope`   sl    ! 	F?&|~~7H!$',@(+KLLLLL '&r   r   )r0   r1   r2   r3   r4   r   r5   floatr   r   r!   __classcell__)r?   s   @r   r9   r9   K   s         H HS H8De4D+E HQU H H H H H H    M M M M M M M M Mr   r9   )r   r   r   r   c                "   t           j        sd S t          j                    }t	          t
          dg           t
          _        t
          j                            || f           t          j        ||            |rt          j	        ||           |S )Nscopes)
r   r   r   r   getattrthread_local_scopesrG   appendr   r   r   s      r   r   r   i   s     t			!	!B!()<h!K!K%%r4j111"d### +b'***Ir   c                    t           j        sd S t          j                                        \  }}| r| |k    rt          d|  d|           | s|} t          j        ||            |rt          j        ||           |S )NzScope name mismatch: z != )	r   r   rI   rG   popr>   r   r    r   )r   r   r   popped_names       r   r    r    u   s     t)04466OB ##HHH;HHIII T""" +b'***Ir   r   )	threadingrA   	functoolsr   typingr   r   r   triton._C.libprotonr	   r   localrI   rD   intr6   r   r9   r4   r5   r   r    r7   r   r   <module>rT      s              " " " " " " " "       3 3 3 3 3 3%io'' s
#: : : : : : : :zM M M M Me M M M< OS 	 	 	c 	xS/5I0J'K 	W_`cWd 	 	 	 	^b   Xc] xS/EY@Z7[ gopsgt      r   