Current File : //usr/lib/python3/dist-packages/cloudinit/analyze/__pycache__/show.cpython-312.pyc
�

Ӈg,+����ddlZddlZddlZddlZddlmZmZddlmZdddddd	d
ddd
dd�Z	dZ
dZdZedddfZ
d�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�ZGd�d�Zd �Zd!�Zd"�Z	d&d#�Zd$�Zd%�Zy)'�N)�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���c���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)�msg�event�i�js    �8/usr/lib/python3/dist-packages/cloudinit/analyze/show.py�
format_recordr 6sm��� � �"�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&As����y�y�� � �r!c�*�|r|jd�Sy)Nr	r#r%s rr	r	Gs����y�y��&�&�r!c�B�|rt|�jd�dSy)N�/r)r&�splitr%s r�event_parentr+Ms#����%� �&�&�s�+�A�.�.�r!c�6�t|jd��S�Nr)�floatr$r%s r�event_timestampr/Ss������;�'�(�(r!c��tjjt|�tjj�S�N)�datetime�
fromtimestampr/�timezone�utcr%s r�event_datetimer6Ws1�����*�*����� 1� 1� 5� 5��r!c�(�||z
j�Sr1)�
total_seconds)�t1�t2s  r�
delta_secondsr;]s����G�"�"�$�$r!c�>�tt|�t|��Sr1)r;r6)�start�finishs  r�event_durationr?as�����.��v�0F�G�Gr!c	���|j�}|jt||�t|t	|��ddt|�j
d�dz
zzdzd��|S)N�|� r)�z`->)rrr
)�copy�updater?r;r6r&�count)�
start_timer=r>�records    r�event_recordrIese��
�[�[�]�F�
�M�M�#�E�6�2�$�Z���1F�G��C�:�e�#4�#:�#:�3�#?�!�#C�D�D�u�L�	
���Mr!c��d|zS)NzTotal Time: %3.5f seconds
r)rs r�total_time_recordrKrs
��(�:�5�5r!c�$�eZdZdZdd�Zd�Zd�Zy)�SystemctlReaderzQ
    Class for dealing with all systemctl subp calls in a consistent manner.
    Nc���d|_tjd�dg|_|r|jj	|�|jjd|g�|j�|_y)N�	systemctl�showz-p)�epochr�which�args�append�extendr)�self�property�	parameters   r�__init__zSystemctlReader.__init__{sY����
��Z�Z��,�f�5��	���I�I���Y�'��	�	���$��)�*��y�y�{��r!c��	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)rrSrQ�	Exception)rV�value�err�systemctl_fails    rrzSystemctlReader.subp�sG��	"����4�9�9�d�;�J�E�3���
��D�J����	"�!�!��	"�s�'2�2�	A�A�A�Ac��|jr$tdj|j���|jj	d�d}t|�dzS)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 ({})�=rCi@B)r�RuntimeErrorrrQr*r.)rVrs  r�parse_epoch_as_floatz$SystemctlReader.parse_epoch_as_float�sV���<�<��,�,2�F�4�<�<�,@��
��J�J�$�$�S�)�!�,�	��Y��'�)�)r!r1)�__name__�
__module__�__qualname__�__doc__rYrrdrr!rrMrMvs���	#�"� *r!rMc��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_UNKNOWNrr!r�dist_check_timestamprr�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
    �dmesgTr[rzUTF-8�userrrC�])
r�
splitlines�decode�findr*�stripr.�timer�uptime�SUCCESS_CODEr]rq)	�data�_�
split_entriesr�splitup�stripped�user_space_timestamp�kernel_start�
kernel_ends	         rrprp�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��ttj��ttj��z
}	t	d�j�}t	dd�j�}|}t}tj�rt}||z}||z}||||fS#t$r}t|�tcYd}~Sd}~wwxYw)z�
    Gather timestamps that corresponds to kernel begin initialization,
    kernel finish initialization. and cloud-init systemd unit activation

    :return: the three timestamps
    �UserspaceTimestampMonotonic�InactiveExitTimestampMonotoniczcloud-init-localN)r.r{rr|rMrdr}�is_container�CONTAINER_CODEr]�printrq)r��delta_k_end�
delta_ci_s�	base_time�statusr��cloudinit_sysd�es        rrlrl�s��������%��d�k�k�m�(<�<�L�!�%�)�
�
�
�
 �	�%�,�.@�
�
�
�
 �	�!�	�������#�F���,�
�"�Z�/���<��^�;�;��
�!�	�a�� � ��!�s�AB"�"	C�+C�;C�Cc���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(r6t	|�d	k(s��|j
t|t||
|�����|j
d
|
jd�z�|j
|
���|j�}t|
�t|�k(rAt|||
�}
|j
td|
�dz�||
jd
�z
}��m|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��|dSr-r)�xs r�<lambda>z"generate_records.<locals>.<lambda>s
���;��r!)�keyNgrCr=rz
init-localr>zStarting stage: %szFinished stage: (%n) %d seconds�
r)�sorted�range�len�
IndexErrorr	r$rTrKr6r+r&r rI�pop)�events�print_format�
sorted_events�recordsrGr�stage_start_time�boot_records�unprocessedr�r�next_evt�prev_evtrHs              r�generate_recordsr�s����6�'?�@�M��G��J��J����L��K�
�3�}�%�
&�,-���q�	��	��a�!�e�}�H��e���'��5�9�9�V�,��<����0��<�=��#�#�G�,���!�
� �
��!�+�E�2�
�8B� ��e�!4�5��%� �J�x�$8�8��h�'�8�3��N�N�%�(�(��U�H�E������3�e�i�i��6G�G�H��"�"�5�)��"���(�H��%� �J�x�$8�8�%�j�(�E�B�����!�"C�V�L�����f�j�j��1�1�
��"�"�8�,�Y,-�\�N�N�$�Z�0�1����� ����Y�	��H�	�s�G�G,�+G,c��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�Ks���F��>�>r!c��|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
rCN)
�readrz�sys�stderr�writer�exit�json�loads�
ValueError)�infiler~s  r�load_events_infiler�Xsq���;�;�=�D��:�:�<��
�
���*�V�[�[�8�9��������z�z�$���%�%�����T�z���s�#A:�:
B
�	B
)z(%n) %d seconds in %I%D)r2r�r�r{�	cloudinitrr�cloudinit.distrosrrr}�	FAIL_CODEr�rqr r&r	r+r/r6r;r?rIrKrMrrrprlr�r�r�rr!r�<module>r�s�����
�� �*�,�
�
�
�
�
�
�
�
�
�
��
����	�����B��+������)��%�H�
�6�2*�2*�j�,�><�F+�G�T
?�r!