%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /snap/core20/2599/lib/python3/dist-packages/cloudinit/analyze/__pycache__/
Upload File :
Create Path :
Current File : //snap/core20/2599/lib/python3/dist-packages/cloudinit/analyze/__pycache__/show.cpython-38.pyc

U

Ӈg,+�@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�deltaZdescription�elapsed�
event_type�indent�level�name�origin�result�	timestamp�
total_time)z%dz%Dz%Ez%ez%Iz%lz%nz%oz%rz%tz%TZ
successful�failureZ	container���cCsPt��D]:\}}||kr|dkr2|�|d|�}q|�|d|�}q|jf|�S)N)rrr
z
{%s:08.5f}z{%s})�
format_key�items�replace�format)�msg�event�i�j�r�8/usr/lib/python3/dist-packages/cloudinit/analyze/show.py�
format_record6srcCs|r|�d�SdS)Nr
��get�rrrr�
event_nameAs
rcCs|r|�d�SdS)NrrrrrrrGs
cCs|rt|��d�dSdS)N�/r)r�splitrrrr�event_parentMsr"cCst|�d��S�Nr
)�floatrrrrr�event_timestampSsr%cCstj�t|�tjj�S�N)�datetimeZ
fromtimestampr%�timezoneZutcrrrr�event_datetimeWs�r)cCs||��Sr&)Z
total_seconds)�t1�t2rrr�
delta_seconds]sr,cCstt|�t|��Sr&)r,r))�start�finishrrr�event_durationasr/c	CsH|��}|�t||�t|t|��ddt|��d�ddd��|S)N�|� r �z`->)rrr)�copy�updater/r,r)r�count)�
start_timer-r.�recordrrr�event_recordes��r8cCsd|S)NzTotal Time: %3.5f seconds
r)rrrr�total_time_recordrsr9c@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�args�append�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)rr<r;�	Exception)r?�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 ({})�=r2i@B)r�RuntimeErrorrr;r!r$)r?r
rrr�parse_epoch_as_float�s	��z$SystemctlReader.parse_epoch_as_float)N)�__name__�
__module__�__qualname__�__doc__rArrHrrrrr:vs
r:cCs2t�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

rRc	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
    ZdmesgTrBrzUTF-8�userrr2�])
r�
splitlines�decode�findr!�stripr$�timer�uptime�SUCCESS_CODErCrQ)	�data�_Z
split_entriesrZsplitup�strippedZuser_space_timestamp�kernel_start�
kernel_endrrrrP�srPc
Cs�tt���tt���}zBtd���}tdd���}|}t}t��rHt}||}||}Wn2t	k
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-localN)r$rYrrZr:rHr[Zis_container�CONTAINER_CODErC�printrQ)r_Zdelta_k_endZ
delta_ci_sZ	base_timeZstatusr`Zcloudinit_sysd�errrrN�s&��rN�(%n) %d seconds in %I%Dc	Cs�t|dd�d�}g}d}d}i}g}g}tt|��D�]F}	||	}
z||	d}Wntk
rjd}YnXt|
�dk�r(|r�|
�d�d	kr�|�t|��|�|�g}d}d}|dkr�t|
�}||t	|
�<t
|
�t
|�k�rt|�d
k�r&|�t|t||
|���n |�d|
�d��|�|
�q4q4|�
�}t
|
�t
|�k�rrt|||
�}
|�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>)�keyNgr2r-r
z
init-localr.zStarting stage: %szFinished stage: (%n) %d seconds�
r)�sorted�range�len�
IndexErrorrrr=r9r)r"rrr8�pop)�events�print_formatZ
sorted_eventsZrecordsr6rZstage_start_timeZboot_recordsZunprocessedrcrZnext_evtZprev_evtr7rrr�generate_recordss^


��
��
rqcCs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
    )rp)rq)rorprrr�show_eventsKs
rrcCs^|��}|��s,tj�d|j�t�d�zt�|�|fWSt	k
rXd|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
    zEmpty file %s
r2N)
�readrX�sys�stderr�writer
�exit�json�loads�
ValueError)Zinfiler\rrr�load_events_infileXs
r{)rd)r'rxrtrYZ	cloudinitrrZcloudinit.distrosrrr[Z	FAIL_CODErarQrrrr"r%r)r,r/r8r9r:rRrPrNrqrrr{rrrr�<module>sN�
5#�
J

Zerion Mini Shell 1.0