Your IP : 18.119.135.67


Current Path : /opt/cloudlinux/venv/lib64/python3.11/site-packages/psutil/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib64/python3.11/site-packages/psutil/__pycache__/_pslinux.cpython-311.pyc

�

��bg�S�
�	�dZddlmZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlmZddlmZddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddlm#Z#ddlm$Z$ddlm%Z%ddlm&Z&ddlm'Z'ddlm(Z(ddlm)Z)ddlm*Z*ddlm+Z+ddl,m-Z-dd l,m.Z.dd!l,m/Z/dd"l,m0Z0dd#l,m1Z1dd$l,m2Z2ej3d%krddl4Z4ndZ4gd&�Z5d'Z6ej7�8d(ej9��z��Z:ej7�8d)ej9��z��Z;e<ed*��Z=e<ed+��Z>ej?d,��Z@ejA��ZBdaCejDd-kZEd.ZFe4�e
jGZHn(e4jId/d0eJe
jG��i��ZKeKjHZHe4�	dZLdZMd1ZNd2ZOn5Gd3�d4e4jI��ZPeQ���RePjS��ejTejUejVejWejXejYejZejZej[ej\ej]ej^d5�Z_ej`ejaejbejcejdejeejfejgejhejiejjd6�Zked7gd8���Zled9gd:���Zmed;gd<���Zned=d>��Zoed?eojpd@z��ZqedAgdB���ZredCdDdE�serjp��z��ZtedFgdG���ZuedHgdI���ZvdJ�ZwdK�ZxdL�Zye$dM���Zz	ezdN��n1#e{$r)e
j|��edOdP��dQdQdQ��a}YnwxYwdZ~	ddRlm~Z~n1#e�$r)ddl�Z�e�j�ddS�T��Z�e<e�dU��rd}dV�Z~YnwxYwe~�(e5��dW�e�e��D����dX�Z�dY�Z�dZ�Z�d[�Z�d\�Z�d]�Z�d^�Z�d_�Z�d`�Z�ej7�8da��sej7�8db��rdc�Z�ndd�Z�ej�Z�Gde�dfe{��Z�Gdg�dh��Z�e���Z�d~dj�Z�dk�Z�dl�Z�ej�Z�ddn�Z�Gdo�dp��Z�ddq�Z�dr�Z�ds�Z�dt�Z�du�Z�dv�Z�dw�Z�dx�Z�dy�Z�dz�Z�Gd{�d|e���Z�dS)�zLinux platform implementation.�)�divisionN)�defaultdict)�
namedtuple�)�_common)�_psposix)�
_psutil_linux)�
_psutil_posix)�NIC_DUPLEX_FULL)�NIC_DUPLEX_HALF)�NIC_DUPLEX_UNKNOWN)�AccessDenied)�
NoSuchProcess)�
ZombieProcess)�bcat)�cat)�debug)�decode)�get_procfs_path)�
isfile_strict)�memoize)�memoize_when_activated)�open_binary)�	open_text)�parse_environ_block)�path_exists_strict)�
supports_ipv6)�
usage_percent)�PY3)�FileNotFoundError)�PermissionError)�ProcessLookupError)�b)�
basestring)��)�PROCFS_PATH�IOPRIO_CLASS_NONE�IOPRIO_CLASS_RT�IOPRIO_CLASS_BE�IOPRIO_CLASS_IDLE�CONN_ESTABLISHED�
CONN_SYN_SENT�
CONN_SYN_RECV�CONN_FIN_WAIT1�CONN_FIN_WAIT2�CONN_TIME_WAIT�
CONN_CLOSE�CONN_CLOSE_WAIT�
CONN_LAST_ACK�CONN_LISTEN�CONN_CLOSINGz/sys/class/power_supplyz/proc/%s/smapsz/proc/%s/smaps_rollup�proc_ioprio_get�proc_cpu_affinity_get�
SC_CLK_TCK�littlei�
AddressFamily�AF_LINK�r%c��eZdZdZdZdZdZdS)�
IOPriorityrrr=r%N)�__name__�
__module__�__qualname__r(r)r*r+���F/opt/cloudlinux/venv/lib64/python3.11/site-packages/psutil/_pslinux.pyr?r?vs&���������������rDr?)�R�S�D�T�t�Z�X�x�K�W�I�P)�01�02�03�04�05�06�07�08�09�0A�0B�svmem)�total�	available�percent�used�free�active�inactive�buffers�cached�shared�slab�sdiskio)	�
read_count�write_count�
read_bytes�write_bytes�	read_time�
write_time�read_merged_count�write_merged_count�	busy_time�	popenfile)�path�fd�position�mode�flags�pmemz"rss vms shared text lib data dirty�pfullmem)�uss�pss�swap�
pmmap_grouped)rt�rss�sizer|�shared_clean�shared_dirty�
private_clean�
private_dirty�
referenced�	anonymousr}�	pmmap_extzaddr perms � �pio)rjrkrlrm�
read_chars�write_chars�	pcputimes)�user�system�
children_user�children_system�iowaitc��t|t��s
J|���tj|��}|�d��d}|�d��rt
|��s
|dd�}|S)zWrapper around os.readlink().�r�
 (deleted)N���)�
isinstancer$�os�readlink�split�endswithr)rts rEr�r��s���d�J�'�'�-�-��-�-�'�
�;�t���D��:�:�f���a� �D��}�}�\�"�"��+=�d�+C�+C���D�S�D�z���KrDc�(�tjdtjdtjdi}||tjtjztjzz}|tjzr|�ddd��}|�dd��}|S)zZConvert file's open() flags into a readable string.
    Used by Process.open_files().
    �r�wzw+�arzr+)r��O_RDONLY�O_WRONLY�O_RDWR�O_APPEND�replace)rx�	modes_maprws   rE�file_flags_to_moder��sw����c�2�;��R�Y��E�I��U�b�k�B�K�7�"�)�C�D�E�D��r�{��)��|�|�C��a�(�(���<�<��d�#�#�D��KrDc��|�dd��}d}|rd|z}nd|z}tj|tj��S)z�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.
    �/�!Tz
/sys/block/%sz/sys/block/%s/device)r�r��access�F_OK)�name�including_virtualrts   rE�is_storage_devicer��sO���<�<��S�!�!�D����-���%���%��,��
�9�T�2�7�#�#�#rDc��td|z��5}|������dd�}ddd��n#1swxYwYgd�}t|��}|dkr|�d��|dkr|�d��|d	kr|�d
��td|��adS)z�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/statrN)r��nicer��idler��irq�softirq��steal�	�guest�
�
guest_nice�	scputimes)r�readliner��len�appendrr�)�procfs_path�f�values�fields�vlens     rE�set_scputimes_ntupler�s��
�Y��,�	-�	-�*�������#�#�%�%�a�b�b�)��*�*�*�*�*�*�*�*�*�*�*����*�*�*�*�
K�
K�
K�F��v�;�;�D��q�y�y��
�
�g�����q�y�y��
�
�g�����r�z�z��
�
�l�#�#�#��;��/�/�I�I�Is�/A�A�A�/procr�zuser system idle�)�prlimitT)�	use_errnor�c��Gd�dtj��}|��}|�0t�||dtj|����}ne|��}|d|_|d|_t�||tj|��tj|����}|dkr5tj��}t|tj
|�����|j|jfS)Nc�2�eZdZdejfdejfgZdS)�prlimit.<locals>.StructRlimit�rlim_cur�rlim_maxN)r@rArB�ctypes�
c_longlong�_fields_rCrDrE�StructRlimitr�9s+������'��):�;�'��):�;�=���rDr�rr)r��	Structure�libcr��byrefr�r��	get_errno�OSErrorr��strerror)�pid�	resource_�limitsr��current�ret�new�errno_s        rEr�r�8s���
=�
=�
=�
=�
=�v�/�
=�
=�
=�#�l�n�n�G��~��l�l�3�	�4���g�9N�9N�O�O���#�l�n�n��%�a�y���%�a�y����l�l���F�L��$5�$5�v�|�G�7L�7L�N�N���a�x�x��)�+�+���f�b�k�&�&9�&9�:�:�:��$�g�&6�7�7rDc�d�g|]-}|�d���|����+|��.S)�RLIM)�
startswith�isupper��.0rMs  rE�
<listcomp>r�Qs6��F�F�F�q����f�!5�!5�F�!�)�)�+�+�F��F�F�FrDc���|d}||�dd��z}	|d}|d}|d}n6#t$r)}td|jdz��|cYd}~Sd}~wwxYw	t	d	t��z��}n#t$r|cYSwxYwd}|5|D]U}	|	���}	|	�d
��r*|t|	�
��d��z
}�V	ddd��n#1swxYwY|tz}||z
}
||z}|t|dz|��z}|
|z
}
|
|t|d
z|��z
z
}
t|
��S)axFallback for kernels < 3.14 where /proc/meminfo does not provide
    "MemAvailable", 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

    We use this function also when "MemAvailable" returns 0 (possibly a
    kernel bug, see: https://github.com/giampaolo/psutil/issues/1915).
    In that case this routine matches "free" CLI tool result ("available"
    column).

    XXX: on recent kernels this calculation may differ by ~1.5% compared
    to "MemAvailable:", as it's calculated slightly differently.
    It is still way more realistic than doing (free + cached) though.
    See:
    * https://gitlab.com/procps-ng/procps/issues/42
    * https://github.com/famzah/linux-memavailable-procfs/issues/2
    �MemFree:�Cached:rs
Active(file):sInactive(file):�
SReclaimable:zY%r is missing from /proc/meminfo; using an approximation for calculating available memoryNz%s/zoneinfoslowrr=g@)
�get�KeyErrorr�argsrr�IOError�stripr��intr��PAGESIZE�min)�memsrb�fallback�lru_active_file�lru_inactive_file�slab_reclaimable�errr��
watermark_low�line�avail�	pagecaches            rE�calculate_avail_vmemr�Ys��<���D��d�h�h�z�1�-�-�-�H���/�0�� �!3�4��� 0�1��������
�1�36�8�A�;�?�	@�	@�	@������������������
��(9�(9�9�:�:�����������������M�	
�6�6��	6�	6�D��:�:�<�<�D����v�&�&�
6���T�Z�Z�\�\�!�_�!5�!5�5�
��	6�6�6�6�6�6�6�6�6�6�6�6����6�6�6�6�
�X��M��=� �E��"3�3�I�
��Y��]�M�2�2�2�I�	�Y��E�	�
��$4�s�$:�M� J� J�
J�J�E��u�:�:�s@�<�
A/�A*�$A/�*A/�3B�B!� B!�(AD�D�Dc
���g}i}tdt��z��5}|D]7}|���}t|d��dz||d<�8	ddd��n#1swxYwY|d}|d}	|d}n'#t$rd}|�d	��YnwxYw	|d
}||�dd��z
}n'#t$rd}|�d��YnwxYw	|d
}	nA#t$r4	|d}	n'#t$rd}	|�d��YnwxYwYnwxYw	|d}
n'#t$rd}
|�d��YnwxYw	|d}nS#t$rF	|d|dz|dz}n'#t$rd}|�d��YnwxYwYnwxYw	|d}n#t$rd}YnwxYw||z
|z
|z
}
|
dkr||z
}
	|d}|dkrt|��}n#t$rt|��}YnwxYw|dkrd}|�d��n||kr|}t||z
|d���}|rLd�	|���dt|��dkrdnd�d�}tj|td �!��t||||
||
||||	|��S)"a8Report virtual memory stats.
    This implementation mimicks procps-ng-3.3.12, aka "free" CLI tool:
    https://gitlab.com/procps-ng/procps/blob/
        24fd2605c51fccc375ab0287cec33aa767f06718/proc/sysinfo.c#L778-791
    The returned values are supposed to match both "free" and "vmstat -s"
    CLI tools.
    �
%s/meminfor�rNs	MemTotal:r�sBuffers:rer�r�rfsShmem:s
MemShared:rgsActive:rcs	Inactive:sInact_dirty:sInact_clean:sInact_laundry:rdsSlab:s
MemAvailable:r_��round_�, z) memory stats couldn't be determined and �was�werez	 set to 0r=��
stacklevel)rrr�r�r�r�r�r�r�joinr��warnings�warn�RuntimeWarningr])�missing_fieldsr�r�r�r�r^rbrerfrgrcrdrhrar�r`�msgs                 rE�virtual_memoryr�sl���N�
�D�	�\�O�$5�$5�5�	6�	6�4�!��	4�	4�D��Z�Z�\�\�F�!�&��)�n�n�t�3�D����O�O�	4�4�4�4�4�4�4�4�4�4�4�4����4�4�4�4�
���E����D�)��{�#�����)�)�)������i�(�(�(�(�(�)����0��j�!��	�$�(�(�+�Q�/�/�/�����(�(�(������h�'�'�'�'�'�(����,��i������,�,�,�	,��-�(�F�F���	,�	,�	,��F��!�!�(�+�+�+�+�+�	,������,����(��j�!�����(�(�(������h�'�'�'�'�'�(����
.���%�����.�.�.�	.��_�%��_�%�&��&�'�(�
�H���	.�	.�	.��H��!�!�*�-�-�-�-�-�	.������
.������H�~�����������������4�<�&� �7�*�D��a�x�x��t�|��
/��%�&���A�:�:�
)��.�.�E����+�+�+�$�T�*�*����+����
�q�y�y������k�*�*�*�*�	�������U�U�]�U�1�=�=�=�G��9��I�I�n�%�%�%�%���(�(�A�-�-�E�E�6�9�9�;��	�
�c�>�a�8�8�8�8����w��d���7�F�F�D�B�B�Bs��;A+�+A/�2A/�B�!B4�3B4�8C�!C>�=C>�D�
E	�D�E	�!E�E	�E�E	�E	�
E�!E:�9E:�>F�
G�F-�,G�-!G�G�G�G�G�G$�$G3�2G3�
H+�+I�Ic�L�i}tdt��z��5}|D]7}|���}t|d��dz||d<�8	ddd��n#1swxYwY	|d}|d}n5#t$r(tj��\}}}}}}}||z}||z}YnwxYw||z
}t||d���}		td	t��z��}|5dx}
}|D]�}|�d
��r/t|�d��d��dzdz}
nC|�d
��r.t|�d��d��dzdz}|
�|�n#��d}tj
|td���dx}
}ddd��n#1swxYwYnI#t$r<}
dt|
��z}tj
|td���dx}
}Yd}
~
nd}
~
wwxYwtj||||	|
|��S)zReturn swap memory metrics.r�rr�rNs
SwapTotal:s	SwapFree:r�z	%s/vmstatspswpin� r&spswpoutzK'sin' and 'sout' swap memory stats couldn't be determined and were set to 0r=rzP'sin' and 'sout' swap memory stats couldn't be determined and were set to 0 (%s))rrr�r�r��cext�
linux_sysinforr�rrr	r��strr�sswap)r�r�r�r�r^rb�_�unit_multiplierrar`�sin�soutrr�s              rE�swap_memoryrs���
�D�	�\�O�$5�$5�5�	6�	6�4�!��	4�	4�D��Z�Z�\�\�F�!�&��)�n�n�t�3�D����O�O�	4�4�4�4�4�4�4�4�4�4�4�4����4�4�4�4� ��]�#���L�!����� � � �37�3E�3G�3G�0��1�a��E�4��
�� �������� ����
�4�<�D��D�%��2�2�2�G����o�&7�&7�7�8�8���	�	���C�$��
�
���?�?�9�-�-�?��d�j�j��.�.�q�1�2�2�Q�6��=�C�C��_�_�Z�0�0�?��t�z�z�$�/�/��2�3�3�a�7�$�>�D��?�t�'7��E��
8���
�c�>�a�@�@�@�@����d�%	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�������5�7:�3�x�x�@���
�c�>�a�8�8�8�8����d�d�d�d�d�d���������4�=���d�G�S�$�?�?�?sN�;A)�)A-�0A-�5B�/B8�7B8�G�3B9F8�8F<�?F<�
H
�2H�H
c�N�t��}t|��td|z��5}|������}ddd��n#1swxYwY|dttj��dz�}d�|D��}t
|�S)z�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.
    r�Nrc�<�g|]}t|��tz��SrC��float�CLOCK_TICKSr�s  rEr�zcpu_times.<locals>.<listcomp>Ts#��
5�
5�
5��e�A�h�h��$�
5�
5�
5rD)rr�rr�r�r�r��_fields)r�r�r�r�s    rE�	cpu_timesrHs���"�#�#�K���%�%�%�	�Y��,�	-�	-�&�������#�#�%�%��&�&�&�&�&�&�&�&�&�&�&����&�&�&�&�
�A�c�)�+�,�,�q�0�0�
1�F�
5�
5�f�
5�
5�
5�F��f��s�'A#�#A'�*A'c��t��}t|��g}td|z��5}|���|D]y}|�d��rb|���}|dt
tj��dz�}d�|D��}t|�}|�	|���z|cddd��S#1swxYwYdS)zfReturn a list of namedtuple representing the CPU times
    for every CPU available on the system.
    r�scpurc�<�g|]}t|��tz��SrCrr�s  rEr�z!per_cpu_times.<locals>.<listcomp>fs#��A�A�A�Q�%��(�(�[�0�A�A�ArDN)
rr�rr�r�r�r�r�rr�)r��cpusr�r�r�r��entrys       rE�
per_cpu_timesr#Xs%��"�#�#�K���%�%�%�
�D�	�Y��,�	-�	-�
��	�
�
�����	#�	#�D����v�&�&�
#���������#�i�&7�"8�"8�1�"<� <�=��A�A�&�A�A�A��!�6�*�����E�"�"�"���
�
�
�
�
�
�
�
�
�
�
�
����
�
�
�
�
�
s�BC�C�Cc�N�	tjd��S#t$�rd}tdt	��z��5}|D].}|����d��r|dz
}�/	ddd��n#1swxYwY|dkr�tjd��}tdt	��z��5}|D]7}|�
d	��d}|�|��r|dz
}�8	ddd��n#1swxYwY|dkrYdS|cYSwxYw)
z0Return the number of logical CPUs in the system.�SC_NPROCESSORS_ONLNr�
%s/cpuinfos	processorrNzcpu\dr�r�)r��sysconf�
ValueErrorrr�lowerr��re�compilerr��match)�numr�r��searchs    rE�cpu_count_logicalr/ls�����z�/�0�0�0��������
���(9�(9�9�
:�
:�	�a��
�
���:�:�<�<�*�*�<�8�8���1�H�C��
�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	��!�8�8��Z��)�)�F��9��'8�'8�8�9�9�
!�Q��!�!�D��:�:�c�?�?�1�-�D��|�|�D�)�)�!��q����!�
!�
!�
!�
!�
!�
!�
!�
!�
!�
!�
!����
!�
!�
!�
!��!�8�8��4�4��
�
�
�-���s]��+D$�2B�4D$�B	�D$�B	�;D$�;D�?D$�D	�D$�D	�	D$�D$�#D$c�P�t��}d}d}tj|��ptj|��D]b}t|��5}|�|��������ddd��n#1swxYwY�ct
|��}|dkr|Si}i}tdt��z��5}|D]�}|������}|s&	|d||d<n#t$rYnwxYwi}�P|�
d��r+|�d	d
��\}	}
t|
��||	<��	ddd��n#1swxYwYt|�����}|pdS)z-Return the number of CPU cores in the system.z9/sys/devices/system/cpu/cpu[0-9]*/topology/core_cpus_listz?/sys/devices/system/cpu/cpu[0-9]*/topology/thread_siblings_listNrr&�	cpu cores�physical id)r2r1s	:r)�set�globr�add�readr�r�rr)r�r�r�r��sumr�)�ls�p1�p2rtr��result�mapping�current_infor��key�values           rE�cpu_count_coresr@�s0��

���B�
E�B�	J�B��	�"�
�
�.���2���%�%��
��
�
�	%�!��F�F�1�6�6�8�8�>�>�#�#�$�$�$�	%�	%�	%�	%�	%�	%�	%�	%�	%�	%�	%����	%�	%�	%�	%��
��W�W�F�
��{�{��
��G��L�	�\�O�$5�$5�5�	6�	6�3�!��	3�	3�D��:�:�<�<�%�%�'�'�D��
3��$�\�2��L��8�9�9�������D�����!����?�?�#A�B�B�3�!%���F�A�!6�!6�J�C��(+�E�
�
�L��%��	3�3�3�3�3�3�3�3�3�3�3�3����3�3�3�3�"����!�!�
"�
"�F��>�T�sI�:B�B	�B	�-E8�D�E8�
D$�!E8�#D$�$AE8�8E<�?E<c�2�tdt��z��5}d}d}d}|D]�}|�d��r(t|���d��}ny|�d��r(t|���d��}n<|�d��r't|���d��}|�|�|�n��ddd��n#1swxYwYd}tj||||��S)z*Return various CPU stats as a named tuple.r�Nsctxtrsintrssoftirqr)rrr�r�r�r�	scpustats)r��ctx_switches�
interrupts�soft_interruptsr��syscallss      rE�	cpu_statsrG�sR��	�Y��!2�!2�2�	3�	3�
�q����
����		�		�D����w�'�'�
7�"�4�:�:�<�<��?�3�3�������)�)�
7� ������a��1�1�
�
�����,�,�
7�"%�d�j�j�l�l�1�o�"6�"6���'�O�,G�"�.����
�
�
�
�
�
�
�
�
�
�
����
�
�
�
��H����j�/�8�=�=�=s�C
C5�5C9�<C9c
�H�g}tdt��z��5}|D]e}|����d��r<|�t|�dd��d�����f	ddd��n#1swxYwY|S)z<Return current CPU frequency from cpuinfo if available.
    r&scpu mhz�:rN)rrr)r�r�rr�)r�r�r�s   rE�_cpu_get_cpuinfo_freqrJ�s���
�C�	�\�O�$5�$5�5�	6�	6�:�!��	:�	:�D��z�z�|�|�&�&�z�2�2�
:��
�
�5����D�!�!4�!4�Q�!7�8�8�9�9�9��	:�:�:�:�:�:�:�:�:�:�:�:����:�:�:�:��Js�A)B�B�Bz'/sys/devices/system/cpu/cpufreq/policy0z$/sys/devices/system/cpu/cpu0/cpufreqc	��t��}tjd��ptjd��}|�d����g}tjj}t
|��D�]\}}t|��t|��kr||dz}nt||d��d���}|�,t||d	��d���}|�td
���t|��dz}tt||d������dz}tt||d������dz}|�tj
|||������
|S)
z�Return frequency metrics for all CPUs.
        Contrarily to other OSes, Linux updates these values in
        real-time.
        z,/sys/devices/system/cpu/cpufreq/policy[0-9]*z)/sys/devices/system/cpu/cpu[0-9]*/cpufreqc�j�ttjd|�������S)Nz[0-9]+)r�r*r.�group)rMs rE�<lambda>zcpu_freq.<locals>.<lambda>�s&���R�Y�y�!�%<�%<�%B�%B�%D�%D�!E�!E�rD)r>i��scaling_cur_freqN�r��cpuinfo_cur_freqz!can't find current frequency file�scaling_max_freq�scaling_min_freq)rJr4�sortr�rtr�	enumerater�r�NotImplementedErrorr�r�r�scpufreq)	�
cpuinfo_freqs�pathsr��pjoin�irt�curr�max_�min_s	         rE�cpu_freqr_�s���
.�/�/�
��I�D�E�E�
C��I�A�B�B�	�	�
�
�E�E�
�F�F�F������� ��'�'�	;�	;�G�A�t��5�z�z�S��/�/�/�/�%�Q�'�$�.����E�E�$�(:�;�;�d�K�K�K���|��E�E�$�(:�;�;�d�K�K�K���<�-�;�=�=�=��t�9�9�t�#�D��t�E�E�$�(:�;�;�<�<�=�=��D�D��t�E�E�$�(:�;�;�<�<�=�=��D�D��J�J�w�'��d�D�9�9�:�:�:�:��
rDc�2�d�t��D��S)z}Alternate implementation using /proc/cpuinfo.
        min and max frequencies are not available and are set to None.
        c�:�g|]}tj|dd����S)r�)rrWr�s  rEr�zcpu_freq.<locals>.<listcomp>�s'��M�M�M��� ��B��+�+�M�M�MrD)rJrCrDrEr_r_�s ��N�M�5J�5L�5L�M�M�M�MrDc��eZdZdS)�_Ipv6UnsupportedErrorN)r@rArBrCrDrErcrcs�������DrDrcc�r�eZdZdZd�Zd�Zd�Zed���Zed
d���Z	ed
d���Z
d
d	�ZdS)�ConnectionsawA 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�L�dtjtjf}dtjtjf}dtjtjf}dtjtjf}dtjdf}|||||f||f|f|f||f|f|f|f||||f||f||fd�|_d|_dS)N�tcp�tcp6�udp�udp6�unix)�allrg�tcp4rhri�udp4rjrk�inet�inet4�inet6)�socket�AF_INET�SOCK_STREAM�AF_INET6�
SOCK_DGRAM�AF_UNIX�tmap�_procfs_path)�selfrmrhrnrjrks      rE�__init__zConnections.__init__s����v�~�v�'9�:������);�<���v�~�v�'8�9������):�;������-���$��d�D�1��$�<��G��G��$�<��G��G��G��4��t�,��D�\��D�\�
�
��	�!����rDc��tt��}tj|j�d|�d���D]�}	t|j�d|�d|����}|�d��r<|dd�dd�}||�|t|��f���q#ttf$rY��t$rI}|jtj
krYd}~��|jtjkrt|��Yd}~�Ђd}~wwxYw|S)Nr��/fd�/fd/zsocket:[r����)r�listr��listdirryr�r�r�r�r r"r��errno�EINVAL�ENAMETOOLONGr)rzr��inodesru�inoder�s      rE�get_proc_inodeszConnections.get_proc_inodes,s<���T�"�"���*�4�+<�+<�+<�c�c�c�B�C�C�	9�	9�B�
9� �$�2C�2C�2C�S�S�S�"�"�!M�N�N�� �#�#�J�/�/�9�!�!�"�"�I�c�r�c�N�E��5�M�(�(�#�s�2�w�w��8�8�8���%&�'9�:�
�
�
����
�
�
��9���,�,��H�H�H�H��9�� 2�2�2��#�J�J�J��H�H�H�H������
�����
s)�B%�%D
�8	D
�D�$D�D�D
c��i}t��D]H}	|�|�|�����,#ttt
f$rY�EwxYw|S�N)�pids�updater�r r"r!)rzr�r�s   rE�get_all_inodeszConnections.get_all_inodesFss�����6�6�	�	�C�

��
�
�d�2�2�3�7�7�8�8�8�8��%�'9�?�K�
�
�
���
�����
s�(=�A�Ac
�(�|�d��\}}t|d��}|sdStr|�d��}|tjkr`tr1t	j|tj	|��ddd���}n�t	j|tj	|����}n�tj	|��}	trCt	jtj
tjdgtj
d|���R���}nBt	jtj
tjdgtj
d|���R���}n$#t$rt��st ��wxYwt#j||��S)	a�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
        �:�rC�asciiNrz>4Iz<4I)r�r�r�encoderrrs�
LITTLE_ENDIAN�	inet_ntop�base64�	b16decoderu�struct�pack�unpackr(rrcr�addr)r��family�ip�ports    rE�decode_addresszConnections.decode_addressVs���"�:�:�c�?�?���D��4��}�}���	��2��	$����7�#�#�B��V�^�#�#��
D��%�f�f�.>�r�.B�.B�4�4�R�4�.H�I�I����%�f�f�.>�r�.B�.B�C�C����!�"�%�%�B�
� �G��)�����E�E�F�M�%��,D�,D�E�E�E�G�G�B�B� �)�����E�E�F�M�%��,D�,D�E�E�E�G�G�B����
�
�
�$����/�/��
�����|�B��%�%�%s
�BE�!E<Nc#�K�|�d��r!tj�|��sdSt	|��5}|���t
|d��D]�\}}	|���dd�\
}}	}
}}}}}}}n&#t$rtd|�d|�d|�����wxYw||vr||d\}
}nd	\}
}|�||
kr�x|tjkrt|}ntj}	t�|	|��}	t�|
|��}
n#t"$rY��wxYw||||	|
||
fV���	ddd��dS#1swxYwYdS)
z.Parse /proc/net/tcp* and /proc/net/udp* files.�6Nrr��error while parsing �; malformed line r�r�Nr)r�r�rt�existsrr�rUr�r(�RuntimeErrorrrrt�TCP_STATUSESr�	CONN_NONErer�rc)�filer��type_r��
filter_pidr��linenor�r�laddr�raddr�statusr�r�rus               rE�process_inetzConnections.process_inet�s.�����=�=����	�b�g�n�n�T�&:�&:�	��F�
�t�_�_� 	I��
�J�J�L�L�L� )�!�Q���
I�
I����1��
�
���S�b�S�)�B�A�u�e�V�Q��1�a��E�E��!�1�1�1�&�,� �D�D�&�&�&�$�$�0�1�1�1�1�����F�?�?�%�U�m�A�.�G�C���&�G�C���)�j�C�.?�.?���� 2�2�2�!-�f�!5���!(�!2��!� +� :� :�5�&� I� I�� +� :� :�5�&� I� I����0�!�!�!� ��!�����v�u�e�U�F�C�H�H�H�H�H�=
I� 	I� 	I� 	I� 	I� 	I� 	I� 	I� 	I� 	I� 	I� 	I� 	I���� 	I� 	I� 	I� 	I� 	I� 	IsO�*E1�3'B�E1�#B>�>AE1�6E�E1�
E�E1�E�E1�1E5�8E5c
#�"K�t|��5}|���|D]�}|���}	|dd�\}}}}}}}	n)#t$rd|vrY�:t	d|�d|�����wxYw|	|vr	||	}
ndg}
|
D]f\}}|�||kr�t|��dkr	|d	}
nd
}
t
jt|����}d
}tj	}||||
|||fV��g��	ddd��dS#1swxYwYdS)zParse /proc/net/unix files.r�r�r�r�r�Nr�r�)
rr�r�r(r�r�r�socktype_to_enumr�r�)r�r�r�r�r�r��tokensrr�r��pairsr�rurtr�r�s                rE�process_unixzConnections.process_unix�s������t�_�_�!	L��
�J�J�L�L�L��
L�
L��������)�28��1��+�/�A�q�!�Q��q�%�%��!�)�)�)��$��� ��&�,� �D�D�$�$�(�)�)�)�	)�����F�?�?�#�5�M�E�E�'�L�E�$�L�L�G�C��!�-�*��2C�2C� ��v�;�;�!�+�+�#)�"�:�D�D�#%�D� '� 8��U��� D� D��!#��!(�!2��!�6�5�$��v�s�K�K�K�K�K�L�#
L�!	L�!	L�!	L�!	L�!	L�!	L�!	L�!	L�!	L�!	L�!	L�!	L����!	L�!	L�!	L�!	L�!	L�!	Ls6�-D�A�D�A9�!D�#A9�9A=D�D�Dc���||jvr7td|�dd�d�|jD���������t��|_|�|�|��}|sgSn|���}t��}|j|D]�\}}}|j�d|��}|tj	tj
fvr|�|||||���}	n|�||||���}	|	D]U\}
}}}}}
}|rtj|
|||||
��}ntj|
|||||
|��}|�|���V��t#|��S)Nzinvalid z kind argument; choose between rc�,�g|]}t|����SrC)�reprr�s  rEr�z(Connections.retrieve.<locals>.<listcomp>�s��0L�0L�0L�Q��a���0L�0L�0LrDz/net/)r�)rxr(rrryr�r�r3rrrsrur�r�r�pconn�sconnr5r�)rz�kindr�r�r��
proto_namer�r�rtr8rur�r�r��	bound_pid�conns                rE�retrievezConnections.retrieve�s����t�y� � ��*� $���d�i�i�0L�0L�$�)�0L�0L�0L�&M�&M�&M�O�P�P�
P�+�-�-����?��)�)�#�.�.�F��
��	�
��(�(�*�*�F��e�e��)-��4��	�	�%�J���"&�"3�"3�"3�Z�Z�@�D��&�.�&�/�:�:�:��&�&��&�%��C�'�A�A����&�&��&�&�S�'�:�:��FH�
�
�B��F�E�5�%����<�"�=��V�U�E�5�)/�1�1�D�D�#�=��V�U�E�5�)/��<�<�D�����
�
�
�
�
��C�y�y�rDr�)r@rArB�__doc__r{r�r��staticmethodr�r�r�r�rCrDrErere	s�������	�	�!�!�!�.���4��� �0&�0&��\�0&�d�%I�%I�%I��\�%I�N�#L�#L�#L��\�#L�J�����rDreroc�6�t�|��S)z$Return system-wide open connections.)�_connectionsr�)r�s rE�net_connectionsr��s��� � ��&�&�&rDc��tdt��z��5}|���}ddd��n#1swxYwYi}|dd�D]�}|�d��}|dksJt	|�����|d|����}||dzd�������}tt|��\}}}	}
}}}
}}}}}}}}}|||||	||
|f||<��|S)zsReturn network I/O statistics for every network interface
    installed on the system as a dict of raw tuples.
    z
%s/net/devNr=r�rr)	rr�	readlines�rfindr�r�r��mapr�)r��lines�retdictr��colonr�r��
bytes_recv�packets_recv�errin�dropin�fifoin�framein�compressedin�multicastin�
bytes_sent�packets_sent�errout�dropout�fifoout�
collisionsout�
carrierout�
compressedouts                       rE�net_io_countersr��sj��
�<�/�"3�"3�3�	4�	4������
�
���������������������G��a�b�b�	�9�9���
�
�3�����q�y�y�y�$�t�*�*�y�y�y��F�U�F�|�!�!�#�#���e�a�i�j�j�!�'�'�)�)�/�/�1�1��&�c�6�*�*�!	��	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�#�Z��|�����9���
�
��Ns�A�A�Ac�*�tjttjttjti}t�����}i}|D]�}	tj
|��}tj|��}tj|��\}}d�
|��}d|v}	tj|	|||||��||<�}#t $r/}
|
jt"jkr�t'|
��Yd}
~
��d}
~
wwxYw|S)z)Get NIC stats (isup, duplex, speed, mtu).�,�runningN)r�DUPLEX_FULLr�DUPLEX_HALFr�DUPLEX_UNKNOWNr
r��keys�
cext_posix�
net_if_mtu�net_if_flags�net_if_duplex_speedrr�	snicstatsr�r��ENODEVr)�
duplex_map�namesr�r��mturx�duplex�speed�output_flags�isupr�s           rE�net_if_statsr�$s���"�O��"�O��%�'9�;�J�
���"�"�$�$�E�
�C��8�8��	8��'��-�-�C��+�D�1�1�E� �4�T�:�:�M�F�E��8�8�E�?�?�L���%�D��)�$�
�6�0B�E�3�*6�8�8�C��I�I���	�	�	��y�E�L�(�(���c�
�
�
�
�
�
�
�
�����	�����Js�?C�
D�!%D�DFc��d�}d�}tj�dt��z��r|��}nHtj�d��r|��}nt	dt��z���i}|D]C}|\
}}}}	}
}}}
}}|st|��s�!|	tz}	|
tz}
|||	|
|||
||f	||<�D|S)zcReturn disk I/O statistics for every disk installed on the
    system as a dict of raw tuples.
    c3�K�tdt��z��5}|���}ddd��n#1swxYwY|D�]}|���}t	|��}|dkrF|d}t|d��}t
t
|dd���\
}}}	}
}}}
}}}n�|dks|dkr2|d}t
t
|dd���\}}}}	}
}}}
}}}nM|dkr5|d}t
t
|dd���\}}}
}d	x}	x}
x}x}}ntd
|z���|||
|||	|
|||f
V���
dS)N�%s/diskstats�r%r=r&��r�rz!not sure how to interpret line %r)rrr�r�r�r�r�r()r�r�r�r��flenr��reads�reads_merged�rbytes�rtime�writes�
writes_merged�wbytes�wtimerrrs                rE�read_procfsz%disk_io_counters.<locals>.read_procfsJs�����"�~��(9�(9�9�
:�
:�	"�a��K�K�M�M�E�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"����	"�	"�	"�	"��	;�	;�D��Z�Z�\�\�F��v�;�;�D��r�z�z��a�y���F�1�I����69�#�v�a��d�|�6L�6L�4��v�u�f�m��E�1�i�������t�r�z�z��a�y��69�#�v�a��d�|�6L�6L�4���f�e�V�]��E�1�i��������a�y��03�C������0D�0D�-��v�v�v�KL�L��L��L��L�}�y�y� �!D�t�!K�L�L�L�������u���	�;�
;�
;�
;�
;�+	;�	;s�A�A�	Ac3�\K�tjd��D�]}tjtj�d|����D]�\}}}d|vr�ttj�|d����5}|���������}ddd��n#1swxYwYtj�	|��}tt|dd���\
}}}	}
}}}
}}}||||	|
|
||||f
V��ސ�dS)N�
/sys/block�statr�)r�r��walkrtrrr6r�r��basenamer�r�)�block�rootr�filesr�r�r�r�r�r�r�r�r�r�rrrs                rE�
read_sysfsz$disk_io_counters.<locals>.read_sysfsus}�����Z��-�-�
	F�
	F�E�"$�'�"�'�,�,�|�U�*K�*K�"L�"L�	
F�	
F���a����&�&���r�w�|�|�D�&�9�9�:�:�6�a��V�V�X�X�^�^�-�-�3�3�5�5�F�6�6�6�6�6�6�6�6�6�6�6����6�6�6�6��w�'�'��-�-��36�s�F�3�B�3�K�3H�3H�1���f�e�V�]��E�1�i��U�F�F�F�E��l�M�9�F�F�F�F�F�	
F�
	F�
	Fs�9C	�	C
�C
r�rzC%s/diskstats nor /sys/block filesystem are available on this system)r�rtr�rrVr��DISK_SECTOR_SIZE)�perdiskrr
�genr�r"r�r�r�r�r�r�rr�r�rrs                rE�disk_io_countersrFs-��);�);�);�VF�F�F�
�w�~�~�n��'8�'8�8�9�9�*��k�m�m���	�����	%�	%�*��j�l�l���!�
�&�(�(�
)�*�*�	*��G��A�A��(-�	&��u�f�f�f�e�U�L��9��	�0��6�6�	�
��"�"���"�"�������u�%�}�i�A���
�
��NrDc�8�eZdZdZddgZd�Zd�Zd�Zd�Zd�Z	d	S)
�RootFsDeviceFinderaEdisk_partitions() may return partitions with device == "/dev/root"
    or "rootfs". This container class uses different strategies to try to
    obtain the real device path. Resources:
    https://bootlin.com/blog/find-root-device/
    https://www.systutorials.com/how-to-find-the-disk-where-root-is-on-in-bash-on-linux/
    �major�minorc��tjd��j}tj|��|_tj|��|_dS�Nr�)r�r�st_devrr)rz�devs  rEr{zRootFsDeviceFinder.__init__�s4���g�c�l�l�!���X�c�]�]��
��X�c�]�]��
�
�
rDc�.�tdt��z��5}|���dd�D]�}|���}t	|��dkr�*|d���rt
|d��nd}|d���rt
|d��nd}|d}||jkr ||jkr|rd|zccddd��S��	ddd��dS#1swxYwYdS)Nz
%s/partitionsr=r&rrr%�/dev/%s)	rrr�r�r��isdigitr�rr)rzr�r�r�rrr�s       rE�ask_proc_partitionsz&RootFsDeviceFinder.ask_proc_partitions�sq��
���):�):�:�
;�
;�
	0�q����
�
�a�b�b�)�	
0�	
0���������v�;�;��?�?��*0��)�*;�*;�*=�*=�G��F�1�I����4��*0��)�*;�*;�*=�*=�G��F�1�I����4���a�y���D�J�&�&�5�D�J�+>�+>��0�(�4�/�/�/�
	0�
	0�
	0�
	0�
	0�
	0�
	0�
	0��	
0�
	0�
	0�
	0�
	0�
	0�
	0�
	0�
	0�
	0�
	0�
	0�
	0����
	0�
	0�
	0�
	0�
	0�
	0s�CD
�;D
�
D�Dc�6�d|j�d|j�d�}t|��5}|D]Y}|�d��rB|����d��d}|rd|zccddd��S�Z	ddd��dS#1swxYwYdS)Nz/sys/dev/block/r�z/ueventzDEVNAME=r=r)rrrr�r��
rpartition)rzrtr�r�r�s     rE�ask_sys_dev_blockz$RootFsDeviceFinder.ask_sys_dev_block�s���04�
�
�
�D�J�J�J�G��
�t�_�_�	0���
0�
0���?�?�:�.�.�0��:�:�<�<�2�2�:�>�>�q�A�D��0�(�4�/�/�/�	0�	0�	0�	0�	0�	0�	0�	0��
0�	0�	0�	0�	0�	0�	0�	0�	0�	0�	0�	0�	0����	0�	0�	0�	0�	0�	0s�AB�?B�B�Bc���|j�d|j��}tjd��}|D]�}	t	|��}|5|������}||krOtj�	tj�
|����}d|zcddd��cS	ddd��n#1swxYwY��#t$rY��wxYwdS)Nr�z/sys/class/block/*/devr)rrr4�iglobrr6r�r�rtr�dirnamer )rz�needler	r�r��datar�s       rE�ask_sys_class_blockz&RootFsDeviceFinder.ask_sys_class_block�sO�� �J�J�J��
�
�3���
�3�4�4���
	0�
	0�D�	
0��d�O�O���0�0��6�6�8�8�>�>�+�+�D��v�~�~�!�w�/�/������0E�0E�F�F��(�4�/�	0�0�0�0�0�0�0�0�0�0�%�0�0�0�0�0�0�0�0�0�0�0����0�0�0�0���%�
�
�
���
����
	0�
	0s#�C�A-C�C		�C		�
C�Cc���d}|�C	|���}n-#ttf$r}t|��Yd}~nd}~wwxYw|�C	|���}n-#ttf$r}t|��Yd}~nd}~wwxYw|�C	|���}n-#ttf$r}t|��Yd}~nd}~wwxYw|�!tj�|��r|SdSdSr�)	rr�r�rrr#r�rtr�)rzrtr�s   rE�findzRootFsDeviceFinder.find�s7�����<�
��/�/�1�1�����W�%�
�
�
��c�
�
�
�
�
�
�
�
�����
�����<�
��-�-�/�/�����W�%�
�
�
��c�
�
�
�
�
�
�
�
�����
�����<�
��/�/�1�1�����W�%�
�
�
��c�
�
�
�
�
�
�
�
�����
����������t� 4� 4���K����sD��A�A�A�A � B
�1B�B
�B%�%C�6C
�
CN)
r@rArBr��	__slots__r{rrr#r%rCrDrErr�su���������'�"�I�#�#�#�
0�0�0�0�0�0�
0�
0�
0�����rDrc	��t��}t��}|s�td|z��5}|D]�}|���}|�d��s(|�|������S|�d��d}|dkr|�d����	ddd��n#1swxYwY|dkr?tj�	d��r tj�
d��}n"tj�
d	|z��}g}tj|��}|D]v}	|	\}
}}}|
d
krd}
|
dvr"t�����p|
}
|s|
dks||vr�Ddx}
}tj|
||||
|��}|�|���w|S)
z8Return mounted disk partitions as a list of namedtuples.z%s/filesystems�nodev�	r�zfsNr�z	/etc/mtabz%s/self/mounts�noner�)z	/dev/root�rootfs)r3rrr�r�r5r�r�rt�isfile�realpathr�disk_partitionsrr%r�	sdiskpartr�)rl�fstypesr�r�r��fstype�mounts_path�retlist�
partitions�	partition�device�
mountpoint�opts�maxfile�maxpath�ntuples                rEr/r/�s'���e�e�G�!�#�#�K��
+�
�'�+�5�
6�
6�		+�!��
+�
+���z�z�|�|�����w�/�/�+��K�K��
�
���-�-�-�-�"�Z�Z��-�-�a�0�F��������E�*�*�*��
+�		+�		+�		+�		+�		+�		+�		+�		+�		+�		+�		+����		+�		+�		+�		+��g���"�'�.�.��"=�"=���g�&�&�{�3�3����g�&�&�'7�+�'E�F�F���G��%�k�2�2�J����	�+4�(��
�F�D��V����F��,�,�,�'�)�)�.�.�0�0�:�F�F��	���|�|�v�W�4�4�� � ��'��"�6�:�v�t�#*�G�5�5�����v������Ns�B
C�C�Cc	�8	�tjt��}tjd��}|�tjd����tt
d�|D������}tjd��}tjd��}|D]1}|�	d|��}||vr|�
|���2|D�]a}	|dz}tt|����dz}tj�tj�|��d	��}t#|�����}	n#t&t(t*f$rY��wxYwt|d
zd���}
t|d
zd���}t#|dzd������}|
�&	t|
��dz}
n#t*$rd}
YnwxYw|�&	t|��dz}n#t*$rd}YnwxYw||	�
|||
|f����c|�sNtjd��}tt
|����}|D�]}	tj�|d��}tt|����dz}tj�|d��}t#|�����}	n3#t&t(t*f$r}
t-|
��Yd}
~
��d}
~
wwxYwtj|dz��}t
d�|D����}d}d}
|D�]}tj�||dz��}t#|d������}|dkr3ttj�||dz��d���}n8|dkr2ttj�||dz��d���}
|
�&	t|
��dz}
n#t*$rd}
YnwxYw|�'	t|��dz}��#t*$rd}Y��wxYw��
||	�
d||
|f����t/|��S)a�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
    z/sys/class/hwmon/hwmon*/temp*_*z&/sys/class/hwmon/hwmon*/device/temp*_*c�D�g|]}|�d��d��S�rr�r�r�s  rEr�z(sensors_temperatures.<locals>.<listcomp>0�&��?�?�?��A�G�G�C�L�L��O�?�?�?rDz5/sys/devices/platform/coretemp.*/hwmon/hwmon*/temp*_*z'/sys/devices/platform/coretemp.*/hwmon/z/sys/class/hwmon/�_inputg@�@r��_maxNrP�_crit�_labelr�z /sys/class/thermal/thermal_zone*�temp�typez/trip_point*c��g|]O}d�tj�|���d��dd�����PS)rrr%)rr�rtrr�)r��ps  rEr�z(sensors_temperatures.<locals>.<listcomp>psf��J�J�J�9:� #�x�x��� � ��#�#�)�)�#�.�.�q��s�3� 5� 5�J�J�JrD�_type�critical�_temp�high)�collectionsrr�r4�extend�sortedr3r*r+�subr�rrr�rtrr rr�r�r�r(r�dict)r��	basenames�
basenames2�replr��altname�basertr��	unit_namerMrK�labelr��
trip_paths�trip_points�
trip_point�	trip_types                  rE�sensors_temperaturesr^s���
!�$�
'�
'�C��	�;�<�<�I����T�Y�G�H�H�I�I�I��s�?�?�Y�?�?�?�@�@�A�A�I���?�A�A�J�
�:�?�@�@�D��#�#���(�(�.��5�5���)�#�#����T�"�"�"��� @� @��	��(�?�D��D��J�J�'�'�&�0�G��7�<�<������ 5� 5�v�>�>�D��D�	�	���)�)�I�I����*�-�		�		�		�
�H�		�����D�6�M�D�1�1�1����w���6�6�6���D�8�O�b�1�1�1�7�7�9�9����
��T�{�{�V�+�����
�
�
�����
������
 � ��?�?�V�3�����
 �
 �
 �����
 ����	�I����u�g�t�X�>�?�?�?�?��(A��I�@�A�A�	��3�y�>�>�*�*�	��$	A�$	A�D�
��w�|�|�D�&�1�1����T�
�
�+�+�f�4���w�|�|�D�&�1�1����I�I�O�O�-�-�	�	���W�j�1�
�
�
��c�
�
�
����������
������4�.�#8�9�9�J��J�J�>H�J�J�J�K�K�K��H��D�)�
(�
(�
��w�|�|�D�*�w�*>�?�?����r�2�2�2�8�8�:�:�	��
�*�*�#�B�G�L�L��z�G�7K�$L�$L�-1� 3� 3� 3�H�H��&�(�(������T�:��3G� H� H�)-�/�/�/�D��#�$�$�T�{�{�V�3����%�$�$�$�#����$�����'�(�#(��?�?�V�#;����%�(�(�(�#'����(����(�
�	�N�!�!�2�w��h�"?�@�@�@�@���9�9�st�BE � E:�9E:�G!�!G0�/G0�6H	�	H�H�5BK6�6L&�
L!�!L&�P/�/P>�=P>�Q�Q'�&Q'c��tjt��}tjd��}|stjd��}t	td�|D������}|D�]}	t
t|dz����}n-#ttf$r}t|��Yd}~�Id}~wwxYwttj
�tj
�|��d�������}t|dzd�	�����}||�t%j||������t)|��S)
a�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
    z/sys/class/hwmon/hwmon*/fan*_*z%/sys/class/hwmon/hwmon*/device/fan*_*c�D�g|]}|�d��d��Sr?r@r�s  rEr�z sensors_fans.<locals>.<listcomp>�rArDrBNr�rEr�rP)rNrr�r4rPr3r�rr�r�rrr�rtrr r�r�r�sfanrR)r�rSrWr�r�rXrYs       rE�sensors_fansrb�sZ���
!�$�
'�
'�C��	�:�;�;�I��G��I�E�F�F�	��s�?�?�Y�?�?�?�@�@�A�A�I��<�<��	��$�t�h��/�/�0�0�G�G����!�	�	�	��#�J�J�J��H�H�H�H�����	���������R�W�_�_�T�%:�%:�F�C�C�D�D�J�J�L�L�	��D�8�O�b�1�1�1�7�7�9�9���I����g�l�5�'�:�:�;�;�;�;���9�9�s�0B�B:�!B5�5B:c�h��t����fd�}d�tjt��D��}|sdStj�tt
|��d��}||dz|dz��}||dz|dz��}||d	z|d
z��}||dz��}|�|�	d|z|z}n;#t$rd
}Yn-wxYwtt|dzd�����}|dkrdSd}|tj�td��tj�td����}	|	�|	dk}nGt|dzd����
�����}
|
dkrd}n|
dvrd}|r
tj
}nj|�5|�3	t||zdz��}nO#t$rtj}Yn7wxYw|�%t|dz��}|dkrtj}ntj}tj|||��S)aReturn 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���|D]Q}t|����}|�kr8	t|��cS#t$r|���cYcSwxYw�RdS)zvAttempt to read the content of multiple files which may
        not exist. If none of them exist return None.
        rPN)rr�r(r�)rYrtr��nulls   �rE�
multi_bcatz#sensors_battery.<locals>.multi_bcat�s�����	'�	'�D��t�d�+�+�+�C��d�{�{�'��s�8�8�O�O�O��!�'�'�'��9�9�;�;�&�&�&�&�&�'�����
�ts�/�A�Ac�h�g|]/}|�d��sd|���v�-|��0S)�BAT�battery)r�r)r�s  rEr�z#sensors_battery.<locals>.<listcomp>�sG��$�$�$�!����U�8K�8K�$�������"�"�
�"�"�"rDNrz/energy_nowz/charge_nowz
/power_nowz/current_nowz/energy_fullz/charge_fullz/time_to_empty_nowgY@r�z	/capacityrrPz
AC0/onlinez	AC/onliner�/statusr��dischargingF)�charging�fullTi�<)�objectr�r��POWER_SUPPLY_PATHrtrrP�ZeroDivisionErrorr�rr�r)r�POWER_TIME_UNLIMITED�POWER_TIME_UNKNOWN�sbattery)
rf�batsr�
energy_now�	power_now�energy_full�
time_to_emptyr`�
power_plugged�onliner��secsleftres
            @rE�sensors_batteryr}�s�����8�8�D������$�$�r�z�"3�4�4�$�$�$�D����t��7�<�<�)�6�$�<�<��?�;�;�D����}���}����J��
��|���~����I��*��~���~����K��J�t�&:�:�;�;�M���:�#9�	��j�(�;�6�G�G�� �	�	�	��G�G�G�	�����c�$��,�r�:�:�:�;�;���b�=�=��4�
�M�
�Z�
����&��5�5�
����&��4�4�6�6�F����!��
�
��T�I�%��3�3�3�9�9�;�;�A�A�C�C���]�"�"�!�M�M�
�+�
+�
+� �M��.��/���	�	�I�$9�	2��:�	�1�D�8�9�9�H�H�� �	2�	2�	2��1�H�H�H�	2����	�	"��}�r�)�*�*���a�<�<��1�H���-����G�X�}�=�=�=s$�=C�C�C�9G�G(�'G(c��g}tj��}|D]C}|\}}}}}}|s�|dvrd}tj||pd|||��}	|�|	���D|S)z:Return currently connected users as a list of namedtuples.)z:0.0z:0�	localhostN)r�usersr�suserr�)
r4�rawlist�itemr��tty�hostname�tstamp�user_processr��nts
          rEr�r�s����G��j�l�l�G��
�
��9=�6��c�8�V�\�3��	���~�%�%�"�H�
�]�4����h���
D�
D�����r������NrDc�L�dt��z}t|��5}|D]b}|�d��rKt|������d��}|a|ccddd��S�ctd|z���#1swxYwYdS)zAReturn the system boot time expressed in seconds since the epoch.r�sbtimerNzline 'btime' not found in %s)rrr�rr�r��	BOOT_TIMEr�)rtr�r�r�s    rE�	boot_timer� s�����(�(�(�D�	�T�	�	�3�a��	�	�D����x�(�(�
��D�J�J�L�L�.�.�0�0��3�4�4���	��
�
�3�3�3�3�3�3�3�3�
��*�T�1�3�3�	3�
3�3�3�3����3�3�3�3�3�3s�AB�B�B� Bc�p�d�tjtt������D��S)z7Returns a list of PIDs currently running on the system.c�T�g|]%}|����t|����&SrC)rr�r�s  rEr�zpids.<locals>.<listcomp>5s+��L�L�L�q��	�	���L�C��F�F�L�L�LrD)r�r�r#rrCrDrEr�r�3s.��L�L�B�J�q��):�):�';�';�<�<�L�L�L�LrDc��tj|��sdS	t���d|�d�}t|��5}|D]R}|�d��r;t|���d��}||kccddd��S�Std|z���#1swxYwYdS#ttf$r|t��vcYSwxYw)zcCheck for the existence of a unix PID. Linux TIDs are not
    supported (always return False).
    Fr�rjsTgid:rNz'Tgid' line not found in %s)
r�
pid_existsrrr�r�r�r(�EnvironmentErrorr�)r�rtr�r��tgids     rEr�r�8s[����s�#�#�!��u�	!�&5�%6�%6�%6�%6����<�D��T�"�"�
G�a��+�+�D����x�0�0�+�"�4�:�:�<�<��?�3�3�� $�s�{�*�*�

G�
G�
G�
G�
G�
G�
G�
G�+�
!�!>��!E�F�F�F�
G�
G�
G�
G����
G�
G�
G�
G�
G�
G��!�*�-�	!�	!�	!��$�&�&�=� � � �	!���s;�#B0�AB#�B0�B#�#B'�'B0�*B'�+B0�0!C�Cc��i}t��}t��D]�}	t|�d|�d���5}|���}ddd��n#1swxYwY|�d��}||dzd����}t
|d��}|||<��#ttf$rY��wxYw|S)zsObtain a {pid: ppid, ...} dict for all running processes in
    one shot. Used to speed up Process.children().
    r��/statN�)r=r)	rr�rr6r�r�r�r r")r�r�r�r�r"�rpar�dset�ppids        rE�ppid_mapr�Xs!��
�C�!�#�#�K��v�v����	��[�[�[�#�#�#�>�?�?�
 �1��v�v�x�x��
 �
 �
 �
 �
 �
 �
 �
 �
 �
 �
 ����
 �
 �
 �
 ��:�:�d�#�#�D���q��	�	�?�(�(�*�*�D��t�A�w�<�<�D��C��H�H��"�#5�6�	�	�	�
�D�	�����Js4�B2�A�B2�A	�B2�A	� B2�2C�Cc�F��tj����fd���}|S)zlDecorator which translates bare OSError and IOError exceptions
    into NoSuchProcess and AccessDenied.
    c�X��	�|g|�Ri|��S#t$rt|j|j���t$rt|j|j���t$rJtj�	|j
�d|j����st|j|j����wxYwr)r!rr��_namer"rr r�rtr�ry)rzr��kwargs�funs   �rE�wrapperz wrap_exceptions.<locals>.wrapperrs����	��3�t�-�d�-�-�-�f�-�-�-���	5�	5�	5��t�x���4�4�4�!�	6�	6�	6����$�*�5�5�5� �	�	�	��7�>�>�T�->�->�->����"I�J�J�
:�#�D�H�d�j�9�9�9�
�	���s
��BB))�	functools�wraps)r�r�s` rE�wrap_exceptionsr�ns:����_�S�����������NrDc���eZdZdZgd�Zd�Zd�Zeed�����Z	eed�����Z
eed�����Zd�Zd	�Z
ed
���Zd�Zed���Zed
���Zed���Zej�dej��z��red���Zed���Zed���Zed7d���Zed���Zed���ZeserHed���Zee j!d��e j!d��e j!d��fd���Z"d�Z#neZ#ered���Z$ed���Z%ee j!d��fd ���Z&ee j!d!��fd"���Z'ed#���Z(ed$���Z)ed%���Z*e+r)ed&���Z,e j!d'��fd(�Z-ed)���Z.e/red*���Z0ed+���Z1e2�ed7d,���Z3ed-���Z4ed.���Z5ed8d0���Z6ed1���Z7ed2���Z8ee j!d3��fd4���Z9ee j!d5��fd6���Z:dS)9�ProcesszLinux process implementation.)r�r��_ppidry�_cachec�V�||_d|_d|_t��|_dSr�)r�r�r�rry)rzr�s  rEr{zProcess.__init__�s+�������
���
�+�-�-����rDc�L�tj|j�d|j����dS)z+Raise NSP if the process disappeared on us.r�N)r�rryr��rzs rE�
_assert_alivezProcess._assert_alive�s,��	��4�,�,�,�d�h�h�7�8�8�8�8�8rDc���t|j�d|j�d���}|�d��}||�d��dz|�}||dzd����}i}||d<|d	|d
<|d|d<|d|d
<|d|d<|d|d<|d|d<|d|d<|d|d<|d|d<|d|d<|S)aYParse /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 subtract 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.
        r�r�r��(rr=Nr�rr�r�r&�ttynr��utime��stime�
�children_utimer��children_stime��create_time�$�cpu_num�'�blkio_ticks)rryr�r�r%r�)rzr"r�r�r�r�s      rE�_parse_stat_filezProcess._parse_stat_file�s���D�$5�$5�$5�t�x�x�x�@�A�A���z�z�$�����D�I�I�d�O�O�a�'��,�-���d�Q�h�i�i��&�&�(�(������F���q�	��H�
��Q�i��F���a�y��G���b�z��G���b�z��G�� &�r�
���� &�r�
����#�B�Z��M������I��#�B�Z��M���
rDc��t|j�d|j�d���5}|���cddd��S#1swxYwYdS)z�Read /proc/{pid}/stat file and return its content.
        The return value is cached in case oneshot() ctx manager is
        in use.
        r�rjN)rryr�r6�rzr�s  rE�_read_status_filezProcess._read_status_file�s����4�+<�+<�+<�d�h�h�h�G�
H�
H�	�A��6�6�8�8�	�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�	�	s�A�A�Ac��t|j�d|j�d���5}|������cddd��S#1swxYwYdS)Nr�z/smaps)rryr�r6r�r�s  rE�_read_smaps_filezProcess._read_smaps_file�s����$�*;�*;�*;�T�X�X�X�F�
G�
G�	$�1��6�6�8�8�>�>�#�#�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$����	$�	$�	$�	$�	$�	$s�&A�A�Ac��|j�|��|j�|��|j�|��dSr�)r��cache_activater�r�r�s rE�
oneshot_enterzProcess.oneshot_enter�sM����,�,�T�2�2�2���-�-�d�3�3�3���,�,�T�2�2�2�2�2rDc��|j�|��|j�|��|j�|��dSr�)r��cache_deactivater�r�r�s rE�oneshot_exitzProcess.oneshot_exit�sM����.�.�t�4�4�4���/�/��5�5�5���.�.�t�4�4�4�4�4rDc�f�|���d}trt|��}|S)Nr�)r�rr)rzr�s  rEr�zProcess.name�s0���$�$�&�&�v�.���	 ��$�<�<�D��rDc��	t|j�d|j�d���S#ttf$r�t
j�|j�d|j����rYdSt|j��st|j|j
���t|j|j
|j���t$rt|j|j
���wxYw)Nr�z/exer�)r�ryr�r r"r�rt�lexistsr�rr�rr�r!rr�s rE�exezProcess.exe�s���	5��4�+<�+<�+<�d�h�h�h�G�H�H�H��!�#5�6�
	J�
	J�
	J��w���$�*;�*;�*;�T�X�X�F�G�G�
J��r�r�!�$�(�+�+�J�'���$�*�=�=�=�'���$�*�d�j�I�I�I��	5�	5�	5��t�x���4�4�4�	5���s�!�?C�#A2Cc��t|j�d|j�d���5}|���}ddd��n#1swxYwY|sgS|�d��rdnd}|�|��r
|dd�}|�|��}|dkr,t
|��dkrd|vr|�d��}|S)Nr�z/cmdliner�r�rr)rryr�r6r�r�r�)rzr�r"�sep�cmdlines     rEr�zProcess.cmdline�s��
�$�*;�*;�*;�T�X�X�X�F�
G�
G�	�1��6�6�8�8�D�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	��	��I��
�
�f�-�-�6�f�f�3���=�=����	�����9�D��*�*�S�/�/���&�=�=�S��\�\�Q�.�.�3�$�;�;��j�j��o�o�G����A�A�Ac��t|j�d|j�d���5}|���}ddd��n#1swxYwYt	|��S)Nr�z/environ)rryr�r6r)rzr�r"s   rE�environzProcess.environs���
�$�*;�*;�*;�T�X�X�X�F�
G�
G�	�1��6�6�8�8�D�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�"�4�(�(�(r�c��t|���d��}tj��}	||S#t$rYdSwxYw)Nr�)r�r�r�get_terminal_mapr�)rz�tty_nrrxs   rE�terminalzProcess.terminals_���T�*�*�,�,�W�5�6�6���(�*�*��	���<����	�	�	��4�4�	���s�A�
A�Az/proc/%s/ioc	�*�|j�d|j�d�}i}t|��5}|D]T}|���}|r<	|�d��\}}t|��||<�D#t$rY�PwxYw�U	ddd��n#1swxYwY|std|z���	t|d|d|d|d|d	|d
��S#t$r'}t
|j
d�d|�d
|�����d}~wwxYw)Nr�z/ios: z%s file was emptyssyscrssyscws
read_bytesswrite_bytessrcharswcharrz field was not found in z; found fields are )ryr�rr�r�r�r(r�r�r�r�)rz�fnamer�r�r�r�r?r�s        rE�io_counterszProcess.io_counterss���"&�"3�"3�"3�T�X�X�X�>�E��F��U�#�#�
6�q��
6�
6�D��:�:�<�<�D��6�6�*.�*�*�U�*;�*;�K�D�%�
,/�u�:�:�F�4�L�L��	 *�%�%�%�$�H�%����6�
6�
6�
6�
6�
6�
6�
6�
6�
6�
6�
6�
6����
6�
6�
6�
6��
@�"�#6��#>�?�?�?�
J���8�$��8�$��=�)��>�*��8�$��8�$�
�����
J�
J�
J� �-0�X�a�[�[�[�%�%�%���"I�J�J�J�����
J���sM�B	�A+�B	�+
A8�5B	�7A8�8B	�	B
�B
�)7C!�!
D�+"D
�
Dc�r�|���}t|d��tz}t|d��tz}t|d��tz}t|d��tz}t|d��tz}t|||||��S)Nr�r�r�r�r�)r�rrr�)rzr�r�r�r�r�r�s       rErzProcess.cpu_times2s����&�&�(�(���f�W�o�&�&��4���f�W�o�&�&��4���v�&6�7�8�8�;�F���v�&6�7�8�8�;�F���v�m�,�-�-��;�����~�~�v�N�N�NrDc�P�t|���d��S)zWhat CPU the process is on.r��r�r�r�s rEr�zProcess.cpu_num<s#���4�(�(�*�*�9�5�6�6�6rDNc�B�tj|j||j��Sr�)r�wait_pidr�r�)rz�timeouts  rE�waitzProcess.waitAs��� ���7�D�J�?�?�?rDc��t|���d��}tp
t��}|tz|zS)Nr�)rr�r�r�r)rz�ctime�bts   rEr�zProcess.create_timeEs@���d�+�+�-�-�m�<�=�=���
%�)�+�+����#�r�)�)rDc	��t|j�d|j�d���5}d�|������dd�D��\}}}}}}}ddd��n#1swxYwYt|||||||��S)Nr�z/statmc�<�g|]}t|��tz��SrC)r�r�r�s  rEr�z'Process.memory_info.<locals>.<listcomp>_s#��E�E�E�q��Q���(�"�E�E�ErDr�)rryr�r�r�ry)	rzr��vmsrrg�text�libr"�dirtys	         rE�memory_infozProcess.memory_infoPs����$�*;�*;�*;�T�X�X�X�F�
G�
G�	F�1�E�E�A�J�J�L�L�,>�,>�,@�,@��!��,D�E�E�E�
5�C��f�d�C��u�	F�	F�	F�	F�	F�	F�	F�	F�	F�	F�	F����	F�	F�	F�	F��C��f�d�C��u�=�=�=s�AA-�-A1�4A1c���dx}x}}	td�|j|j����5}|D]�}|�d��r.|t|���d��dzz
}�E|�d��r+t|���d��dz}��|�d��r*t|���d��dz}��	ddd��n#1swxYwYn\#t$rOt|j��st|j|j
���t|j|j
|j���wxYw|||fS)Nrz{}/{}/smaps_rollupsPrivate_rr��Pss:�Swap:)
r�formatryr�r�r�r�r"r�rr�rr�)rzr{r|r}r�r�s      rE�_parse_smaps_rollupzProcess._parse_smaps_rollupds���
 !� �C� �#��
J� �!5�!<�!<��)�4�8�"5�"5�6�6�	?�9:� !�?�?���?�?�;�7�7�?��3�t�z�z�|�|�A��#7�#7�$�#>�>�C�C�!�_�_�W�5�5�?�"%�d�j�j�l�l�1�o�"6�"6��"=�C�C�!�_�_�X�6�6�?�#&�t�z�z�|�|�A��#7�#7�$�#>�D��?�	?�	?�	?�	?�	?�	?�	?�	?�	?�	?�	?����	?�	?�	?�	?���&�
J�
J�
J�!�$�(�+�+�J�'���$�*�=�=�=�'���$�*�d�j�I�I�I�	
J����
��d�#�#s0�-D�CD
�>D�
D�D�D�D�AE/s\nPrivate.*:\s+(\d+)s\nPss\:\s+(\d+)s\nSwap\:\s+(\d+)c��|���}ttt|�|������dz}ttt|�|������dz}ttt|�|������dz}|||fS)Nr�)r�r7r�r��findall)rz�_private_re�_pss_re�_swap_re�
smaps_datar{r|r}s        rE�_parse_smapszProcess._parse_smaps|s���,�.�.�0�0�J��c�#�{�2�2�:�>�>�?�?�@�@�4�G�C��c�#�w���z�:�:�;�;�<�<�t�C�C��s�3�� 0� 0�� <� <�=�=�>�>��E�D���d�#�#rDc��tr|���\}}}n|���\}}}|���}t	||||fz�Sr�)�HAS_PROC_SMAPS_ROLLUPr�r�r�rz)rzr{r|r}�	basic_mems     rE�memory_full_infozProcess.memory_full_info�sb��$�
5�!%�!9�!9�!;�!;���S�$�$�!%�!2�!2�!4�!4���S�$��(�(�*�*�I��Y�#�s�D�)9�9�:�:rDc��d�}|���}|sgS|�d��}g}|�d��}|g}|||��D�]�\}}|�dd��}	|\}	}
}}}
}n#t$r|dgz\}	}
}}}
}YnwxYw|sd}nXtrt|��}|���}|�d��rt|��s
|dd	�}|�	t|	��t|
��||�
d
d��|�
dd��|�
dd��|�
d
d��|�
dd��|�
dd��|�
dd��|�
dd��|�
dd��|�
dd��f
�����|S)aPReturn 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.
            c3��K�i}|D]�}|�dd��}|d�d��s.|���|fV�|�|���a	t	|d��dz||d<��#t
$r0|d�d��rY��td|z���wxYw|���|fV�dS)N�rrIrr�sVmFlags:z#don't know how to interpret line %r)r�r��popr�r�r(r�)r��
current_blockr"r�r�s     rE�
get_blocksz'Process.memory_maps.<locals>.get_blocks�s*������!�I�I�D�!�Z�Z��a�0�0�F�!�!�9�-�-�d�3�3�
I�,�0�0�2�2�D�9�9�9�9�%�,�,�T�2�2�2�2�I�.1�&��)�n�n�t�.C�D����O�O��)�I�I�I�%�a�y�3�3�K�@�@�I� (��&0�2A�CG�2H�'I�'I�!I�I����%�(�(�*�*�D�1�1�1�1�1�1s�)!B�%C�2C�
rNr�r�z[anon]r�r�sRss:sSize:r�s
Shared_Clean:s
Shared_Dirty:sPrivate_Clean:sPrivate_Dirty:sReferenced:s
Anonymous:r�)r�r�r�r(rrr�r�rr�r�)rzr�r"r�r8�
first_liner��header�hfieldsr��perms�offsetrr�rts               rE�memory_mapszProcess.memory_maps�s+��
2�
2�
2�(�(�(�*�*�D��
��	��J�J�u�%�%�E��B����1���J�'�L�M� *�
�5�-� @� @�
�
���� �,�,�t�Q�/�/��'�<C�9�D�%���e�T�T��!�'�'�'��2�$��:�D�%���e�T�T�T�'�����*�#�D�D��,�%�d�|�|���:�:�<�<�D��
�
�l�3�3�*�.�t�4�4�*�#�D�S�D�z���	�	��4�L�L�&��-�-���H�H�W�a�(�(��H�H�X�q�)�)��H�H�W�a�(�(��H�H�-�q�1�1��H�H�-�q�1�1��H�H�.��2�2��H�H�.��2�2��H�H�^�Q�/�/��H�H�]�A�.�.��H�H�X�q�)�)�������Is�4	A>�>B�Bc��	t|j�d|j�d���S#ttf$rOt|j��st
|j|j���t|j|j|j	���wxYw)Nr�z/cwd)
r�ryr�r r"r�rr�rr�r�s rE�cwdzProcess.cwd�s���	F��4�+<�+<�+<�d�h�h�h�G�H�H�H��!�#5�6�	F�	F�	F��d�h�'�'�
F�#�D�H�d�j�9�9�9�#�D�H�d�j�$�*�E�E�E�	F���s
�!�A Bsctxt_switches:\t(\d+)c��|���}|�|��}|s td|j�d|j�d����tjt|d��t|d����S)NzR'voluntary_ctxt_switches' and 'nonvoluntary_ctxt_switches'lines were not found in r�z1/status; the kernel is probably older than 2.6.23rr)r�r�rVryr�r�pctxswr�)rz�	_ctxsw_rer"�ctxsws    rE�num_ctx_switcheszProcess.num_ctx_switches�s����%�%�'�'���!�!�$�'�'���	@�%�%��%�%�%�t�x�x�x�1�2�2�
2��>�#�e�A�h�-�-��U�1�X���?�?�?rDsThreads:\t(\d+)c�z�|���}t|�|��d��S�Nr)r�r�r�)rz�_num_threads_rer"s   rE�num_threadszProcess.num_threadss6��
�%�%�'�'���?�*�*�4�0�0��3�4�4�4rDc��tj|j�d|j�d���}|���g}d}|D�]'}|j�d|j�d|�d�}	t|��5}|������}ddd��n#1swxYwYn#ttf$rd}Y�|wxYw||�
d��dzd�}|�d	��}t|d
��tz}	t|d��tz}
tjt!|��|	|
��}|�|����)|r|���|S)Nr�z/taskFz/task/r�Tr�r=rr�r�)r�r�ryr�rTrr6r�r r"r%r�rrr�pthreadr�r�r�)rz�
thread_idsr4�
hit_enoent�	thread_idr�r��str�r�r�r<s            rE�threadszProcess.threadss����Z��0A�0A�0A�4�8�8�8� L�M�M�
����������
�#�	#�	#�I��!�!�!�4�8�8�8�Y�Y�Y�8�E�
� ��'�'�*�1��������)�)�B�*�*�*�*�*�*�*�*�*�*�*����*�*�*�*���%�'9�:�
�
�
�"�
���	
�����B�G�G�D�M�M�A�%�&�&�'�B��X�X�d�^�^�F��&��*�%�%��3�E��&��*�%�%��3�E��_�S��^�^�U�E�B�B�F��N�N�6�"�"�"�"��	!���� � � ��s6�B&�''B�B&�B	�B&�!B	�"B&�&B<�;B<c�4�tj|j��Sr�)r��getpriorityr�r�s rE�nice_getzProcess.nice_get(s���%�d�h�/�/�/rDc�6�tj|j|��Sr�)r��setpriorityr�)rzr?s  rE�nice_setzProcess.nice_set1s���%�d�h��6�6�6rDc�4�tj|j��Sr�)rr8r�r�s rE�cpu_affinity_getzProcess.cpu_affinity_get8s���-�d�h�7�7�7rDsCpus_allowed_list:\t(\d+)-(\d+)c	�f�|���}|�|��}|rRttt	|dd��t	|dd��dz����Stttt
��������S)Nrr)r�r�r��ranger�r�r#)rz�_rer"r,s    rE�_get_eligible_cpuszProcess._get_eligible_cpus<s����)�)�+�+�D��K�K��%�%�E��
9��E�#�e�A�h�q�k�"2�"2�C��a����4D�4D�q�4H�I�I�J�J�J��E�#�m�o�o�"6�"6�7�7�8�8�8rDc	���	tj|j|��dS#ttf$r�}t|t��s|jtjkr�|���}tttt��������}|D]4}||vrt	d|�d|�����||vrt	d|�d|������5�d}~wwxYw)Nzinvalid CPU number z; choose between zCPU number z! is not eligible; choose between )
r�proc_cpu_affinity_setr�r�r(r�r�r�r"�tupler r�r#)rzr!r��
eligible_cpus�all_cpus�cpus      rE�cpu_affinity_setzProcess.cpu_affinity_setFs��
��*�4�8�T�:�:�:�:�:���Z�(�

�

�

��c�:�.�.�E�#�)�u�|�2K�2K�$(�$;�$;�$=�$=�M�$�U�3�}���+?�+?�%@�%@�A�A�H�#�E�E���h�.�.�",�*�$'�C�C���!8�#9�#9�9��m�3�3�",�*�03���]�]�!D�#E�#E�E�4������

���s��C�B+C�Cc��tj|j��\}}t�t	|��}tj||��Sr�)rr7r��enumr?r�pionice�rz�ioclassr?s   rE�
ionice_getzProcess.ionice_get\s=��!�1�$�(�;�;�N�G�U���$�W�-�-���?�7�E�2�2�2rDc��|�d}|r"|ttfvrtd|z���|dks|dkrtd���tj|j||��S)Nrz%r ioclass accepts no valuer�zvalue not in 0-7 range)r+r(r(r�proc_ioprio_setr�r-s   rE�
ionice_setzProcess.ionice_setcsq���}����
J��%6�8I�$J�J�J� �!>��!H�I�I�I��q�y�y�E�A�I�I� �!9�:�:�:��'���'�5�A�A�ArDc��|jdkrtd���	|�t|j|��St|��dkrtdt	|��z���t|j||��dS#t
$rO}|jtjkr4t|j��r t|j|j
|j����d}~wwxYw)Nrz)can't use prlimit() against PID 0 processr=z4second argument must be a (soft, hard) tuple, got %s)r�r(r�r�r�r�r��ENOSYSr�rr�r�)rzr�r�r�s    rE�rlimitzProcess.rlimitos���
�x�1�}�}� �!L�M�M�M�
��>�"�4�8�Y�7�7�7��6�{�{�a�'�'�(�%�'+�F�|�|�4�5�5�5��D�H�i��8�8�8�8�8���
�
�
��9���,�,��D�H�1E�1E�,�(���$�*�d�j�I�I�I������

���s�A=�AA=�=
C�A
C�Cc��|���d}tr|���}t�|d��S)Nr��?)r�rr�
PROC_STATUSESr�)rz�letters  rEr�zProcess.status�sC���&�&�(�(��2���	%��]�]�_�_�F�� � ���-�-�-rDc�6�g}tj|j�d|j�d���}d}|D�]�}|j�d|j�d|��}	t	|��}|�d���r,t
|���r|j�d|j�d|��}	t|��5}t|�	���
��d��}t|�	���
��dd��}	ddd��n#1swxYwYt|	��}
t|t|��t|��|
|	��}|�
|����O#ttf$rd}Y��ewxYw��k#ttf$rd}Y���t $rK}|jt"jkrYd}~���|jt"jkrt)|��Yd}~��ςd}~wwxYw|r|���|S)	Nr�r}Fr~z/fdinfo/rr�T)r�r�ryr�r�r�rrr�r�r�r�rsr�r r"r�r�r�r�rr�)
rzr4r	rrur�rtr��posrxrwr<r�s
             rE�
open_fileszProcess.open_files�s������
��):�):�):�D�H�H�H�E�F�F���
��&	/�&	/�B�$(�$5�$5�$5�t�x�x�x���D�D�$
/���~�~��&�?�?�3�'�'�/�M�$�,?�,?�/��)�)�)�4�8�8�8�R�R�9�D�/�(��.�.�D�!�"%�a�j�j�l�l�&8�&8�&:�&:�1�&=�">�">�C�$'��
�
���(:�(:�(<�(<�Q�(?��$C�$C�E�D�D�D�D�D�D�D�D�D�D�D����D�D�D�D� 2�%�8�8��!*� �#�b�'�'�3�s�8�8�T�5�"B�"B�����v�.�.�.�.��.�/A�B�*�*�*�&*�
�
�
�*������5&�'9�:�
�
�
�!�
����
�
�
��9���,�,��H�H�H�H��9�� 2�2�2��#�J�J�J��H�H�H�H������
����>�	!���� � � ��sa�F�
E:�A4D�E:�D 	� E:�#D 	�$E:�:F�F�H�,	H�5G;�$G;�:G;�;Hroc�n�t�||j��}|���|Sr�)r�r�r�r�)rzr�r�s   rE�connectionszProcess.connections�s0���#�#�D�$�(�3�3���������
rDc�d�ttj|j�d|j�d�����S)Nr�r})r�r�r�ryr�r�s rE�num_fdszProcess.num_fds�s.���2�:�D�,=�,=�,=�t�x�x�x�H�I�I�J�J�JrDc�P�t|���d��S)Nr�r�r�s rEr�zProcess.ppid�s!���4�(�(�*�*�6�2�3�3�3rDsUid:\t(\d+)\t(\d+)\t(\d+)c���|���}|�|��d\}}}tjt	|��t	|��t	|����Sr
)r�r�r�puidsr�)rz�_uids_rer"�real�	effective�saveds      rE�uidszProcess.uids��X���%�%�'�'��!)�!1�!1�$�!7�!7��!:���i���}�S��Y�Y��I����E�
�
�C�C�CrDsGid:\t(\d+)\t(\d+)\t(\d+)c���|���}|�|��d\}}}tjt	|��t	|��t	|����Sr
)r�r�r�pgidsr�)rz�_gids_rer"rErFrGs      rE�gidszProcess.gids�rIrDr��ro);r@rArBr�r&r{r�r�rr�r�r�r�r�r�r�r�r�r�r�rtr��getpidr�rr�r�r�r�r��HAS_PROC_SMAPSr�r*r+r�r�rrrrrrr�HAS_CPU_AFFINITYrr"r)�HAS_PROC_IO_PRIORITYr/r2r�r5r�r<r>r@r�rHrMrCrDrEr�r��s}������'�'�C�C�C�I�.�.�.�9�9�9��������_��@�������_����$�$����_�$�3�3�3�
5�5�5�
����_��5�5�5�"����_��0�)�)��_�)�
����_��
�w�~�~�m�i�b�i�k�k�1�2�2�J�	�	J�	J�
��	J�<�O�O��_�O��7�7��_�7��@�@�@��_�@��*�*��_�*��>�>��_�>�"�A'��A'�	�	$�	$�
��	$�.
�'�B�J�'?�@�@�"��
�#6�7�7�#���$8�9�9�	$�	$�	$�
��	$�:	;�	;�	;�	;�'���D�	�A	�A	�
��A	�F�F�F��_�F��#-�2�:�.G�#H�#H�@�@�@��_�@��*4�"�*�5H�*I�*I�5�5�5��_�5�����_��6�0�0��_�0��7�7��_�7��!�	�	8�	8�
��	8�%�"�*�%H�I�I�	9�	9�	9�	9�
�	�	�
��	�&�B�	�	3�	3�
��	3�
�	B�	B�
��	B���	�	�	�	�
��	�2�.�.��_�.��-�-��_�-�^�����_��
�K�K��_�K��4�4��_�4��&�B�J�'D�E�E�D�D�D��_�D�
�&�B�J�'D�E�E�D�D�D��_�D�D�DrDr�r�rN)F)�r��
__future__rr�rNr�r�r4r�r*rrr��sys�	tracebackrrrr�rrr	rr
r�rrr
rrrrrrrrrrrrrrrrr�_compatrr r!r"r#r$�version_infor+�__extra__all__rprtr�rOrPr��hasattrrRrQr'r�getpagesizer�r��	byteorderr�r�	AF_PACKETr<�IntEnumr�r;r(r)r*r+r?�globalsr��__members__�STATUS_RUNNING�STATUS_SLEEPING�STATUS_DISK_SLEEP�STATUS_STOPPED�STATUS_TRACING_STOP�
STATUS_ZOMBIE�STATUS_DEAD�STATUS_WAKE_KILL�
STATUS_WAKING�STATUS_IDLE�
STATUS_PARKEDr8r,r-r.r/r0r1r2r3r4r5r6r�r]rirsryrrzr~rr�r�r�r�r�r�r��	Exception�	print_excr�r��resource�ImportErrorr��CDLLr�rO�dirr�rrrr#r/r@rGrJr_�net_if_addrsrcrer�r�r�r��
disk_usagerrr/r^rbr}r�r�r�r�r�r�ror�rCrDrE�<module>rss�
��
%�$�������
�
�
�
�����������������	�	�	�	�	�	�	�	�
�
�
�
�
�
�
�
�
�
�
�
���������#�#�#�#�#�#�"�"�"�"�"�"�������������#�#�#�#�#�#�)�)�)�)�)�)�$�$�$�$�$�$�$�$�$�$�$�$�'�'�'�'�'�'�!�!�!�!�!�!�"�"�"�"�"�"�"�"�"�"�"�"�������������������������$�$�$�$�$�$�"�"�"�"�"�"�������+�+�+�+�+�+� � � � � � �������(�(�(�(�(�(�'�'�'�'�'�'�"�"�"�"�"�"�"�"�"�"�"�"�������&�&�&�&�&�&�$�$�$�$�$�$�'�'�'�'�'�'���������������v����K�K�K�K��D�	6�	6�	6��".������ 0�9�2�9�;�;� >�?�?������'>������'L�M�M���w�t�%6�7�7���7�4�!8�9�9���b�j��&�&��!�:�!�#�#���	��
��)�
����<���G�G� �D�L��"+�S�S��1A�-B�-B�!C�E�E�M��#�G��<����O��O���������T�\�����G�I�I���Z�+�,�,�,�
�	�	�	 �	�	"�	�	�	�	$�	�	�	�	�	�	�	�	!�	�	�	�	�	�	�
�
�
�"�
"�
�
�
�
�
�
 �
�
 �
�
 �
�
�
�
!�
�
�
�
�
�
����*	�
��K�K�K�	L�	L���*�
�������
�J��<�<�<�
>�
>�	��z�&�>�?�?���:�j�$�,�1G�"G�H�H���
��J�J�J�K�K�
�

�J������-�*?�!@�!@�@�
B�
B�	��j��6�6�6�7�7��
�J�{�"�"�"�
#�
#�	����(
�
�
�$�$�$�&	�0�0�	��0�0K����!�!�!�!���K�K�K��I�����;�
�
�;�(:�;�;�C��c�J�J�I�I�I�K���� ��8� � � � � � � ���8�8�8��M�M�M��6�;�t�t�,�,�,�D��w�t�Y���8�	8�	8�	8�	8���8����<�����F�F�C�C��I�I�F�F�F�H�H�H�:�:�:�zuB�uB�uB�p2@�2@�2@�t
�
�
� ���(���:'�'�'�T=�=�=�*����7�>�>�;�<�<�'N�
����=�>�>�'N�����BN�N�N��&��	�	�	�	�	�I�	�	�	�k�k�k�k�k�k�k�k�\�{�}�}��'�'�'�'�
"�"�"�J���>�
 �
�\�\�\�\�~G�G�G�G�G�G�G�G�T&�&�&�&�\n�n�n�b���>Y>�Y>�Y>�B���$3�3�3�&M�M�M�
!�!�!�@���,���*V	D�V	D�V	D�V	D�V	D�f�V	D�V	D�V	D�V	D�V	Ds$�M)�)+N�N�N$�$+O�O

?>