Your IP : 216.73.216.158


Current Path : /snap/core24/1587/lib/python3/dist-packages/cloudinit/analyze/__pycache__/
Upload File :
Current File : //snap/core24/1587/lib/python3/dist-packages/cloudinit/analyze/__pycache__/show.cpython-312.pyc

�

�t�h*7���ddlZddlZddlZddlZddlmZmZmZmZm	Z	m
Z
mZmZddl
mZmZddlmZddddd	d
ddd
ddd�ZdZdZdZedddfZeZdededefd�Zde	ede	efd�Zde	ede	efd�Zde	ede	efd�Zdedefd�Zdedejfd�Zdejdejdefd �Z d!ed"edefd#�Z!d$ejd!ed"edefd%�Z"dedefd&�Z#Gd'�d(�Z$de
eeeeffd)�Z%de
eeeeffd*�Z&de
eeeeffd+�Z'	d2d,eed-edeeefd.�Z(d,eed-edeeefd/�Z)d0ede
e	eeffd1�Z*y)3�N)�IO�Any�Dict�List�Optional�Tuple�Union�cast)�subp�util)�uses_systemd�delta�description�elapsed�
event_type�indent�level�name�origin�result�	timestamp�
total_time)z%dz%Dz%Ez%ez%Iz%lz%nz%oz%rz%tz%T�
successful�failure�	container����msg�event�returnc���tj�D]9\}}||vs�|dvr|j|d|z�}�%|j|d|z�}�;|jdi|��S)N)rrrz
{%s:08.5f}z{%s}�)�
format_key�items�replace�format)rr�i�js    �8/usr/lib/python3/dist-packages/cloudinit/analyze/show.py�
format_recordr)9sm��� � �"�1���1���8��5�5��k�k�!�\�A�%5�6���k�k�!�V�a�Z�0��
1��3�:�:�����c�*�|r|jd�Sy)Nr��get�rs r(�
event_namer/Ds����y�y�� � �r*c�*�|r|jd�Sy)Nrr,r.s r(rrJs����y�y��&�&�r*c�F�t|�}|r|jd�dSy)N�/r)r/�split)rrs  r(�event_parentr4Ps%���e��D���z�z�#��q�!�!�r*c�T�|jd�}|�td��t|�S)NrzEvent is missing a 'timestamp')r-�
ValueError�float)r�tss  r(�event_timestampr9Ws+��	���;�	�B�	�z��9�:�:���9�r*c��tjjt|�tjj�S�N)�datetime�
fromtimestampr9�timezone�utcr.s r(�event_datetimer@^s1�����*�*����� 1� 1� 5� 5��r*�t1�t2c�(�||z
j�Sr;)�
total_seconds)rArBs  r(�
delta_secondsrEds����G�"�"�$�$r*�start�finishc�>�tt|�t|��Sr;)rEr@)rFrGs  r(�event_durationrIhs�����.��v�0F�G�Gr*�
start_timec	���|j�}t|�}d}|r|d|jd�dz
zdzz
}|jt	||�t|t
|��|d��|S)N�|� r2�z`->)rrr)�copyr/�count�updaterIrEr@)rJrFrG�recordrrs      r(�event_recordrSlsv��
�[�[�]�F��e��D�
�F���#����C��1�,�-��5�5��
�M�M�#�E�6�2�$�Z���1F�G��	
���Mr*c��d|zS)NzTotal Time: %3.5f seconds
r!)rs r(�total_time_recordrU�s
��(�:�5�5r*c�P�eZdZdZd	dedeefd�Zdeeeeffd�Z	de
fd�Zy)
�SystemctlReaderzQ
    Class for dealing with all systemctl subp calls in a consistent manner.
    N�property�	parameterc���d|_tjd�dg|_|r|jj	|�|jjd|dg�|j
�|_y)N�	systemctl�showz-pz--timestamp=us+utc)�stdoutr�which�args�append�extend�_subpr)�selfrXrYs   r(�__init__zSystemctlReader.__init__�s^��%)����*�*�[�1�6�:��	���I�I���Y�'�	
�	�	���$��*>�?�@�
�z�z�|��r*rc��	tj|jd��\}}|r|S||_y#t$r}|cYd}~Sd}~wwxYw)z�
        Make a subp call based on set args and handle errors by setting
        failure code

        :return: whether the subp call failed or not
        T��captureN)rr_r]�	Exception)rc�value�err�systemctl_fails    r(rbzSystemctlReader._subp�sG��	"����4�9�9�d�;�J�E�3���
��D�K����	"�!�!��	"�s�'2�2�	A�A�A�Ac���|jr$tdj|j���|j�td��|jj	d�dj�}|j
�rt|�dz}|Stjj|d�jtjj��j�}|S)z{
        If subp call succeeded, return the timestamp from subp as a float.

        :return: timestamp as a float
        zBSubprocess call to systemctl has failed, returning error code ({})z.stdout of subprocess call to systemctl is None�=rNi@Bz%a %Y-%m-%d %H:%M:%S.%f %Z)�tzinfo)r�RuntimeErrorr%r]r3�strip�	isnumericr7r<�strptimer$r>r?r)rc�valrs   r(�convert_val_to_floatz$SystemctlReader.convert_val_to_float�s����<�<��,�,2�F�4�<�<�,@��
��;�;���@��
��k�k����$�Q�'�-�-�/���=�=�?��c�
�W�,�I����!�!�*�*�3�0L�M���� 1� 1� 5� 5��6����
��r*r;)�__name__�
__module__�__qualname__�__doc__�strrrdr	rhrbr7rtr!r*r(rWrW�sD���$��$��#��$�$"�x��c�9�n� 5�6�"� +�e�+r*rWc��t�r
t�Stj�s'dtj�dj�vr
t
�StS)a)
    Determine which init system a particular linux distro is using.
    Each init system (systemd, etc) has a different way of
    providing timestamps.

    :return: timestamps of kernelboot, kernelendboot, and cloud-initstart
    or TIMESTAMP_UNKNOWN if the timestamps cannot be retrieved.
    �gentoo�system)r
�gather_timestamps_using_systemdr�
is_FreeBSD�system_info�lower�gather_timestamps_using_dmesg�TIMESTAMP_UNKNOWNr!r*r(�dist_check_timestampr��sM���~�.�0�0�����H��(8�(8�(:�8�(D�(J�(J�(L�L�,�.�.��r*c��	tjdgd��\}}|dj�}|D]�}|jd�jd�dk7s�'|jd�j	�}|djd	�}t
|�}t
tj��t
tj��z
}||z}t|||fcS	tS#t$rYtSwxYw)
a
    Gather timestamps that corresponds to kernel begin initialization,
    kernel finish initialization using dmesg as opposed to systemctl

    :return: the two timestamps plus a dummy timestamp to keep consistency
    with gather_timestamps_using_systemd
    �dmesgTrfrzUTF-8�userrrN�])
r�
splitlines�decode�findr3rpr7�timer�uptime�SUCCESS_CODErhr�)	�data�_�
split_entriesr&�splitup�stripped�user_space_timestamp�kernel_start�
kernel_ends	         r(r�r��s���
��)�)�W�I�t�4���a��Q��*�*�,�
��
	J�A��x�x�� �%�%�f�-��3��(�(�7�+�1�1�3��"�1�:�+�+�C�0��(-�X��$�$�T�Y�Y�[�1�E�$�+�+�-�4H�H��)�,@�@�
�$�\�:�z�I�I�
	J�"����
����
�s�AC+�B	C+�#C+�+	C<�;C<c��	tj�r3td�j�}td�j�}n2td�j�}td�j�}td�j�|z
}tdd�j�|z
}tj�rtnt}||||z||zfS#t$r}t|�tcYd}~Sd}~wwxYw)z�
    Gather timestamps that corresponds to kernel begin initialization,
    kernel finish initialization. and cloud-init systemd unit activation

    :return: the three timesread_propertystamps
    �UserspaceTimestamp�UserspaceTimestampMonotonic�KernelTimestamp�KernelTimestampMonotonic�InactiveExitTimestampMonotoniczcloud-init-localN)	r�is_containerrWrtrh�printr��CONTAINER_CODEr�)r��monotonic_offsetr��cloudinit_sysd�e�statuss      r(r}r}s!��&!�����+�$��"�"�$�
� /�-� �"�"�$�
�+�!��"�"�$�
� /�*� �"�"�$�
�
�-�
�"�"�$��
�	�
�0�2D�
�"�"�$��
�	� $�0�0�2�^��F�	���z�!��~�%�	����!�	�a�� � ��!�s�B2C � 	D�)C?�9D�?D�events�print_formatc��t|d���}g}d}d}i}g}g}tt|��D�]�}	||	}
	||	dz}t	|
�dk(r�|rE|
jd�dk(r1|j
t|��|j
|�g}d}d}|�t|
�}||t|
�<t|
�t|�k(rFt	|�d	k(s��tt|�}|j
t|t||
|�����|j
d
|
jd�z�|j
|
���|j�}t|
�t|�k(rI|s��@t|||
�}
|j
td|
�dz�||
jd
�xsdz
}���|j
|����|j
t|��|j
|�|S#t$rd}Y���wxYw)as
    Take in raw events and create parent-child dependencies between events
    in order to order events in chronological order.

    :param events: JSONs from dump that represents events taken from logs
    :param print_format: formatting to represent event, time stamp,
    and time taken by the event in one line

    :return: boot records ordered chronologically
    c��|dS)Nrr!)�xs r(�<lambda>z"generate_records.<locals>.<lambda>Ws
���;��r*)�keyNgrNrFrz
init-localrGzStarting stage: %szFinished stage: (%n) %d seconds�
r)�sorted�range�len�
IndexErrorrr-r`rUr@r4r/r
rr)rS�pop)r�r��
sorted_events�recordsrJr�stage_start_time�boot_records�unprocessedr�r�next_evt�prev_evtrRs              r(�generate_recordsr�Hs���6�'?�@�M��G��J��J����L��K�
�3�}�%�
&�2-���q�	��	��a�!�e�}�H��e���'��5�9�9�V�,��<����0��<�=��#�#�G�,���!�
� �
��!�+�E�2�
�8B� ��e�!4�5��%� �J�x�$8�8��h�'�8�3� $�D�(�3�H��N�N�%�(�(��U�H�E������3�e�i�i��6G�G�H��"�"�5�)��"���(�H��%� �J�x�$8�8��)�*�h��F�F��N�N�%�=�v������&�*�*�W�"5�"<��<�J��"�"�8�,�e2-�h�N�N�$�Z�0�1����� ����e�	��H�	�s�G5�5H�Hc��t||��S)a<
    A passthrough method that makes it easier to call generate_records()

    :param events: JSONs from dump that represents events taken from logs
    :param print_format: formatting to represent event, time stamp,
    and time taken by the event in one line

    :return: boot records ordered chronologically
    )r�)r�)r�r�s  r(�show_eventsr��s���F��>�>r*�infilec��|j�}|j�sAtjj	d|j
z�tjd�	tj|�|fS#t$rd|fcYSwxYw)z�
    Takes in a log file, read it, and convert to json.

    :param infile: The Log file to be read

    :return: json version of logfile, raw file
    zEmpty file %s
rNN)
�readrp�sys�stderr�writer�exit�json�loadsr6)r�r�s  r(�load_events_infiler��sq���;�;�=�D��:�:�<��
�
���*�V�[�[�8�9��������z�z�$���%�%�����T�z���s�#A:�:
B
�	B
)z(%n) %d seconds in %I%D)+r<r�r�r��typingrrrrrrr	r
�	cloudinitrr�cloudinit.distrosr
r"r��	FAIL_CODEr�r��Eventryr)r/rr4r7r9r@rErIrSrUrWr�r�r}r�r�r�r!r*r(�<module>r�sf����
��D�D�D� �*�,�
�
�
�
�
�
�
�
�
�
��
����	�����B��+�����s��5��S���h�u�o��(�3�-���h�u�o��(�3�-�������H�S�M���5��U���%��H�$5�$5��%�h�'�'�%�X�->�->�%�5�%�H�%�H��H�5�H���!�!����
���	�*6�%�6�C�6�R�R�j�e�C���u�$<�=��,�u�S�%���-E�'F��>6��s�E�5�%�/G�)H�6�v2�M���K�M��M�
�$�s�)�_�M�`
?��U��
?�3�
?�4��S�	�?�
?��r��e�H�S�M�3�,>�&?�r*