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   R/home/ubuntu/veenaModal/venv/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 )SharedMetricszHolds 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    '