
    &e                         d dl Z d dlmZ d dlmZmZ d dlmZmZ d dl	m
Z  G d de          Ze G d d	e                      Z G d
 d          ZdS )    N)abstractmethod)List
NamedTuple)Protocolruntime_checkable)Metricc                   N    e Zd ZU dZeed<   eed<   eed<   defdZdeddfd	Z	dS )
	CacheStatae  Describes a single cache entry.

    Properties
    ----------
    category_name : str
        A human-readable name for the cache "category" that the entry belongs
        to - e.g. "st.memo", "session_state", etc.
    cache_name : str
        A human-readable name for cache instance that the entry belongs to.
        For "st.memo" and other function decorator caches, this might be the
        name of the cached function. If the cache category doesn't have
        multiple separate cache instances, this can just be the empty string.
    byte_length : int
        The entry's memory footprint in bytes.
    category_name
cache_namebyte_lengthreturnc                 6    d| j         d| j        d| j        S )Nzcache_memory_bytes{cache_type="z	",cache="z"} r   r   r   selfs    7lib/python3.11/site-packages/streamlit/runtime/stats.pyto_metric_strzCacheStat.to_metric_str-   s,     OOO
 	
    metricNc                 
   |j                                         }d|_        | j        |_        |j                                         }d|_        | j        |_        |j                                        }| j        |j        _	        dS )z-Fill an OpenMetrics `Metric` protobuf object.
cache_typecacheN)
labelsaddnamer   valuer   metric_pointsr   gauge_value	int_value)r   r   labelmetric_points       r   marshall_metric_protozCacheStat.marshall_metric_proto4   sq    !!##!
(!!##
o+//11-1-= ***r   )
__name__
__module____qualname____doc__str__annotations__intr   MetricProtor#    r   r   r
   r
      s            OOO
s 
 
 
 
>K >D > > > > > >r   r
   c                   6    e Zd Zedee         fd            ZdS )CacheStatsProviderr   c                     t           N)NotImplementedErrorr   s    r   	get_statszCacheStatsProvider.get_statsD   s    !!r   N)r$   r%   r&   r   r   r
   r2   r,   r   r   r.   r.   B   s=        "4	? " " " ^" " "r   r.   c                   <    e Zd Zd ZdeddfdZdee         fdZdS )StatsManagerc                     g | _         d S r0   )_cache_stats_providersr   s    r   __init__zStatsManager.__init__J   s    @B###r   providerr   Nc                 :    | j                             |           dS )zRegister a CacheStatsProvider with the manager.
        This function is not thread-safe. Call it immediately after
        creation.
        N)r6   append)r   r8   s     r   register_providerzStatsManager.register_providerM   s!    
 	#**844444r   c                 
   g }| j         D ]x}|                                }t          j        |d           }|D ]I\  \  }}}|                    t          ||t          t          d |                                         Jy|S )z|Return a list containing all stats from each registered provider.
        Stats are grouped by category_name and cache_type.c                     | j         | j        fS r0   )r   r   )individual_stats    r   <lambda>z(StatsManager.get_stats.<locals>.<lambda>\   s    #1#.) r   c                     | j         S r0   )r   )items    r   r?   z(StatsManager.get_stats.<locals>.<lambda>g   s	    9I r   r   )r6   r2   	itertoolsgroupbyr:   r
   summap)r   	all_statsr8   provider_statsgrouped_statsr   r   statss           r   r2   zStatsManager.get_statsT   s     &(	3 	 	H%//11N%-  M 7D  2+
U  &3#-$',I,I5(Q(Q$R$R      r   )	r$   r%   r&   r7   r.   r;   r   r
   r2   r,   r   r   r4   r4   I   sh        C C C5*< 5 5 5 5 54	?      r   r4   )rB   abcr   typingr   r   typing_extensionsr   r   *streamlit.proto.openmetrics_data_model_pb2r   r+   r
   r.   r4   r,   r   r   <module>rN      s              # # # # # # # # 9 9 9 9 9 9 9 9 L L L L L L'> '> '> '> '>
 '> '> '>T " " " " " " " "" " " " " " " " " "r   