HOME


Mini Shell 1.0
DIR: /lib/python3/dist-packages/landscape/lib/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/landscape/lib/__pycache__/process.cpython-312.pyc
�

�~�e���j�ddlZddlZddlmZddlmZddlmZddlmZddlm	Z	Gd�d�Z
d	�Zy)
�N)�datetime)�	timedelta)�sysstats)�detect_jiffies)�to_timestampc�,�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__s\���� �*�*�,�?�?�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$s^�����
�
�4�>�>�2�	#�H�
� ��]�
� �0�0��<�L��"�"�	#���
��
�s-�#A�A�A�A�	A�A�A�Ac�F�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�OSError)rr!�
cmd_line_name�process_dirr"�file�cmd_line�line�partsr1�value_parts�
start_time�utime�stimer�pcpu�deltas                 rrz#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�&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%�������� 	#�frr	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)rTrUrrS�hertzrV�
total_time�secondss        rrHrH�sR��
�D����J��
�U�*�+�G���C��%�'�'�1����S��t�_�a�(�!�,�,r)rIrrr�
landscape.libr�landscape.lib.jiffiesr�landscape.lib.timestamprr	rHr\rr�<module>rhs,���	���"�0�0�J�J�Z-r