HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux ip-10-0-8-47 6.8.0-1021-aws #23~22.04.1-Ubuntu SMP Tue Dec 10 16:31:58 UTC 2024 aarch64
User: ubuntu (1000)
PHP: 8.1.2-1ubuntu2.22
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/cloudinit/analyze/__pycache__/show.cpython-310.pyc
o

�Adm0�@s4ddlZddlZddlZddlZddlZddlmZmZddlm	Z	dddddd	d
ddd
dd�Z
d�dd�e
��D��Z
dZdZdZedddfZdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�ZGd,d-�d-�Zd.d/�Zd0d1�Zd2d3�Z 	4	5	4	4d<d6d7�Z!d8d9�Z"d:d;�Z#dS)=�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� cCs$g|]\}}d�|�dd�|��qS)z{0}: {1}�%z%%)�format�replace��.0�k�v�r�8/usr/lib/python3/dist-packages/cloudinit/analyze/show.py�
<listcomp>2s$r�
successful�failure�	container���cCsTt��D]\}}||vr!|dvr|�|d|�}q|�|d|�}q|jdi|��S)N)rrrz
{%s:08.5f}z{%s}r)�
format_key�itemsrr)�msg�event�i�jrrr�
format_record:s�r%cCsntdd�|��D��}|d}g}|D]!}|d}tj�|�}t�|d��d�}t�	||�|�
|�q|S)Ncss$�|]
\}}|dvr||fVqdS))�contentNrrrrr�	<genexpr>Fs�"z#dump_event_files.<locals>.<genexpr>�files�pathr&�ascii)�dictr �osr)�basename�base64�	b64decode�decoder�
write_file�append)r"r&r(�saved�f�fname�fn_local�fcontentrrr�dump_event_filesEsr8cC�|r|�d�SdS)Nr��get�r"rrr�
event_nameS�
r=cCr9)Nrr:r<rrrrYr>cCs|rt|��d�dSdS)N�/r)r=�splitr<rrr�event_parent_srAcCst|�d��S�Nr)�floatr;r<rrr�event_timestampesrDcCstj�t|��S�N)�datetime�utcfromtimestamprDr<rrr�event_datetimeisrHcCs||��SrE)�
total_seconds)�t1�t2rrr�
delta_secondsmsrLcCstt|�t|��SrE)rLrH)�start�finishrrr�event_durationqsrOc	CsH|��}|�t||�t|t|��ddt|��d�ddd��|S)N�|rr?�z`->)rrr	)�copy�updaterOrLrHr=�count)�
start_timerMrN�recordrrr�event_recordus��rWcCsd|S)NzTotal Time: %3.5f seconds
r)rrrr�total_time_record�srXc@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)N�	systemctl�showz-p)�epochr�which�argsr2�extendr)�self�property�	parameterrrr�__init__�szSystemctlReader.__init__c
CsTztj|jdd�\}}|r|WS||_WdSty)}z|WYd}~Sd}~ww)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)r`�value�err�systemctl_failrrrr�s��zSystemctlReader.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 ({})�=rQi@B)r�RuntimeErrorrr\r@rC)r`rrrr�parse_epoch_as_float�s	�z$SystemctlReader.parse_epoch_as_floatrE)�__name__�
__module__�__qualname__�__doc__rcrrlrrrrrY�s

rYcCs2t�rt�St��sdt��d��vrt�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_UNKNOWNrrrr�dist_check_timestamp�s

ryc	Cs�zMtjdgdd�\}}|d��}|D]7}|�d��d�dkrJ|�d���}|d�d	�}t|�}tt���tt�	��}||}t
|||fWSqWtStyWYtSw)
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
    �dmesgTrdrzUTF-8�userrrQ�])
r�
splitlinesr0�findr@�striprC�timer�uptime�SUCCESS_CODErfrx)	�data�_�
split_entriesr#�splitup�stripped�user_space_timestamp�kernel_start�
kernel_endrrrrw�s$����rwc

Cs�tt���tt���}zLtd���}tdd���}|}t}t��rOtt���tt���}z
t	�
d�}|j}WntyL}zt
d�|��|�d}~wwt}||}||}Wntyp}	zt|	�tWYd}	~	Sd}	~	ww||||fS)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)rCr�rr�rYrlr��is_container�	monotonicr,�stat�st_atime�OSErrorrkr�CONTAINER_CODErf�printrx)
r��delta_k_end�
delta_ci_s�	base_time�status�	file_statrhr��cloudinit_sysd�errrrs�sJ����

������rsF�(%n) %d seconds in %I%Dc	Cs�t|dd�d�}g}d}d}i}	g}
g}tdt|��D]�}||}
z||d}Wnty4d}Ynwt|
�dkr�|rV|
�d	�d
krV|�t|��|
�|�g}d}d}|durdt|
�}||	t	|
�<t
|
�t
|�krt|�dkr~|�t|t||
|���q|�d|
�d	��|�|
�q|�
�}t
|
�t
|�kr�t|||
�}|�td
|�d�||�d�7}q|�|�q|�t|��|
�|�|
S)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
    cSs|dSrBr)�xrrr�<lambda>3sz"generate_records.<locals>.<lambda>)�keyNgrrQrMrz
init-localrNzStarting stage: %szFinished stage: (%n) %d seconds�
r)�sorted�range�len�
IndexErrorrr;r2rXrHrAr=r%rW�pop)�events�
blame_sort�print_format�
dump_files�
log_datafiles�
sorted_events�recordsrUr�stage_start_time�boot_records�unprocessedr�r"�next_evt�prev_evtrVrrr�generate_recordssb�

���
��
r�cCs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
    )r�)r�)r�r�rrr�show_eventsns
r�cCs4|��}zt�|�|fWStyd|fYSw)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
    N)�read�json�loads�
ValueError)�infiler�rrr�load_events_infile{s�r�)Fr�FF)$r.rFr�r,r��	cloudinitrr�cloudinit.distrosrr�joinr �formatting_helpr��	FAIL_CODEr�rxr%r8r=rrArDrHrLrOrWrXrYryrwrsr�r�r�rrrr�<module>s`��
50
�P