o
    c²“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 )Ú_TimerzÜA 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   úB/home/ubuntu/.local/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    