L iddlmZddlZddlmZddlmZmZmZm Z erddl m Z GddeZ d dZe Gd d eZGd d Zy)) annotationsN)abstractmethod) TYPE_CHECKING NamedTupleProtocolruntime_checkable)Metricc@eZdZUdZded<ded<ded<d dZd dZy ) CacheStataeDescribes 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. str category_name cache_nameint byte_lengthcTd|jd|jd|jS)Nzcache_memory_bytes{cache_type="z ",cache="z"} r rrselfs ]/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/streamlit/runtime/stats.py to_metric_strzCacheStat.to_metric_str.s01$2D2D1EYtN__cdhdtdtcuvvc6|jj}d|_|j|_|jj}d|_|j |_|j j}|j|j_ y)z-Fill an OpenMetrics `Metric` protobuf object. cache_typecacheN) labelsaddnamer valuer metric_pointsr gauge_value int_value)rmetriclabel metric_points rmarshall_metric_protozCacheStat.marshall_metric_proto1st !!#! ((  !!# oo ++//1 -1-=-=   *rN)returnr )r" MetricProtor&None)__name__ __module__ __qualname____doc____annotations__rr%rrr r s% Ow >rr c dd}g}t||}tj||}|D]5\\}}}|jt ||t d|D7|S)zOGroup a list of CacheStats by category_name and cache_name and sum byte_length.c2|j|jfSN)r r)individual_stats r key_functionz!group_stats..key_functionBs,,o.H.HHHr)keyc34K|]}|jywr1)r).0items r zgroup_stats..OsPT 0 0Psr)r2r r&ztuple[str, str])sorted itertoolsgroupbyappendr sum)statsr3result sorted_stats grouped_statsr rsingle_group_statss r group_statsrC?swI!F%\2L%%l EM;H 7# %7 +%P=OPP    MrceZdZeddZy)CacheStatsProviderctr1)NotImplementedErrorrs r get_statszCacheStatsProvider.get_statsWs!!rNr&list[CacheStat])r)r*r+rrHr.rrrErEUs""rrEc$eZdZddZddZddZy) StatsManagercg|_yr1)_cache_stats_providersrs r__init__zStatsManager.__init__]s @B#rc:|jj|y)zRegister a CacheStatsProvider with the manager. This function is not thread-safe. Call it immediately after creation. N)rNr<)rproviders rregister_providerzStatsManager.register_provider`s ##**84rcjg}|jD]!}|j|j#|S)zAReturn a list containing all stats from each registered provider.)rNextendrH)r all_statsrQs rrHzStatsManager.get_statsgs;%' 33 3H   X//1 2 3rN)r&r()rQrEr&r(rI)r)r*r+rOrRrHr.rrrLrL\sC5rrL)r>rJr&rJ) __future__rr:abcrtypingrrrr*streamlit.proto.openmetrics_data_model_pb2r r'r rCrErLr.rrrZsS#IIP#> #>L,""" r