%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /snap/core/17212/usr/lib/python3/dist-packages/cloudinit/analyze/__pycache__/
Upload File :
Create Path :
Current File : //snap/core/17212/usr/lib/python3/dist-packages/cloudinit/analyze/__pycache__/show.cpython-35.pyc



"�T`j2�@s�ddlZddlZddlZddlZddlZddlZddlmZddlmZddl	m
Z
ddddd	d
ddd
dddddddddddddiZdjdd�ej
�D��ZdZdZd ZedGdHdIfZd"d#�Zd$d%�Zd&d'�Zd(d�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�ZGd7d8�d8e�Zd9d:�Z d;d<�Z!d=d>�Z"d?d@d?d?dAdB�Z#dCdD�Z$dEdF�Z%dS)J�N)�subp)�util)�uses_systemdz%d�deltaz%DZdescriptionz%E�elapsedz%e�
event_typez%I�indentz%l�levelz%n�namez%o�originz%r�resultz%t�	timestampz%T�
total_time� cCs4g|]*\}}dj|jdd�|��qS)z{0}: {1}�%z%%)�format�replace)�.0�k�v�r�8/usr/lib/python3/dist-packages/cloudinit/analyze/show.py�
<listcomp>3s	rZ
successful�failureZ	container�cCsqxatj�D]S\}}||kr
|dkrJ|j|d|�}q
|j|d|�}q
W|j|�S)Nrrr
z
{%s:08.5f}z{%s})rzelapsedz	timestamp)�
format_key�itemsrr)�msg�event�i�jrrr�
format_record;sr!cCs�tdd�|j�D��}|d}g}xc|D][}|d}tjj|�}tj|d�jd�}tj	||�|j
|�q6W|S)Ncss-|]#\}}|dkr||fVqdS)�contentN)zcontentr)rrrrrr�	<genexpr>Gsz#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_filesFs


r/cCs|r|jd�SdS)Nr
)�get)rrrr�
event_nameTs
r1cCs|r|jd�SdS)Nr)r0)rrrrrZs
cCs!|rt|�jd�dSdS)N�/r)r1�split)rrrr�event_parent`sr4cCst|jd��S)Nr
)�floatr0)rrrr�event_timestampfsr6cCstjjt|��S)N)�datetimeZutcfromtimestampr6)rrrr�event_datetimejsr8cCs||j�S)N)Z
total_seconds)Zt1Zt2rrr�
delta_secondsnsr9cCstt|�t|��S)N)r9r8)�start�finishrrr�event_durationrsr<c
Csf|j�}|jdt||�dt|t|��dddt|�jd�ddi�|S)	Nrrr�|rr2rz`->)�copy�updater<r9r8r1�count)�
start_timer:r;�recordrrr�event_recordvs,rCcCsd|S)NzTotal Time: %3.5f seconds
r)rrrr�total_time_record�srDc@s=eZdZdZddd�Zdd�Zdd�ZdS)	�SystemctlReaderzQ
    Class for dealing with all systemctl subp calls in a consistent manner.
    NcCsWd|_ddg|_|r.|jj|�|jjd|g�|j�|_dS)Nz/bin/systemctlZshowz-p)�epoch�argsr,�extendrr)�self�propertyZ	parameterrrr�__init__�s	zSystemctlReader.__init__cCsiy9tj|jdd�\}}|r+|S||_dSWn)tk
rd}z	|SWYdd}~XnXdS)z�
        Make a subp call based on set args and handle errors by setting
        failure code

        :return: whether the subp call failed or not
        �captureTN)rrGrF�	Exception)rI�value�errZsystemctl_failrrrr�s	zSystemctlReader.subpcCsE|jr!tdj|j���|jjd�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 ({})�=ri@B)r�RuntimeErrorrrFr3r5)rIr
rrr�parse_epoch_as_float�s
			z$SystemctlReader.parse_epoch_as_float)�__name__�
__module__�__qualname__�__doc__rKrrRrrrrrE�srEcCsCt�rt�Stj�s8dtj�dj�kr?t�StS)a2
    Determine which init system a particular linux distro is using.
    Each init system (systemd, upstart, 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
	r\c	Cs�y�tjdgdd�\}}|dj�}x�|D]�}|jd�jd�d	kr8|jd�j�}|djd�}t|�}ttj��ttj	��}||}t
|||fSq8WWntk
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
    ZdmesgrLTrzUTF-8�userr�]���)
r�
splitlinesr+�findr3�stripr5�timer�uptime�SUCCESS_CODErMr[)	�data�_Z
split_entriesrZsplitupZstrippedZuser_space_timestamp�kernel_start�
kernel_endrrrrZ�s
"
	
rZc
Cs[ttj��ttj��}y�td�j�}tdd�j�}|}t}tj�rtj	dkr�ttj��ttj
��}ytjd�}|j
}Wn=tk
r�}ztdj|��|�WYdd}~XnXt}nt}||}||}Wn3tk
rJ}	zt|	�tSWYdd}	~	XnX||||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-local�z/proc/1/cmdlinezBCould not determine container boot time from /proc/1/cmdline. ({})N)rjrj)r5rcrrdrErRreZis_container�sys�version_infoZ	monotonicr(�stat�st_atime�OSErrorrQr�CONTAINER_CODE�	FAIL_CODErM�printr[)
rhZdelta_k_endZ
delta_ci_sZ	base_timeZstatusZ	file_statrOriZcloudinit_sysd�errrrX�s0""
	"	

rXFz(%n) %d seconds in %I%DcCsIt|ddd��}g}d}d}i}	g}
g}g}x�tdt|��D]�}
||
}y||
d}Wntk
r�d}YnXt|�dkr�|jd	�|
kr�|jt|��|j|�g}d}d}|dkrg}
t|�}||	t	|�<t
|�t
|�krkt|�d
kr�|jt|t|||���q!|jd|jd	��|j|�|
j|jd	��qXqX|j
�}t
|�t
|�krt|||�}|jtd|�d
�||jd�7}qX|j|�qXW|jt|��|j|�|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
    �keycSs|dS)Nr
r)�xrrr�<lambda>/sz"generate_records.<locals>.<lambda>Ngrrr:r
r;zStarting stage: %szFinished stage: (%n) %d seconds�
r)�sorted�range�len�
IndexErrorrr0r,rDr8r4r1r!rC�pop)�eventsZ
blame_sort�print_formatZ
dump_filesZ
log_datafilesZ
sorted_eventsZrecordsrArZstage_start_timeZstages_seenZboot_recordsZunprocessedrsrZnext_evtZprev_evtrBrrr�generate_recordssZ




rcCst|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_eventsjs
r�cCsF|j�}ytj|�|fSWntk
rAd|fSYnXdS)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)Zinfilerfrrr�load_events_infilews

r�r_r_r_)&r*r7r�r(rcrkZ	cloudinitrrZcloudinit.distrosrr�joinrZformatting_helprerqrpr[r!r/r1rr4r6r8r9r<rCrD�objectrEr\rZrXrr�r�rrrr�<module>sZ3 /J

Zerion Mini Shell 1.0