Hacked By AnonymousFox

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

3

�{Meʍ�@s�ddlZddlZddlZddlZddlmZddlmZddlm	Z	dZ
dd�Zdd	�ZGd
d�d�Z
dd
�Zdd�ZGdd�d�ZGdd�d�ZGdd�d�ZGdd�d�ZGdd�d�ZGdd�d�ZGdd�d�ZGdd�d�ZGd d!�d!�ZGd"d#�d#�Zed$k�r�ddlZe�Zx0eejj��D]Ze e�d%eje����q*We�Z!x0ee!j!j��D]Z"e e"�d%e!j!e"����qbWe�Z#e d&e#j$�d'��x,ee#j��D]Z%e e%�d(e#e%����q�We d)d*d+�ee&ej'd,��Z(x8ee(j)�D]*Ze e(j*ej+d-�d.e(j*ej,����q�We d*d+�x&e(j-ej'd/�D]Z.e e.d0��qDWe�Z/e e/d,�e�Z0xFej1d,�e0j2�x$e0D]Z#e e#�d%e0e#����q�We d2��qtWdS)3�N)�reduce)�range)�bitmasklistz0.7.3cCstj�}ttjd|��S)z) Return True if running on s390 or s390x Zs390)�platform�machine�bool�re�search)r�r
�/usr/lib/python3.6/procfs.py�is_s390src	Cs:|drtdd�|d�j�Sy|ddSdSdS)z�
    Returns the process command line, if available in the given `process' class,
    if not available, falls back to using the comm (short process name) in its
    pidstat key.
    �cmdlinecSs|d|S)Nz %sr
)�a�br
r
r�<lambda>!sz!process_cmdline.<locals>.<lambda>�stat�commN)r�strip)Zpid_infor
r
r�process_cmdlinesrc+@sNeZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZd
ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!dZ"dZ#dZ$d Z%d!Z&d!Z'd"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLg+Z(dcdNdO�Z)dPdQ�Z*dRdS�Z+dTdU�Z,dVdW�Z-dXdY�Z.dZd[�Z/ddd\d]�Z0d^d_�Z1d`da�Z2dbS)e�pidstatam
    Provides a dictionary to access the fields in the
    per process /proc/PID/stat files.

    One can obtain the available fields by asking for the keys of the
    dictionary, e.g.:

        >>> p = procfs.pidstat(1)
        >>> print p.keys()
        ['majflt', 'rss', 'cnswap', 'cstime', 'pid', 'session', 'startstack', 'startcode', 'cmajflt', 'blocked', 'exit_signal', 'minflt', 'nswap', 'environ', 'priority', 'state', 'delayacct_blkio_ticks', 'policy', 'rt_priority', 'ppid', 'nice', 'cutime', 'endcode', 'wchan', 'num_threads', 'sigcatch', 'comm', 'stime', 'sigignore', 'tty_nr', 'kstkeip', 'utime', 'tpgid', 'itrealvalue', 'kstkesp', 'rlim', 'signal', 'pgrp', 'flags', 'starttime', 'cminflt', 'vsize', 'processor']

       And then access the various process properties using it as a dictionary:

        >>> print p['comm']
        systemd
        >>> print p['priority']
        20
        >>> print p['state']
        S

       Please refer to the 'procfs(5)' man page, by using:

        $ man 5 procfs

       To see information for each of the above fields, it is part of the
           'man-pages' RPM package.
    ������ �@��iiiii i@i�iiiiii i@i�iiiiii i@l�pidr�stateZppidZpgrpZsessionZtty_nrZtpgid�flagsZminfltZcminfltZmajfltZcmajflt�utimeZstimeZcutimeZcstimeZpriority�niceZnum_threadsZitrealvalueZ	starttimeZvsizeZrssZrlimZ	startcodeZendcodeZ
startstackZkstkespZkstkeip�signalZblockedZ	sigignoreZsigcatchZwchanZnswapZcnswapZexit_signal�	processor�rt_priorityZpolicyZdelayacct_blkio_ticks�environ�/proccCs0||_y|j|�Wntk
r*�YnXdS)N)r�load�FileNotFoundError)�selfr�basedirr
r
r�__init__~s
zpidstat.__init__cCs
|j|S)N)�fields)r+�	fieldnamer
r
r�__getitem__�szpidstat.__getitem__cCst|jj��S)N)�listr.�keys)r+r
r
rr2�szpidstat.keyscCst|jj��S)N)r1r.�values)r+r
r
rr3�szpidstat.valuescCs
||jkS)N)r.)r+r/r
r
r�has_key�szpidstat.has_keycCs|jS)N)r.)r+r
r
r�items�sz
pidstat.itemscCs
||jkS)N)r.)r+r/r
r
r�__contains__�szpidstat.__contains__cCs�yt|�d|j�d��}Wntk
r0�YnX|j�j�jd�}|j�|djd�|dj�}i|_tt	|�t	|j
��}xft|�D]Z}|j
|}||}|dkr�|jd�|jd<q�yt|�|j|<Wq�||j|<Yq�Xq�WdS)	N�/z/statz) rz (rrz())
�openrr*�readliner�split�closer.�min�len�proc_stat_fieldsr�int)r+r,�fr.�	nr_fields�iZattrname�valuer
r
rr)�s$
zpidstat.loadcCst|jd|j@�S)z�
        Returns true if this process has a fixed smp affinity mask,
                not allowing it to be moved to a different set of CPUs.
        r!)rr.�PF_THREAD_BOUND)r+r
r
r�is_bound_to_cpu�szpidstat.is_bound_to_cpucCsNg}xDt|�D]8}|dd�dkr$qt||�}||jd@r|j|�qW|S)a�
        Returns a list with all the process flags known, details depend
        on kernel version, declared in the file include/linux/sched.h in
        the kernel sources.

        As of v4.2-rc7 these include (from include/linux/sched.h comments):

            PF_EXITING        Getting shut down
            PF_EXITPIDONE     Pi exit done on shut down
            PF_VCPU           I'm a virtual CPU
            PF_WQ_WORKER      I'm a workqueue worker
            PF_FORKNOEXEC     Forked but didn't exec
            PF_MCE_PROCESS    Process policy on mce errors
            PF_SUPERPRIV      Used super-user privileges
            PF_DUMPCORE       Dumped core
            PF_SIGNALED       Killed by a signal
            PF_MEMALLOC       Allocating memory
            PF_NPROC_EXCEEDED Set_user noticed that RLIMIT_NPROC was exceeded
            PF_USED_MATH      If unset the fpu must be initialized before use
            PF_USED_ASYNC     Used async_schedule*(), used by module init
            PF_NOFREEZE       This thread should not be frozen
            PF_FROZEN          Frozen for system suspend
            PF_FSTRANS         Inside a filesystem transaction
            PF_KSWAPD          I am kswapd
            PF_MEMALLOC_NOIO   Allocating memory without IO involved
            PF_LESS_THROTTLE   Throttle me less: I clean memory
            PF_KTHREAD         I am a kernel thread
            PF_RANDOMIZE       Randomize virtual address space
            PF_SWAPWRITE       Allowed to write to swap
            PF_NO_SETAFFINITY  Userland is not allowed to meddle with cpus_allowed
            PF_MCE_EARLY       Early kill for mce process policy
            PF_MUTEX_TESTER    Thread belongs to the rt mutex tester
            PF_FREEZER_SKIP    Freezer should not count it as freezable
            PF_SUSPEND_TASK    This thread called freeze_processes and
                               should not be frozen

        N�ZPF_r!)�dir�getattrr.�append)r+Zsflags�attrrCr
r
r�
process_flags�s&
zpidstat.process_flagsN)r()r()3�__name__�
__module__�__qualname__�__doc__ZPF_ALIGNWARNZPF_STARTINGZ
PF_EXITINGZ
PF_EXITPIDONEZPF_VCPUZPF_WQ_WORKERZ
PF_FORKNOEXECZPF_MCE_PROCESSZPF_SUPERPRIVZPF_DUMPCOREZPF_SIGNALEDZPF_MEMALLOCZPF_NPROC_EXCEEDEDZ
PF_FLUSHERZPF_USED_MATHZ
PF_USED_ASYNCZPF_NOFREEZEZ	PF_FROZENZ
PF_FSTRANSZ	PF_KSWAPDZPF_MEMALLOC_NOIOZ
PF_SWAPOFFZPF_LESS_THROTTLEZ
PF_KTHREADZPF_RANDOMIZEZPF_SWAPWRITEZPF_SPREAD_PAGEZPF_SPREAD_SLABrD�PF_NO_SETAFFINITYZPF_MCE_EARLYZPF_MEMPOLICYZPF_MUTEX_TESTERZPF_FREEZER_SKIPZPF_FREEZER_NOSIGZPF_SUSPEND_TASKr>r-r0r2r3r4r5r6r)rErKr
r
r
rr*st


	
rc
Cs2d}ytt|j|dd�|@�SdSdS)Nirr!T)rr?�	processes)r+rrPr
r
r�cannot_set_affinity�srRc
Cs8d}y$tt|j|j|dd�|@�SdSdS)Nirr!T)rr?rQ�threads)r+r�tidrPr
r
r�cannot_set_thread_affinity�srUc@sTeZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
ddd�ZdS)�	pidstatusa
    Provides a dictionary to access the fields
    in the per process /proc/PID/status files.
    This provides additional information about processes and threads to
    what can be obtained with the procfs.pidstat() class.

    One can obtain the available fields by asking for the keys of the
    dictionary, e.g.:

        >>> import procfs
        >>> p = procfs.pidstatus(1)
        >>> print p.keys()
        ['VmExe', 'CapBnd', 'NSpgid', 'Tgid', 'NSpid', 'VmSize', 'VmPMD', 'ShdPnd', 'State', 'Gid', 'nonvoluntary_ctxt_switches', 'SigIgn', 'VmStk', 'VmData', 'SigCgt', 'CapEff', 'VmPTE', 'Groups', 'NStgid', 'Threads', 'PPid', 'VmHWM', 'NSsid', 'VmSwap', 'Name', 'SigBlk', 'Mems_allowed_list', 'VmPeak', 'Ngid', 'VmLck', 'SigQ', 'VmPin', 'Mems_allowed', 'CapPrm', 'Seccomp', 'VmLib', 'Cpus_allowed', 'Uid', 'SigPnd', 'Pid', 'Cpus_allowed_list', 'TracerPid', 'CapInh', 'voluntary_ctxt_switches', 'VmRSS', 'FDSize']
        >>> print p["Pid"]
        1
        >>> print p["Threads"]
        1
        >>> print p["VmExe"]
        1248 kB
        >>> print p["Cpus_allowed"]
        f
        >>> print p["SigQ"]
        0/30698
        >>> print p["VmPeak"]
        320300 kB
        >>>

    Please refer to the 'procfs(5)' man page, by using:

        $ man 5 procfs

    To see information for each of the above fields, it is part of the
    'man-pages' RPM package.

    In the man page there will be references to further documentation, like
        referring to the "getrlimit(2)" man page when explaining the "SigQ"
        line/field.
    �/proccCs||_|j|�dS)N)rr))r+rr,r
r
rr-!szpidstatus.__init__cCs
|j|S)N)r.)r+r/r
r
rr0%szpidstatus.__getitem__cCst|jj��S)N)r1r.r2)r+r
r
rr2(szpidstatus.keyscCst|jj��S)N)r1r.r3)r+r
r
rr3+szpidstatus.valuescCs
||jkS)N)r.)r+r/r
r
rr4.szpidstatus.has_keycCs|jS)N)r.)r+r
r
rr51szpidstatus.itemscCs
||jkS)N)r.)r+r/r
r
rr64szpidstatus.__contains__cCs�i|_t|�d|j�d���n}xf|j�D]Z}|jd�}t|�dkrDq(|d}|dj�}yt|�|j|<Wq(||j|<Yq(Xq(WWdQRXdS)Nr7z/status�:rrr)r.r8r�	readlinesr:r=rr?)r+r,r@�liner.�namerCr
r
rr)7s
zpidstatus.loadN)rW)rW)rLrMrNrOr-r0r2r3r4r5r6r)r
r
r
rrV�s&
rVc@sReZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�processa+
    Information about a process with a given pid, provides a dictionary with
    two entries, instances of different wrappers for /proc/ process related
    meta files: "stat" and "status", see the documentation for procfs.pidstat
    and procfs.pidstatus for further info about those classes.
    �/proccCs||_||_dS)N)rr,)r+rr,r
r
rr-Nszprocess.__init__cCs�t||�s�|dkrX|dkr t}nt}yt||||j|j��Wq�tk
rT�Yq�XnF|dkrj|j�n4|dkr||j�n"|dkr�|j	�n|dkr�|j
�t||�S)Nr�statusr
rS�cgroupsr')rr^)�hasattrrrV�setattrrr,r*�load_cmdline�load_threads�load_cgroups�load_environrH)r+rJZsclassr
r
rr0Rs$




zprocess.__getitem__cCs
t||�S)N)r`)r+rJr
r
rr4jszprocess.has_keycCs
t||�S)N)r`)r+rJr
r
rr6mszprocess.__contains__cCsvy>td|j�d���"}|j�j�jd�dd�|_WdQRXWn2tk
rXd|_Yntk
rpd|_YnXdS)Nz/proc/z/cmdline�r���)r8rr9rr:r
r*�UnicodeDecodeError)r+r@r
r
rrbps*
zprocess.load_cmdlinecCs"td|j�d��|_|j|j=dS)Nz/proc/z/task/)�pidstatsrrS)r+r
r
rrc{szprocess.load_threadscCstd|_td|j�d���R}xJt|j��D]:}t|j�dkrT|jd|dd�|_q(|dd�|_q(WWdQRXdS)	N�z/proc/z/cgroupr�,rrgrg)r_r8r�reversedrYr=)r+r@rZr
r
rrd�szprocess.load_cgroupscCshi|_td|j�d���F}x>|j�jd�D],}t|�dkr*|jd�}|d|j|d<q*WWdQRXdS)aD
        Loads the environment variables for this process. The entries then
        become available via the 'environ' member, or via the 'environ'
        dict key when accessing as p["environ"].

        E.g.:


        >>> all_processes = procfs.pidstats()
        >>> firefox_pid = all_processes.find_by_name("firefox")
        >>> firefox_process = all_processes[firefox_pid[0]]
        >>> print firefox_process["environ"]["PWD"]
        /home/acme
        >>> print len(firefox_process.environ.keys())
        66
        >>> print firefox_process["environ"]["SHELL"]
        /bin/bash
        >>> print firefox_process["environ"]["USERNAME"]
        acme
        >>> print firefox_process["environ"]["HOME"]
        /home/acme
        >>> print firefox_process["environ"]["MAIL"]
        /var/spool/mail/acme
        >>>
        z/proc/z/environrfr�=rN)r'r8rr9r:r=)r+r@�x�yr
r
rre�s
zprocess.load_environN)r])rLrMrNrOr-r0r4r6rbrcrdrer
r
r
rr\Fs
	r\c@s�eZdZdZd$dd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#S)%ria#
    Provides access to all the processes in the system, to get a picture of
    how many processes there are at any given moment.

    The entries can be accessed as a dictionary, keyed by pid. Also there are
    methods to find processes that match a given COMM or regular expression.
    �/proccCs||_i|_|j�dS)N)r,rQ�reload)r+r,r
r
rr-�szpidstats.__init__cCs
|j|S)N)rQ)r+�keyr
r
rr0�szpidstats.__getitem__c	Csy|j|=WnYnXdS)N)rQ)r+rrr
r
r�__delitem__�szpidstats.__delitem__cCst|jj��S)N)r1rQr2)r+r
r
rr2�sz
pidstats.keyscCst|jj��S)N)r1rQr3)r+r
r
rr3�szpidstats.valuescCs
||jkS)N)rQ)r+rrr
r
rr4�szpidstats.has_keycCs|jS)N)rQ)r+r
r
rr5�szpidstats.itemscCs
||jkS)N)rQ)r+rrr
r
rr6�szpidstats.__contains__c
CsV|`i|_tj|j�}x:|D]2}yt|�}WnwYnXt||j�|j|<qWdS)a'
        This operation will throw away the current dictionary contents,
        if any, and read all the pid files from /proc/, instantiating a
        'process' instance for each of them.

        This is a high overhead operation, and should be avoided if the
        perf python binding can be used to detect when new threads appear
        and existing ones terminate.

        In RHEL it is found in the python-perf rpm package.

        More information about the perf facilities can be found in the
        'perf_event_open' man page.
        N)rQ�os�listdirr,r?r\)r+�pidsZspidrr
r
rrq�s
zpidstats.reloadcCshg}xHt|jj��D]6}y|j|j�Wqtk
rH|j|�YqXqWx|D]}|j|=qTWdS)N)r1rQr2rc�OSErrorrI)r+Z	to_removerr
r
r�reload_threads�s
zpidstats.reload_threadscCsn|dd�}g}xXt|jj��D]F}y$||j|ddkrF|j|�Wq tk
rd|j|=Yq Xq W|S)N�rr)r1rQr2rI�IOError)r+r[rvrr
r
r�find_by_name�szpidstats.find_by_namecCsdg}xZt|jj��D]H}y&|j|j|dd�r<|j|�Wqtk
rZ|j|=YqXqW|S)Nrr)r1rQr2�matchrIrz)r+�regexrvrr
r
r�
find_by_regexszpidstats.find_by_regexcCs`g}xVt|jj��D]D}y"|jt|j|��r8|j|�Wqtk
rV|j|=YqXqW|S)N)r1rQr2r|rrIrz)r+r}rvrr
r
r�find_by_cmdline_regexszpidstats.find_by_cmdline_regexcs�d}d}g�x�|�d|��}|j|�}|sFt�fdd�|D��dkrHPxF|D]>}y||j|dd�7}WqNtk
r�|j|=YqNXqNW�|7�|d7}qW|jd	�}|S)
Nrrjr7csg|]}|�kr|�qSr
r
)�.0�n)�processed_pidsr
r�
<listcomp>'sz0pidstats.get_per_cpu_rtprios.<locals>.<listcomp>rr&rrk)r{r=rQrzr)r+�basename�cpu�
prioritiesr[rvrr
)r�r�get_per_cpu_rtprios s"
 

zpidstats.get_per_cpu_rtprioscs�d}d}g�x�|j|�}|s8t�fdd�|D��dkr:PxF|D]>}y||j|dd�7}Wq@tk
r||j|=Yq@Xq@W�|7�|d7}qW|jd�}|S)	Nrrjcsg|]}|�kr|�qSr
r
)r�r�)r�r
rr�=sz(pidstats.get_rtprios.<locals>.<listcomp>rr&rrk)r{r=rQrzr)r+r[r�r�rvrr
)r�r�get_rtprios7s 
 

zpidstats.get_rtprioscCs|j|dj�S)zQ
        Checks if a given pid can't have its SMP affinity mask changed.
        r)rQrE)r+rr
r
rrEMszpidstats.is_bound_to_cpuN)rp)rLrMrNrOr-r0rsr2r3r4r5r6rqrxr{r~rr�r�rEr
r
r
rri�s"


ric@speZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)�
interruptsam
    Information about IRQs in the system. A dictionary keyed by IRQ number
    will have as its value another dictionary with "cpu", "type" and "users"
    keys, with the SMP affinity mask, type of IRQ and the drivers associated
    with each interrupt.

    The information comes from the /proc/interrupts file, documented in
    'man procfs(5)', for instance, the 'cpu' dict is an array with one entry
    per CPU present in the sistem, each value being the number of interrupts
    that took place per CPU.

    E.g.:

    >>> import procfs
    >>> interrupts = procfs.interrupts()
    >>> thunderbolt_irq = interrupts.find_by_user("thunderbolt")
    >>> print thunderbolt_irq
    34
    >>> thunderbolt = interrupts[thunderbolt_irq]
    >>> print thunderbolt
    {'affinity': [0, 1, 2, 3], 'type': 'PCI-MSI', 'cpu': [3495, 0, 81, 0], 'users': ['thunderbolt']}
    >>>
    cCsi|_|j�dS)N)r�rq)r+r
r
rr-mszinterrupts.__init__cCs|jt|�S)N)r��str)r+rrr
r
rr0qszinterrupts.__getitem__cCst|jj��S)N)r1r�r2)r+r
r
rr2tszinterrupts.keyscCst|jj��S)N)r1r�r3)r+r
r
rr3wszinterrupts.valuescCst|�|jkS)N)r�r�)r+rrr
r
rr4zszinterrupts.has_keycCs|jS)N)r�)r+r
r
rr5}szinterrupts.itemscCst|�|jkS)N)r�r�)r+rrr
r
rr6�szinterrupts.__contains__cCs�|`i|_td���}x�|j�D]�}|j�}|j�}|ddd�dkrRt|�|_q|djd�}i|j|<|j|dd�|�|j|<yt|�}WnwYnX|j	|�|j|d<qWWdQRXdS)Nz/proc/interruptsrrFZCPUrXrZaffinity)
r�r8rYrr:r=�nr_cpus�parse_entryr?�parse_affinity)r+r@rZr.�irqZnirqr
r
rrq�s"


zinterrupts.reloadcCs�i}g|d<|djt|d��t|�}||jkr�|ddd�|d|j�D�7<||jkr�||j|d<||jdkr�dd�||djd�D�|d	<ng|d	<|S)
Nr�rcSsg|]}t|��qSr
)r?)r�rBr
r
rr��sz*interrupts.parse_entry.<locals>.<listcomp>r�typecSsg|]}|j��qSr
)r)r�rr
r
rr��srk�users)rIr?r=r�r:)r+r.rZ�dictrAr
r
rr��s
$
zinterrupts.parse_entrycCsLy0td|�d���}|j�}WdQRXt||j�Stk
rFdgSXdS)Nz
/proc/irq/z
/smp_affinityr)r8r9rr�rz)r+r�r@rZr
r
rr��szinterrupts.parse_affinitycCs@x:t|jj��D](}d|j|kr||j|dkr|SqWdS)a�
        Looks up a interrupt number by the name of one of its users"

        E.g.:

        >>> import procfs
        >>> interrupts = procfs.interrupts()
        >>> thunderbolt_irq = interrupts.find_by_user("thunderbolt")
        >>> print thunderbolt_irq
        34
        >>> thunderbolt = interrupts[thunderbolt_irq]
        >>> print thunderbolt
        {'affinity': [0, 1, 2, 3], 'type': 'PCI-MSI', 'cpu': [3495, 0, 81, 0], 'users': ['thunderbolt']}
        >>>
        r�N)r1r�r2)r+�userrBr
r
r�find_by_user�s
zinterrupts.find_by_usercCs^g}xTt|jj��D]B}d|j|kr(qx,|j|dD]}|j|�r8|j|�Pq8WqW|S)a�
        Looks up a interrupt number by a regex that matches names of its users"

        E.g.:

        >>> import procfs
        >>> import re
        >>> interrupts = procfs.interrupts()
        >>> usb_controllers = interrupts.find_by_user_regex(re.compile(".*hcd"))
        >>> print usb_controllers
        ['22', '23', '31']
        >>> print [ interrupts[irq]["users"] for irq in usb_controllers ]
        [['ehci_hcd:usb4'], ['ehci_hcd:usb3'], ['xhci_hcd']]
        >>>
        r�)r1r�r2r|rI)r+r}ZirqsrBr�r
r
r�find_by_user_regex�s


zinterrupts.find_by_user_regexN)rLrMrNrOr-r0r2r3r4r5r6rqr�r�r�r�r
r
r
rr�Tsr�c@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)r
a9
    Parses the kernel command line (/proc/cmdline), turning it into a dictionary."

    Useful to figure out if some kernel boolean knob has been turned on,
    as well as to find the value associated to other kernel knobs.

    It can also be used to find out about parameters passed to the
    init process, such as 'BOOT_IMAGE', etc.

    E.g.:
    >>> import procfs
    >>> kcmd = procfs.cmdline()
    >>> print kcmd.keys()
    ['LANG', 'BOOT_IMAGE', 'quiet', 'rhgb', 'rd.lvm.lv', 'ro', 'root']
    >>> print kcmd["BOOT_IMAGE"]
    /vmlinuz-4.3.0-rc1+
    >>>
    cCsi|_|j�dS)N)�options�parse)r+r
r
rr-�szcmdline.__init__cCsjtd��X}xP|j�j�j�D]<}|jd�}t|�dkrFd|j|d<q|d|j|d<qWWdQRXdS)Nz
/proc/cmdlinermrTr)r8r9rr:r=r�)r+r@Zoptionr.r
r
rr��s

z
cmdline.parsecCs
|j|S)N)r�)r+rrr
r
rr0szcmdline.__getitem__cCst|jj��S)N)r1r�r2)r+r
r
rr2szcmdline.keyscCst|jj��S)N)r1r�r3)r+r
r
rr3szcmdline.valuescCs|jS)N)r�)r+r
r
rr5
sz
cmdline.itemsN)
rLrMrNrOr-r�r0r2r3r5r
r
r
rr
�s	r
c@sBeZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�cpuinfoa�
    Dictionary with information about CPUs in the system.

    Please refer to 'man procfs(5)' for further information about the
    '/proc/cpuinfo' file, that is the source of the information provided
    by this class. The 'man lscpu(1)' also has information about a program that
    uses the '/proc/cpuinfo' file.

    Using this class one can obtain the number of CPUs in a system:

      >>> cpus = procfs.cpuinfo()
          >>> print cpus.nr_cpus
          4

    It is also possible to figure out aspects of the CPU topology, such as
    how many CPU physical sockets exists, i.e. groups of CPUs sharing
    components such as CPU memory caches:

      >>> print len(cpus.sockets)
      1

    Additionally dictionary with information common to all CPUs in the system
    is available:

      >>> print cpus["model name"]
          Intel(R) Core(TM) i7-3667U CPU @ 2.00GHz
          >>> print cpus["cache size"]
          4096 KB
          >>>
    �
/proc/cpuinfocCs i|_d|_g|_|j|�dS)Nr)�tagsr��socketsr�)r+�filenamer
r
rr-.szcpuinfo.__init__cCs|j|j�S)N)r��lower)r+rrr
r
rr04szcpuinfo.__getitem__cCst|jj��S)N)r1r�r2)r+r
r
rr27szcpuinfo.keyscCst|jj��S)N)r1r�r3)r+r
r
rr3:szcpuinfo.valuescCs|jS)N)r�)r+r
r
rr5=sz
cpuinfo.itemscCs(t|���}x�|j�D]�}|j�}|s&q|jd�}|dj�j�}|dkrX|jd7_qt�rv|dkrv|jd7_q|dkr�q|dj�|j|<|dkr|j|}||jkr|jj	|�qWWdQRX|jr�t
|j�p�|jd|jkr�t|jd�p�d|_d	|jk�rt|jd	��pd|j|_
dS)
NrXrr%rz
cpu numberzcore idzphysical idZsiblingsz	cpu cores)r8rYrr:r�r�rr�r�rIr=r?Z
nr_socketsZnr_cores)r+r�r@rZr.ZtagnameZ	socket_idr
r
rr�@s2



 z
cpuinfo.parseN)r�)
rLrMrNrOr-r0r2r3r5r�r
r
r
rr�s
r�c@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�	smaps_libat
    Representation of an mmap in place for a process. Can be used to figure
    out which processes have an library mapped, etc.

    The 'perm' member can be used to figure out executable mmaps,
    i.e. libraries.

    The 'vm_start' and 'vm_end' in turn can be used when trying to resolve
    processor instruction pointer addresses to a symbol name in a library.
    c
Cs�|dj�}dd�|djd�D�\|_|_|d|_t|dd�|_|djd	�\|_|_t|d
�|_t	|�dkr�|d|_
nd|_
i|_x^|dd�D]N}|j�}|ddd�j�}yt|d�|j|<Wq�||j|<Yq�Xq�WdS)
NrcSsg|]}t|d��qS)r)r?)r�rr
r
rr�jsz&smaps_lib.__init__.<locals>.<listcomp>�-rrrrFrXr�rg)
r:�vm_startZvm_endZpermsr?�offset�major�minor�inoder=r[r�r�)r+�linesr.rZ�tagr
r
rr-hs" 
zsmaps_lib.__init__cCs|j|j�S)N)r�r�)r+rrr
r
rr0}szsmaps_lib.__getitem__cCst|jj��S)N)r1r�r2)r+r
r
rr2�szsmaps_lib.keyscCst|jj��S)N)r1r�r3)r+r
r
rr3�szsmaps_lib.valuescCs|jS)N)r�)r+r
r
rr5�szsmaps_lib.itemsN)	rLrMrNrOr-r0r2r3r5r
r
r
rr�\s
r�c@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�smapsa~
    List of libraries mapped by a process. Parses the lines in
    the /proc/PID/smaps file, that is further documented in the
    procfs(5) man page.

    Example: Listing the executable maps for the 'sshd' process:

          >>> import procfs
          >>> processes = procfs.pidstats()
          >>> sshd = processes.find_by_name("sshd")
          >>> sshd_maps = procfs.smaps(sshd[0])
          >>> for i in range(len(sshd_maps)):
          ...     if 'x' in sshd_maps[i].perms:
          ...         print "%s: %s" % (sshd_maps[i].name, sshd_maps[i].perms)
          ...
          /usr/sbin/sshd: r-xp
          /usr/lib64/libnss_files-2.20.so: r-xp
          /usr/lib64/librt-2.20.so: r-xp
          /usr/lib64/libkeyutils.so.1.5: r-xp
          /usr/lib64/libkrb5support.so.0.1: r-xp
          /usr/lib64/libfreebl3.so: r-xp
          /usr/lib64/libpthread-2.20.so: r-xp
      ...
    cCs||_g|_|j�dS)N)r�entriesrq)r+rr
r
rr-�szsmaps.__init__cCsxg}|s|j�j�}|sdS|j|�x<|j�}|s6P|j�}|j�dddkr^|j|�q(Pq(W|jjt|��|S)NrrrXrg)r9rrIr:r�r�)r+r@rZr�r
r
rr��s 
zsmaps.parse_entrycCs
t|j�S)N)r=r�)r+r
r
r�__len__�sz
smaps.__len__cCs
|j|S)N)r�)r+�indexr
r
rr0�szsmaps.__getitem__c
CsJd}td|j�d���}x|j||�}|sPqWWdQRXt|j�|_dS)Nz/proc/z/smaps)r8rr�r=r��
nr_entries)r+rZr@r
r
rrq�szsmaps.reloadcCsNg}xDt|j�D]6}|j|jr|j|jj|�dkr|j|j|�qW|S)Nr)rr�r�r[�findrI)r+Zfragment�resultrBr
r
r�find_by_name_fragment�szsmaps.find_by_name_fragmentN)
rLrMrNrOr-r�r�r0rqr�r
r
r
rr��s	r�c@s eZdZdZdd�Zdd�ZdS)�cpustatz�
    CPU statistics, obtained from a line in the '/proc/stat' file, Please
    refer to 'man procfs(5)' for further information about the '/proc/stat'
    file, that is the source of the information provided by this class.
    cCst|d|_dd�|dd�D�\|_|_|_|_|_|_|_t|�dkrpt	|d�|_
t|�dkrpt	|d�|_dS)NrcSsg|]}t|��qSr
)r?)r�rBr
r
rr��sz$cpustat.__init__.<locals>.<listcomp>rr�)r[r�r#�system�idle�iowaitr��softirqr=r?�steal�guest)r+r.r
r
rr-�s
2zcpustat.__init__cCsxd|j�d|j�d|j�d|j�d|j�d|j�d|j��}t|d�rV|d	|j��7}t|d
�rp|d|j	��7}|dS)
Nz< user: z, nice: z
, system: z, idle: z
, iowait: z, irq: z, softirq: r�z	, steal: r�z	, guest: �>)
r�r#r�r�r�r�r�r`r�r�)r+�sr
r
r�__repr__�s<

zcpustat.__repr__N)rLrMrNrOr-r�r
r
r
rr��sr�c@sReZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�	cpusstatsaN
    Dictionary with information about CPUs in the system. First entry in the
    dictionary gives an aggregate view of all CPUs, each other entry is about
    separate CPUs. Please refer to 'man procfs(5)' for further information
    about the '/proc/stat' file, that is the source of the information provided
    by this class.
    �
/proc/statcCs*i|_d|_tjd�|_||_|j�dS)Nr)r��timert�sysconf�hertzr�rq)r+r�r
r
rr-�s
zcpusstats.__init__cCs
t|j�S)N)�iterr�)r+r
r
r�__iter__szcpusstats.__iter__cCs
|j|S)N)r�)r+rrr
r
rr0szcpusstats.__getitem__cCstt|jj���S)N)r=r1r�r2)r+r
r
rr�	szcpusstats.__len__cCst|jj��S)N)r1r�r2)r+r
r
rr2szcpusstats.keyscCst|jj��S)N)r1r�r3)r+r
r
rr3szcpusstats.valuescCs|jS)N)r�)r+r
r
rr5szcpusstats.itemscCs:|j}i|_t|j��v}xn|j�D]b}|j�j�}|ddd�j�dkrLq"t|�}|jdkrdd}nt	|jdd��d}||j|<q"WWdQRX|j
}t
j
�|_
|�r6|j
|}||j}	xxt|jj
��D]f}
|
|kr�d|_q�|j|
}||
}|j|j|j|j|j|j}
|
|	d|_t|jd�|_q�WdS)NrrFr�r�d)r�r8r�rYrr:r�r�r[r?r�r�r1r2Zusager�r#r�r<)r+Zlast_entriesr@rZr.�c�idxZ	last_timeZ	delta_secZinterval_hzr�Zcurr�prevZdeltar
r
rrqs6




zcpusstats.reloadN)r�)rLrMrNrOr-r�r0r�r2r3r5rqr
r
r
rr��s
r��__main__z: z
cpuinfo data: z processorsrmzsmaps:
r��(rz#x� rZSize�
z
----------)3rtrrr��	functoolsrZ	six.movesrZprocfs.utilistr�VERSIONrrrrRrUrVr\rir�r
r�r�r�r�r�rL�sysZintsr1r2rB�printr��or�r�r�r?�argvr�r�r�r�r[r�rZpsZcsZsleeprqr
r
r
r�<module>	sj>		Me*
.N.KB
*



Hacked By AnonymousFox1.0, Coded By AnonymousFox