File: //snap/core20/2669/lib/python3/dist-packages/cloudinit/__pycache__/performance.cpython-38.pyc
U
Ӈgg � @ sN d dl Z d dlZd dlZe�e�ZG dd� d�Zddd�eeed�dd �Z dS )
� Nc @ s: e Zd ZdZddd�eeed�dd�Zdd � Zd
d� ZdS )
�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
```
�{�G�z�?� threshold�r �log_mode��msgr r c C s( || _ || _|| _d| _d| _d| _d S )N� g )r r r �output�start�delta)�selfr r r � r �7/usr/lib/python3/dist-packages/cloudinit/performance.py�__init__% s zTimed.__init__c C s t �� | _| S )N)�time� monotonicr )r
r r r � __enter__3 s
zTimed.__enter__c C s� t �� | j | _d| jd�d�}d| jkr<t�d| j|� nZd| jkrJd S d| jkr�| j| jkr�t�d| j|� | j� d|� �| _ nt
d | j� d
���d S )Nztook z.3fz seconds�alwaysz%s %s�skipr � zInvalid Timed log_mode value: 'z'.)r r r r r �LOG�debugr r r
�
ValueError)r
�exc_typeZexc_valZexc_tb�suffixr r r �__exit__7 s
�zTimed.__exit__N) �__name__�
__module__�__qualname__�__doc__�str�floatr r r r r r r r s ��r r r r r c s � ��fdd�}|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 s t �� �� ���fdd��}|S )Nc
s0 t ���d�� � | |�W 5 Q R � S Q R X d S )Nr )r )�args�kwargs)�funcr r r r r � decoratord s z)timed.<locals>.wrapper.<locals>.decorator)� functools�wraps)r% r&