o
    $iU                     @   s   d dl Z G dd dZdS )    Nc                   @   sf   e Zd ZdZdddZdd Zdd Zd	d
 Zdd Zdd Z	e
dd Ze
dd Ze
dd ZdS )_TimerzA running stat for conveniently logging the duration of a code block.

    Example:
        wait_timer = TimerStat()
        with wait_timer:
            ray.wait(...)

    Note that this class is *not* thread-safe.
    
   c                 C   s(   || _ g | _g | _d | _d| _d| _d S )N        r   )_window_size_samples_units_processed_start_time_total_timecount)selfwindow_size r   K/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/ray/util/timer.py__init__   s   
z_Timer.__init__c                 C   s    | j d u s	J dt | _ d S )Nz concurrent updates not supported)r   timer   r   r   r   	__enter__   s   z_Timer.__enter__c                 C   s0   | j d usJ t | j  }| | d | _ d S )N)r   r   push)r   exc_type	exc_valuetb
time_deltar   r   r   __exit__   s   

z_Timer.__exit__c                 C   sH   | j | t| j | jkr| j d |  jd7  _|  j|7  _d S )Nr      )r   appendlenr   popr
   r	   )r   r   r   r   r   r   !   s
   z_Timer.pushc                 C   s0   | j | t| j | jkr| j d d S d S Nr   )r   r   r   r   r   )r   nr   r   r   push_units_processed(   s   z_Timer.push_units_processedc                 C   s   t | jdkS r   )r   r   r   r   r   r   has_units_processed-   s   z_Timer.has_units_processedc                 C   *   t | jdkr	dS tt| jt | j S Nr   r   )r   r   floatsumr   r   r   r   mean0      z_Timer.meanc                 C   r!   r"   )r   r   r#   r$   r   r   r   r   mean_units_processed6   r&   z_Timer.mean_units_processedc                 C   s(   t t| j}|sdS t t| j| S )Nr   )r#   r$   r   r   )r   
time_totalr   r   r   mean_throughput<   s   z_Timer.mean_throughputN)r   )__name__
__module____qualname____doc__r   r   r   r   r   r    propertyr%   r'   r)   r   r   r   r   r      s    



r   )r   r   r   r   r   r   <module>   s    