o
    `Û·i³  ã                   @   sT   d dl Z d dlmZ d dlmZ d dlmZ eG dd„ dƒƒZeG dd„ dƒƒZdS )	é    N)ÚList)Ú
Deprecated)Ú_Timerc                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚMetricsContexta†  Metrics context object for a local iterator.

    This object is accessible by all operators of a local iterator. It can be
    used to store and retrieve global execution metrics for the iterator.
    It can be accessed by calling LocalIterator.get_metrics(), which is only
    allowable inside iterator functions.

    Attributes:
        counters: dict storing increasing metrics.
        timers: dict storing latency timers.
        info: dict storing misc metric values.
        current_actor: reference to the actor handle that
            produced the current iterator output. This is automatically set
            for gather_async().
    c                 C   s(   t  t¡| _t  t¡| _i | _d | _d S ©N)ÚcollectionsÚdefaultdictÚintÚcountersr   ÚtimersÚinfoÚcurrent_actor©Úself© r   úK/home/ubuntu/vllm_env/lib/python3.10/site-packages/ray/util/iter_metrics.pyÚ__init__   s   
zMetricsContext.__init__c                 C   s   t | jƒt | jƒddœS )z+Return a serializable copy of this context.N)r
   r   r   )Údictr
   r   r   r   r   r   Úsave    s   ýzMetricsContext.savec                 C   s2   | j  ¡  | j  |d ¡ | j ¡  |d | _dS )z*Restores state given the output of save().r
   r   N)r
   ÚclearÚupdater   r   )r   Úvaluesr   r   r   Úrestore(   s   

zMetricsContext.restoreN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r      s
    r   c                   @   s:   e Zd ZdZ	ddeded  fdd„Zdd„ Zd	d
„ ZdS )ÚSharedMetricszÌHolds an indirect reference to a (shared) metrics context.

    This is used by LocalIterator.union() to point the metrics contexts of
    entirely separate iterator chains to the same underlying context.NÚmetricsÚparentsc                 C   s&   |pt ƒ | _|p	g | _|  | j¡ d S r   )r   r   r   Úset)r   r   r   r   r   r   r   7   s   
zSharedMetrics.__init__c                 C   s    || _ | jD ]}| |¡ qdS )z>Recursively set self and parents to point to the same metrics.N)r   r   r    )r   r   Úparentr   r   r   r    >   s   
ÿzSharedMetrics.setc                 C   s   | j S r   )r   r   r   r   r   ÚgetD   s   zSharedMetrics.get)NN)	r   r   r   r   r   r   r   r    r"   r   r   r   r   r   0   s    ÿÿ
ÿr   )	r   Útypingr   Úray.util.annotationsr   Úray.util.timerr   r   r   r   r   r   r   Ú<module>   s    '