Current File : //proc/self/root/lib/python3/dist-packages/cloudinit/__pycache__/performance.cpython-312.pyc
�

x[hg��p�ddlZddlZddlZeje�ZGd�d�Zddd�dededefd	�Z	y)
�Nc�8�eZdZdZddd�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�msgrc�X�||_||_||_d|_d|_d|_y)N�g)r	rr�output�start�delta)�selfr	rrs    �7/usr/lib/python3/dist-packages/cloudinit/performance.py�__init__zTimed.__init__%s.�����"��� ��
������
���
�c�8�tj�|_|S)N)�time�	monotonicr
)rs r�	__enter__zTimed.__enter__3s���^�^�%��
��rc���tj�|jz
|_d|jd�d�}d|jk(r"t
j
d|j|�yd|jk(ryd|jk(rR|j|jkDr8t
j
d|j|�|j�d|��|_	yytd	|j�d
���)Nztook z.3fz seconds�alwaysz%s %s�skipr� zInvalid Timed log_mode value: 'z'.)rrr
rr�LOG�debugr	rr�
ValueError)r�exc_type�exc_val�exc_tb�suffixs     r�__exit__zTimed.__exit__7s����^�^�%��
�
�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��
rN)	�__name__�
__module__�__qualname__�__doc__�str�floatrrr"�rrrrs;���@ �#��
���	�
���rrrrrr	rc��������fd�}|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���tj������fd��}|S)Nc�\��t�����5�|i|��cddd�S#1swYyxYw)Nr)r)�args�kwargs�funcrr	rs  ����r�	decoratorz)timed.<locals>.wrapper.<locals>.decoratords1����s�i�(�C�
-��T�,�V�,�
-�
-�
-�s�"�+)�	functools�wraps)r/r0rr	rs` ���r�wrapperztimed.<locals>.wrappercs&���	����	�	-�
�	-��rr))r	rrr3s``` r�timedr4Hs���6��Nr)
r1�loggingr�	getLoggerr#rrr'r(r4r)rr�<module>r7sL������g����!��=�=�@+/��#�s�#�%�#�#�#r