
    1Vh                         d Z ddlZddlZddlZddlZddlmZ  ej                         Zd	dZ	 G d dej                        Z e       Zej                  d        Zd Zy)
z%Utilities for measuring elapsed time.    N)
tb_loggingc                     |t         j                  }t        | t              r| }t	        ||      S | }t        |dd      }|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	decorators         G/home/dcms/DCMS/lib/python3.12/site-packages/tensorboard/util/timing.pylog_latencyr      so    N LL	5s;9K33B/F/0H 95	-..    c                       e Zd Zd Zy)_ThreadLocalStorec                     d| _         y )Nr   )nesting_level)selfs    r   __init__z_ThreadLocalStore.__init__R   s
    r   N)__name__
__module__r   r    r   r   r   r   Q   s    r   r   c           	   #     K   t         j                  |      sd  y t        j                  }	 t	        j                         }|dz   t        _        d|z  }t        j                         }d|j                  |j                  |fz  }t        |d||        d  |t        _        t	        j                         |z
  }t        |d|| |       y # |t        _        t	        j                         z
  }t        |d| |       w xY w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elapseds           r   r
   r
   Y   s     y)&&K
))+*Q[())+v{{FLL&AAYvt4*))+'*	
  +))+'*	
s   +C?A)C	 2C?	3C<<C?c                 2    t        j                  | |g|  y N)r    log)r   msgargss      r   r(   r(   t   s     JJy#%%r   r0   )__doc__
contextlibr   r$   r#   tensorboard.utilr   
get_loggerr    r   localr   r"   contextmanagerr
   r(   r   r   r   <module>r:      sh    ,     '				 3/l	 
 
	 
 
4&r   