+
    {Meʍ  c                   s|   ^ RI t ^ RIt^ RIt^ RIt^ RIHt ^ RIHt ^ RIH	t	 Rt
R tR t ! R R	4      tR
 tR t ! R R4      t ! R R4      t ! R R4      t ! R R4      t ! R R4      t ! R R4      t ! R R4      t ! R R4      t ! R R4      t ! R R4      t]R 8X  Ed   ^ RIt]! 4       t]! ]P&                  P=                  4       4       F!  t] ! ] R!]P&                  ],           24       K#  	  ]! 4       t!]! ]!PB                  P=                  4       4       F!  t"] ! ]" R!]!PB                  ]",           24       K#  	  ]! 4       t#] ! R"]#PH                   R#24       ]! ]#P=                  4       4       F  t%] ! ]% R$]#]%,           24       K  	  ] ! R)4       ]! ]&! ]PN                  ^,          4      4      t(]! ](PR                  4       FG  t] ! ](PT                  ],          PV                  R% R&](PT                  ],          PX                   24       KI  	  ] ! R(4       ](P[                  ]PN                  ^,          4       F  t.] ! ].R',          4       K  	  ]! 4       t/] ! ]/^,          4       ]! 4       t0 ]Pb                  ! ^4       ]0Pe                  4        ]0 F  t#] ! ]# R!]0]#,           24       K  	  ] ! R*4       KJ  R# )+    N)reduce)range)bitmasklistz0.7.3c                 sl    \         P                  ! 4       p \        \        P                  ! RV 4      4      # )z(Return True if running on s390 or s390x Zs390)platformmachineboolreZsearch)r   s    2/usr/lib/python3.14/site-packages/procfs/procfs.pyis_s390r	      s&     G		&'*++    c                s    V R,          '       d#   \        R V R,          4      P                  4       #   V R,          R,          #     R# ; i)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.
cmdlinec                 s"    V R V,          ,           # )z %s )aZb   &&r   Z<lambda>Z!process_cmdline.<locals>.<lambda>!   s    1uqy=r
   statcommN)r   strip)Zpid_info   &r   process_cmdliner      sM     	0(92EFLLNNC''s   A A	c                   s  a  ] tR t^*t o Rt^t^t^t^t^t	^ t
^@t^tRtRtRtRtRtRtRtRtR	tR
tRtRtRtRtRtRtRtRtRtRt Rt!Rt"Rt#Rt$Rt%Rt&Rt'Rt(. RNRNRNRNRNRNR NR!NR"NR#NR$NR%NR&NR'NR(NR)NR*NR+NR,NR-NR.NR/NR0NR1NR2NR3NR4NR5NR6NR7NR8NR9NR:NR;NR<NR=NR>NR?NR@NRANRBNRCNRDNt)RQRE lt*RF t+RG t,RH t-RI t.RJ t/RK t0RQRL lt1RM t2RN t3ROt4V t5RP# )Rpidstata!  
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.
i   i   i   i   i   i    i @  i   i   i   i   i   i   i    i  @ i   i   i      i   i   i    i   @l        pidr   ZstateZppidZpgrpZsessionZtty_nrZtpgidflagsZminfltZcminfltZmajfltZcmajfltZutimeZstimeZcutimeZcstimeZpriorityniceZnum_threadsZitrealvalueZ	starttimeZvsizeZrssZrlimZ	startcodeZendcodeZ
startstackZkstkespZkstkeipZsignalZblockedZ	sigignoreZsigcatchZwchanZnswapZcnswapZexit_signal	processorrt_priorityZpolicyZdelayacct_blkio_ticksenvironc                sV    Wn          V P                  V4       R #   \         d    h i ; iN)r   loadFileNotFoundErrorselfr   basedir   &&&r   __init__Zpidstat.__init__~   s,    	IIg  	 	s    (c                (    V P                   V,          # r   fieldsr    Z	fieldnamer   r   __getitem__Zpidstat.__getitem__       {{9%%r
   c                H    \        V P                  P                  4       4      # r   listr&   keysr    r   r   r-   Zpidstat.keys       DKK$$&''r
   c                r*   r   r,   r&   valuesr.   r   r   r1   Zpidstat.values       DKK&&())r
   c                    WP                   9   # r   r%   r'   r   r   has_keyZpidstat.has_key       KK''r
   c                    V P                   # r   r%   r.   r   r   itemsZpidstat.items       {{r
   c                r3   r   r%   r'   r   r   __contains__Zpidstat.__contains__   r5   r
   c                s    \        V R V P                   R24      pTP                  4       P	                  4       P                  R4      pTP                  4        T^ ,          P                  R4      T^,          P                  4       ,           p/ T n        \        \        T4      \        T P                  4      4      p\        T4       F^  pT P                  T,          pY5,          pTR8X  d!   TP	                  R4      T P                  R&   KE   \        T4      T P                  T&   K`  	  R#   \         d    h i ; i   YpP                  T&    K  ; i)/z/statz) z (r   z()N)openr   r   readliner   splitZcloser&   minlenproc_stat_fieldsr   int)r    r!   fr&   	nr_fieldsiZattrnamevalue   &&      r   r   Zpidstat.load   s   	y$((512A ##%++D1		&)::FS)>)>%?@	y!A,,Q/HIE6!&+kk$&7F#2,/JDKK) " ! 		 2,1KK)s   D, D<,D9<Ec                s\    \        V P                  R,          V P                  ,          4      # )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   )r   r&   PF_THREAD_BOUNDr.   r   r   is_bound_to_cpuZpidstat.is_bound_to_cpu   s#    
 DKK(4+?+??@@r
   c                s    . p\        V 4       FP  pVR,          R8w  d   K  \        W4      pW0P                  R,          ,          '       g   K?  VP                  V4       KR  	  V# )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   NZPF_r   )Zdirgetattrr&   append)r    ZsflagsattrrE      &   r   process_flagsZpidstat.process_flags   sV    L IDBx5 D'E{{7+++d#  r
   r&   r   Nz/proc)6__name__
__module____qualname____firstlineno____doc__ZPF_ALIGNWARNZPF_STARTINGZ
PF_EXITINGZPF_EXITPIDONEZPF_VCPUZPF_WQ_WORKERZPF_FORKNOEXECZPF_MCE_PROCESSZPF_SUPERPRIVZPF_DUMPCOREZPF_SIGNALEDZPF_MEMALLOCZPF_NPROC_EXCEEDEDZ
PF_FLUSHERZPF_USED_MATHZPF_USED_ASYNCZPF_NOFREEZEZ	PF_FROZENZ
PF_FSTRANSZ	PF_KSWAPDZPF_MEMALLOC_NOIOZ
PF_SWAPOFFZPF_LESS_THROTTLEZ
PF_KTHREADZPF_RANDOMIZEZPF_SWAPWRITEZPF_SPREAD_PAGEZPF_SPREAD_SLABrG   PF_NO_SETAFFINITYZPF_MCE_EARLYZPF_MEMPOLICYZPF_MUTEX_TESTERZPF_FREEZER_SKIPZPF_FREEZER_NOSIGZPF_SUSPEND_TASKr@   r#   r(   r-   r1   r4   r7   r9   r   rH   rO   __static_attributes____classdictcell__Z__classdict__   @r   r   r   *   s    > LKJMGLMNLKKK"JLMKIJI!J!JLLNN O"LL O O! O
< 
<v 
<w 
< 
< 
<	 
< 
<")
<+2
<4<
<>G
< 
<"+
<-4
<6=
<?G
< !
< #-
< /5
< 7D
< &	
< (3	
< 5<	
< >C	
<
 
<
 !,
<
 .7
<
 9E
< "
< $-
< /7
< 9B
< $
< &0
< 29
< ;B
< !
< #0
< 2=
< &
< (0
< 0
< 2;
<&(*((2,A. .r
   r   c                 s    R p \        \        V P                  V,          R,          R,          4      V,          4      #     R# ; ir   r   r   T)r   rA   	processes)r    r   rW      && r   cannot_set_affinityr_      sF    "Cs+F3G<=%& ' 	's	   9> Ac                 s    R p \        \        V P                  V,          P                  V,          R,          R,          4      V,          4      #     R# ; ir\   )r   rA   r]   threads)r    r   ZtidrW      &&& r   cannot_set_thread_affinityrb      sQ    "Cs+33C8@IJ%& ' 	's   A
A Ac                   s\   a  ] tR t^t o RtRR ltR tR tR tR t	R t
R tRR	 ltR
tV tR# )	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.
c                s4    Wn         V P                  V4       R # r   )r   r   r   r"   r   r#   Zpidstatus.__init__!  s    		'r
   c                r$   r   r%   r'   r   r   r(   Zpidstatus.__getitem__%  r)   r
   c                r*   r   r+   r.   r   r   r-   Zpidstatus.keys(  r/   r
   c                r*   r   r0   r.   r   r   r1   Zpidstatus.values+  r2   r
   c                r3   r   r%   r'   r   r   r4   Zpidstatus.has_key.  r5   r
   c                r6   r   r%   r.   r   r   r7   Zpidstatus.items1  r8   r
   c                r3   r   r%   r'   r   r   r9   Zpidstatus.__contains__4  r5   r
   c                s   / V n         \        V R V P                   R24      ;_uu_ 4       pVP                  4        F_  pVP	                  R4      p\        V4      ^8w  d   K&  V^ ,          pV^,          P                  4       p \        V4      V P                   V&   Ka  	  RRR4       R#    Y`P                   T&    K  ; i  + '       g   i     R# ; i)r:   z/status:N)r&   r;   r   	readlinesr=   r?   r   rA   )r    r!   rB   liner&   namerE      &&     r   r   Zpidstatus.load7  s    WIQtxxj011QCv;!#ayq	).(+E
DKK% & 21.(-KK% 211s$   AB?B)B?)B<	9B??C	rP   NrQ   )rR   rS   rT   rU   rV   r#   r(   r-   r1   r4   r7   r9   r   rX   rY   rZ   r[   r   rc   rc      s8     %N&(*((. .r
   rc   c                   X   a  ] tR tRt o RtRR ltR tR tR tR t	R t
R	 tR
 tRtV tR# )processiF  a  
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.
c                s    Wn         W n        R # r   )r   r!   r   r"   r   r#   Zprocess.__init__N  s    r
   c                s   \        W4      '       g   VR9   d>   VR 8X  d   \        pM\        p \        WV! V P                  V P
                  4      4       M_VR8X  d   V P                  4        MGVR8X  d   V P                  4        M/VR8X  d   V P                  4        MVR8X  d   V P                  4        \        W4      #   \         d    h i ; i)r   r   r`   cgroupsr   )r   Zstatus)hasattrr   rc   Zsetattrr   r!   r   load_cmdlineload_threadsload_cgroupsload_environrK   )r    rM   Zsclassr^   r   r(   Zprocess.__getitem__R  s    t""))6>$F&FDtxx(FG "!!#"!!#"!!#"!!#t"" ) s   'C   Cc                    \        W4      # r   rl   r    rM   r   r   r4   Zprocess.has_keyj      t""r
   c                rq   r   rr   rs   r   r   r9   Zprocess.__contains__m  rt   r
   c                sL    \        R V P                   R24      ;_uu_ 4       pVP                  4       P                  4       P	                  R4      RR V n        RRR4       R#   + '       g   i     R# ; i  \         d     RT n         R# \         d     RT n         R# i ; i)/proc/z/cmdline N)r;   r   r<   r   r=   r   r   ZUnicodeDecodeError)r    rB      & r   rm   Zprocess.load_cmdlinep  s    	 txxj122a zz|11399$?D 3222  	 9DL! 	 JDL	 s:   !A7 6A#A7 #A4	.A7 4A7 7B#B#	B#"B#c                sp    \        R V P                   R24      V n        V P                  V P                   R# )ru   z/task/N)pidstatsr   r`   r.   r   r   rn   Zprocess.load_threads{  s+    &
& 9:LL"r
   c                s`   R V n         \        RV P                   R24      ;_uu_ 4       p\        VP	                  4       4       FK  p\        V P                   4      ^ 8w  d%   V P                   R,           VRR ,           V n         KA  VRR V n         KM  	  RRR4       R#   + '       g   i     R# ; i) ru   z/cgroup,Nrw   )rk   r;   r   Zreversedre   r?   )r    rB   rf      &  r   ro   Zprocess.load_cgroups  s    F488*G,-- /t||$)#'<<##5Sb	#ADL#'9DL	 0 .---s   A)BB-	c                s\   / V n         \        RV P                   R24      ;_uu_ 4       pVP                  4       P	                  R4       FC  p\        V4      ^ 8  g   K  VP	                  R4      pV^,          V P                   V^ ,          &   KE  	  RRR4       R#   + '       g   i     R# ; i)a  
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
>>>
ru   z/environrv   =N)r   r;   r   r<   r=   r?   )r    rB   ZxZyrN   r   rp   Zprocess.load_environ  s}    4 F488*H-..!ZZ\''-q6A:A)*1DLL1& . /...s   0B2BB+	)r!   rk   r   r   r   r`   NrQ   )rR   rS   rT   rU   rV   r#   r(   r4   r9   rm   rn   ro   rp   rX   rY   rZ   r[   r   rj   rj   F  s7     #0##	 #
-. .r
   rj   c                   s   a  ] tR tRt o RtRR ltR tR tR tR t	R t
R	 tR
 tR tR tR tR tR tR tR tR tRtV tR# )ry   i  a  
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.
c                s@    Wn         / V n        V P                  4        R # r   )r!   r]   reload)r    r!   r   r   r#   Zpidstats.__init__  s    r
   c                r$   r   r]   r    Zkeyr   r   r(   Zpidstats.__getitem__  s    ~~c""r
   c                s2     V P                   V R #     R # ; ir   r   r   r   r   __delitem__Zpidstats.__delitem__  s    	s#	s    c                r*   r   )r,   r]   r-   r.   r   r   r-   Zpidstats.keys  s    DNN'')**r
   c                r*   r   )r,   r]   r1   r.   r   r   r1   Zpidstats.values  s    DNN))+,,r
   c                r3   r   r   r   r   r   r4   Zpidstats.has_key      nn$$r
   c                r6   r   r   r.   r   r   r7   Zpidstats.items  s    ~~r
   c                r3   r   r   r   r   r   r9   Zpidstats.__contains__  r   r
   c                s    V = / V n         \        P                  ! V P                  4      pV F1  p \	        V4      p\        Y0P                  4      T P                   T&   K3  	  R#     K<  ; i)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)r]   osZlistdirr!   rA   rj   )r    pidsZspidr   rN   r   r~   Zpidstats.reload  s]     Nzz$,,'D$i #*#||"<DNN3 s   A##A(c                s   . p\        V P                  P                  4       4       F%  p V P                  V,          P                  4        K'  	  V F  pV P                  V K  	  R #   \         d    TP                  T4        K`  i ; ir   )r,   r]   r-   rn   ZOSErrorrL   )r    Z	to_remover   r|   r   reload_threadsZpidstats.reload_threads  st    	++-.C&s#002 / Cs#   &  %&s   !A''BBc                s    VR ,          p. p\        V P                  P                  4       4       F<  p WP                  V,          R,          R,          8X  d   VP                  V4       K<  K>  	  V#   \         d    T P                  T  K]  i ; i):Ni   Nr   r   )r,   r]   r-   rL   IOError)r    rg   r   r      &&  r   find_by_nameZpidstats.find_by_name  s    Cy++-.C(>>#.v6v>>KK$ ? /   ( NN3'	(s   6A11BBc                s0   . p\        V P                  P                  4       4       FM  p VP                  V P                  V,          R ,          R,          4      '       d   VP	                  V4       KM  KO  	  V#   \
         d    T P                  T  Kn  i ; i)r   r   )r,   r]   r-   matchrL   r   r    regexr   r   r   r   find_by_regexZpidstats.find_by_regex  s    ++-.C(;;t~~c26:6BCCKK$ D /   ( NN3'	(s   AA99BBc                s&   . p\        V P                  P                  4       4       FH  p VP                  \	        V P                  V,          4      4      '       d   VP                  V4       KH  KJ  	  V#   \         d    T P                  T  Ki  i ; ir   )r,   r]   r-   r   r   rL   r   r   r   r   find_by_cmdline_regexZpidstats.find_by_cmdline_regex  s}    ++-.C(;;t~~c/BCDDKK$ E /   ( NN3'	(s   AA44BBc                s   ^ pRp. p V RV 2pV P                  V4      pV'       d)   \        V Uu. uF  qwV9  g   K  VNK  	  up4      ^ 8X  d   MEV F,  p W0P                  V,          R,          R,           ,          pK.  	  WF,          pV^,          pK  VP	                  R4      pV# u upi   \         d    T P                  T  Kv  i ; i)r    rz   r:   r   r   r{   r   r?   r]   r   r   )	r    Zbasenamecpu
prioritiesprocessed_pidsrg   r   nr   s	   &&       r   get_per_cpu_rtpriosZpidstats.get_per_cpu_rtprios   s    
Zq&D$$T*D34K4aN3J4KLPQQ,^^C%8%@%O$PQJ  "N1HC%%c*
  L
  , s+	,s   B)B)(B..C
	C
c                s   ^ pRp. p V P                  V4      pV'       d)   \        V Uu. uF  qfV9  g   K  VNK  	  up4      ^ 8X  d   MEV F,  p W0P                  V,          R,          R,           ,          pK.  	  WE,          pV^,          pK  VP	                  R4      pV# u upi   \         d    T P                  T  Kv  i ; i)r    rz   r   r   r{   r   )r    rg   r   r   r   r   r   r   rF   r   get_rtpriosZpidstats.get_rtprios7  s    
$$T*D34K4aN3J4KLPQQ,^^C%8%@%O$PQJ  "N1HC%%c*
  L
  , s+	,s   B"B"(B''CCc                sR    V P                   V,          R,          P                  4       # )zA
Checks if a given pid can't have its SMP affinity mask changed.
r   )r]   rH   r    r   r   r   rH   Zpidstats.is_bound_to_cpuM  s!     ~~c"6*::<<r
   )r!   r]   NrQ   )rR   rS   rT   rU   rV   r#   r(   r   r-   r1   r4   r7   r9   r~   r   r   r   r   r   r   rH   rX   rY   rZ   r[   r   ry   ry     s_     
#+-%%=4	$.,= =r
   ry   c                   sl   a  ] tR tRt o RtR tR tR tR tR t	R t
R	 tR
 tR tR tR tR tRtV tR# )
interruptsiT  a!  
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']}
>>>
c                4    / V n         V P                  4        R # r   )r   r~   r.   r   r   r#   Zinterrupts.__init__m  s    r
   c                s:    V P                   \        V4      ,          # r   )r   strr   r   r   r(   Zinterrupts.__getitem__q  s    s3x((r
   c                r*   r   r,   r   r-   r.   r   r   r-   Zinterrupts.keyst  s    DOO((*++r
   c                r*   r   )r,   r   r1   r.   r   r   r1   Zinterrupts.valuesw  s    DOO**,--r
   c                2    \        V4      V P                  9   # r   r   r   r   r   r   r4   Zinterrupts.has_keyz      3x4??**r
   c                r6   r   )r   r.   r   r   r7   Zinterrupts.items}  s    r
   c                r   r   r   r   r   r   r9   Zinterrupts.__contains__  r   r
   c                s@   V = / V n         \        R 4      ;_uu_ 4       pVP                  4        F  pVP                  4       pVP	                  4       pV^ ,          R,          R8X  d   \        V4      V n        KJ  V^ ,          P                  R4      p/ V P                   V&   V P                  VR,          V4      V P                   V&    \        V4      pT P                  T4      T P                   T,          R&   K  	  RRR4       R#     K  ; i  + '       g   i     R# ; i)z/proc/interruptsrI   ZCPUrd      NNZaffinityN)
r   r;   re   r   r=   r?   nr_cpusparse_entryrA   parse_affinity)r    rB   rf   r&   irqZnirqs   &     r   r~   Zinterrupts.reload  s    O$%%zz|!9R=E)#&v;DLQiooc*')$'+'7'7r
D'I$s8D 483F3Ft3L$Z0 & &% &%%s$   B(DD)DD		DD	c           	     s(   / p. VR &   VR ,          P                  \        V^ ,          4      4       \        V4      pW@P                  8  d   TR ;;,          V^V P                    Uu. uF  p\        V4      NK  	  up,          uu&   W@P                  8  ds   WP                  ,          VR&   W@P                  ^,           8  dB   W^,
          ,          P	                  R4       Uu. uF  pVP                  4       NK  	  upVR&   V# . VR&   V# u upi u upi )r   Ztyper{   users)rL   rA   r?   r   r=   r   )r    r&   rf   ZdictrC   rD   r   s   &&&    r   r   Zinterrupts.parse_entry  s    UU3vay>*K	$KF1T\\,BC,BqCF,BCCK<<'%ll3V||a//.4].C.I.I#.N%P.N &'WWY.N%PDM  %'DM D
%Ps   &D

"Dc                s     \        R V R24      ;_uu_ 4       pVP                  4       pRRR4       \        XV P                  4      #   + '       g   i     L&; i  \         d    ^ .u # i ; i)z
/proc/irq/z/smp_affinityN)r;   r<   r   r   r   )r    r   rB   rf   r   r   r   Zinterrupts.parse_affinity  s^    	
3%}566!zz| 7tT\\22 76  	5L	s'   A AA A	A A,+A,c                s    \        V P                  P                  4       4       F?  pRV P                  V,          9   g   K  WP                  V,          R,          9   g   K=  Vu # 	  R# )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   Nr   )r    userrD   r^   r   find_by_userZinterrupts.find_by_user  sO      doo**,-A$//!,,q)'22 . r
   c                s*   . p\        V P                  P                  4       4       Fi  pRV P                  V,          9  d   K  V P                  V,          R,           F.  pVP                  V4      '       g   K  VP	                  V4        Kg  	  Kk  	  V# )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   )r,   r   r-   r   rL   )r    r   ZirqsrD   r   s   &&   r   find_by_user_regexZinterrupts.find_by_user_regex  sx      doo**,-Adooa00*733;;t$$KKN 4 . r
   )r   r   N)rR   rS   rT   rU   rV   r#   r(   r-   r1   r4   r7   r9   r~   r   r   r   r   rX   rY   rZ   r[   r   r   r   T  sL     0),.++M&", r
   r   c                   H   a  ] tR tRt o RtR tR tR tR tR t	R t
R	tV tR
# )r   i  a  
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+
>>>
c                r   r   )optionsparser.   r   r   r#   Zcmdline.__init__  s    

r
   c                sx   \        R 4      ;_uu_ 4       pVP                  4       P                  4       P                  4        FY  pVP                  R4      p\	        V4      ^8X  d   RV P
                  V^ ,          &   K<  V^,          V P
                  V^ ,          &   K[  	  RRR4       R#   + '       g   i     R# ; i)z/proc/cmdliner}   TN)r;   r<   r   r=   r?   r   )r    rB   Zoptionr&   rN   r   r   Zcmdline.parse  s    /""a**,,,.446c*v;!#.2DLL+.4QiDLL+ 7 #"""s   B
B((B9	c                r$   r   r   r   r   r   r(   Zcmdline.__getitem__      ||C  r
   c                r*   r   )r,   r   r-   r.   r   r   r-   Zcmdline.keys      DLL%%'((r
   c                r*   r   )r,   r   r1   r.   r   r   r1   Zcmdline.values      DLL'')**r
   c                r6   r   r   r.   r   r   r7   Zcmdline.items
      ||r
   r   N)rR   rS   rT   rU   rV   r#   r   r(   r-   r1   r7   rX   rY   rZ   r[   r   r   r     s-     &8!)+ r
   r   c                   sL   a  ] tR tRt o RtRR ltR tR tR tR t	R t
R	tV tR
# )cpuinfoi  ae  
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
      >>>
c                sR    / V n         ^ V n        . V n        V P                  V4       R# )r    N)tagsr   socketsr   r    filenamer   r   r#   Zcpuinfo.__init__.  s#    	

8r
   c                D    V P                   VP                  4       ,          # r   r   lowerr   r   r   r(   Zcpuinfo.__getitem__4      yy%%r
   c                r*   r   r,   r   r-   r.   r   r   r-   Zcpuinfo.keys7      DIINN$%%r
   c                r*   r   r,   r   r1   r.   r   r   r1   Zcpuinfo.values:      DII$$&''r
   c                r6   r   r   r.   r   r   r7   Zcpuinfo.items=      yyr
   c                sz   \        V4      ;_uu_ 4       pVP                  4        EF  pVP                  4       pV'       g   K  VP                  R 4      pV^ ,          P                  4       P	                  4       pVR8X  d   V ;P
                  ^,          un        Kv  \        4       '       d#   VR8X  d   V ;P
                  ^,          un        K  VR8X  d   K  V^,          P                  4       V P                  V&   VR8X  g   K  V P                  V,          pW`P                  9  g   EK  V P                  P                  V4       EK"  	  RRR4       V P                  ;'       d    \        V P                  4      ;'       gO    V P
                  RV P                  9   ;'       d%    \        V P                  R,          4      ;'       g    ^,          V n        RV P                  9   ;'       d%    \        V P                  R,          4      ;'       g    ^V P                  ,          V n        R#   + '       g   i     L; i)rd   r   z
cpu numberzcore idzphysical idNZsiblingsz	cpu cores)r;   re   r   r=   r   r   r	   r   r   rL   r?   rA   
nr_socketsnr_cores)r    r   rB   rf   r&   ZtagnameZ	socket_idrh   r   r   Zcpuinfo.parse@  s   (^^qzz|C )//+113k)LLA%L99L!8LLA%Li'%+AY__%6		'"m+ $		' 2I 4++I6% & ( ,,<<3t||+< L L\\DII%DD#dii
.C*DIIK 	 %		1 $ $cIIk"7$ ) )'(DOO</ ^s   C*H* H*) H**H:	)r   r   r   r   r   N)z/proc/cpuinfo)rR   rS   rT   rU   rV   r#   r(   r-   r1   r7   r   rX   rY   rZ   r[   r   r   r     s-     >&&(< <r
   r   c                   sB   a  ] tR tRt o RtR tR tR tR tR t	Rt
V tR	# )
	smaps_libi\  aX  
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                s   V^ ,          P                  4       pV^ ,          P                  R4       Uu. uF  p\        V^4      NK  	  upw  V n        V n        V^,          V n        \        V^,          ^4      V n        V^,          P                  R4      w  V n        V n        \        V^,          4      V n        \        V4      ^8  d   V^,          V n
        MRV n
        / V n        VR,           FM  pVP                  4       pV^ ,          RR P                  4       p \        V^,          4      V P                  V&   KO  	  R# u upi    Y P                  T&    Kk  ; i)r    Z-rd   Nr   rw   )r=   rA   vm_startvm_endpermsoffsetmajorminorinoder?   rg   r   r   )r    linesr&   r   rf   tags   &&    r   r#   Zsmaps_lib.__init__h  s   q!:@)//#:N%O:NQc!Rj:N%O"t{AY
&)R(!'!5
DJ^
v;?q	DIDI	"IIDZZ\F)CR.&&(C(!$VAY		#	  &P(!'		#s   EEEc                r   r   r   r   r   r   r(   Zsmaps_lib.__getitem__}  r   r
   c                r*   r   r   r.   r   r   r-   Zsmaps_lib.keys  r   r
   c                r*   r   r   r.   r   r   r1   Zsmaps_lib.values  r   r
   c                r6   r   r   r.   r   r   r7   Zsmaps_lib.items  r   r
   )	r   r   r   rg   r   r   r   r   r   N)rR   rS   rT   rU   rV   r#   r(   r-   r1   r7   rX   rY   rZ   r[   r   r   r   \  s(     	(*&&( r
   r   c                   r   )smapsi  a*  
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
  ...
c                s@    Wn         . V n        V P                  4        R # r   )r   entriesr~   r   r   r   r#   Zsmaps.__init__  s    r
   c                s   . pV'       g   VP                  4       P                  4       pV'       g   R # VP                  V4        VP                  4       pV'       g   MGVP                  4       pVP                  4       ^ ,          R,          R8X  d   VP                  V4       K`   V P                  P                  \        V4      4       V# )Nrd   rw   )r<   r   rL   r=   r   r   )r    rB   rf   r   ra   r   r   Zsmaps.parse_entry  s    ::<%%'DT::<D::<Dzz|Ar"c)T"Ie,-r
   c                ,    \        V P                  4      # r   )r?   r   r.   r   r   __len__Zsmaps.__len__  s    4<<  r
   c                r$   r   r   )r    Zindexr   r   r(   Zsmaps.__getitem__  s    ||E""r
   c                s    R p\        RV P                   R24      ;_uu_ 4       p V P                  W!4      pV'       d   K   R R R 4       \        T P                  4      T n        R #   + '       g   i     L,; i)Nru   z/smaps)r;   r   r   r?   r   
nr_entries)r    rf   rB   r|   r   r~   Zsmaps.reload  s\    F488*F+,,''0t	 -
 dll+ -,s   A&A&&A6	c                s6   . p\        V P                  4       F}  pV P                  V,          P                  '       g   K(  V P                  V,          P                  P	                  V4      ^ 8  g   K[  VP                  V P                  V,          4       K  	  V# )r    )r   r   r   rg   ZfindrL   )r    ZfragmentZresultrD   r   r   find_by_name_fragmentZsmaps.find_by_name_fragment  sj    t'A||A###||A##((2a7dll1o. (
 r
   )r   r   r   N)rR   rS   rT   rU   rV   r#   r   r   r(   r~   r   rX   rY   rZ   r[   r   r   r     s-     2
&!#, r
   r   c                   s0   a  ] tR tRt o RtR tR tRtV tR# )cpustati  z
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.
c                sj   V^ ,          V n         VR,           Uu. uF  p\        V4      NK  	  upw  V n        V n        V n        V n        V n        V n        V n        \        V4      ^8  dC   \        V^,          4      V n
        \        V4      ^8  d   \        V^,          4      V n        R# R# R# u upi )r    :r   i   NN)rg   rA   r   r   systemidleiowaitr   softirqr?   stealguest)r    r&   rD   r^   r   r#   Zcpustat.__init__  s    1I	 +1+6+Q#a&+6							v;?VAYDJ6{Q ^
   7s   B0c                sn   R V P                    RV P                   RV P                   RV P                   RV P                   RV P
                   RV P                   2p\        V R4      '       d   VRV P                   2,          p\        V R	4      '       d   VR
V P                   2,          pVR,           # )z< user: z, nice: z
, system: z, idle: z
, iowait: z, irq: z, softirq: r   z	, steal: r   z	, guest: Z>)
r   r   r   r   r   r   r   rl   r   r   )r    srx   r   __repr__Zcpustat.__repr__  s    tyyk$))Jt{{m8TXT]T]S^^himitithuu|  ~B  ~F  ~F  }G  GR  SW  S_  S_  R`  a4!!9TZZL))A4!!9TZZL))A3wr
   )
r   r   r   r   rg   r   r   r   r   r   N)	rR   rS   rT   rU   rV   r#   r   rX   rY   rZ   r[   r   r   r     s     , r
   r   c                   ri   )	cpusstatsi  a6  
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.
c                s    / V n         R V n        \        P                  ! ^4      V n        Wn        V P                  4        R # r   )r   timer   Zsysconfhertzr   r~   r   r   r   r#   Zcpusstats.__init__  s-    	ZZ]
 r
   c                r   r   )Ziterr   r.   r   r   __iter__Zcpusstats.__iter__  s    DLL!!r
   c                r$   r   r   r   r   r   r(   Zcpusstats.__getitem__  r   r
   c                sZ    \        \        V P                  P                  4       4      4      # r   )r?   r,   r   r-   r.   r   r   r   Zcpusstats.__len__	  s    4))+,--r
   c                r*   r   )r,   r   r-   r.   r   r   r-   Zcpusstats.keys  r   r
   c                r*   r   )r,   r   r1   r.   r   r   r1   Zcpusstats.values  r   r
   c                r6   r   r   r.   r   r   r7   Zcpusstats.items  r   r
   c                sh   V P                   p/ V n         \        V P                  4      ;_uu_ 4       pVP                  4        F  pVP	                  4       P                  4       pV^ ,          R,          P                  4       R8w  d   KF  \        V4      pVP                  R8X  d   ^ pM#\        VP                  R,          4      ^,           pWPP                   V&   K  	  RRR4       V P                  p\        P                  ! 4       V n
        V'       Ed   V P                  V,
          pWP                  ,          p	\        V P                   P                  4       4       F  p
W9  d
   ^ Xn        K  V P                   V
,          pW,          pVP                  VP                  ,
          VP                   VP                   ,
          ,           VP"                  VP"                  ,
          ,           pW,          ^d,          Vn        \%        VP                  ^d4      Vn        K  	  R# R#   + '       g   i     ELM; i)r    rI   r   :rJ   NNN)r   r;   r   re   r   r=   r   r   rg   rA   r   r   r,   r-   Zusager   r   r   r>   )r    Zlast_entriesrB   rf   r&   ZcZidxZ	last_timeZ	delta_secZinterval_hzr   ZcurrZprevZdeltas   &             r   r~   Zcpusstats.reload  s   ||$--  A++-!9R=&&(E1FO66U?CaffRj/A-C$%S! & ! II	IIK	<		I-I#jj0KDLL--/0*!"DJ||C(#(TYY.YY*,[[4;;.0 $1S8
 S1
 1  !  s   B+H  H1	)r   r   r   r   N)z
/proc/stat)rR   rS   rT   rU   rV   r#   r   r(   r   r-   r1   r7   r~   rX   rY   rZ   r[   r   r   r     s7     "!.)+2 2r
   r   Z__main__z: z
cpuinfo data: z processorsr}   z#xZ ZSizez(----------------------------------------z/smaps:
----------------------------------------z
----------)3r   r   r   r   Z	functoolsr   Z	six.movesr   Zprocfs.utilistr   ZVERSIONr	   r   r   r_   rb   rc   rj   ry   r   r   r   r   r   r   r   rR   ZsysZintsr,   r-   rD   Zprintr   Zor   r   r   rA   Zargvr   r   r   r   rg   r   r   ZpsZcsZsleepr~   r   r
   r   <module>r      s   
  	    &
, z zzJ. J.Zb. b.Jf= f=RI IX+ +\K< K<\+ +\H HV <?2 ?2D z<D$//&&()2dooa()*+ * iG'//&&()2gooa()*+ * )C	S[[M
56CHHJQs3xj!"   

!"c#((1+A1<< 1&&r*!AIIaL,=,=+>?@ !	(O$$SXXa[1ai 2 
B	"Q%L	B


1
		CSEBsG9%& hE r
   