AlkantarClanX12

Your IP : 3.12.73.149


Current Path : /lib/python3.6/site-packages/iotop/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/iotop/__pycache__/data.cpython-36.pyc

3

�bfZ<�
@s�ddlmZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZejj
d�ZyddlmZe�ZWndZYnXdZes�er�ed�ed	�es�ed
�es�ed�ejd�dd
lmZmZddlmZmZmZmZddlmZmZGdd�de �Z!Gdd�de!�Z"dZ#dZ$dZ%dZ&dZ'Gdd�de �Z(dd�Z)dd�Z*dd�Z+Gdd�de!�Z,Gd d!�d!e!�Z-Gd"d#�d#e!�Z.d$d%�Z/dS)&�)�print_functionN)�cmdlinez
/proc/self/io)�VmStatFTz<Could not run iotop as some of the requirements are not met:z- Linux >= 2.6.20 withz~  - I/O accounting support (CONFIG_TASKSTATS, CONFIG_TASK_DELAY_ACCT, CONFIG_TASK_IO_ACCOUNTING, kernel.task_delayacct sysctl)z0  - VM event counters (CONFIG_VM_EVENT_COUNTERS)�)�ioprio�vmstat)�
Connection�NETLINK_GENERIC�U32Attr�
NLM_F_REQUEST)�
Controller�GeNlMessagec@seZdZdZdd�ZdS)�DumpableObjectzFBase class for all objects that allows easy introspection when printedcCs$dtt|��dd�tj|j�fS)Nz%s: %s>r���)�str�type�pprintZpformat�__dict__)�self�r�/usr/lib/python3.6/data.py�__repr__?szDumpableObject.__repr__N)�__name__�
__module__�__qualname__�__doc__rrrrrr=src@sLeZdZdddddgZdZdd
�Zddd�Zdd�Zdd�Ze	dd��Z
dS)�Stats�blkio_delay_total�(�swapin_delay_total�8�
read_bytes��write_bytes��cancelled_write_bytes�NcCsP|j}x6tjD],\}}|||d�}tjd|�d||<qWtjsLt�t_dS)N��Qr)rr�members_offsets�struct�unpack�has_blkio_delay_total�sysctl_task_delayacct)rZtask_stats_buffer�sd�name�offset�datarrr�__init__RszStats.__init__rc	CsB|j}|j}|j}x*tjD] \}}|||||||<qWdS)z3Update destination from operator(self, other_stats)N)rrr))	r�other_stats�destination�coeffZddr.Zod�memberr0rrr�
accumulate]s
zStats.accumulatecCs|j||dd�S)z*Update destination with self - other_statsr)r5r)r7)rr3r4rrr�deltaeszStats.deltacCs.|j}x"tjD]\}}||dkrdSqWdS)NrFT)rrr))rr.r/r0rrr�is_all_zerois
zStats.is_all_zerocCs0tjt�}|j}xtjD]\}}d||<qW|S)Nr)r�__new__rr))�statsZstdr/r0rrr�build_all_zerops

zStats.build_all_zero)rr)rr )r!r")r#r$)r%r&)r)rrrr)r,r2r7r8r9�staticmethodr<rrrrrGs
r��c@s$eZdZdd�Zdd�Zdd�ZdS)�TaskStatsNetlinkcCs*||_tt�|_t|j�}|jd�|_dS)NZ	TASKSTATS)�optionsrr	�
connectionrZ
get_family_id�	family_id)rrAZ
controllerrrrr2�s

zTaskStatsNetlink.__init__cCst|jttt|�gtd�S)N)�cmd�attrs�flags)r
rC�TASKSTATS_CMD_GETr
�TASKSTATS_CMD_ATTR_PIDr)r�tidrrr�
build_request�s
zTaskStatsNetlink.build_requestcCs�|jj|j�ytj|j�}Wn4tk
rR}z|jtjkr@dS�WYdd}~XnXx,|jj	�D]\}}|t
kr`|j�}Pq`WdS|tj
}t|�dkr�dStjd|dd��d}|dks�t�t|�S)Ni�H�rr>)�task_stats_request�sendrBr
Zrecv�OSError�errnoZESRCHrE�items�TASKSTATS_TYPE_AGGR_PID�nested�TASKSTATS_TYPE_STATSr1�lenr*r+�AssertionErrorr)r�threadZreply�eZ	attr_typeZ
attr_valueZtaskstats_dataZtaskstats_versionrrr�get_single_task_stats�s$
z&TaskStatsNetlink.get_single_task_statsN)rrrr2rJrYrrrrr@�sr@cCs�g|_d}x�|jpgD]t}yt|�}WnRtk
rxytj|�}Wn(tk
rltd|tj	d�d}YnX|j
}YnX|s|jj|�qW|r�tjd�dS)zDBuild options.uids from options.users by resolving usernames to UIDsFz
Unknown user:)�fileTrN)
�uidsZusers�int�
ValueError�pwd�getpwnam�KeyError�print�sys�stderrZpw_uid�append�exit)rA�error�u�uidZpasswdrrr�	find_uids�s 
ricCsTi}y6x0td|�D] }|jdd�\}}|j�||<qWWntk
rNYnX|S)Nz/proc/%d/statusz:	r)�open�split�strip�IOError)�pidZresult_dict�line�key�valuerrr�parse_proc_pid_status�srrcCs<y
|jd�Stk
r$|jd�Stk
r6|SXdS)Nzutf-8Z
string_escape)�decode�UnicodeDecodeError�encode�AttributeError)�srrr�safe_utf8_decode�s

rxc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�
ThreadInfozStats for a single threadcCs.||_d|_d|_tjt�|_|j|�|_dS)NT)rI�mark�stats_totalrr:�stats_deltarJrM)rrI�taskstats_connectionrrrr2�s
zThreadInfo.__init__cCstj|j�S)N)r�getrI)rrrr�
get_ioprio�szThreadInfo.get_iopriocCstjtj|j||�S)N)r�
set_ioprioZIOPRIO_WHO_PROCESSrI)r�ioprio_class�ioprio_datarrrr��szThreadInfo.set_iopriocCs&|js||_|j|j|j�||_dS)N)r{r8r|)rr;rrr�update_stats�szThreadInfo.update_statsN)rrrrr2rr�r�rrrrry�s
ryc@sheZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)�ProcessInfoz�Stats for a single process (a single line in the output): if
    options.processes is set, it is a collection of threads, otherwise a single
    thread.cCs:||_d|_d|_i|_tj�|_tj�|_tj�|_	dS)N)
rnrh�user�threadsrr<r|�stats_accum�timeZstats_accum_timestamp)rrnrrrr2�s

zProcessInfo.__init__cCs:|jr|jr|j|jkrdS|jr6|j�|jkr6dSdS)NFT)�pids�	processesrnr[�get_uid)rrArrr�is_monitored�szProcessInfo.is_monitoredcCsZ|jr|jSytjd|j�tj}Wntk
r>d}YnX||jkrVd|_||_|S)Nz/proc/%d)rh�os�statrn�ST_UIDrOr�)rrhrrrr�s

zProcessInfo.get_uidcCs\|j�}|dk	rR|jrRyttj|�j�|_Wn"ttfk
rPt|�|_YnX|jpZdS)Nz{none})	r�r�rxr^�getpwuidZpw_namer`rvr)rrhrrr�get_userszProcessInfo.get_usercCs
ytd|j�}|jd�}Wntk
r0dSXt|j�}|sb|jdd�}|rZd|}nd}|Sd}t|jd|j��}||jkr�t|�jdd�}|jdd�}||kr�|d	|7}|jd
�}	|	djd�r�|	dj	d�d
}
|	d|
d�|	d<dj
|	�j�}t||�S)Nz/proc/%d/cmdlineiz{no such process}�Name�z[%s]z	{no name}ZTgidz [%s]�r�/r� )
rjrn�readrmrrr~r\rk�
startswith�rfind�joinrlrx)rZproc_cmdlinerZproc_statusZproc_status_name�suffix�tgidZ	tgid_nameZthread_name�partsZfirst_command_charrrr�get_cmdlines2



zProcessInfo.get_cmdlinecCs6|r|jj�Sx |jj�D]}|jj�sdSqWdS)NTF)r�r9r��valuesr|)rZaccumulated�trrr�did_some_io<s
zProcessInfo.did_some_iocCs0tdd�|jj�D��}t|�dkr,|j�SdS)Ncss|]}|j�VqdS)N)r)�.0r�rrr�	<genexpr>Esz)ProcessInfo.get_ioprio.<locals>.<genexpr>rz?dif)�setr�r�rU�pop)rZ
prioritiesrrrrDszProcessInfo.get_iopriocCs$x|jj�D]}|j||�qWdS)N)r�r�r�)rr�r�rWrrrr�JszProcessInfo.set_iopriocCstj|j��S)N)rZsort_keyr)rrrr�ioprio_sort_keyNszProcessInfo.ioprio_sort_keycCs*|jj|d�}|s&t||�}||j|<|S)N)r�r~ry)rrIr}rWrrr�
get_threadQs


zProcessInfo.get_threadcCs�tj�}x*|jj�D]\}}|js|j|j|�qWtdd�|jj�D��|_t|j�}|s`dS|j	|_	|j
|_
||_|jj|j|j�dS)NcSsg|]\}}|js||f�qSr)rz)r�rIrWrrr�
<listcomp>]sz,ProcessInfo.update_stats.<locals>.<listcomp>FT)rr<r�rQrzr7r|�dictrUrrr�)rr|rIrWZ
nr_threadsrrrr�Xs
zProcessInfo.update_statsN)rrrrr2r�r�r�r�r�rr�r�r�r�rrrrr��s		r�c@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�ProcessListcCs2i|_||_||_tj�|_tj�|_|j�dS)N)r�r}rAr��	timestamprr�update_process_counts)rr}rArrrr2ms

zProcessList.__init__cCs8|jj|d�}|s$t|�}||j|<|j|j�r4|SdS)zyEither get the specified PID from self.processes or build a new
        ProcessInfo if we see this PID for the first timeN)r�r~r�r�rA)rrn�processrrr�get_processxs
zProcessList.get_processc
Cs�|jjr|jjStjd�}|jjr0dd�|D�Sg}x`|D]X}d|dkoTdknr:y"|jtttjd|d���Wq:tk
r�Yq:Xq:W|S)	Nz/proccSs0g|](}d|dkodknrt|��qS)�0r�9)r\)r�r�rrrr��sz*ProcessList.list_tgids.<locals>.<listcomp>r�rr�z/proc/z/task)	rAr�r��listdirr��extend�mapr\rO)rZtgids�tidsr�rrr�
list_tgids�s

"
zProcessList.list_tgidscCsf|jjs|gSyttttjd|���}Wntk
r>gSX|jjrbtt	|jj�j
t	|���}|S)Nz
/proc/%d/task)rAr��listr�r\r�r�rOr�r��intersection)rr�r�rrr�	list_tids�szProcessList.list_tidsc
Cs�tj�}||j|_||_d}}x||j�D]p}|j|�}|s@q,xZ|j|�D]L}|j||j�}|jj|�}|rL|j	|�|j
}	||	j7}||	j7}d|_
qLWq,W||f|jj�fS)NrF)r�r�Zdurationr�r�r�r�r}rYr�r|r!r#rzrr8)
rZ
new_timestampZ
total_readZtotal_writer�r�rIrWr;r8rrrr��s$



z!ProcessList.update_process_countscCsTx,|jj�D]}x|jj�D]
}d|_qWqW|j�}tdd�|jj�D��|_|S)NTcSs g|]\}}|j�r||f�qSr)r�)r�rnr�rrrr��sz1ProcessList.refresh_processes.<locals>.<listcomp>)r�r�r�rzr�r�rQ)rr�rWZtotal_read_and_writerrr�refresh_processes�szProcessList.refresh_processescCs
i|_dS)N)r�)rrrr�clear�szProcessList.clearN)
rrrr2r�r�r�r�r�r�rrrrr�ls
r�cCsdt�j�kS)a| WAS:
    try:
        with open('/proc/sys/kernel/task_delayacct') as f:
            return bool(int(f.read().strip()))
    except FileNotFoundError:
        return None


    Because /proc/sys/kernel/task_delayacct doesn't exist on RHEL8,
    it always returns None, which is equivalent to False in the end.

    On RHEL8, delayacct_on kernel variable is enabled by default
    Znodelayacct)r�keysrrrrr-�sr-)0Z
__future__rrPr�rr^r�r*rbr�Zprocfsr�path�existsZioaccountingZiotop.vmstatrZvmstat_fZvm_event_countersrareZiotoprrZ
iotop.netlinkrr	r
rZiotop.genetlinkrr
�objectrrrGrHrRZTASKSTATS_TYPE_PIDrTr@rirrrxryr�r�r-rrrr�<module>sV



5)^