Current File : //proc/self/root/usr/lib/python3/dist-packages/cloudinit/__pycache__/performance.cpython-312.pyc |
�
Nhg � �p � d dl Z d dlZd dlZ ej e� Z G d� d� Zddd�dededefd �Z y)
� Nc �8 � e Zd ZdZddd�dededefd�Zd� Zd � Zy
)�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 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__zTimed.__init__% s. � � ���"��� ��
������
���
� c �8 � t j � | _ | S )N)�time� monotonicr
)r s r � __enter__zTimed.__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( ry d| j k( rR| j | j kD r8t
j
d| j |� | j � d|� �| _ y y t d | j � d
�� �)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_type�exc_val�exc_tb�suffixs r �__exit__zTimed.__exit__7 s� � ��^�^�%��
�
�2��
�����C�(��1���t�}�}�$��I�I�g�t�x�x��0�
�t�}�}�
$��
�D�M�M�
)��z�z�D�N�N�*�� � �'�4�8�8�V�4�!%���
�!�F�8�4��� +� �1�$�-�-���C��
r N) �__name__�
__module__�__qualname__�__doc__�str�floatr r r"