Your IP : 18.223.238.150


Current Path : /lib64/python3.6/site-packages/psutil/__pycache__/
Upload File :
Current File : //lib64/python3.6/site-packages/psutil/__pycache__/_psbsd.cpython-36.pyc

3

��JZ$v�@sldZddlZddlZddlZddlZddljjZddl	m
Z
ddlmZddl
mZddl
mZddl
mZdd	l
mZdd
lmZddlmZddlmZdd
lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddl m!Z!ddl m"Z"ddl m#Z#gZ$e�rhej%ej&ej'ej(ej)ej*ej+ej,ej-ej.ej/ej0ej1ej2iZ3n�e�ste�r�ej%ej&ej)ej*ej+ej,ej4ej.ej-ej.ej'ej5ej6ej(iZ3nBe�r�ej%ej&ej7ej(ej8ej.ej+ej,ej-ej.ej4ej9ej:ej;iZ3ej<ej=ej>ej?ej@ejAejBejCejDejEejFejGejHejIejJejKejLejMejNejOejPejQejRejSiZTe�rjejUd�ZVn
ejUd�ZVejWZWeXddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1�ZYe
d2d3d4d5d6d7d8d9d:d;d<d=g�ZZe
d>d?d@dAdBdCg�Z[e
dDdEdFdGdHdIg�Z\e\Z]e
dJd?dAdKdLg�Z^e
dMdN�Z_e
dOdP�Z`e�rFe
dQdRdSdTdUdVdWdXg�Zane
dQdRdSdTdUg�ZadYdZ�Zbd[d\�Zcd]d^�Zdeeed_��r�d`d_�Zfndad_�Zfdbef_gdcdd�Zhe�s�e�r�dedf�Zindgdf�Zidhdi�Zjd�djdk�ZkejlZlejmZmejnZnejoZodldm�Zpdndo�Zqe�rdpdq�Zrdrds�Zsdtdu�Ztedvdw��Zudxdy�Zve�s2e�r<dzd{�ZwnejwZwd|d}�Zxejyd~d��ZzGd�d��d�e{�Z|dS)�z5FreeBSD, OpenBSD and NetBSD platforms implementation.�N)�
namedtuple)�AF_INET�)�_common)�_psposix)�_psutil_bsd)�
_psutil_posix)�AF_INET6)�	conn_tmap)�FREEBSD)�memoize)�memoize_when_activated)�NETBSD)�OPENBSD)�sockfam_to_enum)�socktype_to_enum)�
usage_percent)�which)�AccessDenied)�
NoSuchProcess)�
ZombieProcess�SC_PAGESIZE�SC_PAGE_SIZE��������	�
���
�����������)�ppid�status�real_uid�
effective_uid�	saved_uid�real_gid�
effective_gid�	saved_gid�ttynr�create_time�ctx_switches_vol�ctx_switches_unvol�
read_io_count�write_io_count�	user_time�sys_time�ch_user_time�ch_sys_time�rss�vms�memtext�memdata�memstack�cpunum�name�svmem�totalZ	available�percent�used�free�active�inactive�buffers�cached�shared�wired�	scputimes�user�nice�system�idle�irq�pmemrBrC�text�data�stack�	pcputimes�
children_user�children_system�
pmmap_groupedz*path rss, private, ref_count, shadow_count�	pmmap_extz6addr, perms path rss, private, ref_count, shadow_count�sdiskioZ
read_countZwrite_countZ
read_bytesZwrite_bytesZ	read_timeZ
write_timeZ	busy_timecCs�tj�}|\}}}}}}}}tr�tdd��R}	xJ|	D]B}
|
jd�rVt|
j�d�d}q2|
jd�r2t|
j�d�d}q2WWdQRX|||}|||}t|||dd�}
t|||
||||||||�S)	z&System virtual memory as a namedtuple.z
/proc/meminfo�rbsBuffers:ris
MemShared:N)�_round)	�cextZvirtual_memr�open�
startswith�int�splitrrI)ZmemrJrMrNrOrSrQrPrR�f�lineZavailrLrK�rm�/usr/lib64/python3.6/_psbsd.py�virtual_memory�s


"rocCs4tj�\}}}}}t||dd�}tj||||||�S)z@System swap memory as (total, used, free, sin, sout) namedtuple.r)re)rfZswap_memrrZsswap)rJrLrMZsinZsoutrKrmrmrn�swap_memory�srpcCs"tj�\}}}}}t|||||�S)z+Return system per-CPU times as a namedtuple)rf�	cpu_timesrT)rUrVrWrXrYrmrmrnrq�srq�
per_cpu_timescCsBg}x8tj�D],}|\}}}}}t|||||�}|j|�qW|S)z'Return system CPU times as a namedtuple)rfrrrT�append)�retZcpu_trUrVrWrXrY�itemrmrmrnrr�scCs.t�dkrt�gStjr td��dt_t�gS)z'Return system CPU times as a namedtuplerz&supported only starting from FreeBSD 8T)�cpu_count_logicalrqrr�
__called__�NotImplementedErrorrmrmrmrnrr�s
FcCstj�S)z0Return the number of logical CPUs in the system.)rfrvrmrmrmrnrv�srvcCst�dkrdSdS)Nr)rvrmrmrmrn�cpu_count_physical�sryc
Csxd}tj�}|dk	rb|jd�}|dkrb|d|d�}tj|�}zt|jd��pRd}Wd|j�X|stt�dkrtdS|S)z1Return the number of physical CPUs in the system.Nz	</groups>rr zgroup/children/group/cpu���)	rfZcpu_count_phys�rfind�ETZ
fromstring�len�findall�clearrv)rt�s�index�rootrmrmrnry�s



c	Cs�trtj�\}}}}}nttrrtj�\}}}}}}}tdd��.}x&|D]}|jd�rDt|j�d�}qDWWdQRXntr�tj�\}}}}}}}t	j
||||�S)z*Return various CPU stats as a named tuple.z
/proc/statrdsintrrN)rrf�	cpu_statsrrgrhrirjrrZ	scpustats)	ZctxswZintrsZ
soft_intrsZsyscallsZtrapsZfaultsZforksrkrlrmrmrnr�s

 r�c	CsDg}tj�}x2|D]*}|\}}}}tj||||�}|j|�qW|S)z�Return mounted disk partitions as a list of namedtuples.
    'all' argument is ignored, see:
    https://github.com/giampaolo/psutil/issues/906
    )rf�disk_partitionsrZ	sdiskpartrs)	�all�retlistZ
partitions�	partitionZdeviceZ
mountpointZfstypeZopts�ntuplermrmrnr�<s
r�cCsjt�j�}i}xV|D]N}tj|�}tj|�}tj|�\}}ttd�rNtj|�}tj	||||�||<qW|S)z)Get NIC stats (isup, duplex, speed, mtu).�	NicDuplex)
�net_io_counters�keys�
cext_posixZ
net_if_mtuZnet_if_flagsZnet_if_duplex_speed�hasattrrr�Z	snicstats)�namesrtrHZmtuZisupZduplexZspeedrmrmrn�net_if_statsWs





r�cCs�trzg}xlt�D]b}yt|�j|�}Wnttfk
r@wYqXx.|D]&}t|�}|j|�|jtj	|��qHWqW|S|tj
kr�td|djdd�t
D��f��t
|\}}t
�}tr�tjd�}ntj�}x�|D]�}|\}	}
}}}
}}|
|ko�||kr�yt|}Wn tk
�r&ttj}YnX|
ttfk�rV|�rFtj|�}|
�rVtj|
�}
t|
�}
t|�}tj	|	|
|||
||�}|j|�q�Wt|�S)z System-wide network connections.z+invalid %r kind argument; choose between %sz, cSsg|]}t|��qSrm)�repr)�.0�xrmrmrn�
<listcomp>wsz#net_connections.<locals>.<listcomp>rrz)r�pids�Process�connectionsrr�listrsrZsconnr
�
ValueError�join�setrrf�net_connections�TCP_STATUSES�KeyError�PSUTIL_CONN_NONErr	�addrrr�add)�kindrt�pidZconsZconn�families�types�rawlistru�fd�fam�type�laddr�raddrr1�ntrmrmrnr�esJ





r�cCsbytj�\}}}Wntk
r&dSX|dk}|r<tj}n|dkrLtj}n|d}tj|||�S)zReturn battery info.Nr�<rz)rf�sensors_batteryrxrZPOWER_TIME_UNLIMITEDZPOWER_TIME_UNKNOWNZsbattery)rKZminsleftZ
power_pluggedZsecsleftrmrmrnr��sr�cCstj�S)z:The system boot time expressed in seconds since the epoch.)rf�	boot_timermrmrmrnr��sr�c	Csjg}tj�}xX|D]P}|\}}}}}|dkr8ts4t�d}|dkrBqtj||pNd|||�}|j|�qW|S)z:Return currently connected users as a list of namedtuples.rN�~rz)rf�usersr�AssertionErrorrZsuserrs)	r�r�rurUZttyZhostnameZtstampr�r�rmrmrnr��s
r�cCs@ytd�j�Wn&tk
r$dStk
r6dSXdSdS)NrFT)r�rHrrrmrmrmrn�
_pid_0_exists�sr�cCs*tj�}tr&d|kr&t�r&|jdd�|S)z7Returns a list of PIDs currently running on the system.r)rfr�rr��insert)rtrmrmrnr��sr�cCs tj|�}|s|t�kSdSdS)zReturn True if pid exists.TN)r�
pid_existsr�)r��existsrmrmrnr��s

r�cstj���fdd��}|S)z`Decorator which translates bare OSError exceptions into
    NoSuchProcess and AccessDenied.
    cs�y�|f|�|�Stk
r�}z�|jdkrHdt�krFt|j|j��n�|jtjkr�t|j�snt|j|j��nt	|j|j|j
��|jtjtjfkr�t|j|j���WYdd}~XnXdS)Nr)
�OSErrorr�r�r�_name�errno�ESRCHr�rr�_ppid�EPERM�EACCES)�self�args�kwargs�err)�funrmrn�wrapper�s


z wrap_exceptions.<locals>.wrapper)�	functools�wraps)r�r�rm)r�rn�wrap_exceptions�sr�ccs�y
dVWn�tk
r�}zf|jtjtjfkrZt|j�sHt|j|j��nt|j|j|j	��|jtj
tjfkrzt|j|j���WYdd}~XnXdS)z8Same as above, for routines relying on reading /proc fs.N)
�EnvironmentErrorr��ENOENTr�r�r�rr�rr�r�r�r)Zinstr�rmrmrn�wrap_exceptions_procfs
s

r�c@s�eZdZdZdddgZdd�Zedd��Zd	d
�Zdd�Z	e
d
d��Ze
dd��Ze
dd��Z
e
dd��Ze
dd��Ze
dd��Ze
dd��Ze
dd��Zer�e
dd��Ze
dd ��ZeZe
d!d"��Ze
d#d$��Ze
d%d&��Ze
d'd(��Ze
dJd*d+��Ze
dKd-d.��Ze
d/d0��Ze
d1d2��Ze
d3d4��Ze
d5d6��Z e
d7d8��Z!e"d9d:�Z#e"d9d;�Z$d<d=�Z%e&e'd>��rxe
d?d@��Z(ne%Z(e&e'dA��r�e
dBdC��Z)ne%Z)e�r�e
dDdE��Z*e
dFdG��Z+e
dHdI��Z,d,S)Lr�z1Wrapper class around underlying C implementation.r�r�r�cCs||_d|_d|_dS)N)r�r�r�)r�r�rmrmrn�__init__"szProcess.__init__cCs$tj|j�}t|�tt�ks t�|S)z;Retrieves multiple process info in one shot as a raw tuple.)rfZproc_oneshot_infor�r}�kinfo_proc_mapr�)r�rtrmrmrn�oneshot'szProcess.oneshotcCs|jj�dS)N)r�Zcache_activate)r�rmrmrn�
oneshot_enter.szProcess.oneshot_entercCs|jj�dS)N)r�Zcache_deactivate)r�rmrmrn�oneshot_exit1szProcess.oneshot_exitcCs(|j�td}|dk	r|Stj|j�S)NrH)r�r�rfZ	proc_namer�)r�rHrmrmrnrH4szProcess.namec
Csdtrtj|j�StrD|jdkr"dSt|��tjd|j�SQRXn|j�}|r\t	|d�SdSdS)Nr�z/proc/%s/exe)
rrfZproc_exer�rr��os�readlink�cmdliner)r�r�rmrmrn�exe9s

zProcess.execCs�tr|jdkrgStr�ytj|j�Stk
r�}zB|jtjkrnt|j�sZt	|j|j
��qpt|j|j
|j��n�WYdd}~Xq�Xntj|j�SdS)Nr)
rr�rrfZproc_cmdliner�r��EINVALr�rr�rr�)r�r�rmrmrnr�Os
zProcess.cmdlinecCs:|j�td}tj�}y||Stk
r4dSXdS)Nr8)r�r�rZget_terminal_mapr�)r�Ztty_nrZtmaprmrmrn�terminaleszProcess.terminalcCs|j�td|_|jS)Nr0)r�r�r�)r�rmrmrnr0nszProcess.ppidcCs.|j�}tj|td|td|td�S)Nr2r3r4)r�rZpuidsr�)r��rawtuplermrmrn�uidsss


zProcess.uidscCs.|j�}tj|td|td|td�S)Nr5r6r7)r�rZpgidsr�)r�r�rmrmrn�gids{s


zProcess.gidscCs8|j�}tj|td|td|td|td�S)Nr>r?r@rA)r�rr^r�)r�r�rmrmrnrq�s


zProcess.cpu_timescCs|j�tdS)NrG)r�r�)r�rmrmrn�cpu_num�szProcess.cpu_numcCs@|j�}t|td|td|td|td|td�S)NrBrCrDrErF)r�rZr�)r�r�rmrmrn�memory_info�s



zProcess.memory_infocCs|j�tdS)Nr9)r�r�)r�rmrmrnr9�szProcess.create_timecCs&ttd�rtj|j�St|j��SdS)N�proc_num_threads)r�rfr�r�r}�threads)r�rmrmrn�num_threads�s
zProcess.num_threadscCs$|j�}tj|td|td�S)Nr:r;)r�rZpctxswr�)r�r�rmrmrn�num_ctx_switches�s
zProcess.num_ctx_switchescCsLtj|j�}g}x*|D]"\}}}tj|||�}|j|�qWtrH|j�|S)N)rfZproc_threadsr�rZpthreadrsrrH)r�r�r�Z	thread_id�utimeZstimer�rmrmrnr��szProcess.threads�inetcCs�|tkr(td|djdd�tD��f��t�rt|\}}t�}tj|j�}x�|D]�}|\}}}	}
}}}
|
|jksvt�||ko�|	|krRyt	|}Wnt
k
r�t	tj}YnX|tt
fkr�|
r�tj|
�}
|r�tj|�}t|�}t|	�}	tj|||	|
||�}|j|�qRW|j�t|�St|\}}tj|j||�}g}x�|D]z}|\}}}	}
}}|tt
fk�r�|
�rttj|
�}
|�r�tj|�}t|�}t|	�}	t	|}tj|||	|
||�}|j|��qBWt�r�|j�|S)Nz+invalid %r kind argument; choose between %sz, cSsg|]}t|��qSrm)r�)r�r�rmrmrnr��sz'Process.connections.<locals>.<listcomp>)r
r�r�rr�rfr�r�r�r�r�r�rr	rr�rrZpconnr�rHr�Zproc_connectionsrsr)r�r�r�r�rtr�rur�r�r�r�r�r1r�r�rmrmrnr��sX





zProcess.connectionsNcCstj|j||j�S)N)rZwait_pidr�r�)r�Ztimeoutrmrmrn�wait�szProcess.waitcCstj|j�S)N)r��getpriorityr�)r�rmrmrn�nice_get�szProcess.nice_getcCstj|j|�S)N)r��setpriorityr�)r��valuermrmrn�nice_set�szProcess.nice_setcCs|j�td}tj|d�S)Nr1�?)r�r��
PROC_STATUSES�get)r��codermrmrnr1szProcess.statuscCs(|j�}tj|td|tddd�S)Nr<r=rrzrz)r�rZpior�)r�r�rmrmrn�io_counterss

zProcess.io_countersc
Csftr|jdkrdStr8t|��tjd|j�SQRXn*ttd�rRtj|j�pPdSt	t
r\dnd��dS)z)Return process current working directory.rNz/proc/%s/cwd�proc_open_filesz&supported only starting from FreeBSD 8r�)rr�rr�r�r�r�rfZproc_cwdrxr)r�rmrmrn�cwds

zProcess.cwdZmmapz*path rss, private, ref_count, shadow_countz6addr, perms path rss, private, ref_count, shadow_countcCst�dS)N)rx)r�rmrmrn�_not_implemented)szProcess._not_implementedr�cCstj|j�}dd�|D�S)z8Return files opened by process as a list of namedtuples.cSsg|]\}}tj||��qSrm)rZ	popenfile)r��pathr�rmrmrnr�3sz&Process.open_files.<locals>.<listcomp>)rfr�r�)r�r�rmrmrn�
open_files/szProcess.open_files�proc_num_fdscCstj|j�}tr|j�|S)z=Return the number of file descriptors opened by this process.)rfr�r�rrH)r�rtrmrmrn�num_fds:szProcess.num_fdscCstj|j�S)N)rfZproc_cpu_affinity_getr�)r�rmrmrn�cpu_affinity_getJszProcess.cpu_affinity_getcCs�tttt����}x$|D]}||krtd||f��qWytj|j|�Wn\tk
r�}z@|j	t	j
t	jfkr�x$|D]}||krttd||f��qtW�WYdd}~XnXdS)Nz#invalid CPU #%i (choose between %s))�tuple�ranger}rrr�rfZproc_cpu_affinity_setr�r�r�r�ZEDEADLK)r�ZcpusZallcpusZcpur�rmrmrn�cpu_affinity_setNs

zProcess.cpu_affinity_setcCstj|j�S)N)rfZproc_memory_mapsr�)r�rmrmrn�memory_mapsgszProcess.memory_maps)r�)N)-�__name__�
__module__�__qualname__�__doc__�	__slots__r�r
r�r�r�r�rHr�r�r�r0r�r�rqrr�r�Zmemory_full_infor9r�r�r�r�r�r�r�r1r�r�rZnt_mmap_groupedZnt_mmap_extr�r�rfr�r�r�r�r�rmrmrmrnr�s\
		
6	
r�)F)}r��
contextlibr�r�r�Zxml.etree.ElementTreeZetreeZElementTreer|�collectionsrZsocketrr�rrrrfrr�r	r
rrr
rrrrrZ_compatr�_exceptionsrrrZ__extra__all__ZSIDLZSTATUS_IDLEZSRUNZSTATUS_RUNNINGZSSLEEPZSTATUS_SLEEPINGZSSTOPZSTATUS_STOPPEDZSZOMBZ
STATUS_ZOMBIEZSWAITZSTATUS_WAITINGZSLOCKZ
STATUS_LOCKEDr�ZSDEADZ
STATUS_WAKINGZSONPROCZSACTIVEZSDYINGZSTATUS_DEADZ
SSUSPENDEDZSTATUS_SUSPENDEDZTCPS_ESTABLISHEDZCONN_ESTABLISHEDZ
TCPS_SYN_SENTZ
CONN_SYN_SENTZTCPS_SYN_RECEIVEDZ
CONN_SYN_RECVZTCPS_FIN_WAIT_1ZCONN_FIN_WAIT1ZTCPS_FIN_WAIT_2ZCONN_FIN_WAIT2ZTCPS_TIME_WAITZCONN_TIME_WAITZTCPS_CLOSEDZ
CONN_CLOSEZTCPS_CLOSE_WAITZCONN_CLOSE_WAITZ
TCPS_LAST_ACKZ
CONN_LAST_ACKZTCPS_LISTENZCONN_LISTENZTCPS_CLOSINGZCONN_CLOSINGr�Z	CONN_NONEr��sysconfZPAGESIZEZAF_LINK�dictr�rIrTrZZpfullmemr^rarbrcrorprqr�rrrwrvryr�r�Z
disk_usageZdisk_io_countersr�Znet_if_addrsr�r�r�r�r�r�r�r�r��contextmanagerr��objectr�rmrmrmrn�<module>s




	
#
6




?>