a
    2`/b   ã                	   @   s¦   d dl Z d dl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j d¡rpeƒ jZnejZejZz
ejZW n eefy    eZY n0 dS )é    N)ÚwrapsÚ_empty_namedtuple© c                    sH   zddl }W n ty"   ˆ  Y S 0 t|| ƒ‰tˆƒ‡ ‡fdd„ƒ}|S )zx
    Return a function calling the given psutil *method_name*,
    or returning *default* if psutil is not present.
    r   Nc                      s&   zˆƒ W S  t y    ˆ ƒ  Y S 0 d S ©N)ÚRuntimeErrorr   ©ÚdefaultÚmethr   ú2lib/python3.9/site-packages/distributed/metrics.pyÚwrapper   s    z_psutil_caller.<locals>.wrapper)ÚpsutilÚImportErrorÚgetattrr   )Úmethod_namer   r   r   r   r   r
   Ú_psutil_caller	   s    

r   Údisk_io_countersÚnet_io_countersc                   @   s2   e Zd ZdZdZdd„ ZejZdd„ Zdd„ Z	d	S )
Ú_WindowsTimezh
    Combine time.time() and time.perf_counter() to get an absolute clock
    with fine resolution.
    iX  c                 C   s   d | _ tdƒ| _d S )Nz-inf)ÚdeltaÚfloatÚlast_resync)Úselfr   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   Zcurr   r   r
   Útime5   s    z_WindowsTime.timec                    s°   t 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ŽJ |ƒ‚ˆt|ƒt|ƒ  | _	| j	S qd S )Né   c                    s   g | ]}ˆƒ ˆ ƒ f‘qS r   r   )Ú.0Úi)Ú_perf_counterÚ_timer   r
   Ú
<listcomp>B   ó    z'_WindowsTime.resync.<locals>.<listcomp>é   c                 s   s   | ]}|d  V  qdS )r   Nr   ©r   Útr   r   r
   Ú	<genexpr>C   r#   z&_WindowsTime.resync.<locals>.<genexpr>r   c                    s    g | ]}|d  ˆ kr|d ‘qS )r   é   r   r%   )Úfirstr   r
   r"   I   r#   éÿÿÿÿr(   )
Útimemodr   r   ÚrangeÚcollectionsÚCounterÚmost_commonÚlenÚ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   r+   r   r   r   r   r   r   r
   r   &   s   r   Úwin)r-   Úsysr   r+   Ú	functoolsr   Ú
namedtupler   r   r   r   r   ÚplatformÚ
startswithÚprocess_timeÚthread_timeÚAttributeErrorÚOSErrorr   r   r   r
   Ú<module>   s    *

