HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/landscape/lib/__pycache__/process.cpython-38.pyc
U

���c��@slddlmZddlZddlZddlmZmZddlmZddlm	Z	ddl
mZGdd�de�Z
d	d
�ZdS)�)�absolute_importN)�	timedelta�datetime)�sysstats)�to_timestamp)�detect_jiffiesc@s*eZdZdZd
dd�Zdd�Zdd	�ZdS)�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).
    �/procNcCsH|dkrt����}|dk	r&t�|�}||_||_|p:t�|_||_	dS)N)
rZ	BootTimesZget_last_boot_timerZutcfromtimestamp�
_boot_time�	_proc_dirr�_jiffies_per_sec�_uptime)�selfZproc_dirZjiffiesZ	boot_time�uptime�r�7/usr/lib/python3/dist-packages/landscape/lib/process.py�__init__s
zProcessInformation.__init__c	csPt�|j�D]>}zt|�}Wntk
r4YqYnX|�|�}|r|VqdS)z8Get process information for all processes on the system.N)�os�listdirr�int�
ValueError�get_process_info)r�filename�
process_id�process_inforrr�get_all_process_info s

z'ProcessInformation.get_all_process_infocCs�d}tj�|jt|��}d|i}�z*ttj�|d�d�}z"|��}tj�|�	d�d�}W5|��Xttj�|d�d�}�z|D]�}|�	dd	�}|dd
kr�|�
�p�|d	�
�|d<q�|ddkr�|d	�
�}	|	d
kr�|	��}	|	d�d�|d<q�|ddk�r |d	�	�}
t
|
d�|d<q�|ddk�rL|d	�	�}
t
|
d�|d<q�|ddkr�|d	�	�}
t
|
d�|d<�q|q�W5|��Xttj�|d�d�}z�|���	�}t
|d�}t
|d�}t
|d�}
|j�p�t��}t||
|||j�}||d<td||j�}|jdk�r*t�d�W�WdSt|j|�|d<W5|��XWntk
�rdYdSXd|k�r�d|k�r�d|k�r�d|k�r�d|k�r�d|k�s�t�|S)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.
        ��pidZcmdline�r�rZstatus�:��Name�name�StatezT (tracing stop)�ascii�stateZUidZuidZGid�gidZVmSizezvm-size�stat��
�zpercent-cpuNz,Skipping process (PID %s) without boot time.z
start-time)r�path�joinr�str�open�close�readline�basename�split�strip�lower�encoder�readr
rZ
get_uptime�calculate_pcpurrr
�loggingZwarningr�IOError�AssertionError)rrZ
cmd_line_nameZprocess_dirr�fileZcmd_line�line�partsr&Zvalue_parts�
start_time�utime�stimer�pcpuZdeltarrrr+s�

�

��
�����z#ProcessInformation.get_process_info)r	NNN)�__name__�
__module__�__qualname__�__doc__rrrrrrrrs�
rcCsBd}||}|||}|r,|d||}ttt|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�dg�X@r!)�round�max�min)r@rArr?ZhertzrBZ
total_timeZsecondsrrrr8�sr8)Z
__future__rr9rrrZ
landscape.librZlandscape.lib.timestamprZlandscape.lib.jiffiesr�objectrr8rrrr�<module>sz