B
    F.\                 @   s   d dl mZmZmZ d dlZd dlmZ d dlZd dlZ	e
ddZefddZedZed	ZG d
d deZejdre jZne	jZdd Zdd Zdd Zdd Zdd Zdd Ze Ze ZdS )    )print_functiondivisionabsolute_importN)wraps_empty_namedtuple c                sF   yddl }W n tk
r     S X 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"   y S  t k
r     S X d S )N)RuntimeErrorr   )defaultmethr   2lib/python3.7/site-packages/distributed/metrics.pywrapper   s    z_psutil_caller.<locals>.wrapper)psutilImportErrorgetattrr   )Zmethod_namer	   r   r   r   )r	   r
   r   _psutil_caller   s    
r   disk_io_countersnet_io_countersc               @   sD   e Zd ZdZdZdd Zejdkr*ej	Z	n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__2   s    z_WindowsTime.__init__)   c             C   s4   | j }|  }|| j | jkr,|  }|| _|| S )N)r   perf_counterr   RESYNC_EVERYresync)r   r   Zcurr   r   r   time;   s    z_WindowsTime.timec                s   t j| j d}x fddt|d D }tdd |D }| d \}||k r^qqfdd|D d d	 }t||d
 kst|t	|t|  | _
| j
S qW d S )N   c                s   g | ]}   fqS r   r   ).0i)_perf_counter_timer   r   
<listcomp>H   s    z'_WindowsTime.resync.<locals>.<listcomp>   c             s   s   | ]}|d  V  qdS )r   Nr   )r   tr   r   r   	<genexpr>I   s    z&_WindowsTime.resync.<locals>.<genexpr>r   c                s    g | ]}|d   kr|d qS )r      r   )r   r%   )firstr   r   r#   O   s    r'   )timemodr   r   rangecollectionsCountermost_commonlenAssertionErrorsumr   )r   Zmin_samplestimesZ	abs_timesZnfirstZ
perf_timesr   )r!   r"   r(   r   r   C   s    z_WindowsTime.resyncN)__name__
__module____qualname____doc__r   r   sysversion_infor*   r   clockr   r   r   r   r   r   r   )   s   
r   winc               C   s   t  S )N)r*   thread_timer   r   r   r   _native_thread_time]   s    r<   c               C   s   t jdkrttdS )NZlinuxr   )r7   platformOSErrorr*   Zclock_gettimer   r   r   r   _linux_thread_timeb   s    
r?   c               C   s   t  S )N)r*   process_timer   r   r   r   _native_process_timei   s    rA   c               C   s   t  S )N)r*   r9   r   r   r   r   _native_clock_funcn   s    rB   c           
   C   s8   x2t gD ](} y
|   | S  ttfk
r.   Y qX qW tS )z`
    Return a per-process CPU timer function if possible, otherwise
    a wall-clock timer.
    )rA   AttributeErrorr>   rB   )funcr   r   r   _detect_process_timeu   s    
rE   c           
   C   s<   x6t ttgD ](} y
|   | S  ttfk
r2   Y qX qW tS )z
    Return a per-thread CPU timer function if possible, otherwise
    a per-process CPU timer function, or at worse a wall-clock timer.
    )r<   r?   rA   rC   r>   r   )rD   r   r   r   _detect_thread_time   s    

rF   )Z
__future__r   r   r   r,   	functoolsr   r7   r   r*   
namedtupler   r   r   r   objectr   r=   
startswithr<   r?   rA   rB   rE   rF   r@   r;   r   r   r   r   <module>   s(   -
