
    x[hg                     t    S SK r S SKrS SKr\R                  " \5      r " S S5      rSSS.S\S\S\4S	 jjr	g)
    Nc                   D    \ rS rSrSrSSS.S\S\S\4S jjrS	 rS
 r	Sr
g)Timed   af  
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                R    Xl         X l        X0l        SU l        SU l        SU l        g )N g        )r
   r   r	   outputstartdelta)selfr
   r   r	   s       7/usr/lib/python3/dist-packages/cloudinit/performance.py__init__Timed.__init__%   s(     " 

    c                 :    [         R                  " 5       U l        U $ )N)time	monotonicr   )r   s    r   	__enter__Timed.__enter__3   s    ^^%
r   c                    [         R                  " 5       U R                  -
  U l        SU R                  S S3nSU R                  :X  a"  [
        R                  SU R                  U5        g SU R                  :X  a  g SU R                  :X  aS  U R                  U R                  :  a8  [
        R                  SU R                  U5        U R                   SU 3U l	        g g [        S	U R                   S
35      e)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__Timed.__exit__7   s    ^^%

2
C(1t}}$IIgtxx0t}}$DMM)zzDNN*		'488V4!%
!F84 + 1$--C r   )r   r	   r
   r   r   r   N)__name__
__module____qualname____firstlineno____doc__strfloatr   r   r%   __static_attributes__ r   r   r   r      s;    @  # 	
 r   r   r   r   r   r
   r	   c                   ^ ^^ UU U4S jnU$ )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                 N   >^  [         R                  " T 5      U UUU4S j5       nU$ )Nc                  `   > [        TTTS9   T" U 0 UD6sS S S 5        $ ! , (       d  f       g = f)Nr   )r   )argskwargsfuncr	   r
   r   s     r   	decorator)timed.<locals>.wrapper.<locals>.decoratord   s)    si(CT,V, DCCs   
-)	functoolswraps)r5   r6   r	   r
   r   s   ` r   wrappertimed.<locals>.wrapperc   s&    			- 
	- r   r/   )r
   r   r	   r:   s   ``` r   timedr<   H   s    6 Nr   )
r8   loggingr   	getLoggerr'   r   r   r,   r-   r<   r/   r   r   <module>r?      sJ      != =@ +/ #s #% ## #r   