HOME


Mini Shell 1.0
DIR: /usr/lib/python3/dist-packages/cloudinit/analyze/__pycache__/
Upload File :
Current File : //usr/lib/python3/dist-packages/cloudinit/analyze/__pycache__/show.cpython-312.pyc
�

�f>/���ddlZddlZddlZddlZddlZddlmZmZddlm	Z	dddddd	d
ddd
dd�Z
dje
j�D��cgc]'\}}dj|jdd�|���)c}}�ZdZdZdZedddfZd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd �Zd!�ZGd"�d#�Zd$�Zd%�Z d&�Z!				d*d'�Z"d(�Z#d)�Z$ycc}}w)+�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� z{0}: {1}�%z%%�
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":sm��� � �"�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(Es����y�y�� � �r#c�*�|r|jd�Sy)Nr	r%r's r!r	r	Ks����y�y��&�&�r#c�B�|rt|�jd�dSy)N�/r)r(�splitr's r!�event_parentr-Qs#����%� �&�&�s�+�A�.�.�r#c�6�t|jd��S�Nr)�floatr&r's r!�event_timestampr1Ws������;�'�(�(r#c�R�tjjt|��S�N)�datetime�utcfromtimestampr1r's r!�event_datetimer6[s�����-�-�o�e�.D�E�Er#c�(�||z
j�Sr3)�
total_seconds)�t1�t2s  r!�
delta_secondsr;_s����G�"�"�$�$r#c�>�tt|�t|��Sr3)r;r6)�start�finishs  r!�event_durationr?cs�����.��v�0F�G�Gr#c	���|j�}|jt||�t|t	|��ddt|�j
d�dz
zzdzd��|S)N�|rr+�z`->)rrr
)�copy�updater?r;r6r(�count)�
start_timer=r>�records    r!�event_recordrHgse��
�[�[�]�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_recordrJts
��(�:�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)rrRrP�	Exception)rU�value�err�systemctl_fails    r!rzSystemctlReader.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 ({})�=rBi@B)r�RuntimeErrorrrPr,r0)rUrs  r!�parse_epoch_as_floatz$SystemctlReader.parse_epoch_as_float�sV���<�<��,�,2�F�4�<�<�,@��
��J�J�$�$�S�)�!�,�	��Y��'�)�)r#r3)�__name__�
__module__�__qualname__�__doc__rXrrcrr#r!rLrLxs���	#�"� *r#rLc��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_timestamprq�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
    �dmesgTrZrzUTF-8�userrrB�])
r�
splitlines�decode�findr,�stripr0�timer�uptime�SUCCESS_CODEr\rp)	�data�_�
split_entriesr�splitup�stripped�user_space_timestamp�kernel_start�
kernel_ends	         r!roro�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�rcttj��ttj��z
}	tjd�}|j}t}||z}||z}||||fS#t$r }tdj|��|�d}~wwxYw#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 timestamps
    �UserspaceTimestampMonotonic�InactiveExitTimestampMonotoniczcloud-init-localz/proc/1/cmdlinezBCould not determine container boot time from /proc/1/cmdline. ({})N)r0rzrr{rLrcr|�is_container�	monotonic�os�stat�st_atime�OSErrorrbr�CONTAINER_CODEr\�printrp)
r��delta_k_end�
delta_ci_s�	base_time�status�	file_statr^r��cloudinit_sysd�es
          r!rkrk�s8�������%��d�k�k�m�(<�<�L�"!�%�)�
�
�
�
 �	�%�,�.@�
�
�
�
 �	�!�	��������d�i�i�k�*�U�4�>�>�3C�-D�D�I�
��G�G�$5�6�	�(�1�1��$�F���,�
�"�Z�/���<��^�;�;���
�"�6�6<�f�S�k�����
���!�	�a�� � ��!�sB�B
D+�!C?�)D+�?	D(�D#�#D(�(D+�+	E�4E
�E�
Ec���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)a2
    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 blame_sort: whether to sort by timestamp or by time taken.
    :param print_format: formatting to represent event, time stamp,
    and time taken by the event in one line
    :param dump_files: whether to dump files into JSONs
    :param log_datafiles: whether or not to log events generated

    :return: boot records ordered chronologically
    c��|dSr/r)�xs r!�<lambda>z"generate_records.<locals>.<lambda>%s
���;��r#)�keyNgrBr=rz
init-localr>zStarting stage: %szFinished stage: (%n) %d seconds�
r)�sorted�range�len�
IndexErrorr	r&rSrJr6r-r(r"rH�pop)�events�
blame_sort�print_format�
dump_files�
log_datafiles�
sorted_events�recordsrFr�stage_start_time�boot_records�unprocessedr�r�next_evt�prev_evtrGs                 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�`s���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
rBN)
�readry�sys�stderr�writer�exit�json�loads�
ValueError)�infiler}s  r!�load_events_infiler�msq���;�;�=�D��:�:�<��
�
���*�V�[�[�8�9��������z�z�$���%�%�����T�z���s�#A:�:
B
�	B
)Fz(%n) %d seconds in %I%DFF)%r4r�r�r�rz�	cloudinitrr�cloudinit.distrosrr�joinrrr�formatting_helpr|�	FAIL_CODEr�rpr"r(r	r-r1r6r;r?rHrJrLrqrorkr�r�r�)�k�vs00r!�<module>r�s����	�
�� �*�,�
�
�
�
�
�
�
�
�
�
��
��(�(�<F�<L�<L�<N�O�D�A�q�Z���q�y�y��d�+�Q�/�O������	�����B��+������)�F�%�H�
�6�2*�2*�j�,�>+<�`�*���M�`
?���w	Ps�,C