AlkantarClanX12

Your IP : 18.116.43.109


Current Path : /proc/self/root/usr/lib/python3.6/site-packages/iotop/__pycache__/
Upload File :
Current File : //proc/self/root/usr/lib/python3.6/site-packages/iotop/__pycache__/ui.cpython-36.pyc

3

�bf�b�@szddlmZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlm
Z
mZmZmZmZddlmZddlmZddlmZddlmZdd	d
ddd
dgZdd�Zdd�Zdd�Zdd�Zdd�Ze�ZGdd�de �Z!Gdd�de �Z"Gdd�de �Z#Gdd �d e �Z$Gd!d"�d"e �Z%Gd#d$�d$e&�Z'd%d&�Z(d'd(�Z)d)d*�Z*d+e
j+dZ,d,d-�Z-dS).�)�print_functionN)�	find_uids�TaskStatsNetlink�ProcessList�Stats�sysctl_task_delayacct)�
ThreadInfo)�VERSION)�ioprio)�IoprioSetError�B�K�M�G�T�P�EcCs`|dkrd}n|dkr"d}|}ndSttj|dd�d�}d|t|�dd|>t|fS)	Nr��-z0.00 B��
z	%s%.2f %s�)�int�math�log�float�UNITS)�sizeZsignZexpo�r�/usr/lib/python3.6/ui.py�
human_size-sr cCs|jrd|dSt|�S)Nz%.2f Kg�@)�	kilobytesr )�options�bytesrrr�format_size9sr$cCst||ot|�|�dS)Nz/s)r$r)r"r�durationrrr�format_bandwidth>sr&cs��fdd�}�jr4|j}�fdd�}tj�|j�n|j}�fdd�}||j�}||j�}||j��}|j|j	}	t
d|	�}	||	��}
||||
fS)Ncsdtd|�d�S)Nz%.2f %%g��(\�X@g�cA)�min)Zdelay)r%rr�
delay2percentDsz#format_stats.<locals>.delay2percentcs
t�|�S)N)r$)rr%)r"rr�<lambda>Hszformat_stats.<locals>.<lambda>cst�||�S)N)r&)rr%)r"rrr)Lsr)�accumulated�stats_accum�timeZstats_accum_timestamp�stats_delta�blkio_delay_total�swapin_delay_total�
read_bytes�write_bytes�cancelled_write_bytes�max)r"Zprocessr%r(�statsZdisplay_format�io_delay�swapin_delayr0Z
written_bytesr1r)r%r"r�format_statsAs



r7cCsByttd�j�j��Stk
r<}zt|�dSd}~XnXdS)Nz/proc/sys/kernel/pid_max�)�len�open�read�strip�	Exception�print)�errr�get_max_pid_widthVs
r@c@seZdZdS)�CancelInputN)�__name__�
__module__�__qualname__rrrrrAdsrAc@seZdZdS)�
InvalidIntN)rBrCrDrrrrrEesrEc@seZdZdS)�
InvalidPidN)rBrCrDrrrrrFfsrFc@seZdZdS)�
InvalidTidN)rBrCrDrrrrrGgsrGc@seZdZdS)�InvalidIoprioDataN)rBrCrDrrrrrHhsrHc	@s�eZdZdd�dfdd�dfdd�dfdd�dfdd�dfd	d�dfd
d�dfdd�dfgZdd
�Zdd�Zdd�Zdd�Zdd�Zd0dd�Z	d1dd�Z
dd�Zdd�Zdd �Z
d!d"�Zd2d#d$�Zd3d&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�ZdS)4�IOTopUIcCs|jS)N)�pid)�p�srrrr)qszIOTopUI.<lambda>FcCs|j�S)N)Zioprio_sort_key)rKrLrrrr)rscCs|j�S)N)�get_user)rKrLrrrr)sscCs|jS)N)r0)rKrLrrrr)tsTcCs|j|jS)N)r1r2)rKrLrrrr)uscCs|jS)N)r/)rKrLrrrr)vscCs|jpt|jp|j�S)N)r.rr0r1)rKrLrrrr)yscCs|j�S)N)�get_cmdline)rKrLrrrr){scCst||_||_d|_tj|jd|_|jjsp||_|j�yt	j
�t	j�t	jd�Wnt	j
k
rnYnXdS)N�rr)�process_listr"�sorting_keyrI�sorting_keys�sorting_reverse�batch�win�resize�cursesZuse_default_colorsZstart_color�curs_set�error)�selfrUrPr"rrr�__init__~szIOTopUI.__init__cCs|jj�\|_|_dS)N)rUZgetmaxyx�height�width)rZrrrrV�szIOTopUI.resizec
Cs^d}tj�}|jjs.|jtjj�tjtj	B��x(|jj
dksL||jj
k�rX|jj�\}}|j
|dk|||jj�|jj
dk	r�|d7}||jj
kr�Pn|dkr�d}y|j|jjd�}WnBtjk
r�}z$|jr�|jdtjkr�g}n�WYdd}~XnXx.|D]&\}}|tjtjB@�rtjd��qW|jj�s>|j�|r2|jj�}	|j|	�q2WdS)Nrrg@�@)�select�pollr"rT�register�sys�stdin�filenoZPOLLINZPOLLPRI�
iterationsrP�refresh_processes�refresh_displayr%�
delay_secondsrY�args�errnoZEINTRZPOLLERRZPOLLHUP�exitrVrU�getch�
handle_key)
rZrdr_�total�actualZeventsr?�fdZevent�keyrrr�run�s:


zIOTopUI.runcCs|j|_dS)N)rS)rZrrr�reverse_sorting�szIOTopUI.reverse_sortingcCs�|j}|j|7_td|j�|_tttj�d|j�|_|jsh|jdkrh|dkrZd|_n|dkrhd|_||jkr�tj|jd|_dS)Nrrr8rO��)r8rO)rQr3r'r9rIrR�
has_swapin_iorS)rZZdeltaZorig_sorting_keyrrr�adjust_sorting_key�s

zIOTopUI.adjust_sorting_keyNcCs�|jjddtd�tjB|j�|jjdd|tj�|jj�tj	�tj
d�|jjdt|��}tj
d�tj
�|dkr~|S|r�t��|S)Nrr� r)Nr)rU�hline�ordrW�A_NORMALr]�addstr�A_BOLD�refreshZechorXZgetstrr9ZnoechorA)rZ�prompt�default�empty_is_cancel�inprrr�
prompt_str�s


zIOTopUI.prompt_strcCs6|j|||�}yt|�Stk
r0t��YnXdS)N)r�r�
ValueErrorrE)rZr~rr�r�rrr�
prompt_int�s
zIOTopUI.prompt_intcCs>y
|jd�Stk
r$t��Yntk
r8�YnXdS)NzPID to ionice: )r�rErFrA)rZrrr�
prompt_pid�s

zIOTopUI.prompt_pidcCs>y
|jd�Stk
r$t��Yntk
r8�YnXdS)NzTID to ionice: )r�rErGrA)rZrrr�
prompt_tid�s

zIOTopUI.prompt_tidcCsdy.|dk	r|jd||d�}n|jddd�}Wntk
rHt��YnX|dksZ|dkr`t��|S)Nz'I/O priority data (0-7, currently %s): FzI/O priority data (0-7): rrt)r�rErH)rZ�ioprio_datar�rrr�prompt_data�szIOTopUI.prompt_datacCsvy|j|�}Wntk
r&d}YnXt|�d}�x:|jjddtd�tjB|j�|jj	dd|tj
�t|�}xPt|�D]D\}}d|}	||kr�tj}
ntj}
|jj	d||	|
�|t|	�7}q|Wx�|jj
�}|tjtd�fkr�|dkr�|d8}Pq�|tjtd�fk�r ||k�r |d7}Pq�|tjtd�td�fk�rB||S|d	tjtjtjtd
�td�fkr�t��q�Wq8WdS)
Nrrrwz %s �l�r�
�
��q�Q���)�indexr�r9rUrxryrWrzr]�insstrr|�	enumerate�	A_REVERSErk�KEY_LEFT�	KEY_RIGHTZ	KEY_ENTERZ
KEY_CANCELZ	KEY_CLOSEZKEY_EXITrA)rZr~Zdisplay_listZret_listZselectedZset_len�offset�i�itemZdisplay�attrrprrr�
prompt_set�s:

zIOTopUI.prompt_setcCs8d}dddg}dddg}|dkr$d}|j||||�}|S)	NzI/O priority class: z	Real-timezBest-effortZIdleZrtZbe�idler)r�)rZ�ioprio_classr~Zclasses_promptZclasses_retr�rrr�prompt_classs

zIOTopUI.prompt_class�Error!cCsN|jjddtd�tjB|j�|jjddd|tj�|jj�t	j
d�dS)Nrrrwz  %s  )rUrxryrWrzr]r�r�r}r,Zsleep)rZrYrrr�prompt_error"s
zIOTopUI.prompt_errorcCs,|jjddtd�tjB|j�|jj�dS)Nrrrw)rUrxryrWrzr]r})rZrrr�prompt_clear(szIOTopUI.prompt_clearc"s��fdd�}�fdd�}�fdd�}�fdd�}td	�d
d�td�d
d�td��fdd�td��fdd�td�|td�|td�|td�|td�|td�|td�|td�|tj�fdd�tj�fdd�tj�fdd�tj�fdd�i}|j|dd��}|�dS)Ncs�jjdN_dS)NT)r"r*r)rZrr�toggle_accumulated-sz.IOTopUI.handle_key.<locals>.toggle_accumulatedcs�jjdN_dS)NT)r"�onlyr)rZrr�toggle_only_io/sz*IOTopUI.handle_key.<locals>.toggle_only_iocs(�jjdN_�jj��jj�dS)NT)r"�	processesrP�clearrer)rZrr�toggle_processes1s
z,IOTopUI.handle_key.<locals>.toggle_processescs`y��jjr �j�}�jj|�}n�j�}t|�jj�}|j�}t	j
|�\}}�j|�}|dkrdd}n
�j|�}|j
||��jj��jj�Wn�tk
r�}z�jd|j�WYdd}~Xn�tk
r��jd�Yn~tk
r��jd�Ynbtk
�r�jd�YnDtk
�r6�jd�Yn&tk
�rR�j�Yn
X�j�dS)Nr�rzError setting I/O priority: %szInvalid process id!zInvalid thread id!zInvalid I/O priority data!zInvalid integer!)r"r�r�rPZget_processr�r�taskstats_connection�
get_ioprior
Zto_class_and_datar�r�Z
set_ioprior�rerr��errrFrGrHrErAr�)rJZ	exec_unit�tidZioprio_valuer�r�r?)rZrr�ionice5s:



 z"IOTopUI.handle_key.<locals>.ionicer�cSs
tjd�S)Nr)rarjrrrrr)Zsz$IOTopUI.handle_key.<locals>.<lambda>r�cSs
tjd�S)Nr)rarjrrrrr)\sr�cs�j�S)N)rrr)rZrrr)^s�Rcs�j�S)N)rrr)rZrrr)`s�a�A�o�OrKrr��Ics
�jd�S)Nrr�)rvr)rZrrr)rscs
�jd�S)Nr)rvr)rZrrr)tscs�jttj��S)N)rvr9rIrRr)rZrrr)vscs�jttj��S)N)rvr9rIrRr)rZrrr)xscSsdS)Nrrrrrr){s)ryrWr�r�ZKEY_HOMEZKEY_END�get)rZrpr�r�r�r�Zkey_bindings�actionr)rZrrl,sL$




zIOTopUI.handle_keycs��fdd�}�fdd�}tt|�jjj���}tj�jd��jj	rPdd��ndd��|j
��fd	d��jd
��jjs�|�j
dd�=tt||��S)Nc
sRt�j|�jj�}|\}}}}dt}|jf}|d7}||j�f7}|d7}||j�dd�f7}|d7}|||f7}�jr�|d7}|||f7}n�jj	r�|d7}|d
7}|d	7}||}|j
�}	�jj	�s.�jt|�}
d
|
ko�t|	�kn�r.|
dd
}|
|d}|	d|�d|	|d�}	||	7}�jj	�sN|d�j�}|S)Nz%%%ddz %4sz %-8s�z
 %11s %11sz %7s %7sz %s �
?unavailable?rwrr�~)r�)
r7r"rPr%�
MAX_PID_WIDTHrJr�rMrurTrNr]r9)
rKr4r5r6r0r1�formatZparams�lineZcmdlineZremaining_lengthZlen1Zoffset2)rZrrr�s:

z IOTopUI.get_data.<locals>.formatcs�jjp|j�jj�S)N)r"r�Zdid_some_ior*)rK)rZrr�
should_format�s
z'IOTopUI.get_data.<locals>.should_formatrcSs|jS)N)r+)rKrrrr)�sz"IOTopUI.get_data.<locals>.<lambda>cSs|jS)N)r-)rKrrrr)�scs�|�|��S)Nr)rK)rp�stats_lambdarrr)�s)rp�reverser)�list�filterrPr��valuesrIrRrQr"r*�sortrSrTr\�map)rZr�r�r�r)rprZr�r�get_data~s

zIOTopUI.get_datacs�dt�j|d|�jd�t�j|d|�jd�fdt�j|d|�jd�t�j|d|�jd�fg�tdtd�d}�jjr�|d7}n|d	7}|d
ddd
dddg}tj�_�jr�t	�dkr�d�_�j
d��j�}�jj�rdg|}tj
d���fdd�|D�}�fdd��D���jj�r��jjdk�rjx�D]}t|��q8W�jjt|�k�rjtdj|��x|D]}	t|	jd���qpWtjj��n�jj�x0t��D]$\�}�jj�d|d�j���q�W�jjt��dtd�tj B�j��j}
x�t!t|��D]���j�r$�d!k�r$�qtj }|�}��j"k�rJ|dd�}��j"k�rv|tj#O}|�j$�rpd�prd7}|d|
�}|
t|�8}
�jj||��qW�jdk	�r�d}
nd}
t%t|��j&dtt'|
���}xzt!|�D]n�yN���fdd �}y||��Wn(t(k
�r0||�jd��YnXWntj)k
�rLYnX�q�W|
�rx�jj*�j&t��d|
tj#��jj+�dS)"Nz,Total DISK READ : %s | Total DISK WRITE : %sr�rz,Actual DISK READ: %s | Actual DISK WRITE: %s�rw�PIDZTIDz  PRIOz  USERz     DISK READz  DISK WRITEz  SWAPINz      IOz    COMMANDFz    TIMEz	%H:%M:%S csg|]}�|�qSrr)�.0r�)�current_timerr�
<listcomp>�sz+IOTopUI.refresh_display.<locals>.<listcomp>csg|]}�|�qSrr)r�rL)r�rrr��srrzutf-8r8rO�>�<zoCONFIG_TASK_DELAY_ACCT and kernel.task_delayacct sysctl not enabled in kernel, cannot determine SWAPIN and IO %cs �jj�t��dd|�dS)Nrr)rUr{r9)r�)r�rZ�summaryrr�
print_line�sz+IOTopUI.refresh_display.<locals>.print_line)r8rO),r&r"�rjustr3r�r�rZhas_blkio_delay_totalrurrvr�r,ZstrftimerT�quietr>r�join�encodera�stdout�flushrUZeraser�r{r]rxr9ryrWr��rangerQr|rSr'r\�bool�UnicodeEncodeErrorrYr�r})rZZ
first_timermrnr%rJZtitles�linesrLr�Zremaining_colsr��titleZ
status_msgZ	num_linesr�r)r�r�rZr�rrf�s�











 
 zIOTopUI.refresh_display)NT)NT)N)r�)rBrCrDrRr[rVrqrrrvr�r�r�r�r�r�r�r�r�rlr�rfrrrrrIns4





!


 
	
R1rIcCsf|jrtjtjtj�n$dd�}tjtj|�tjtj|�t|�}t||�}t|||�}|j	�dS)Nc_stjd�dS)Nr)rarj)rh�kwargsrrr�
clean_exit	sz$run_iotop_window.<locals>.clean_exit)
rT�signal�SIGPIPE�SIG_DFL�SIGINT�SIGTERMrrrIrq)rUr"r�r�rPZuirrr�run_iotop_windows
r�cCs�y |jrtd|�Stjt|�SWn�tk
rx}z<|jtjkrft|tj	d�tdtj	d�tj
d�n�WYdd}~XnZtjk
r�}z<t|�}|j
d�dkr�|j
d�dks�|j
d�dkr�n�WYdd}~XnXdS)N)�filea�
The Linux kernel interfaces that iotop relies on now require root priviliges
or the NET_ADMIN capability. This change occured because a security issue
(CVE-2011-2494) was found that allows leakage of sensitive data across user
boundaries. If you require the ability to run iotop as a non-root user, please
configure sudo to allow you to run iotop as root.

Please do not file bugs on iotop about this.rZERRrz
nocbreak()zendwin())rTr�rW�wrapper�OSErrorriZEPERMr>ra�stderrrjrY�str�find)r"r?Zstrerrr�	run_iotops"
r�cCs�d}y:ddl}ddl}td�|jdt�t�|�|j|�}WnXtk
r�ddl}ddl	}|j
|dd�}td�|j|�|j�|j
j|�}YnX|j�|jdd	�|jd
�|jd
�tj|�dS)Nz
iotop.profrzProfiling using cProfilezcontinuation()r)Z
lineeventszProfiling using hotshotr,Zcalls�2)�cProfile�pstatsr>Zrunctx�globals�localsr�ImportError�hotshotZ
hotshot.statsZProfileZruncall�closer4�loadZ
strip_dirsZ
sort_statsZprint_statsZ
print_callees�os�remove)ZcontinuationZ	prof_filer�r�r4r�Zprofrrr�_profile6s(


r�aF%s [OPTIONS]

DISK READ and DISK WRITE are the block I/O bandwidth used during the sampling
period. SWAPIN and IO are the percentages of time the thread spent respectively
while swapping in and waiting on I/O more generally. PRIO is the I/O priority at
which the thread is running (set using the ionice command).

Controls: left and right arrows to change the sorting column, r to invert the
sorting order, o to toggle the --only option, p to toggle the --processes
option, a to toggle the --accumulated option, i to change I/O priority, q to
quit, any other key to force a refresh.cs�ytjtjd�Wntjk
r0td�YnXtjtdtd�}|j	ddddd	d
d�|j	dd
dddd�|j	ddddddd�|j	dddddddd�|j	d d!dd"d#d$d%d&�|j	d'd(d)d*d#d+d,d&�|j	d-d.dd/d	d0d�|j	d1d2dd3d	d4d�|j	d5d6dd7d	d8d�|j	d9d:dd;d<d�|j	d=d>d?d@dAdBd�|j	dCddDd	tj
d�|j�\�}|�rt|jdEdFj
|��t���j�p�g�_�j�p��j�p��j�_�fdGdH���j�ṙfdIdJ�}t|�n��dS)KNrz8unable to set locale, falling back to the default localeziotop )Zusage�versionz-oz--only�
store_truer�Fz1only show processes or threads actually doing I/O)r��destr�helpz-bz--batchrTznon-interactive mode)r�r�r�z-nz--iterrrdZNUMz-number of iterations before ending [infinite])�typer��metavarr�z-dz--delayrrgz#delay between iterations [1 second]ZSECr)r�r�r�r�rz-pz--pid�pids�appendz"processes/threads to monitor [all]r�)r�r�r�r�r�z-uz--userr�Zuserszusers to monitor [all]ZUSERz-Pz--processesr�z$only show processes, not all threadsz-az
--accumulatedr*z)show accumulated I/O instead of bandwidthz-kz--kilobytesr!z.use kilobytes instead of a human friendly unitz-tz--timer,z.add a timestamp on each line (implies --batch)z-qz--quiet�countr�rz/suppress some lines of header (implies --batch)z	--profile�profilezUnexpected arguments: rwcst��S)N)r�r)r"rrr)�szmain.<locals>.<lambda>c	sy
��WnYnXdS)Nrr)�	main_looprr�safe_main_loop�s
zmain.<locals>.safe_main_loop)�locale�	setlocale�LC_ALL�Errorr>�optparseZOptionParser�USAGEr	Z
add_optionZ
SUPPRESS_HELP�
parse_argsrYr�rr�rTr,r�r�r�)�parserrhr�r)r�r"r�main\s\








r).Z
__future__rrWrirrrr�r^r�rar,Z
iotop.datarrrrrrZ
iotop.versionr	Ziotopr
Ziotop.iopriorrr r$r&r7r@r�r=rArErFrGrH�objectrIr�r�r��argvrrrrrr�<module>sH
$$