/ lib / psutil / _psbsd.pyc
_psbsd.pyc
  1  o

  2  #��cO~�@s�dZddlZddlZddlZddlZddlmmZddl	m
  3  Z
  4  ddl	mZddlm
Z
ddlmZddlmZdd	lmZdd
  5  l
mZddl
mZddl
mZdd
l
mZddl
mZddl
mZddl
mZddl
mZddl
mZddl
mZddl
mZddlmZddlm Z ddlm!Z!ddlm"Z"gZ#er�ej$e
j%ej&e
j'ej(e
j)ej*e
j+ej,e
j-ej.e
j/ej0e
j1iZ2n=er�ej$e
j%ej(e
j)ej*e
j+ej3e
j-ej,e
j-ej&e
j4ej5e
j'iZ2ner�ej$e
j%ej(e
j)ej*e
j+ej,e
j-ej&e
j4ej5e
j'iZ2ej6e
j7ej8e
j9ej:e
j;ej<e
j=ej>e
j?ej@e
jAejBe
jCejDe
jEejFe
jGejHe
jIejJe
jKejLe
jMiZNe�O�ZPejQZQeRed�ZSeRed�ZTeRed�ZUeRed�ZVeWd�idd�dd�dd �d!d"�d#d$�d%d&�d'd(�d)d*�d+d,�d-d.�d/d0�d1d2�d3d4�d5d6�d7d8�d9d:�d;d<�d=d>�d?d@�dAdB�dCdD�dEdF�dGdH�dIdJ�dKdL��ZXedMgdN��ZYedOgdP��ZZedQgdR��Z[e[Z\edSgdT��Z]edUdV�Z^edWdX�Z_e�r�edYgdZ��Z`nedYgd[��Z`d\d]�Zad^d_�Zbd`da�ZceS�r�dbd�Zdndcd�Zddded_ededf�Zfe�s�e�r�dgdh�Zgndidh�Zgdjdk�Zhe�r
  6  dldm�Zine�rdndm�Zid�dodp�ZjejkZkejlZlejmZmejnZndqdr�Zodsdt�Zpe�r5dudv�Zqdwdx�Zrdydz�Zsd{d|�Zted}d~��Zudd��Zve�sMe�rRd�d��ZwnejwZwd�d��Zxd�d��Zyejzd�d���Z{Gd�d��d�e|�Z}dS)�z5FreeBSD, OpenBSD and NetBSD platforms implementation.�N)�defaultdict)�
  7  namedtuple�)�_common)�_psposix)�_psutil_bsd)�
_psutil_posix)�FREEBSD)�NETBSD)�OPENBSD)�AccessDenied)�
NoSuchProcess)�
ZombieProcess)�	conn_tmap)�conn_to_ntuple)�memoize)�memoize_when_activated)�
usage_percent)�FileNotFoundError)�PermissionError)�ProcessLookupError)�which�
per_cpu_times�proc_num_threads�proc_open_files�proc_num_fds�ppid�status�real_uid��
effective_uid��	saved_uid��real_gid��
effective_gid��	saved_gid��ttynr��create_time�	�ctx_switches_vol�
  8  �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)�total�	available�percent�used�free�active�inactive�buffers�cached�shared�wired�	scputimes��user�nice�system�idle�irq�pmem)r>r@�text�data�stack�	pcputimes)rZr\�
children_user�children_system�
pmmap_grouped�*path rss, private, ref_count, shadow_count�	pmmap_ext�6addr, perms path rss, private, ref_count, shadow_count�sdiskio)�
  9  read_count�write_count�
 10  read_bytes�write_bytes�	read_time�
 11  write_time�	busy_time)rkrlrmrncCs�t��}|\}}}}}}}}trYtdd��<}	|	D]1}
 12  |
 13  �d�r*t|
 14  ��d�d}q|
 15  �d�r:t|
 16  ��d�d}q|
 17  �d�rIt|
 18  ��d�d}qWd�n1sTwY|||}|||}t|||dd	�}
t|||
||||||||�S)
 19  z&System virtual memory as a namedtuple.z
/proc/meminfo�rbsBuffers:ris
 20  MemShared:sCached:N��round_)	�cext�virtual_memr
 21  �open�
 22  startswith�int�splitrrL)�memrMrQrRrSrWrUrTrV�f�line�availrPrO�r��C:\Users\Jacks.GUTTSPC\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\psutil\_psbsd.py�virtual_memory�s(
 23  
 24  
 25  ����r�cCs4t��\}}}}}t||dd�}t�||||||�S)z@System swap memory as (total, used, free, sin, sout) namedtuple.rrs)ru�swap_memrr�sswap)rMrPrQ�sin�soutrOrrr��swap_memory�sr�cCs"t��\}}}}}t|||||�S)z+Return system per-CPU times as a namedtuple)ru�	cpu_timesrXrYrrr�r��sr�cCs>g}t��D]}|\}}}}}t|||||�}|�|�q|S)�'Return system CPU times as a namedtuple)rurrX�append)�ret�cpu_trZr[r\r]r^�itemrrr�r�scCs.t�dkr	t�gStjrtd��dt_t�gS)r�r�&supported only starting from FreeBSD 8T)�cpu_count_logicalr�r�
 26  __called__�NotImplementedErrorrrrr�r�s
 27  FcC�t��S)z0Return the number of logical CPUs in the system.)rur�rrrr�r���r�cCst�dkrdSdS)Nr)r�rrrr��cpu_count_cores��r�cCs�d}t��}|dur5|�d�}|dkr5|d|d�}t�|�}zt|�d��p)d}W|��n|��w|s>t�dkr>dS|S)z-Return the number of CPU cores in the system.Nz	</groups>�����r-zgroup/children/group/cpur)	ruZcpu_topology�rfind�ET�
 28  fromstring�len�findall�clearr�)r��s�index�rootrrr�r�s
 29  
 30  
 31  c	Cs�trt��\}}}}}nBtrAt��\}}}}}}}tdd��}|D]}|�d�r0t|��d�}q!Wd�n1s;wYn
trNt��\}}}}}}}t	�
 32  ||||�S)z*Return various CPU stats as a named tuple.z
 33  /proc/statrrsintrrN)r	ru�	cpu_statsr
 34  rwrxryrzrr�	scpustats)	�ctxswZintrsZ
 35  soft_intrs�syscalls�traps�faultsZforksr|r}rrr�r�s"�
 36  �����r�c
 37  Cs�g}t�}t|�D]]}z	t�|�\}}Wn	tyYq	w|r\zt|�d�d�d�d�}Wn
ttfy=d}Ynwzt|�d�d�d�d�}Wn
ttfy[d}Ynw|�	t
 38  �|||��q	|S)z�Return frequency metrics for CPUs. As of Dec 2018 only
 39          CPU 0 appears to be supported by FreeBSD and all other cores
 40          match the frequency of CPU 0.
 41          � r��/rN)r��rangeru�cpu_freqr�ryrz�
 42  IndexError�
 43  ValueErrorr�r�scpufreq)r��num_cpus�cpu�currentZavailable_freqZmin_freqZmax_freqrrr�r�<s*� � �r�cCstt���}t�|dd�gS)Ng)�floatrur�rr�)�currrrr�r�Tsc	CsLg}t��}|D]}|\}}}}d}}	t�||||||	�}
 44  |�|
 45  �q|S)z�Return mounted disk partitions as a list of namedtuples.
 46      'all' argument is ignored, see:
 47      https://github.com/giampaolo/psutil/issues/906
 48      N)ru�disk_partitionsr�	sdiskpartr�)�all�retlist�
 49  partitions�	partition�device�
 50  mountpoint�fstype�opts�maxfile�maxpath�ntuplerrr�r�^s�r�c
 51  Cs�t���}i}|D]M}zt�|�}t�|�}t�|�\}}Wnty7}z
|jtjkr-�WYd}~q	d}~wwt	t
 52  d�rBt
 53  �|�}d�|�}d|v}	t
 54  �
|	||||�||<q	|S)z)Get NIC stats (isup, duplex, speed, mtu).N�	NicDuplex�,�running)�net_io_counters�keys�
 55  cext_posix�
 56  net_if_mtu�net_if_flags�net_if_duplex_speed�OSError�errno�ENODEV�hasattrrr��join�	snicstats)
 57  �namesr�rJ�mtu�flags�duplex�speed�err�output_flags�isuprrr��net_if_stats{s*
 58  
 59  
 60  ���
 61  
 62  
 63  
 64  �r�c
 65  Cstr7g}t�D]-}z	t|��|�}WnttfyYqw|D]}t|�}|�|�|�tj	|��q q|S|tj
 66  vrLtd|d�dd�t
 67  D��f��t
 68  |\}}t
�}tr]t�d�}nt��}|D]#}|\}	}
 69  }}}
}}|
 70  |vr�||vr�t|	|
 71  |||
|t|�}|�|�qct|�S)z System-wide network connections.�+invalid %r kind argument; choose between %s�, cS�g|]}t|��qSr��repr��.0�xrrr��
 72  <listcomp>��z#net_connections.<locals>.<listcomp>r�)r�pids�Process�connectionsr
r�listr�r�sconnrr�r��setr
 73  ru�net_connectionsr�TCP_STATUSES�add)�kindr��pid�cons�conn�families�types�rawlistr��fd�fam�type�laddr�raddrr�ntrrr�r��s@
 74  �
 75  �
 76  ��
 77  �r�cCsbz	t��\}}}Wn
 78  tyYdSw|dk}|rtj}n|dkr&tj}n|d}t�|||�S)zReturn battery info.Nrr��<)ru�sensors_batteryr�r�POWER_TIME_UNLIMITED�POWER_TIME_UNKNOWN�sbattery)rO�minsleft�
power_plugged�secsleftrrr�r��s�r�c	Csrtt�}t�}t|�D]+}z t�|�\}}|dkrd}d|}|d�t�||||��Wqt	y6Yqw|S)z?Return CPU cores temperatures if available, else an empty dict.rNzCore %sZcoretemp)
 79  rr�r�r�ruZsensors_cpu_temperaturer�r�shwtempr�)r�r�r�r��highrJrrr��sensors_temperatures�s��rcCr�)z:The system boot time expressed in seconds since the epoch.)ru�	boot_timerrrr�r�r�rc	Csfg}t��}|D](}|\}}}}}|dkrtsJ�d}|dkr qt�||p&d|||�}|�|�q|S)z:Return currently connected users as a list of namedtuples.r�N�~)ru�usersrr�suserr�)	r�r�r�rZ�tty�hostname�tstampr�r�rrr�r�srcCs:z	td���WdStyYdStyYdSw)NrFT)r�rJr
rrrrr��
_pid_0_exists�s��rcCs*t��}trd|vrt�r|�dd�|S)z7Returns a list of PIDs currently running on the system.r)rur�rr�insert)r�rrr�r�	sr�cCst�|�}|s|t�vSdS)zReturn True if pid exists.T)r�
 80  pid_existsr�)r��existsrrr�r
 81  s
 82  
 83  r
 84  cCs4zt�|�td}|tjkWStyYdSw)NrF)ru�proc_oneshot_info�kinfo_proc_map�SZOMB�	Exception)r��strrr��	is_zombie!s�rcst����fdd��}|S)z`Decorator which translates bare OSError exceptions into
 85      NoSuchProcess and AccessDenied.
 86      cs�z�|g|�Ri|��WSty(t|j�r!t|j|j|j��t|j|j��ty5t|j|j��t	yN|jdkrMdt
 87  �vrLt|j|j����w�Nr)rrr�r�_name�_ppidr
rrr�r�)�self�args�kwargs��funrr��wrapper-s
 88  
 89  
 90  �z wrap_exceptions.<locals>.wrapper)�	functools�wraps)rrrrr��wrap_exceptions)src	csf�zdVWdSttfy%t|j�rt|j|j|j��t|j|j��ty2t	|j|j��w)z8Same as above, for routines relying on reading /proc fs.N)
 91  rrrr�rrrr
rr)�instrrr��wrap_exceptions_procfsBs�
 92  �rc@s�eZdZdZgd�Zdd�Zdd�Zeedd���Z	d	d
 93  �Z
 94  dd�Zed
d��Zedd��Z
edd��Zedd��Zedd��Zedd��Zedd��Zedd��Zedd��Zer`edd ��Zed!d"��ZeZed#d$��Zed%d&��Zed'd(��Zed)d*��ZedLd,d-��ZedMd/d0��Zed1d2��Zed3d4��Z ed5d6��Z!ed7d8��Z"ed9d:��Z#e$d;d<�Z%e$d;d=�Z&d>d?�Z'e(r�ed@dA��Z)ne'Z)e*r�edBdC��Z+ne'Z+er�edDdE��Z,edFdG��Z-edHdI��Z.edMdJdK��Z/d.Sd.S)Nr�z1Wrapper class around underlying C implementation.)r�rr�_cachecCs||_d|_d|_dS�N)r�rr)rr�rrr��__init__Xs
 95  zProcess.__init__cCst�|j�dS)z+Raise NSP if the process disappeared on us.N)ru�	proc_namer��rrrr��
_assert_alive]szProcess._assert_alivecCs$t�|j�}t|�tt�ksJ�|S)z;Retrieves multiple process info in one shot as a raw tuple.)rurr�r�r
�rr�rrr��oneshotcszProcess.oneshotcC�|j�|�dSr!)r'�cache_activater$rrr��
oneshot_enterk�zProcess.oneshot_entercCr(r!)r'�cache_deactivater$rrr��oneshot_exitnr+zProcess.oneshot_exitcCs(|��td}|dur|St�|j�S)NrJ)r'r
rur#r�)rrJrrr�rJqszProcess.namecCs�tr|jdkr	dSt�|j�Str6|jdkrdSt|��t�d|j�Wd�S1s/wYdS|��}|rDt	|d�pCdSdS)Nr�z/proc/%s/exe)
 96  r	r�ru�proc_exer
 97  r�os�readlink�cmdliner)rr2rrr��exevs
 98  
 99  
100  $�zProcess.exec
101  Cs�tr	|jdkr	gStrJzt�|j�WStyI}z+|jtjkrDt|j�r.t	|j|j
102  |j��t|j�s<t
|j|j
103  |j��gWYd}~S�d}~wwt�|j�Sr)rr�r
104  ru�proc_cmdliner�r��EINVALrrrrr
105  r
)rr�rrr�r2�s 
106  
107  ��
zProcess.cmdlinecC�t�|j�Sr!)ru�proc_environr�r$rrr��environ��zProcess.environcCs8|��td}t��}z||WStyYdSw)Nr*)r'r
r�get_terminal_map�KeyError)r�tty_nr�tmaprrr��terminal�s
108  �zProcess.terminalcCs|��td|_|jS)Nr)r'r
rr$rrr�r�szProcess.ppidcC�.|��}t�|td|td|td�S)Nrr r")r'r�puidsr
�r�rawtuplerrr��uids��
109  
110  
111  �zProcess.uidscCr?)Nr$r&r()r'r�pgidsr
rArrr��gids�rDzProcess.gidscCs8|��}t�|td|td|td|td�S)Nr6r8r:r<)r'rrcr
rArrr�r��s
112  
113  
114  
115  �zProcess.cpu_timescC�|��tdS)NrH�r'r
r$rrr��cpu_num��zProcess.cpu_numcCs@|��}t|td|td|td|td|td�S)Nr>r@rBrDrF)r'r_r
rArrr��memory_info�s
116  
117  
118  
119  
120  �zProcess.memory_infocCrG)Nr,rHr$rrr�r,�rJzProcess.create_timecCstrt�|j�St|���Sr!)�HAS_PROC_NUM_THREADSrurr�r��threadsr$rrr��num_threads�szProcess.num_threadscCs$|��}t�|td|td�S)Nr.r0)r'r�pctxswr
rArrr��num_ctx_switches�s
121  
122  
123  �zProcess.num_ctx_switchescCsHt�|j�}g}|D]\}}}t�|||�}|�|�q
124  tr"|��|Sr!)ru�proc_threadsr�r�pthreadr�rr%)rr�r��	thread_id�utime�stimer�rrr�rM�szProcess.threads�inetc	Cs|tvrtd|d�dd�tD��f��trXt|\}}g}t�|j�}|D])}|\}}}	}
125  }}}
|
|jks8J�||vrO|	|vrOt|||	|
126  ||t�}|�	|�q&|�
127  �t|�St|\}}t�|j||�}g}|D]}|\}}}	}
128  }}t|||	|
129  ||t�}|�	|�qjt
r�|�
130  �|S)Nr�r�cSr�rr�r�rrr�r�r�z'Process.connections.<locals>.<listcomp>)rr�r�r
131  rur�r�rr�r�r%r��proc_connectionsr)rr�r�r�r�r�r�r�r�r�r�r�rr�r�rrr�r�s>��
132  ��zProcess.connectionsNcCst�|j||j�Sr!)r�wait_pidr�r)r�timeoutrrr��wait%r�zProcess.waitcCr6r!)r��getpriorityr�r$rrr��nice_get)r9zProcess.nice_getcCst�|j|�Sr!)r��setpriorityr�)r�valuerrr��nice_set-szProcess.nice_setcCs|��td}t�|d�S)Nr�?)r'r
�
PROC_STATUSES�get)r�coderrr�r1szProcess.statuscCs(|��}t�|td|tddd�S)Nr2r4r�)r'r�pior
rArrr��io_counters7s
133  
134  �zProcess.io_counterscCs<tr	|jdkr	dSts
trt�|j�pdSttrd��d��)z)Return process current working directory.rNr�r.)rr�r
135  �HAS_PROC_OPEN_FILESru�proc_cwdr�r	r$rrr��cwd@s���zProcess.cwd�mmaprgricCst�r!)r�r$rrr��_not_implementedUszProcess._not_implementedcCst�|j�}dd�|D�S)z8Return files opened by process as a list of namedtuples.cSsg|]
136  \}}t�||��qSr)r�	popenfile)r��pathr�rrr�r�_sz&Process.open_files.<locals>.<listcomp>)rurr�)rr�rrr��
137  open_files[szProcess.open_filescCst�|j�}tr|��|S)z=Return the number of file descriptors opened by this process.)rurr�r
138  r%r&rrr��num_fdsfszProcess.num_fdscCr6r!)ru�proc_cpu_affinity_getr�r$rrr��cpu_affinity_gettr9zProcess.cpu_affinity_getc
139  Cs�tttt����}|D]}||vrtd||f��qz
140  t�|j|�WdStyK}z|j	t	j
141  t	jfvrF|D]}||vrEtd||f��q7�d}~ww)Nz#invalid CPU #%i (choose between %s))�tupler�r�rr�ru�proc_cpu_affinity_setr�r�r�r5ZEDEADLK)r�cpus�allcpusr�r�rrr��cpu_affinity_setxs,�������zProcess.cpu_affinity_setcCr6r!)ru�proc_memory_mapsr�r$rrr��memory_maps�r9zProcess.memory_mapscCsL|durt�|j|�St|�dkrtdt|���|\}}t�|j|||�S)Nrz4second argument must be a (soft, hard) tuple, got %s)ruZproc_getrlimitr�r�r�r�Zproc_setrlimit)r�resource�limits�soft�hardrrr��rlimit�s��zProcess.rlimit)rVr!)0�__name__�
142  __module__�__qualname__�__doc__�	__slots__r"r%rrr'r*r-rJr3r2r8r>rrCrFr�r	rIrK�memory_full_infor,rNrPrMr�rZr\r_rrerhr�nt_mmap_grouped�nt_mmap_extrjrfrm�HAS_PROC_NUM_FDSrnrprurwr|rrrr�r�Ss�
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  	
154  
155  
156  
157  !
158  
159  
160  
161  
162  ��
163  
164  
165  �r�r)F)~r��
166  contextlibr�rr0�xml.etree.ElementTree�etree�ElementTreer��collectionsrrr.rrrrurr�r	r
167  rrr
rrrrrr�_compatrrrr�__extra__all__�SIDL�STATUS_IDLE�SRUN�STATUS_RUNNING�SSLEEP�STATUS_SLEEPING�SSTOP�STATUS_STOPPEDr�
STATUS_ZOMBIE�SWAIT�STATUS_WAITINGZSLOCK�
STATUS_LOCKEDraZSDEAD�
STATUS_WAKING�SONPROC�TCPS_ESTABLISHED�CONN_ESTABLISHED�
TCPS_SYN_SENT�
CONN_SYN_SENT�TCPS_SYN_RECEIVED�
CONN_SYN_RECV�TCPS_FIN_WAIT_1�CONN_FIN_WAIT1�TCPS_FIN_WAIT_2�CONN_FIN_WAIT2�TCPS_TIME_WAIT�CONN_TIME_WAIT�TCPS_CLOSED�
168  CONN_CLOSE�TCPS_CLOSE_WAIT�CONN_CLOSE_WAIT�
TCPS_LAST_ACK�
CONN_LAST_ACK�TCPS_LISTEN�CONN_LISTEN�TCPS_CLOSING�CONN_CLOSING�PSUTIL_CONN_NONE�	CONN_NONEr��getpagesize�PAGESIZE�AF_LINKr��HAS_PER_CPU_TIMESrLrfr��dictr
rLrXr_�pfullmemrcrfrhrjr�r�r�rr�r�r�r�r�r��
169  disk_usage�disk_io_countersr��net_if_addrsr�r�r�rrrrr�r
170  rr�contextmanagerr�objectr�rrrr��<module>sn�	��
171  �
172  
173  
174  
175  ��������	�
176  ���
�������������#�����	
177  	
178  
179  
180  
181  (
182  
183  
184  
185  
186