
Gq]c           @   s  d  Z  d d l m Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l	 Z	 d d l
 Z
 d d l Z d d l Z d d l Z d d l Z d d l m Z d d l m Z d d l m Z d d l m Z d d	 l m Z d d
 l m Z d d l m Z d d l m Z d d l m Z d d l m Z d d l m Z d d l m Z d d l m Z d d l m Z d d l m  Z  d d l m! Z! d d l m" Z" d d l m# Z# d d l m$ Z$ d d l m% Z% d d l& m' Z' d d l& m( Z( d d l& m) Z) e j* d k r4d d l+ Z+ n d Z+ d d d  d! d" d# d$ d% d& d' d( d) d* d+ d, d- g Z- d. Z. e j/ j0 d/ e j1    Z2 e3 e d0  Z4 e3 e d1  Z5 e6   Z7 e4 rx6 e8 e  D]% Z9 e9 j: d2  re- j; e9  qqWn  e j< d3  Z= e j< d4  Z> d a? e) r(d n d5 Z@ e jA d6 k ZB d7 ZC e+ d k r[e
 jD ZE n+ e+ jF d8 i eG e
 jD  d9 6 ZH eH jE ZE e+ d k rd: ZI d ZJ d; ZK d ZL n, d< e+ jF f d=     YZM eN   jO eM jP  i e jQ d> 6e jR d? 6e jS d@ 6e jT dA 6e jU dB 6e jV dC 6e jW dD 6e jW dE 6e jX dF 6e jY dG 6e jZ dH 6e j[ dI 6Z\ i e j] dJ 6e j^ dK 6e j_ dL 6e j` dM 6e ja dN 6e jb dO 6e jc dP 6e jd dQ 6e je dR 6e jf dS 6e jg dT 6Zh d Zi d Zj d Zk d Zl e dU dV dW dX dY dZ d[ d\ d] d^ d_ d` g  Zm e da db dc dd de df dg dh di dj g	  Zn e dk dl dm dn do dp g  Zo e dq dr  Zp e ds ep jq d  Zr e dw dl dx dy du dz d{ d| d} d~ d dv g  Zs e d d d jt es jq   Zu e d db dc dd de d d g  Zv d   Zw d   Zx d   Zy e d    Zz e7 e{ d  Z| y ez d  Wn6 e} k
 roe j~   e d d  d d d  a n Xd   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z e j/ j0 d  se j/ j0 d  rd   Z n' e j/ j0 d  rd   Z n	 d   Z e j Z d e} f d     YZ d d d     YZ e   Z d d  Z d   Z d   Z e j Z e d  Z e d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d e6 f d     YZ d S(   s   Linux platform implementation.i(   t   divisionN(   t   defaultdict(   t
   namedtuplei   (   t   _common(   t   _psposix(   t   _psutil_linux(   t   _psutil_posix(   t   decode(   t   get_procfs_path(   t   isfile_strict(   t   memoize(   t   memoize_when_activated(   t   NIC_DUPLEX_FULL(   t   NIC_DUPLEX_HALF(   t   NIC_DUPLEX_UNKNOWN(   t   open_binary(   t	   open_text(   t   parse_environ_block(   t   path_exists_strict(   t   supports_ipv6(   t   usage_percent(   t   b(   t
   basestring(   t   PY3i   i   t   PROCFS_PATHt   IOPRIO_CLASS_NONEt   IOPRIO_CLASS_RTt   IOPRIO_CLASS_BEt   IOPRIO_CLASS_IDLEt   CONN_ESTABLISHEDt   CONN_SYN_SENTt   CONN_SYN_RECVt   CONN_FIN_WAIT1t   CONN_FIN_WAIT2t   CONN_TIME_WAITt
   CONN_CLOSEt   CONN_CLOSE_WAITt   CONN_LAST_ACKt   CONN_LISTENt   CONN_CLOSINGs   /sys/class/power_supplys   /proc/%s/smapst   linux_prlimitt   proc_ioprio_gett   RLIMt
   SC_CLK_TCKt   SC_PAGE_SIZEi    t   littlei   t   AddressFamilyt   AF_LINKi    i   t
   IOPriorityc           B   s    e  Z d  Z d Z d Z d Z RS(   i    i   i   i   (   t   __name__t
   __module__R   R   R   R   (    (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyR0   v   s   t   Rt   St   Dt   Tt   tt   Zt   Xt   xt   Kt   Wt   It   Pt   01t   02t   03t   04t   05t   06t   07t   08t   09t   0At   0Bt   svmemt   totalt	   availablet   percentt   usedt   freet   activet   inactivet   bufferst   cachedt   sharedt   slabt   sdiskiot
   read_countt   write_countt
   read_bytest   write_bytest	   read_timet
   write_timet   read_merged_countt   write_merged_countt	   busy_timet	   popenfilet   patht   fdt   positiont   modet   flagst   pmems"   rss vms shared text lib data dirtyt   pfullmemt   usst   psst   swapt   pmmap_groupedt   rsst   sizet   shared_cleant   shared_dirtyt   private_cleant   private_dirtyt
   referencedt	   anonymoust	   pmmap_exts   addr perms t    t   piot
   read_charst   write_charsc         C   sj   t  |  t  s t |    t j |   }  |  j d  d }  |  j d  rf t |   rf |  d  }  n  |  S(   s   Wrapper around os.readlink().s    i    s
    (deleted)i(   t
   isinstanceR   t   AssertionErrort   ost   readlinkt   splitt   endswithR   (   Ra   (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyR|      s    c         C   s~   i d t  j 6d t  j 6d t  j 6} | |  t  j t  j Bt  j B@} |  t  j @rh | j d d d  } n  | j d d  } | S(   sZ   Convert file's open() flags into a readable string.
    Used by Process.open_files().
    t   rt   ws   w+t   ai   s   r+(   R{   t   O_RDONLYt   O_WRONLYt   O_RDWRt   O_APPENDt   replace(   Re   t	   modes_mapRd   (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   file_flags_to_mode   s    $c         C   sH   |  j  d d  }  t } | r+ d |  } n
 d |  } t j | t j  S(   s   Return True if the given name refers to a root device (e.g.
    "sda", "nvme0n1") as opposed to a logical partition (e.g.  "sda1",
    "nvme0n1p1"). If name is a virtual device (e.g. "loop1", "ram")
    return True.
    t   /t   !s   /sys/block/%ss   /sys/block/%s/device(   R   t   TrueR{   t   accesst   F_OK(   t   namet   including_virtualRa   (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   is_storage_device   s    

c         C   s   t  d |    } | j   j   d } Wd QXd d d d d d	 d
 g } t |  } | d k rr | j d  n  | d k r | j d  n  | d k r | j d  n  t d |  a d S(   s   Set a namedtuple of variable fields depending on the CPU times
    available on this Linux kernel version which may be:
    (user, nice, system, idle, iowait, irq, softirq, [steal, [guest,
     [guest_nice]]])
    Used by cpu_times() function.
    s   %s/stati   Nt   usert   nicet   systemt   idlet   iowaitt   irqt   softirqi   t   steali	   t   guesti
   t
   guest_nicet	   scputimes(   R   t   readlineR}   t   lent   appendR   R   (   t   procfs_patht   ft   valuest   fieldst   vlen(    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   set_scputimes_ntuple  s    	c         C   sl   y; | r t  |   n	 t |    } | j   j   SWd QXWn* t t f k
 rg | t k	 ra | S  n Xd S(   s   Return file content.
    fallback: the value returned in case the file does not exist or
              cannot be read
    binary: whether to open the file in binary or text mode.
    N(   R   R   t   readt   stript   IOErrort   OSErrort   _DEFAULT(   t   fnamet   fallbackt   binaryR   (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   cat  s    !s   /procR   s   user system idleg        c      	   C   sI  |  d } | |  j  d d  } y" |  d } |  d } |  d } Wn t k
 rV | SXy t d t    } Wn t k
 r | SXd } | N xF | D]> } | j   } | j d  r | t | j   d	  7} q q WWd
 QX| t	 9} | } | | }	 | | }
 |
 t
 |
 d |  8}
 |	 |
 7}	 |	 | t
 | d |  7}	 t |	  S(   s  Fallback for kernels < 3.14 where /proc/meminfo does not provide
    "MemAvailable:" column, see:
    https://blog.famzah.net/2014/09/24/
    This code reimplements the algorithm outlined here:
    https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/
        commit/?id=34e431b0ae398fc54ea69ff85ec700722c9da773

    XXX: on recent kernels this calculation differs by ~1.5% than
    "MemAvailable:" as it's calculated slightly differently, see:
    https://gitlab.com/procps-ng/procps/issues/42
    https://github.com/famzah/linux-memavailable-procfs/issues/2
    It is still way more realistic than doing (free + cached) though.
    s   MemFree:s   Cached:i    s   Active(file):s   Inactive(file):s   SReclaimable:s   %s/zoneinfot   lowi   Ni   g       @(   t   gett   KeyErrorR   R   R   R   t
   startswitht   intR}   t   PAGESIZEt   min(   t   memsRO   R   t   lru_active_filet   lru_inactive_filet   slab_reclaimableR   t   watermark_lowt   linet   availt	   pagecache(    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   calculate_avail_vmem<  s4    


'



c          C   s+  g  }  i  } t  d t    @ } x6 | D]. } | j   } t | d  d | | d <q) WWd QX| d } | d } y | d } Wn$ t k
 r d } |  j d	  n Xy | d
 } Wn$ t k
 r d } |  j d  n X| | j d d  7} y | d }	 WnF t k
 rKy | d }	 WqLt k
 rGd }	 |  j d  qLXn Xy | d }
 Wn$ t k
 rd }
 |  j d  n Xy | d } WnV t k
 ry | d | d | d } Wqt k
 rd } |  j d  qXn Xy | d } Wn t k
 rd } n X| | | | } | d k  r;| | } n  y | d } Wn t k
 rht |  } n X| d k  rd } |  j d  n  | | k r| } n  t | | | d d } |  rd d j	 |   t
 |   d k rd n d f } t j | t  n  t | | | | | |
 | | | |	 |  S(   s  Report virtual memory stats.
    This implementation matches "free" and "vmstat -s" cmdline
    utility values and procps-ng-3.3.12 source was used as a reference
    (2016-09-18):
    https://gitlab.com/procps-ng/procps/blob/
        24fd2605c51fccc375ab0287cec33aa767f06718/proc/sysinfo.c
    For reference, procps-ng-3.3.10 is the version available on Ubuntu
    16.04.

    Note about "available" memory: up until psutil 4.3 it was
    calculated as "avail = (free + buffers + cached)". Now
    "MemAvailable:" column (kernel 3.14) from /proc/meminfo is used as
    it's more accurate.
    That matches "available" column in newer versions of "free".
    s
   %s/meminfoi   i   i    Ns	   MemTotal:s   MemFree:s   Buffers:RR   s   Cached:RS   s   SReclaimable:s   Shmem:s
   MemShared:RT   s   Active:RP   s	   Inactive:s   Inact_dirty:s   Inact_clean:s   Inact_laundry:RQ   s   Slab:s   MemAvailable:RL   t   round_s6   %s memory stats couldn't be determined and %s set to 0s   , t   wast   were(   R   R   R}   R   R   R   R   R   R   t   joinR   t   warningst   warnt   RuntimeWarningRJ   (   t   missing_fieldsR   R   R   R   RK   RO   RR   RS   RT   RP   RQ   RU   RN   R   RM   t   msg(    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   virtual_memoryq  s    &


		"c       	   C   s  i  }  t  d t    @ } x6 | D]. } | j   } t | d  d |  | d <q# WWd QXy |  d } |  d } WnF t k
 r t j   \ } } } } } } } | | 9} | | 9} n X| | } t | | d d }	 y t  d	 t    } Wn= t k
 r1}
 d
 t	 |
  } t
 j | t  d } } n X|  d } } x | D] } | j d  rt | j d  d  d d } n3 | j d  rt | j d  d  d d } n  | d k	 rJ| d k	 rJPqJqJWd } t
 j | t  d } } Wd QXt j | | | |	 | |  S(   s   Return swap memory metrics.s
   %s/meminfoi   i   i    Ns
   SwapTotal:s	   SwapFree:R   s	   %s/vmstatsP   'sin' and 'sout' swap memory stats couldn't be determined and were set to 0 (%s)t   pswpinRu   i   t   pswpoutsK   'sin' and 'sout' swap memory stats couldn't be determined and were set to 0(   R   R   R}   R   R   t   cextt   linux_sysinfoR   R   t   strR   R   R   t   NoneR   R   t   sswap(   R   R   R   R   RK   RO   t   _t   unit_multiplierRN   RM   t   errR   t   sint   sout(    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   swap_memory  sD    &
!


$$c          C   s   t    }  t |   t d |    } | j   j   } Wd QX| d t t j  d !} g  | D] } t |  t	 ^ q_ } t |   S(   s   Return a named tuple representing the following system-wide
    CPU times:
    (user, nice, system, idle, iowait, irq, softirq [steal, [guest,
     [guest_nice]]])
    Last 3 fields may not be available on all Linux kernel versions.
    s   %s/statNi   (
   R   R   R   R   R}   R   R   t   _fieldst   floatt   CLOCK_TICKS(   R   R   R   R   R:   (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt	   cpu_times%  s    	
#c       	   C   s   t    }  t |   g  } t d |    } | j   x | D]z } | j d  r= | j   } | d t t j  d !} g  | D] } t	 |  t
 ^ q } t |   } | j |  q= q= W| SWd QXd S(   sf   Return a list of namedtuple representing the CPU times
    for every CPU available on the system.
    s   %s/statt   cpui   N(   R   R   R   R   R   R}   R   R   R   R   R   R   (   R   t   cpusR   R   R   R   R:   t   entry(    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   per_cpu_times5  s    	

#c          C   s	  y t  j d  SWn t k
 rd }  t d t    : } x0 | D]( } | j   j d  rD |  d 7}  qD qD WWd QX|  d k r t j d  } t	 d t    G } x= | D]5 } | j
 d	  d } | j |  r |  d 7}  q q WWd QXn  |  d k r d S|  SXd S(
   s0   Return the number of logical CPUs in the system.t   SC_NPROCESSORS_ONLNi    s
   %s/cpuinfot	   processori   Ns   cpu\ds   %s/statRu   (   R{   t   sysconft
   ValueErrorR   R   t   lowerR   t   ret   compileR   R}   t   matchR   (   t   numR   R   t   search(    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   cpu_count_logicalI  s$    c    	   	   C   sY  t    }  xE t j d  D]4 } t |    } |  j t | j     Wd QXq Wt |   } | d k rm | Si  } i  } t d t     } x | D] } | j   j	   } | s d | k r d | k r | d | | d <n  i  } q | j
 d  s| j
 d  r | j d d  \ } } t |  | | <q q WWd QXt | j    } | pXd S(	   s2   Return the number of physical cores in the system.s2   /sys/devices/system/cpu/cpu[0-9]*/topology/core_idNi    s
   %s/cpuinfos   physical ids	   cpu coress   	:i   (   t   sett   globR   t   addR   R   R   R   R   R   R   R}   t   sumR   R   (	   t   core_idsRa   R   t   resultt   mappingt   current_infoR   t   keyt   value(    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   cpu_count_physicalf  s0    		#	c          C   s   t  d t     }  d } d } d } x |  D] } | j d  r] t | j   d  } nP | j d  r t | j   d  } n( | j d  r t | j   d  } n  | d k	 r/ | d k	 r/ | d k	 r/ Pq/ q/ WWd QXd } t j | | | |  S(   s*   Return various CPU stats as a named tuple.s   %s/statt   ctxti   t   intrR   Ni    (   R   R   R   R   R   R}   R   t	   scpustats(   R   t   ctx_switchest
   interruptst   soft_interruptsR   t   syscalls(    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt	   cpu_stats  s"    s'   /sys/devices/system/cpu/cpufreq/policy0s$   /sys/devices/system/cpu/cpu0/cpufreqc          C   s  d   }  g  } xt  t    D] } |  |  } | s= q n  t j j } t | | d  d d	 } | d	 k r t | | d  d d	 } | d	 k r t d   q n  t |  d } t t | | d    d } t t | | d    d } | j	 t
 j | | |   q W| S(
   s   Return frequency metrics for all CPUs.
        Contrarily to other OSes, Linux updates these values in
        real-time.
        c         S   s9   x2 d |  d |  f D] } t  j j |  r | Sq Wd  S(   Ns(   /sys/devices/system/cpu/cpufreq/policy%ss%   /sys/devices/system/cpu/cpu%s/cpufreq(   R{   Ra   t   exists(   R   t   p(    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   get_path  s    
t   scaling_cur_freqR   t   cpuinfo_cur_freqs!   can't find current frequency filei  t   scaling_max_freqt   scaling_min_freqN(   t   rangeR   R{   Ra   R   R   R   t   NotImplementedErrorR   R   R   t   scpufreq(   R   t   rett   nRa   t   pjoint   currt   max_t   min_(    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   cpu_freq  s$    	 s   /proc/cpuinfoc       
   C   s   g  }  t  d t    j } x` | D]X } | j   j d  r# | j d d  \ } } |  j t j t |  d d   q# q# WWd QX|  S(   s}   Alternate implementation using /proc/cpuinfo.
        min and max frequencies are not available and are set to None.
        s
   %s/cpuinfos   cpu mhzs   	:i   g        N(	   R   R   R   R   R}   R   R   R  R   (   R  R   R   R   R   (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyR    s    /c           C   s   g  S(   sG   Dummy implementation when none of the above files are present.
        (    (    (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyR    s    t   _Ipv6UnsupportedErrorc           B   s   e  Z RS(    (   R1   R2   (    (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyR    s   t   Connectionsc           B   sh   e  Z d  Z d   Z d   Z d   Z e d    Z e d d   Z	 e d d   Z
 d d  Z RS(	   sw  A wrapper on top of /proc/net/* files, retrieving per-process
    and system-wide open connections (TCP, UDP, UNIX) similarly to
    "netstat -an".

    Note: in case of UNIX sockets we're only able to determine the
    local endpoint/path, not the one it's connected to.
    According to [1] it would be possible but not easily.

    [1] http://serverfault.com/a/417946
    c         C   s  d t  j t  j f } d t  j t  j f } d t  j t  j f } d t  j t  j f } d t  j d  f } i | | | | | f d 6| | f d 6| f d 6| f d 6| | f d 6| f d 6| f d 6| f d 6| | | | f d	 6| | f d
 6| | f d 6|  _ d  |  _ d  S(   Nt   tcpt   tcp6t   udpt   udp6t   unixt   allt   tcp4t   udp4t   inett   inet4t   inet6(	   t   sockett   AF_INETt   SOCK_STREAMt   AF_INET6t
   SOCK_DGRAMt   AF_UNIXR   t   tmapt   _procfs_path(   t   selfR  R  R  R  R  (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   __init__  s$    




c         C   s   t  t  } x t j d |  j | f  D] } y  t d |  j | | f  } WnO t k
 r } | j t j t j	 f k r q) q | j t j
 k r q) q   q) X| j d  r) | d d  } | | j | t |  f  q) q) W| S(   Ns   %s/%s/fds   %s/%s/fd/%ss   socket:[i   i(   R   t   listR{   t   listdirR   R|   R   t   errnot   ENOENTt   ESRCHt   EINVALR   R   R   (   R!  t   pidt   inodesRb   t   inodeR   (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   get_proc_inodes  s    # $c         C   s{   i  } xn t    D]c } y | j |  j |   Wq t k
 rr } | j t j t j t j t j f k rs   qs q Xq W| S(   N(	   t   pidst   updateR,  R   R%  R&  R'  t   EPERMt   EACCES(   R!  R*  R)  R   (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   get_all_inodes  s    !c         C   sS  |  j  d  \ } } t | d  } | s. d St rF | j d  } n  | t j k r t r t j | t j	 |  d d d   } qCt j | t j	 |   } n t j	 |  } yg t r t j t j
 t j d t j d |    } n- t j t j
 t j d t j d |    } Wn& t k
 rBt   s<t  qC  n Xt j | |  S(	   s  Accept an "ip:port" address as displayed in /proc/net/*
        and convert it into a human readable form, like:

        "0500000A:0016" -> ("10.0.0.5", 22)
        "0000000000000000FFFF00000100007F:9E49" -> ("::ffff:127.0.0.1", 40521)

        The IP address portion is a little or big endian four-byte
        hexadecimal number; that is, the least significant byte is listed
        first, so we need to reverse the order of the bytes to convert it
        to an IP address.
        The port is represented as a two-byte hexadecimal number.

        Reference:
        http://linuxdevcenter.com/pub/a/linux/2000/11/16/LinuxAdmin.html
        t   :i   t   asciiNis   >4Is   <4I(    (   R}   R   R   t   encodeR  R  t   LITTLE_ENDIANt	   inet_ntopt   base64t	   b16decodeR  t   structt   packt   unpackR   R   R  R   t   addr(   R<  t   familyt   ipt   port(    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   decode_address+  s0    +$%		c         c   s  |  j  d  r& t j j |   r& d St |  d t [} | j   xGt | d  D]6\ } } y2 | j   d  \
 } }	 }
 } } } } } } } Wn* t	 k
 r t
 d |  | | f   n X| | k r | | d \ } } n d	 \ } } | d k	 r| | k rqU qU | t j k r)t | } n	 t j } y( t j |	 |  }	 t j |
 |  }
 Wn t k
 rpqU n X| | | |	 |
 | | f VqU WWd QXd S(
   s.   Parse /proc/net/tcp* and /proc/net/udp* files.t   6Nt	   bufferingi   i
   s,   error while parsing %s; malformed line %s %ri    i(   Ni(   R~   R{   Ra   R   R   t   BIGFILE_BUFFERINGR   t	   enumerateR}   R   t   RuntimeErrorR   R  R  t   TCP_STATUSESR   t	   CONN_NONER  R@  R  (   t   fileR=  t   type_R*  t
   filter_pidR   t   linenoR   R   t   laddrt   raddrt   statusR+  R)  Rb   (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   process_inetb  s2    "
2	c         c   sY  t  |  d t A} | j   x-| D]%} | j   } y& | d d !\ } } } } } } }	 Wn9 t k
 r d | k r q& n  t d |  | f   n X|	 | k r | |	 }
 n	 d
 g }
 x |
 D] \ } } | d	 k	 r | | k r q q t |  d k r| d } n d } t |  } d } t	 j
 } | | | | | | | f Vq Wq& WWd	 QXd	 S(   s   Parse /proc/net/unix files.RB  i    i   Ru   s)   error while parsing %s; malformed line %rii   t    N(   Ni(   R   RC  R   R}   R   RE  R   R   R   R   RG  (   RH  R=  R*  RJ  R   R   t   tokensR   RI  R+  t   pairsR)  Rb   Ra   RM  RN  (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   process_unix  s2    
&		c      
   C   s  | |  j  k rM t d | d j g  |  j  D] } t |  ^ q(  f   n  t   |  _ | d  k	 r |  j |  } | s g  Sn |  j   } t	   } x|  j  | D] \ } } } | t
 j t
 j f k r |  j d |  j | f | | | d | }	 n( |  j d |  j | f | | d | }	 xx |	 D]p \ }
 } } } } } } | rjt j |
 | | | | |  } n! t j |
 | | | | | |  } | j |  q(Wq Wt |  S(   Ns+   invalid %r kind argument; choose between %ss   , s	   %s/net/%sRJ  (   R  R   R   t   reprR   R   R   R,  R1  R   R  R  R  RO  RS  R   t   pconnt   sconnR   R#  (   R!  t   kindR)  R:   R*  R  R   R=  RI  t   lsRb   RL  RM  RN  t	   bound_pidt   conn(    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   retrieve  s4    8	"N(   R1   R2   t   __doc__R"  R,  R1  t   staticmethodR@  R   RO  RS  R[  (    (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyR    s   
			7'%R  c         C   s   t  j |   S(   s$   Return system-wide open connections.(   t   _connectionsR[  (   RW  (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   net_connections  s    c          C   s   t  d t     }  |  j   } Wd QXi  } x | d D] } | j d  } | d k sl t t |    | |  j   } | | d j   j   } t t	 |  \ } } }	 }
 } } } } } } } } } } } } | | | | |	 | |
 | f | | <q9 W| S(   ss   Return network I/O statistics for every network interface
    installed on the system as a dict of raw tuples.
    s
   %s/net/devNi   R2  i    i   (
   R   R   t	   readlinest   rfindRz   RT  R   R}   t   mapR   (   R   t   linest   retdictR   t   colonR   R   t
   bytes_recvt   packets_recvt   errint   dropint   fifoint   frameint   compressedint   multicastint
   bytes_sentt   packets_sentt   erroutt   dropoutt   fifooutt   collisionsoutt
   carrieroutt   compressedout(    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   net_io_counters  s    ?c    	      C   s   i t  t j 6t t j 6t t j 6}  t   j   } i  } x | D] } y7 t	 j
 |  } t	 j |  } t j |  \ } } Wn+ t k
 r } | j t j k r   q q@ Xt j | |  | | |  | | <q@ W| S(   s)   Get NIC stats (isup, duplex, speed, mtu).(   R   R   t   DUPLEX_FULLR   t   DUPLEX_HALFR   t   DUPLEX_UNKNOWNRv  t   keyst
   cext_posixt
   net_if_mtut   net_if_flagst   net_if_duplex_speedR   R%  t   ENODEVR   t	   snicstats(	   t
   duplex_mapt   namesR  R   t   mtut   isupt   duplext   speedR   (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   net_if_stats  s    

$c         C   s   d   } d   } t  j j d t    r7 |   } n1 t  j j d  rU |   } n t d t     i  } x | D]} } | \
 } } } }	 }
 } } } } } |  r t |  r qu n  |	 t 9}	 |
 t 9}
 | | |	 |
 | | | | | f	 | | <qu W| S(   sc   Return disk I/O statistics for every disk installed on the
    system as a dict of raw tuples.
    c          s   s  t  d t     }  |  j   } Wd  QXx`| D]X} | j   } t |  } | d k r | d } t | d  } t t | d d ! \
 } } }	 }
 } } } } } } n | d k s | d k r| d } t t | d d ! \ } } } }	 }
 } } } } } } n^ | d k rT| d } t t | d  \ } } }
 } d	 }	 } } } } n t d
 |   | | |
 | | |	 | | | | f
 Vq/ Wd  S(   Ns   %s/diskstatsi   i   i   i   i   i   i   i    s!   not sure how to interpret line %r(   R   R   R`  R}   R   R   Rb  R   (   R   Rc  R   R   t   flenR   t   readst   reads_mergedt   rbytest   rtimet   writest   writes_mergedt   wbytest   wtimeR   R_   (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   read_procfs  s&    
7
:
c          s   s  x t  j d  D] }  x t  j t  j j d |    D] \ } } } d | k rV q5 n  t t  j j | d    } | j   j   j   } Wd  QXt  j j	 |  } t
 t |  \ } } }	 }
 } } } } } } } | | | |	 | |
 | | | | f
 Vq5 Wq Wd  S(   Ns
   /sys/blockt   stat(   R{   R$  t   walkRa   R   R   R   R   R}   t   basenameRb  R   (   t   blockt   rootR   t   filesR   R   R   R  R  R  R  R  R  R  R  R_   (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt
   read_sysfsI  s    .0s   %s/diskstatss
   /sys/blocksC   %s/diskstats nor /sys/block filesystem are available on this system(   R{   Ra   R   R   R  R   t   DISK_SECTOR_SIZE(   t   perdiskR  R  t   genRd  R   R   R  R  R  R  R  R  R  R  R_   (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   disk_io_counters  s&    	*	$

c         C   s  t    } t   } t d |  x } xn | D]f } | j   } | j d  sc | j | j    q, | j d  d } | d k r, | j d  q, q, WWd QX| d k r t j j	 d  r t j j
 d  } n t j j
 d	 |  } g  } t j |  } x | D]y }	 |	 \ }
 } } } |
 d
 k r.d }
 n  |  sU|
 d k s| | k rUqqUn  t j |
 | | |  } | j |  qW| S(   s8   Return mounted disk partitions as a list of namedtuples.s   %s/filesystemst   nodevs   	i   t   zfsNs   /procs	   /etc/mtabs   %s/self/mountst   noneRP  (   R   R   R   R   R   R   R}   R{   Ra   t   isfilet   realpathR   t   disk_partitionsR   t	   sdiskpartR   (   R  t   fstypesR   R   R   t   fstypet   mounts_patht   retlistt
   partitionst	   partitiont   devicet
   mountpointt   optst   ntuple(    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyR  y  s2    				c          C   sd  t  j t  }  t j d  } | j t j d   t t g  | D] } | j d  d ^ qA   } x| D]x} yW | d } t t	 |   d } t
 j j t
 j j |  d  } t	 | d t } Wn9 t t t f k
 r} t j d	 | | f t  qm n Xt	 | d
 d d } t	 | d d d }	 t	 | d d d d t }
 | d k	 ry t |  d } Wqt k
 rd } qXn  |	 d k	 ry t |	  d }	 Wqt k
 rd }	 qXn  |  | j |
 | | |	 f  qm W| sZt j d  } t t |   } xG| D]<} yV t
 j j | d  } t t	 |   d } t
 j j | d  } t	 | d t } Wn9 t t t f k
 r} t j d	 | | f t  qn Xt j | d  } t g  | D]1 } d j t
 j j |  j d  d d ! ^ q } d }	 d } x!| D]} t
 j j | | d  } t	 | d d d t } | d k rt	 t
 j j | | d  d d }	 n4 | d k rt	 t
 j j | | d  d d } n  | d k	 ry t |  d } Wqt k
 rd } qXn  |	 d k	 ry t |	  d }	 Wq2t k
 r.d }	 q2XqqW|  | j d | | |	 f  qWn  t |   S(   s  Return hardware (CPU and others) temperatures as a dict
    including hardware name, label, current, max and critical
    temperatures.

    Implementation notes:
    - /sys/class/hwmon looks like the most recent interface to
      retrieve this info, and this implementation relies on it
      only (old distros will probably use something else)
    - lm-sensors on Ubuntu 16.04 relies on /sys/class/hwmon
    - /sys/class/thermal/thermal_zone* is another one but it's more
      difficult to parse
    s   /sys/class/hwmon/hwmon*/temp*_*s&   /sys/class/hwmon/hwmon*/device/temp*_*R   i    t   _inputg     @@R   R   s   ignoring %r for file %rt   _maxR   t   _critt   _labelRP  s    /sys/class/thermal/thermal_zone*t   tempt   types   /trip_point*i   t   _typet   criticalt   _tempt   highN(   t   collectionsR   R#  R   t   extendt   sortedR   R}   R   R   R{   Ra   R   t   dirnamet   FalseR   R   R   R   R   R   R   R   R  t   dict(   R  t	   basenamesR:   t   baseRa   t   currentt	   unit_nameR   R  R  t   labelt
   trip_pathsR   t   trip_pointst
   trip_pointt	   trip_type(    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   sensors_temperatures  s    2
!	!>$c          C   s6  t  j t  }  t j d  } | s6 t j d  } n  t t g  | D] } | j d  d ^ qC   } x | D] } y t t | d   } Wn0 t	 t
 f k
 r } t j d | t  qo n Xt t j j t j j |  d  d t } t | d	 d
 d d t } |  | j t j | |   qo Wt |   S(   s  Return hardware fans info (for CPU and other peripherals) as a
    dict including hardware label and current speed.

    Implementation notes:
    - /sys/class/hwmon looks like the most recent interface to
      retrieve this info, and this implementation relies on it
      only (old distros will probably use something else)
    - lm-sensors on Ubuntu 16.04 relies on /sys/class/hwmon
    s   /sys/class/hwmon/hwmon*/fan*_*s%   /sys/class/hwmon/hwmon*/device/fan*_*R   i    R  s   ignoring %rR   R   R  R   RP  (   R  R   R#  R   R  R   R}   R   R   R   R   R   R   R   R{   Ra   R   R  R  R   R   t   sfanR  (   R  R  R:   R  R  R   R  R  (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   sensors_fans	  s     
2$	!c             s.  t        f d   }  g  t j t  D] } | j d  r( | ^ q( } | sS d St j j t t |  d  } |  | d | d  } |  | d | d  } |  | d | d	  } | d k s | d k r d S| d k	 ry d
 | | } Wq:t	 k
 r
d } q:Xn, t
 t | d d d  } | d k r:d Sd } |  t j j t d  t j j t d   }	 |	 d k	 r|	 d k } nL t | d d d d t j   }
 |
 d k rt } n |
 d k rt } n  | rt j } n5 y t
 | | d  } Wn t	 k
 rt j } n Xt j | | |  S(   s  Return battery information.
    Implementation note: it appears /sys/class/power_supply/BAT0/
    directory structure may vary and provide files with the same
    meaning but under different names, see:
    https://github.com/giampaolo/psutil/issues/966
    c             sM   xF |  D]> } t  | d   } |   k r | j   rA t |  S| Sq Wd S(   sv   Attempt to read the content of multiple files which may
        not exist. If none of them exist return None.
        R   N(   R   t   isdigitR   R   (   t   pathsRa   R  (   t   null(    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt	   multi_cat2  s
    t   BATi    s   /energy_nows   /charge_nows
   /power_nows   /current_nows   /energy_fulls   /charge_fullg      Y@g        s	   /capacityR   is
   AC0/onlines	   AC/onlinei   s   /statusRP  R   t   dischargingt   chargingt   fulli  N(   R  R  (   t   objectR{   R$  t   POWER_SUPPLY_PATHR   R   Ra   R   R  t   ZeroDivisionErrorR   R   R  R   R   R   t   POWER_TIME_UNLIMITEDt   POWER_TIME_UNKNOWNt   sbattery(   R  R:   t   batsR  t
   energy_nowt	   power_nowt   energy_fullRM   t   power_pluggedt   onlineRN  t   secsleft(    (   R  s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   sensors_battery)  sV    	
1"		c    
      C   s   g  }  t  j   } xu | D]m } | \ } } } } } } | sC q n  | d k rX d } n  t j | | pj d | | |  }	 |  j |	  q W|  S(   s:   Return currently connected users as a list of namedtuples.s   :0.0s   :0t	   localhost(   s   :0.0s   :0N(   R   t   usersR   t   suserR   R   (
   R  t   rawlistt   itemR   t   ttyt   hostnamet   tstampt   user_processR)  t   nt(    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyR    s    	!c          C   s|   d t    }  t |   ] } xC | D]; } | j d  r# t | j   j   d  } | a | Sq# Wt d |    Wd QXd S(   sA   Return the system boot time expressed in seconds since the epoch.s   %s/statt   btimei   s   line 'btime' not found in %sN(   R   R   R   R   R   R}   t	   BOOT_TIMERE  (   Ra   R   R   R  (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt	   boot_time  s    c          C   s;   g  t  j t t     D] }  |  j   r t |   ^ q S(   s7   Returns a list of PIDs currently running on the system.(   R{   R$  R   R   R  R   (   R:   (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyR-    s    c         C   s   t  j |   s t Sy| d t   |  f } t |  W } x= | D]5 } | j d  r? t | j   d  } | |  k Sq? Wt d |   Wd QXWn! t	 t f k
 r |  t
   k SXd S(   sc   Check for the existence of a unix PID. Linux TIDs are not
    supported (always return False).
    s   %s/%s/statuss   Tgid:i   s   'Tgid' line not found in %sN(   R   t
   pid_existsR  R   R   R   R   R}   R   t   EnvironmentErrorR-  (   R)  Ra   R   R   t   tgid(    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyR    s    
c    	      C   s   i  }  t    } x t   D] } y/ t d | | f   } | j   } Wd QXWn4 t k
 r } | j t j t j f k r   q q X| j d  } | | d j	   } t
 | d  } | |  | <q W|  S(   ss   Obtain a {pid: ppid, ...} dict for all running processes in
    one shot. Used to speed up Process.children().
    s
   %s/%s/statNt   )i   i   (   R   R-  R   R   R  R%  R&  R'  Ra  R}   R   (	   R  R   R)  R   t   dataR   t   rpart   dsett   ppid(    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   ppid_map  s    	
c            s"   t  j      f d    } | S(   sl   Decorator which translates bare OSError and IOError exceptions
    into NoSuchProcess and AccessDenied.
    c            s   y   |  | |  SWn t  k
 r } | j t j t j f k rY t |  j |  j   n  | j t j k r t |  j |  j   n  | j t j	 k r t
 j j d |  j |  j f  r t |  j |  j   n    n Xd  S(   Ns   %s/%s(   R  R%  R/  R0  t   AccessDeniedR)  t   _nameR'  t   NoSuchProcessR&  R{   Ra   R   R   (   R!  t   argst   kwargsR   (   t   fun(    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   wrapper  s    (   t	   functoolst   wraps(   R  R  (    (   R  s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   wrap_exceptions  s    t   Processc           B   s  e  Z d  Z d d d d d g Z d   Z d   Z e e d     Z e e d	     Z	 e e d
     Z
 d   Z d   Z e d    Z d   Z e d    Z e d    Z e d    Z e j j d e j    r e d    Z n  e d    Z e d    Z e d7 d   Z e d    Z e d    Z e re e j d  e j d  e j d  d   Z  n e Z  e re d    Z! n  e d    Z" e e j d  d    Z# e e j d!  d"   Z$ e d#    Z% e d$    Z& e d%    Z' e d&    Z( e j d'  d(  Z) e d)    Z* e+ rke d*    Z, e d+    Z- n  e. re d7 d,   Z/ n  e d-    Z0 e d.    Z1 e d/ d0   Z2 e d1    Z3 e d2    Z4 e e j d3  d4   Z5 e e j d5  d6   Z6 RS(8   s   Linux process implementation.R)  R  t   _ppidR   t   _cachec         C   s+   | |  _  d  |  _ d  |  _ t   |  _ d  S(   N(   R)  R   R  R  R   R   (   R!  R)  (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyR"     s    			c         C   s!   t  j d |  j |  j f  d S(   s+   Raise NSP if the process disappeared on us.s   %s/%sN(   R{   R  R   R)  (   R!  (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   _assert_alive  s    c         C   s   t  d |  j |  j f   } | j   } Wd QX| j d  } | | j d  d | !} | | d j   } i  } | | d <| d | d	 <| d | d
 <| d | d <| d | d <| d | d <| d | d <| d | d <| d | d <| d | d <| S(   sZ  Parse /proc/{pid}/stat file and return a dict with various
        process info.
        Using "man proc" as a reference: where "man proc" refers to
        position N always substract 3 (e.g ppid position 4 in
        'man proc' == position 1 in here).
        The return value is cached in case oneshot() ctx manager is
        in use.
        s
   %s/%s/statNR  t   (i   i   R   i    RN  R  i   t   ttynri   t   utimei   t   stimei   t   children_utimei   t   children_stimei   t   create_timei$   t   cpu_num(   R   R   R)  R   Ra  t   findR}   (   R!  R   R  R  R   R   R  (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   _parse_stat_file  s"    
c         C   s3   t  d |  j |  j f   } | j   SWd QXd S(   s   Read /proc/{pid}/stat file and return its content.
        The return value is cached in case oneshot() ctx manager is
        in use.
        s   %s/%s/statusN(   R   R   R)  R   (   R!  R   (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   _read_status_file.  s    c         C   s?   t  d |  j |  j f d t  } | j   j   SWd  QXd  S(   Ns   %s/%s/smapsRB  (   R   R   R)  RC  R   R   (   R!  R   (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   _read_smaps_file8  s    c         C   s4   |  j  j |   |  j j |   |  j j |   d  S(   N(   R  t   cache_activateR  R  (   R!  (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   oneshot_enter?  s    c         C   s4   |  j  j |   |  j j |   |  j j |   d  S(   N(   R  t   cache_deactivateR  R  (   R!  (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   oneshot_exitD  s    c         C   s)   |  j    d } t r% t |  } n  | S(   NR   (   R  R   R   (   R!  R   (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyR   I  s    c         C   s   y t  d |  j |  j f  SWn t k
 r } | j t j t j f k r t j j	 d |  j |  j f  rq d St
 |  j  s t |  j |  j   q t |  j |  j |  j   n  | j t j t j f k r t |  j |  j   n    n Xd  S(   Ns	   %s/%s/exes   %s/%sRP  (   R|   R   R)  R   R%  R&  R'  R{   Ra   t   lexistsR  R  R  t   ZombieProcessR  R/  R0  R  (   R!  R   (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   exeQ  s    "c         C   s   t  d |  j |  j f   } | j   } Wd  QX| s; g  S| j d  rP d n d } | j |  rr | d  } n  | j |  S(   Ns   %s/%s/cmdlines    Ru   i(   R   R   R)  R   R~   R}   (   R!  R   R  t   sep(    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   cmdlined  s    c         C   s;   t  d |  j |  j f   } | j   } Wd  QXt |  S(   Ns   %s/%s/environ(   R   R   R)  R   R   (   R!  R   R  (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   environw  s    c         C   sG   t  |  j   d  } t j   } y | | SWn t k
 rB d  SXd  S(   NR  (   R   R  R   t   get_terminal_mapR   R   (   R!  t   tty_nrR  (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   terminal}  s    s   /proc/%s/ioc      
   C   s  d |  j  |  j f } i  } t |  m } xc | D][ } | j   } | r2 y | j d  \ } } Wn t k
 ry q2 q Xt |  | | <q2 q2 WWd  QX| s t d |   n  y5 t | d | d | d | d | d | d	  SWn0 t	 k
 r} t d
 | d | | f   n Xd  S(   Ns   %s/%s/ios   : s   %s file was emptyt   syscrt   syscwRY   RZ   t   rchart   wchars1   %r field was not found in %s; found fields are %ri    (
   R   R)  R   R   R}   R   R   RE  Rv   R   (   R!  R   R   R   R   R   R   R   (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   io_counters  s0    c         C   sr   |  j    } t | d  t } t | d  t } t | d  t } t | d  t } t j | | | |  S(   NR  R  R  R	  (   R  R   R   R   t	   pcputimes(   R!  R   R  R  R  R	  (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyR     s    c         C   s   t  |  j   d  S(   s   What CPU the process is on.R  (   R   R  (   R!  (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyR    s    c         C   s   t  j |  j | |  j  S(   N(   R   t   wait_pidR)  R  (   R!  t   timeout(    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   wait  s    c         C   s1   t  |  j   d  } t p" t   } | t | S(   NR
  (   R   R  R  R  R   (   R!  t   ctimet   bt(    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyR
    s    c   
      C   s   t  d |  j |  j f  O } g  | j   j   d  D] } t |  t ^ q6 \ } } } } } } }	 Wd  QXt | | | | | | |	  S(   Ns   %s/%s/statmi   (   R   R   R)  R   R}   R   R   Rf   (
   R!  R   R:   t   vmsRl   RT   t   textt   libR  t   dirty(    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   memory_info  s    Ns   \nPrivate.*:\s+(\d+)s   \nPss\:\s+(\d+)s   \nSwap\:\s+(\d+)c   	      C   s   |  j    } |  j   } t t t | j |    d } t t t | j |    d } t t t | j |    d } t | | | | f   S(   Ni   (   R,  R  R   Rb  R   t   findallRg   (	   R!  t   _private_ret   _pss_ret   _swap_ret	   basic_memt
   smaps_dataRh   Ri   Rj   (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   memory_full_info  s    """c         C   s  d   } |  j    } | s g  S| j d  } g  } | j d  } | g } x| | |  D]v\ } } | j d d  } y | \ }	 }
 } } } } Wn0 t k
 r | d g \ }	 }
 } } } } n X| s d } nJ t r t |  } n  | j   } | j d  r"t	 |  r"| d  } n  | j
 t |	  t |
  | | d	 | j d
 d  | j d d  | j d d  | j d d  | j d d  | j d d  | j d d  | j d d  | j d d  f  q\ W| S(   sP  Return process's mapped memory regions as a list of named
            tuples. Fields are explained in 'man proc'; here is an updated
            (Apr 2012) version: http://goo.gl/fmebo

            /proc/{PID}/smaps does not exist on kernels < 2.6.14 or if
            CONFIG_MMU kernel configuration option is not enabled.
            c         s   s   i  } x |  D] } | j  d  d  } | d j d  sY | j   | f V| j |  q y  t | d  d | | d <Wq t k
 r | d j d  r q q t d |   q Xq W| j   | f Vd  S(   Ni   i    R2  i   i   s   VmFlags:s#   don't know how to interpret line %r(   R}   R   R~   t   popR   R   R   R   (   Rc  t   current_blockR  R   R   (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt
   get_blocks  s     s   
i    i   RP  s   [anon]s
    (deleted)is   Rss:s   Size:s   Pss:s   Shared_Clean:s   Shared_Dirty:s   Private_Clean:s   Private_Dirty:s   Referenced:s
   Anonymous:s   Swap:N(   R  R}   R4  R   R   R   R   R   R~   R   R   R   (   R!  R6  R  Rc  RX  t
   first_lineR5  t   headert   hfieldsR<  t   permst   offsett   devR+  Ra   (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   memory_maps  sF    			#	c         C   s   y t  d |  j |  j f  SWnv t k
 r } | j t j t j f k r t |  j  sr t |  j |  j	   q t
 |  j |  j	 |  j   n    n Xd  S(   Ns	   %s/%s/cwd(   R|   R   R)  R   R%  R&  R'  R  R  R  R  R  (   R!  R   (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   cwd?  s    s   ctxt_switches:\t(\d+)c         C   sh   |  j    } | j |  } | s@ t d |  j |  j f   n$ t j t | d  t | d   Sd  S(   Ns   'voluntary_ctxt_switches' and 'nonvoluntary_ctxt_switches'lines were not found in %s/%s/status; the kernel is probably older than 2.6.23i    i   (   R  R-  R  R   R)  R   t   pctxswR   (   R!  t	   _ctxsw_reR  t   ctxsw(    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   num_ctx_switchesL  s    s   Threads:\t(\d+)c         C   s#   |  j    } t | j |  d  S(   Ni    (   R  R   R-  (   R!  t   _num_threads_reR  (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   num_threadsZ  s    c         C   sN  t  j d |  j |  j f  } | j   g  } t } x | D] } d |  j |  j | f } y+ t |   } | j   j   } Wd  QXWn4 t	 k
 r } | j
 t
 j k r t } q< n    n X| | j d  d } | j d  }	 t |	 d  t }
 t |	 d  t } t j t |  |
 |  } | j |  q< W| rJ|  j   n  | S(   Ns
   %s/%s/tasks   %s/%s/task/%s/statR  i   Ru   i   i   (   R{   R$  R   R)  t   sortR  R   R   R   R   R%  R&  R   R  R}   R   R   R   t   pthreadR   R   R  (   R!  t
   thread_idsR  t
   hit_enoentt	   thread_idR   R   t   stR   R   R  R  R  (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   threadsb  s0    
c         C   s   t  j |  j  S(   N(   R{  t   getpriorityR)  (   R!  (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   nice_get  s    c         C   s   t  j |  j |  S(   N(   R{  t   setpriorityR)  (   R!  R   (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   nice_set  s    c         C   s   t  j |  j  S(   N(   R   t   proc_cpu_affinity_getR)  (   R!  (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   cpu_affinity_get  s    s   Cpus_allowed_list:\t(\d+)-(\d+)c         C   sq   |  j    } | j |  } | rT t t t | d d  t | d d  d   St t t t      Sd  S(   Ni    i   (   R  R-  R#  R  R   R   R   (   R!  t   _reR  R   (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   _get_eligible_cpus  s
    3c         C   s   y t  j |  j |  Wn t t f k
 r } t | t  sP | j t j k r |  j   } t	 t
 t t      } x[ | D]P } | | k r t d | | f   n  | | k r~ t d | | f   q~ q~ Wn    n Xd  S(   Ns(   invalid CPU number %r; choose between %ss0   CPU number %r is not eligible; choose between %s(   R   t   proc_cpu_affinity_setR)  R   R   Ry   R%  R(  RS  t   tupleR  R   R   (   R!  R   R   t   eligible_cpust   all_cpusR   (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   cpu_affinity_set  s     !c         C   sC   t  j |  j  \ } } t d  k	 r3 t |  } n  t j | |  S(   N(   R   R)   R)  t   enumR   R0   R   t   pionice(   R!  t   ioclassR   (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt
   ionice_get  s    c         C   s}   | d  k r d } n  | r@ | t t f k r@ t d |   n  | d k  sX | d k rg t d   n  t j |  j | |  S(   Ni    s   %r ioclass accepts no valuei   s   value not in 0-7 range(   R   R   R   R   R   t   proc_ioprio_setR)  (   R!  R[  R   (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt
   ionice_set  s    	c         C   s   |  j  d k r t d   n  ys | d  k r@ t j |  j  |  St |  d k rk t d t |    n  | \ } } t j |  j  | | |  WnU t k
 r } | j t j	 k r t
 |  j   r t |  j  |  j |  j   q   n Xd  S(   Ni    s)   can't use prlimit() against PID 0 processi   s4   second argument must be a (soft, hard) tuple, got %s(   R)  R   R   R   R(   R   RT  R   R%  t   ENOSYSR  R  R  R  (   R!  t   resourcet   limitst   softt   hardR   (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   rlimit  s    !c         C   s5   |  j    d } t r% | j   } n  t j | d  S(   NRN  t   ?(   R  R   R   t   PROC_STATUSESR   (   R!  t   letter(    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyRN    s    c         C   s  g  } t  j d |  j |  j f  } t } x| D]} d |  j |  j | f } y t |  } WnU t k
 r } | j t j t j	 f k r t
 } q2 q| j t j k r q2 q  q2 X| j d  r2 t |  r2 d |  j |  j | f } yT t |  B } t | j   j   d  }	 t | j   j   d d  }
 Wd  QXWn1 t k
 rt} | j t j k rnt
 } q  qXt |
  } t | t |  t |	  | |
  } | j |  q2 q2 W| r|  j   n  | S(   Ns   %s/%s/fds   %s/%s/fd/%sR   s   %s/%s/fdinfo/%si   i   (   R{   R$  R   R)  R  R|   R   R%  R&  R'  R   R(  R   R	   R   R   R   R}   R   R   R`   R   R  (   R!  R  R  RH  Rb   RH  Ra   R   R   t   posRe   Rd   R  (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt
   open_files  s@    )	!R  c         C   s#   t  j | |  j  } |  j   | S(   N(   R^  R[  R)  R  (   R!  RW  R  (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   connections  s    
c         C   s#   t  t j d |  j |  j f   S(   Ns   %s/%s/fd(   R   R{   R$  R   R)  (   R!  (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   num_fds  s    c         C   s   t  |  j   d  S(   NR  (   R   R  (   R!  (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyR  !  s    s   Uid:\t(\d+)\t(\d+)\t(\d+)c         C   sM   |  j    } | j |  d \ } } } t j t |  t |  t |   S(   Ni    (   R  R-  R   t   puidsR   (   R!  t   _uids_reR  t   realt	   effectivet   saved(    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   uids%  s    s   Gid:\t(\d+)\t(\d+)\t(\d+)c         C   sM   |  j    } | j |  d \ } } } t j t |  t |  t |   S(   Ni    (   R  R-  R   t   pgidsR   (   R!  t   _gids_reR  Rn  Ro  Rp  (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   gids+  s    N(7   R1   R2   R\  t	   __slots__R"  R  R  R   R  R  R  R  R  R   R  R  R  R  R{   Ra   R   t   getpidR!  R   R  R   R%  R
  R,  t	   HAS_SMAPSR   R   R3  R=  R>  RB  RD  RK  RM  RO  RQ  RS  RX  t   HAS_PROC_IO_PRIORITYR\  R^  t   HAS_PRLIMITRd  RN  Ri  Rj  Rk  R  Rq  Rt  (    (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyR     sx   		!				
	D		
0(   i   i   (   Rh   Ri   Rj   (    (   R\  t
   __future__R    R7  R  R%  R  R   R{   R   R  R9  t   syst	   tracebackR   R   R   RP  R   R   R   R   R   R{  R   R   R	   R
   R   R   R   R   R   R   R   R   R   R   t   _compatR   R   R   t   version_infoRY  R   t   __extra__all__R  Ra   R   Rv  Rw  t   hasattrRy  Rx  R  R   t   dirR   R   R   R   R   R   R  RC  t	   byteorderR5  R  t	   AF_PACKETR/   t   IntEnumR   R.   R   R   R   R   R0   t   globalsR.  t   __members__t   STATUS_RUNNINGt   STATUS_SLEEPINGt   STATUS_DISK_SLEEPt   STATUS_STOPPEDt   STATUS_TRACING_STOPt   STATUS_ZOMBIEt   STATUS_DEADt   STATUS_WAKE_KILLt   STATUS_WAKINGt   STATUS_IDLEt   STATUS_PARKEDRf  R   R   R   R    R!   R"   R#   R$   R%   R&   R'   RF  R  R  R  t   TimeoutExpiredRJ   RV   R`   Rf   R   Rg   Rk   R   Rt   Rv   R|   R   R   R   R   R   t	   Exceptiont	   print_excR   R   R   R   R   R   R   R   R   R  t   net_if_addrsR  R  R^  R_  Rv  R  t
   disk_usageR  R  R  R  R  R  R  R  R-  R  R  R  R   (    (    (    s.   lib/python2.7/site-packages/psutil/_pslinux.pyt   <module>   sN  					




















					
	5	z	:				$	 				%		^(	h	 	X				 		