Your IP : 216.73.217.13


Current Path : /usr/lib/python3/dist-packages/cloudinit/analyze/__pycache__/
Upload File :
Current File : //usr/lib/python3/dist-packages/cloudinit/analyze/__pycache__/show.cpython-38.pyc

U

�Adm0�@s,ddlZddlZddlZddlZddlZddlmZmZddlm	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 d<d6d7�Z!d8d9�Z"d:d;�Z#dS)=�N)�subp�util)�uses_systemd�deltaZdescription�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>2srZ
successful�failureZ	container���cCsPt��D]:\}}||kr|dkr2|�|d|�}q|�|d|�}q|jf|�S)N)rrr
z
{%s:08.5f}z{%s})�
format_key�itemsrr)�msg�event�i�jrrr�
format_record:sr"cCsntdd�|��D��}|d}g}|D]B}|d}tj�|�}t�|d��d�}t�	||�|�
|�q&|S)Ncss"|]\}}|dkr||fVqdS))�contentNrrrrr�	<genexpr>Fsz#dump_event_files.<locals>.<genexpr>�files�pathr#�ascii)�dictr�osr&�basename�base64Z	b64decode�decoderZ
write_file�append)rr#r%Zsaved�f�fnameZfn_localZfcontentrrr�dump_event_filesEsr0cCs|r|�d�SdS)Nr
��get�rrrr�
event_nameSs
r4cCs|r|�d�SdS)Nrr1r3rrrrYs
cCs|rt|��d�dSdS)N�/r)r4�splitr3rrr�event_parent_sr7cCst|�d��S�Nr
)�floatr2r3rrr�event_timestampesr:cCstj�t|��S�N)�datetimeZutcfromtimestampr:r3rrr�event_datetimeisr=cCs||��Sr;)Z
total_seconds)�t1�t2rrr�
delta_secondsmsr@cCstt|�t|��Sr;)r@r=)�start�finishrrr�event_durationqsrCc	CsH|��}|�t||�t|t|��ddt|��d�ddd��|S)N�|rr5�z`->)rrr)�copy�updaterCr@r=r4�count)�
start_timerArB�recordrrr�event_recordus��rKcCsd|S)NzTotal Time: %3.5f seconds
r)rrrr�total_time_record�srLc@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)�epochrZwhich�argsr-�extendr)�self�propertyZ	parameterrrr�__init__�szSystemctlReader.__init__c
CsZz*tj|jdd�\}}|r |WS||_WdStk
rT}z|WY�Sd}~XYnXdS)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)rrOrN�	Exception)rQ�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 ({})�=rEi@B)r�RuntimeErrorrrNr6r9)rQr
rrr�parse_epoch_as_float�s	��z$SystemctlReader.parse_epoch_as_float)N)�__name__�
__module__�__qualname__�__doc__rSrrZrrrrrM�s
rMcCs2t�rt�St��s(dt��d��kr.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

rdc	Cs�z�tjdgdd�\}}|d��}|D]n}|�d��d�dkr&|�d���}|d�d	�}t|�}tt���tt�	��}||}t
|||fWSq&Wntk
r�YnXt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
    ZdmesgTrTrzUTF-8�userrrE�])
r�
splitlinesr,�findr6�stripr9�timer�uptime�SUCCESS_CODErUrc)	�data�_Z
split_entriesr Zsplitup�strippedZuser_space_timestamp�kernel_start�
kernel_endrrrrb�srbc

Cs�tt���tt���}z�td���}tdd���}|}t}t��r�tt���tt���}zt	�
d�}|j}Wn2tk
r�}zt
d�|��|�W5d}~XYnXt}||}||}Wn2tk
r�}	zt|	�tWY�Sd}	~	XYnX||||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-localz/proc/1/cmdlinezBCould not determine container boot time from /proc/1/cmdline. ({})N)r9rjrrkrMrZrlZis_container�	monotonicr)�stat�st_atime�OSErrorrYr�CONTAINER_CODErU�printrc)
rpZdelta_k_endZ
delta_ci_sZ	base_timeZstatusZ	file_statrWrqZcloudinit_sysd�errrr`�s>��

���r`F�(%n) %d seconds in %I%Dc	Cs�t|dd�d�}g}d}d}i}	g}
g}tdt|��D�]F}||}
z||d}Wntk
rld}YnXt|
�dk�r*|r�|
�d	�d
kr�|�t|��|
�|�g}d}d}|dkr�t|
�}||	t	|
�<t
|
�t
|�k�rt|�dk�r(|�t|t||
|���n |�d|
�d	��|�|
�q6q6|�
�}t
|
�t
|�k�rtt|||
�}|�td
|�d�||�d�7}q6|�|�q6|�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|dSr8r)�xrrr�<lambda>3�z"generate_records.<locals>.<lambda>)�keyNgrrErAr
z
init-localrBzStarting stage: %szFinished stage: (%n) %d seconds�
r)�sorted�range�len�
IndexErrorrr2r-rLr=r7r4r"rK�pop)�eventsZ
blame_sort�print_formatZ
dump_filesZ
log_datafilesZ
sorted_eventsZrecordsrIrZstage_start_timeZboot_recordsZunprocessedrxrZnext_evtZprev_evtrJrrr�generate_recordss^


��
��
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�cCs:|��}zt�|�|fWStk
r4d|fYSXdS)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)Zinfilermrrr�load_events_infile{s
r�)FryFF)$r+r<r�r)rjZ	cloudinitrrZcloudinit.distrosrr�joinrZformatting_helprlZ	FAIL_CODErvrcr"r0r4rr7r:r=r@rCrKrLrMrdrbr`r�r�r�rrrr�<module>s^��
50�
P