o
    2h                     @   st   d Z ddlZddlZddlZddlZddlmZ e ZdddZ	G dd dej
Ze Zejdd	 Zd
d ZdS )z%Utilities for measuring elapsed time.    N)
tb_loggingc                 C   sX   |du rt j}t| tr| }t||S | }t|dd}|du r#t|}t||}||S )a  Log latency in a function or region.

    Three usages are supported. As a decorator:

    >>> @log_latency
    ... def function_1():
    ...     pass
    ...


    As a decorator with a custom label for the region:

    >>> @log_latency("custom_label")
    ... def function_2():
    ...     pass
    ...

    As a context manager:

    >>> def function_3():
    ...     with log_latency("region_within_function"):
    ...         pass
    ...

    Args:
        region_name_or_function_to_decorate: Either: a `str`, in which
            case the result of this function may be used as either a
            decorator or a context manager; or a callable, in which case
            the result of this function is a decorated version of that
            callable.
        log_level: Optional integer logging level constant. Defaults to
            `logging.INFO`.

    Returns:
        A decorated version of the input callable, or a dual
        decorator/context manager with the input region name.
    N__qualname__)loggingINFO
isinstancestr_log_latencygetattr)#region_name_or_function_to_decorate	log_levelregion_namefunction_to_decoratequalname	decorator r   R/var/www/html/chatgem/venv/lib/python3.10/site-packages/tensorboard/util/timing.pylog_latency   s   '


r   c                   @   s   e Zd Zdd ZdS )_ThreadLocalStorec                 C   s
   d| _ d S )Nr   )nesting_level)selfr   r   r   __init__R   s   
z_ThreadLocalStore.__init__N)__name__
__module__r   r   r   r   r   r   r   Q   s    r   c                 c   s    t |sd V  d S tj}z8t }|d t_d| }t }d|j|j|f }t	|d||  d V  W |t_t | }t	|d|| | d S |t_t | }t	|d|| | w )N   z  z%s[%x]%sz%s ENTER %sz%s LEAVE %s - %0.6fs elapsed)
loggerisEnabledFor_storer   time	threadingcurrent_threadnameident_log)r    r   start_levelstartedindentthreadprefixelapsedr   r   r   r   Y   s>   

r   c                 G   s   t j| |g|R   d S N)r   log)r   msgargsr   r   r   r"   t   s   r"   r)   )__doc__
contextlibr   r   r   tensorboard.utilr   
get_loggerr   r   localr   r   contextmanagerr   r"   r   r   r   r   <module>   s   
6
