name : show.cpython-39.pyc
a

'�Dg,+�@sddlZddlZddlZddlZddlmZmZddlmZdddddd	d
ddd
dd�Z	dZ
dZdZedddfZ
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�ZGd'd(�d(�Zd)d*�Zd+d,�Zd-d.�Zd6d0d1�Zd2d3�Zd4d5�ZdS)7�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%TZ
successful�failure�	container���cCsTt��D]:\}}||vr|dvr2|�|d|�}q|�|d|�}q|jfi|��S)N)rrrz
{%s:08.5f}z{%s})�
format_key�items�replace�format)�msg�event�i�j�r�:/usr/lib/python3.9/site-packages/cloudinit/analyze/show.py�
format_record6srcCs|r|�d�SdS)Nr��get�rrrr�
event_nameAs
r!cCs|r|�d�SdS)Nrrr rrrrGs
cCs|rt|��d�dSdS)N�/r)r!�splitr rrr�event_parentMsr$cCst|�d��S�Nr)�floatrr rrr�event_timestampSsr'cCstj�t|�tjj�S�N)�datetimeZ
fromtimestampr'�timezoneZutcr rrr�event_datetimeWs�r+cCs||��Sr()Z
total_seconds)�t1�t2rrr�
delta_seconds]sr.cCstt|�t|��Sr()r.r+)�start�finishrrr�event_durationasr1c	CsH|��}|�t||�t|t|��ddt|��d�ddd��|S)N�|� r"�z`->)rrr	)�copy�updater1r.r+r!�count)�
start_timer/r0�recordrrr�event_recordes��r:cCsd|S)NzTotal Time: %3.5f seconds
r)rrrr�total_time_recordrsr;c@s*eZdZdZd	dd�Zdd�Zdd�ZdS)
�SystemctlReaderzQ
    Class for dealing with all systemctl subp calls in a consistent manner.
    NcCsDd|_t�d�dg|_|r&|j�|�|j�d|g�|��|_dS)NZ	systemctlZshowz-p)�epochr�which�args�append�extendr)�self�propertyZ	parameterrrr�__init__{szSystemctlReader.__init__c
CsXz*tj|jdd�\}}|r |WS||_WdStyR}z|WYd}~Sd}~00dS)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�ZcaptureN)rr?r=�	Exception)rB�value�errZsystemctl_failrrrr�szSystemctlReader.subpcCs2|jrtd�|j���|j�d�d}t|�dS)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 ({})�=r4i@B)r�RuntimeErrorrr=r#r&)rBrrrr�parse_epoch_as_float�s	��z$SystemctlReader.parse_epoch_as_float)N)�__name__�
__module__�__qualname__�__doc__rDrrKrrrrr<vs
r<cCs2t�rt�St��s(dt��d��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.
    Zgentoo�system)r�gather_timestamps_using_systemdrZ
is_FreeBSDZsystem_info�lower�gather_timestamps_using_dmesg�TIMESTAMP_UNKNOWNrrrr�dist_check_timestamp�s

rUc	Cs�z�tjdgdd�\}}|d��}|D]n}|�d��d�dkr&|�d���}|d�d	�}t|�}tt���tt�	��}||}t
|||fWSq&Wnty�Yn0tS)
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
    ZdmesgTrErzUTF-8�userrr4�])
r�
splitlines�decode�findr#�stripr&�timer�uptime�SUCCESS_CODErFrT)	�data�_Z
split_entriesrZsplitup�strippedZuser_space_timestamp�kernel_start�
kernel_endrrrrS�srSc
Cs�tt���tt���}zBtd���}tdd���}|}t}t��rHt}||}||}Wn0t	y�}zt
|�tWYd}~Sd}~00||||fS)z�
    Gather timestamps that corresponds to kernel begin initialization,
    kernel finish initialization. and cloud-init systemd unit activation

    :return: the three timestamps
    ZUserspaceTimestampMonotonicZInactiveExitTimestampMonotoniczcloud-init-localN)r&r\rr]r<rKr^Zis_container�CONTAINER_CODErF�printrT)rbZdelta_k_endZ
delta_ci_sZ	base_time�statusrcZcloudinit_sysd�errrrQ�s$��rQ�(%n) %d seconds in %I%Dc	Cs�t|dd�d�}g}d}d}i}g}g}tt|��D�]D}	||	}
z||	d}Wntyhd}Yn0t|
�dk�r&|r�|
�d�d	kr�|�t|��|�|�g}d}d}|dur�t|
�}||t	|
�<t
|
�t
|�k�rt|�d
k�r$|�t|t||
|���n |�d|
�d��|�|
�q4q4|�
�}t
|
�t
|�k�rpt|||
�}
|�td|
�d
�||
�d�7}q4|�|�q4|�t|��|�|�|S)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
    cSs|dSr%r)�xrrr�<lambda>�z"generate_records.<locals>.<lambda>)�keyNgr4r/rz
init-localr0zStarting stage: %szFinished stage: (%n) %d seconds�
r)�sorted�range�len�
IndexErrorrrr@r;r+r$r!rr:�pop)�events�print_formatZ
sorted_eventsZrecordsr8rZstage_start_timeZboot_recordsZunprocessedrgrZnext_evtZprev_evtr9rrr�generate_recordss^


��
��
rucCst||d�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
    )rt)ru)rsrtrrr�show_eventsKs
rvcCs\|��}|��s,tj�d|j�t�d�zt�|�|fWSt	yVd|fYS0dS)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
r4N)
�readr[�sys�stderr�writer�exit�json�loads�
ValueError)Zinfiler_rrr�load_events_infileXs
r)rh)r)r|rxr\Z	cloudinitrrZcloudinit.distrosrrr^Z	FAIL_CODErdrTrr!rr$r'r+r.r1r:r;r<rUrSrQrurvrrrrr�<module>sN�
5#�
J

© 2025 Cubjrnet7