
    &`i                         d dl Z d dlmZ d dlmZ d dlmZ e G d d                      Ze G d d                      ZdS )	    N)List)
Deprecated)_Timerc                   $    e Zd ZdZd Zd Z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                     t          j        t                    | _        t          j        t                    | _        i | _        d | _        d S N)collectionsdefaultdictintcountersr   timersinfocurrent_actorselfs    i/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/util/iter_metrics.py__init__zMetricsContext.__init__   s;    #/44!-f55	!    c                 V    t          | j                  t          | j                  ddS )z+Return a serializable copy of this context.N)r   r   r   )dictr   r   r   s    r   savezMetricsContext.save    s.     T]++OO
 
 	
r   c                     | j                                          | j                             |d                    | j                                         |d         | _        dS )z*Restores state given the output of save().r   r   N)r   clearupdater   r   )r   valuess     r   restorezMetricsContext.restore(   sT    VJ/0006N			r   N)__name__
__module____qualname____doc__r   r   r    r   r   r   r      sK          " " "
 
 
# # # # #r   r   c                   >    e Zd ZdZ	 ddeded          fdZd Z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                 v    |pt                      | _        |pg | _        |                     | j                   d S r	   )r   r%   r&   set)r   r%   r&   s      r   r   zSharedMetrics.__init__7   s;     2."2"2}"r   c                 R    || _         | j        D ]}|                    |           dS )z>Recursively set self and parents to point to the same metrics.N)r%   r&   r(   )r   r%   parents      r   r(   zSharedMetrics.set>   s9    l 	  	 FJJw	  	 r   c                     | j         S r	   )r%   r   s    r   getzSharedMetrics.getD   s
    |r   )NN)	r   r   r    r!   r   r   r   r(   r,   r"   r   r   r$   r$   0   ss        I I PT %7;O7L            r   r$   )	r
   typingr   ray.util.annotationsr   ray.util.timerr   r   r$   r"   r   r   <module>r0      s              + + + + + + ! ! ! ! ! ! $# $# $# $# $# $# $# $#N          r   