Ë
    ¸~Þe¥  ã                   ój   — d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlmZ d dlm	Z	  G d„ d«      Z
d	„ Zy)
é    N)Údatetime)Ú	timedelta)Úsysstats)Údetect_jiffies)Úto_timestampc                   ó,   — e Zd ZdZ	 	 	 	 dd„Zd„ Zd„ Zy)ÚProcessInformationaI  
    @param proc_dir: The directory to use for process information.
    @param jiffies: The value to use for jiffies per second.
    @param boot_time: An alternate value to use for the last boot time.  If
        None, the system last boot time will be used.
    @param uptime: The uptime value to use (for unit tests only).
    Nc                 óÊ   — |€"t        j                  «       j                  «       }|�t        j                  |«      }|| _        || _        |xs
 t        «       | _        || _	        y )N)
r   Ú	BootTimesÚget_last_boot_timer   ÚutcfromtimestampÚ
_boot_timeÚ	_proc_dirr   Ú_jiffies_per_secÚ_uptime)ÚselfÚproc_dirÚjiffiesÚ	boot_timeÚuptimes        ú7/usr/lib/python3/dist-packages/landscape/lib/process.pyÚ__init__zProcessInformation.__init__   s\   € ð ÐÜ ×*Ñ*Ó,×?Ñ?ÓAˆIØÐ Ü ×1Ñ1°)Ó<ˆIØ#ˆŒØ!ˆŒØ 'Ò ;¬>Ó+;ˆÔØˆ�ó    c              #   óº   K  — t        j                  | j                  «      D ]&  }	 t        |«      }| j                  |«      }|sŒ#|–— Œ( y# t        $ r Y Œ5w xY w­w)z8Get process information for all processes on the system.N)ÚosÚlistdirr   ÚintÚ
ValueErrorÚget_process_info)r   ÚfilenameÚ
process_idÚprocess_infos       r   Úget_all_process_infoz'ProcessInformation.get_all_process_info$   s^   è ø€ äŸ
™
 4§>¡>Ó2ò 	#ˆHðÜ  ›]�
ð  ×0Ñ0°Ó<ˆLÚØ"Ó"ñ	#øô ò Ùðüs-   ‚#A¦A±AÁAÁ	AÁAÁAÁAc                 óF  — d}t         j                  j                  | j                  t	        |«      «      }d|i}	 t        t         j                  j                  |d«      d«      }	 |j                  «       }t         j                  j                  |j                  d«      d   «      }|j                  «        t        t         j                  j                  |d«      d«      }	 |D �]  }|j                  dd	«      }|d   d
k(  r)|j                  «       xs |d	   j                  «       |d<   ŒG|d   dk(  r@|d	   j                  «       }	|	dk(  r|	j                  «       }	|	d   j                  d«      |d<   Œ�|d   dk(  r%|d	   j                  «       }
t        |
d   «      |d<   Œ¼|d   dk(  r%|d	   j                  «       }
t        |
d   «      |d<   Œé|d   dk(  sŒò|d	   j                  «       }
t        |
d   «      |d<    n |j                  «        t        t         j                  j                  |d«      d«      }	 |j                  «       j                  «       }t        |d   «      }t        |d   «      }t        |d   «      }| j                  xs t!        j"                  «       }t%        ||||| j&                  «      }||d<   t)        d|| j&                  z  «      }| j*                  €(t-        j.                  d|«       	 |j                  «        yt1        | j*                  |z   «      |d<   |j                  «        	 d|v rd|v rd|v rd|v rd|v rd|v sJ ‚|S # |j                  «        w xY w# |j                  «        w xY w# |j                  «        w xY w# t2        $ r Y yw xY w)a  
        Parse the /proc/<pid>/cmdline and /proc/<pid>/status files for
        information about the running process with process_id.

        The /proc filesystem doesn't behave like ext2, open files can disappear
        during the read process.
        Ú ÚpidÚcmdlineÚrú r   Ústatusú:é   ÚNameÚnameÚStatezT (tracing stop)ÚasciiÚstateÚUidÚuidÚGidÚgidÚVmSizezvm-sizeÚstaté   é   é   zpercent-cpuNz,Skipping process (PID %s) without boot time.z
start-time)r   ÚpathÚjoinr   ÚstrÚopenÚreadlineÚbasenameÚsplitÚcloseÚstripÚlowerÚencoder   Úreadr   r   Ú
get_uptimeÚcalculate_pcpur   r   r   ÚloggingÚwarningr   ÚOSError)r   r!   Úcmd_line_nameÚprocess_dirr"   ÚfileÚcmd_lineÚlineÚpartsr1   Úvalue_partsÚ
start_timeÚutimeÚstimer   ÚpcpuÚdeltas                    r   r   z#ProcessInformation.get_process_info/   sl  € ð ˆÜ—g‘g—l‘l 4§>¡>´3°z³?ÓCˆØ˜zÐ*ˆðP	ÜœŸ™Ÿ™ [°)Ó<¸cÓBˆDðð  Ÿ=™=›?�Ü "§¡× 0Ñ 0°·±ÀÓ1EÀaÑ1HÓ I�à—
‘
”äœŸ™Ÿ™ [°(Ó;¸SÓAˆDðØ ó �DØ ŸJ™J s¨AÓ.�EØ˜Q‘x 6Ò)à)×/Ñ/Ó1ÒE°U¸1±X·^±^Ó5Eð % VÒ,ð ˜q™ WÒ,Ø % a¡§¡Ó 0˜ð !Ð$6Ò6Ø$)§K¡K£M˜EØ05°a±·±ÀÓ0H˜ WÒ-Ø˜q™ UÒ*Ø&+¨A¡h§n¡nÓ&6˜Ü.1°+¸a±.Ó.A˜ UÒ+Ø˜q™ UÒ*Ø&+¨A¡h§n¡nÓ&6˜Ü.1°+¸a±.Ó.A˜ UÒ+Ø˜q™ XÓ-Ø&+¨A¡h§n¡nÓ&6˜Ü25°kÀ!±nÓ2E˜ YÑ/Ùð/ð2 —
‘
”äœŸ™Ÿ™ [°&Ó9¸3Ó?ˆDð"ð Ÿ	™	›×)Ñ)Ó+�Ü   r¡›^�
Ü˜E "™I›�Ü˜E "™I›�ØŸ™Ò>¬×)<Ñ)<Ó)>�Ü%ØØØØØ×)Ñ)ó�ð /3�˜]Ñ+Ü! ! Z°4×3HÑ3HÑ%HÓI�Ø—?‘?Ð*Ü—O‘OØFØ"ôð  ð
 —
‘
•ô	 .:Ø—O‘O eÑ+ó.�˜\Ñ*ð —
‘
•ð �\Ñ!Ø˜<Ñ'Ø˜,Ñ&Ø˜Ñ%Ø˜Ñ%Ø Ñ,ð	
ð-ð Ðøðc —
‘
•ûð: —
‘
•ûðJ —
‘
•ûäò 	ñ ð	úsn   »*N Á&AM Â':N Ã"C3M* Ç'M* Ç=:N È8CM? Ë<N ÌM? Ì(N ÍM'Í'N Í*M<Í<N Í?NÎN Î	N ÎN )z/procNNN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r#   r   © r   r   r	   r	      s%   „ ñð ØØØóò 	#ófr   r	   c                 óz   — d}| |z   }|||z  z
  }|r|dz  |z  |z  }t        t        t        |d«      d«      d«      S )ao  
    Implement ps' algorithm to calculate the percentage cpu utilisation for a
    process.::

    unsigned long long total_time;   /* jiffies used by this process */
    unsigned pcpu = 0;               /* scaled %cpu, 99 means 99% */
    unsigned long long seconds;      /* seconds of process life */
    total_time = pp->utime + pp->stime;
    if(include_dead_children) total_time += (pp->cutime + pp->cstime);
    seconds = seconds_since_boot - pp->start_time / hertz;
    if(seconds) pcpu = (total_time * 100ULL / hertz) / seconds;
    if (pcpu > 99U) pcpu = 99U;
    return snprintf(outbuf, COLWID, "%2u", pcpu);
    r   éd   g     ÀX@r,   )ÚroundÚmaxÚmin)rT   rU   r   rS   ÚhertzrV   Ú
total_timeÚsecondss           r   rH   rH   ˜   sR   € ð €DØ˜‘€JØ˜
 UÑ*Ñ+€GÙØ˜CÑ %Ñ'¨'Ñ1ˆÜ””S˜˜t“_ aÓ(¨!Ó,Ð,r   )rI   r   r   r   Úlandscape.libr   Úlandscape.lib.jiffiesr   Úlandscape.lib.timestampr   r	   rH   r\   r   r   ú<module>rh      s,   ðÛ Û 	Ý Ý å "Ý 0Ý 0÷Jñ JóZ-r   