
    x[hg                     p    d dl Z d dlZd dlZ ej                  e      Z G d d      Zddddededefd	Z	y)
    Nc                   8    e Zd ZdZddddededefdZd Zd	 Zy
)Timeda  
    A context manager which measures and optionally logs context run time.

    :param msg: A message that describes the thing that is being measured
    :param threshold: Threshold, in seconds. When the context exceeds this
        threshold, a log will be made.
    :param log_mode: Control whether to log. Defaults to "threshold". Possible
        values include:
        "always" - Always log 'msg', even when 'threshold' is not reached.
        "threshold" - Log when context time exceeds 'threshold'.
        "skip" - Do not log. Context time and message are stored in the
            'output' and 'delta' attributes, respectively. Used to manually
            coalesce with other logs at the call site.

    usage:

        this call:
        ```
        with Timed("Configuring the network"):
            run_configure()
        ```

        might produce this log:
        ```
            Configuring the network took 0.100 seconds
        ```
    {Gz?	thresholdr   log_modemsgr   c                X    || _         || _        || _        d| _        d| _        d| _        y )N g        )r	   r   r   outputstartdelta)selfr	   r   r   s       7/usr/lib/python3/dist-packages/cloudinit/performance.py__init__zTimed.__init__%   s.     " 

    c                 8    t        j                         | _        | S )N)time	monotonicr   )r   s    r   	__enter__zTimed.__enter__3   s    ^^%
r   c                    t        j                         | j                  z
  | _        d| j                  dd}d| j                  k(  r"t
        j                  d| j                  |       y d| j                  k(  ry d| j                  k(  rR| j                  | j                  kD  r8t
        j                  d| j                  |       | j                   d| | _	        y y t        d	| j                   d
      )Nztook z.3fz secondsalwaysz%s %sskipr    zInvalid Timed log_mode value: 'z'.)r   r   r   r   r   LOGdebugr	   r   r   
ValueError)r   exc_typeexc_valexc_tbsuffixs        r   __exit__zTimed.__exit__7   s    ^^%

2
C(1t}}$IIgtxx0t}}$DMM)zzDNN*		'488V4!%
!F84 + 1$--C r   N)	__name__
__module____qualname____doc__strfloatr   r   r"    r   r   r   r      s;    @  # 	
 r   r   r   r   r   r	   r   c                      fd}|S )a  
    A decorator which measures and optionally logs context run time.

    :param msg: A message that describes the thing that is being measured
    :param threshold: Threshold, in seconds. When the context exceeds this
        threshold, a log will be made.
    :param log_mode: Control whether to log. Defaults to "threshold". Possible
        values include:
        "always" - Always log 'msg', even when 'threshold' is not reached.
        "threshold" - Log when context time exceeds 'threshold'.

    usage:

        this call:
        ```
        @timed("Configuring the network")
        def run_configure():
            ...
        ```

        might produce this log:
        ```
            Configuring the network took 0.100 seconds
        ```
    c                 J     t        j                          fd       }|S )Nc                  \    t              5   | i |cd d d        S # 1 sw Y   y xY w)Nr   )r   )argskwargsfuncr   r	   r   s     r   	decoratorz)timed.<locals>.wrapper.<locals>.decoratord   s1    si(C -T,V,- - -s   "+)	functoolswraps)r/   r0   r   r	   r   s   ` r   wrapperztimed.<locals>.wrapperc   s&    			- 
	- r   r)   )r	   r   r   r3   s   ``` r   timedr4   H   s    6 Nr   )
r1   loggingr   	getLoggerr#   r   r   r'   r(   r4   r)   r   r   <module>r7      sL      g!= =@ +/ #s #% ## #r   