o
    Á¿i  ã                   @   sf   d dl Zd dlmZ d dlmZ d dlmZ eeƒZ	G dd„ dƒZ
G dd„ deƒZG d	d
„ d
eƒZdS )é    N)ÚTracebackType)ÚOptional)Ú
get_loggerc                   @   s(   e Zd ZdZejZejZejZejZdS )ÚTimea‹  
    References to the standard Python time functions that won't be clobbered by `freezegun`.

    `freezegun`_ scans all loaded modules to check for imported functions from the `time` module, but it does not look
    inside classes or other objects, so these references are safe to use in the tracer.

    .. _freezegun: https://github.com/spulec/freezegun/blob/1.5.3/freezegun/api.py#L817
    N)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úbuiltin_timeÚtimeÚtime_nsÚ	monotonicÚmonotonic_ns© r   r   úO/home/ubuntu/.local/lib/python3.10/site-packages/ddtrace/internal/utils/time.pyr      s    	
r   c                   @   sp   e Zd ZdZddd„Zddd„Zdefdd	„Zdd
d„Zde	e
e  de	e de	e ddfdd„Zddd„ZdS )Ú	StopWatchaB  A simple timer/stopwatch helper class.

    Not thread-safe (when a single watch is mutated by multiple threads at
    the same time). Thread-safe when used by a single thread (not shared) or
    when operations are performed in a thread-safe manner on these objects by
    wrapping those operations with locks.

    It will use the `monotonic`_ pypi library to find an appropriate
    monotonically increasing time providing function (which typically varies
    depending on operating system and Python version).

    .. _monotonic: https://pypi.python.org/pypi/monotonic/
    ÚreturnNc                 C   s   d | _ d | _d S ©N)Ú_started_atÚ_stopped_at©Úselfr   r   r   Ú__init__*   s   
zStopWatch.__init__c                 C   s   t  ¡ | _| S ©zStarts the watch.)r   r   r   r   r   r   r   Ústart.   s   
zStopWatch.startc                 C   s6   | j du r	tdƒ‚| jdu rt ¡ }n| j}|| j  S )zmGet how many seconds have elapsed.

        :return: Number of seconds elapsed
        :rtype: float
        NzNCan not get the elapsed time of a stopwatch if it has not been started/stopped)r   ÚRuntimeErrorr   r   r   )r   Únowr   r   r   Úelapsed3   s   



zStopWatch.elapsedc                 C   ó   |   ¡  | S r   )r   r   r   r   r   Ú	__enter__B   s   zStopWatch.__enter__ÚtpÚvalueÚ	tracebackc                 C   s   |   ¡  dS )úStops the watch.N)Ústop©r   r    r!   r"   r   r   r   Ú__exit__G   s   zStopWatch.__exit__c                 C   s    | j du r	tdƒ‚t ¡ | _| S )r#   Nz2Can not stop a stopwatch that has not been started)r   r   r   r   r   r   r   r   r   r$   M   s   

zStopWatch.stop©r   N)r   r   )r   r   r   r	   r   r   Úfloatr   r   r   ÚtypeÚBaseExceptionr   r&   r$   r   r   r   r   r      s     



ÿÿÿ
þr   c                   @   s„   e Zd ZdZdeddfdd„Zddd„Zdefd	d
„Zdefdd„Z	defdd„Z
ddd„Zdd„ Zdefdd„Zdefdd„ZdS )Ú	HourGlassz"An implementation of an hourglass.Údurationr   Nc                 C   s*   t  ¡ }|| _|| | _|| _| j| _d S r   )r   r   Ú	_durationr   Ú_end_atÚ	_trickledÚ	trickling)r   r,   Útr   r   r   r   X   s
   
zHourGlass.__init__c                 C   sJ   t  ¡ }| j| j }| j| t|| j |ƒ }|| _|| | _| j| _dS )zTurn the hourglass.N)r   r   r.   r   r-   ÚminÚ
_tricklingr0   )r   r1   Útop_0Úbottomr   r   r   Úturna   s   
zHourGlass.turnc                 C   ó   dS )z!Check if sand is still trickling.Fr   r   r   r   r   r0   l   s   zHourGlass.tricklingc                 C   r7   )NFr   r   r   r   r   r/   p   ó   zHourGlass._trickledc                 C   s   t  ¡ | jk r	dS | j| _dS )NTF)r   r   r.   r/   r0   r   r   r   r   r3   s   s   zHourGlass._tricklingc                 C   r   r   )r6   r   r   r   r   r   |   s   zHourGlass.__enter__c                 C   s   d S r   r   r%   r   r   r   r&   €   r8   zHourGlass.__exit__c                 C   s   | j |j k S r   ©r.   ©r   Úotherr   r   r   Ú__lt__ƒ   ó   zHourGlass.__lt__c                 C   s   | j |j kS r   r9   r:   r   r   r   Ú__eq__†   r=   zHourGlass.__eq__r'   )r   r+   )r   r   r   r	   r(   r   r6   Úboolr0   r/   r3   r   r&   r<   r>   r   r   r   r   r+   U   s    
	
	r+   )r   r
   Útypesr   Útypingr   Úddtrace.internal.loggerr   r   Úlogr   Úobjectr   r+   r   r   r   r   Ú<module>   s    :