U
    ÷Õ/e@  ã                	   @  sÚ   d dl mZ d dlZd dlZd dlmZ d dlmZ d dl	Z	d dl
mZ e dd¡Zefdd	„Zed
ƒZedƒZG dd„ dƒZerœeejƒjZeejƒjZnejZejZejZz
ejZW n eefk
rÔ   eZY nX dS )é    )ÚannotationsN)ÚCallable)Úwraps)ÚWINDOWSÚ_empty_namedtuple© c                   s$   t t| ƒ‰tˆƒ‡ ‡fdd„ƒ}|S )zo
    Return a function calling the given psutil *method_name*,
    or returning *default* if psutil fails.
    c                     s(   zˆƒ W S  t k
r"   ˆ ƒ  Y S X d S ©N)ÚRuntimeErrorr   ©ÚdefaultÚmethr   ú7/tmp/pip-unpacked-wheel-g426oqom/distributed/metrics.pyÚwrapper   s    z_psutil_caller.<locals>.wrapper)ÚgetattrÚpsutilr   )Úmethod_namer   r   r   r
   r   Ú_psutil_caller   s    
r   Údisk_io_countersÚnet_io_countersc                   @  s8   e Zd ZdZdZddœdd„ZejZdd„ Zd	d
„ Z	dS )Ú_WindowsTimezxCombine time.time() or time.monotonic() with time.perf_counter() to get an
    absolute clock with fine resolution.
    iX  zCallable[[], float])Úbasec                 C  s   || _ d | _tdƒ| _d S )Nz-inf)Ú
base_timerÚdeltaÚfloatÚlast_resync)Úselfr   r   r   r   Ú__init__.   s    z_WindowsTime.__init__c                 C  s4   | j }|  ¡ }|| j | jkr,|  ¡ }|| _|| S r   )r   Úperf_counterr   ÚRESYNC_EVERYÚresync)r   r   Úcurr   r   r   Útime5   s    z_WindowsTime.timec                   s°   | j ‰| j‰ d}‡ ‡fdd„t|d ƒD ƒ}t dd„ |D ƒ¡}| ¡ d \‰}||k r\qq‡fdd„|D ƒd d	… }t|ƒ|d
 ksŽt|ƒ‚ˆt|ƒt|ƒ  | _	| j	S qd S )Né   c                   s   g | ]}ˆƒ ˆ ƒ f‘qS r   r   )Ú.0Úi)Ú_perf_counterÚ_timer   r   Ú
<listcomp>B   s     z'_WindowsTime.resync.<locals>.<listcomp>é   c                 s  s   | ]}|d  V  qdS )r   Nr   ©r#   Útr   r   r   Ú	<genexpr>C   s     z&_WindowsTime.resync.<locals>.<genexpr>r   c                   s    g | ]}|d  ˆ kr|d ‘qS )r   é   r   r)   )Úfirstr   r   r'   I   s      éÿÿÿÿr,   )
r   r   ÚrangeÚcollectionsÚCounterÚmost_commonÚlenÚAssertionErrorÚsumr   )r   Zmin_samplesÚtimesZ	abs_timesZnfirstZ
perf_timesr   )r%   r&   r-   r   r   =   s    z_WindowsTime.resyncN)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Útimemodr   r!   r   r   r   r   r   r   &   s   r   )Ú
__future__r   r0   r!   r;   Úcollections.abcr   Ú	functoolsr   r   Zdistributed.compatibilityr   Ú
namedtupler   r   r   r   r   Ú	monotonicÚprocess_timeÚthread_timeÚAttributeErrorÚOSErrorr   r   r   r   Ú<module>   s*   *
