ó
ßüÚ\c           @` 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 j
 d d ƒ Z e d „ Z e d ƒ Z e d ƒ Z d e f d	 „  ƒ  YZ e j j d
 ƒ r½ e ƒ  j Z n	 e	 j Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e ƒ  Z e ƒ  Z d S(   i    (   t   print_functiont   divisiont   absolute_importN(   t   wrapst   _empty_namedtuplec         ` sV   y d d l  } Wn t k
 r$ ˆ  SXt | |  ƒ ‰ t ˆ ƒ ‡  ‡ f d †  ƒ } | S(   sx   
    Return a function calling the given psutil *method_name*,
    or returning *default* if psutil is not present.
    i    Nc           ` s'   y ˆ ƒ  SWn t  k
 r" ˆ  ƒ  SXd  S(   N(   t   RuntimeError(    (   t   defaultt   meth(    s2   lib/python2.7/site-packages/distributed/metrics.pyt   wrapper   s    (   t   psutilt   ImportErrort   getattrR   (   t   method_nameR   R	   R   (    (   R   R   s2   lib/python2.7/site-packages/distributed/metrics.pyt   _psutil_caller   s    t   disk_io_counterst   net_io_counterst   _WindowsTimec           B` sS   e  Z d  Z d Z d „  Z e j d k r6 e j Z n	 e j	 Z d „  Z
 d „  Z RS(   sh   
    Combine time.time() and time.perf_counter() to get an absolute clock
    with fine resolution.
    iX  c         C` s   d  |  _ t d ƒ |  _ d  S(   Ns   -inf(   t   Nonet   deltat   floatt   last_resync(   t   self(    (    s2   lib/python2.7/site-packages/distributed/metrics.pyt   __init__2   s    	i   c         C` sK   |  j  } |  j ƒ  } | |  j |  j k rC |  j ƒ  } | |  _ n  | | S(   N(   R   t   perf_counterR   t   RESYNC_EVERYt   resync(   R   R   t   cur(    (    s2   lib/python2.7/site-packages/distributed/metrics.pyt   time;   s    	c         C` s  t  j } |  j } d } xñ t rg  t | d ƒ D] } | ƒ  | ƒ  f ^ q2 } t j d „  | Dƒ ƒ } | j ƒ  d \ } } | | k  r‘ q q g  | D]  }	 |	 d | k r˜ |	 d ^ q˜ d  }
 t |
 ƒ | d k sä t	 |
 ƒ ‚ | t
 |
 ƒ t |
 ƒ |  _ |  j Sq Wd  S(   Ni   i   c         s` s   |  ] } | d  Vq d S(   i    N(    (   t   .0t   t(    (    s2   lib/python2.7/site-packages/distributed/metrics.pys	   <genexpr>I   s    i    i   iÿÿÿÿ(   t   timemodR   R   t   Truet   ranget   collectionst   Countert   most_commont   lent   AssertionErrort   sumR   (   R   t   _timet   _perf_countert   min_samplest   it   timest	   abs_timest   firstt   nfirstR   t
   perf_times(    (    s2   lib/python2.7/site-packages/distributed/metrics.pyR   C   s    			/1"(   i   (   t   __name__t
   __module__t   __doc__R   R   t   syst   version_infoR   R   t   clockR   R   (    (    (    s2   lib/python2.7/site-packages/distributed/metrics.pyR   )   s   			t   winc           C` s
   t  j ƒ  S(   N(   R   t   thread_time(    (    (    s2   lib/python2.7/site-packages/distributed/metrics.pyt   _native_thread_time]   s    c           C` s%   t  j d k r t ‚ n  t j d ƒ S(   Nt   linuxi   (   R3   t   platformt   OSErrorR   t   clock_gettime(    (    (    s2   lib/python2.7/site-packages/distributed/metrics.pyt   _linux_thread_timeb   s    	c           C` s
   t  j ƒ  S(   N(   R   t   process_time(    (    (    s2   lib/python2.7/site-packages/distributed/metrics.pyt   _native_process_timei   s    c           C` s
   t  j ƒ  S(   N(   R   R5   (    (    (    s2   lib/python2.7/site-packages/distributed/metrics.pyt   _native_clock_funcn   s    c          C` sA   x: t  g D]/ }  y |  ƒ  |  SWq
 t t f k
 r8 q
 Xq
 Wt S(   s`   
    Return a per-process CPU timer function if possible, otherwise
    a wall-clock timer.
    (   R?   t   AttributeErrorR;   R@   (   t   func(    (    s2   lib/python2.7/site-packages/distributed/metrics.pyt   _detect_process_timeu   s    c          C` sG   x@ t  t t g D]/ }  y |  ƒ  |  SWq t t f k
 r> q Xq Wt S(   s   
    Return a per-thread CPU timer function if possible, otherwise
    a per-process CPU timer function, or at worse a wall-clock timer.
    (   R8   R=   R?   RA   R;   R   (   RB   (    (    s2   lib/python2.7/site-packages/distributed/metrics.pyt   _detect_thread_time„   s    (    (   t
   __future__R    R   R   R!   t	   functoolsR   R3   R   R   t
   namedtupleR   R   R   R   t   objectR   R:   t
   startswithR8   R=   R?   R@   RC   RD   R>   R7   (    (    (    s2   lib/python2.7/site-packages/distributed/metrics.pyt   <module>   s(   -								