HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/landscape/lib/__pycache__/process.cpython-312.pyc
�

y)�]���p�ddlmZddlZddlZddlmZmZddlmZddlm	Z	ddl
mZGd�de�Z
d	�Zy)
�)�absolute_importN)�	timedelta�datetime)�sysstats)�to_timestamp)�detect_jiffiesc�(�eZdZdZ		dd�Zd�Zd�Zy)�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���|�"tj�j�}|�tj|�}||_||_|xs
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__zProcessInformation.__init__sZ���� �*�*�,�?�?�A�I�� � �1�1�)�<�I�#���!��� '� ;�>�+;������c#�K�tj|j�D]&}	t|�}|j|�}|s�#|���(y#t$rY�5wxYw�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 sY�����
�
�4�>�>�2�H�
� ��]�
� �0�0��<�L��"�"�3���
��
�s-�#A�A�A�A�	A�A�A�Ac�D�d}tjj|jt	|��}d|i}	ttjj|d�d�}	|j
�}tjj|jd�d�}|j�ttjj|d�d�}	|D�]}|jdd	�}|dd
k(r)|j�xs|d	j�|d<�G|ddk(r@|d	j�}	|	d
k(r|	j�}	|	djd�|d<��|ddk(r%|d	j�}
t|
d�|d<��|ddk(r%|d	j�}
t|
d�|d<��|ddk(s��|d	j�}
t|
d�|d<n|j�ttjj|d�d�}	|j�j�}t|d�}t|d�}t|d�}
|jxst!j"�}t%||
|||j&�}||d<t)d||j&z�}|j*�'t-j.d�	|j�yt1|j*|z�|d<|j�	d|vrd|vrd|vrd|vrd|vrd|vsJ�|S#|j�wxYw#|j�wxYw#|j�wxYw#t2$rYywxYw)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�StatezT (tracing stop)�ascii�state�Uid�uid�Gid�gid�VmSizezvm-size�stat��
�zpercent-cpuNz,Skipping process (PID %s) without boot time.z
start-time)r�path�joinr�str�open�readline�basename�split�close�strip�lower�encoder�readrr�
get_uptime�calculate_pcpurrr�logging�warningr�IOError)rr"�
cmd_line_name�process_dirr#�file�cmd_line�line�partsr2�value_parts�
start_time�utime�stimer�pcpu�deltas                 rr z#ProcessInformation.get_process_info+s^���
��g�g�l�l�4�>�>�3�z�?�C���z�*��G	�������[�)�<�c�B�D�
� �=�=�?�� "��� 0� 0�����1E�a�1H� I�
��
�
��������[�(�;�S�A�D�
� �D� �J�J�s�A�.�E��Q�x�6�)�0=�0C�0C�0E�1A�05�a����0@�%�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�/��-!�0�
�
��������[�&�9�3�?�D�
��	�	��)�)�+�� ��r��^�
��E�"�I����E�"�I������>��)<�)<�)>��%�e�U�F�&0�$�2G�2G�I��.2��]�+�!�!�Z�4�3H�3H�%H�I���?�?�*��O�O�F�H���
�
��.:��O�O�e�+�.-��\�*��
�
����$��L�)@���%�%�<�*?���$���)E�	G�F����G�
�
���8�
�
���:�
�
����	��	�sn�*N�&AM�':N�"C3M)�'M)�=:N�8CM>�;N�M>�'N�M&�&N�)M;�;N�>N�N�	N�N)z/procNNN)�__name__�
__module__�__qualname__�__doc__rr$r �rrr
r
s!���BF��	�	#�Xrr
c�z�d}||z}|||zz
}|r|dz|z|z}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)rUrVrrT�hertzrW�
total_time�secondss        rrIrI�sR��
�D����J��
�U�*�+�G���C��%�'�'�1����S��t�_�a�(�!�,�,r)�
__future__rrJrrr�
landscape.libr�landscape.lib.timestampr�landscape.lib.jiffiesr�objectr
rIr]rr�<module>rks.��&��	�(�"�0�0�w��w�t-r