Current File : //lib/python2.7/site-packages/cloudinit/analyze/__main__.pyc
�
oB�]c@s�ddlZddlZddlZddlmZddlmZddlmZddlmZdd�Z
d�Zd	�Zd
�Z
d�Zd�Zd
�Zedkr�e
�Zej�Zej\ZZeee�ndS(i����N(t
json_dumps(tdatetimei(tdump(tshowcCsZ|s!tjdddd�}n|jdddd�}t|_|jd	d
d�}|jdd
ddddddd
d�|jddddddddd
d�|jdd	tf�|jdd
d�}|jddddddddd
d�|jdd
ddddddd
d�|jddddddddd
d �|jddt	f�|jd!d
d"�}|jdd
ddddddd
d#�|jddddddddd
d�|jdd!t
f�|jd$d
d%�}|jdd
ddddddd
d#�|jddddddddd
d �|jdd$tf�|S(&Ntprogscloudinit-analyzetdescriptions,Devel tool: Analyze cloud-init logs and datattitletSubcommandstdestt
subcommandtblamethelps5Print list of executed stages ordered by time to inits-is--infiletactiontstoretinfiletdefaults/var/log/cloud-init.logsspecify where to read input.s-os	--outfiletoutfilet-sspecify where to write output. Rs.Print list of in-order events during executions-fs--formattprint_formats%I%D @%Es +%dssspecify formatting of output.sspecify where to write output.Rs%Dump cloud-init events in JSON formatsspecify where to read input. tboots2Print list of boot times for kernel and cloud-init(targparsetArgumentParsertadd_subparserstTruetrequiredt
add_parsertadd_argumenttset_defaultst
analyze_blametanalyze_showtanalyze_dumptanalyze_boot(tparsert
subparserstparser_blametparser_showtparser_dumptparser_boot((s>/usr/lib/python2.7/site-packages/cloudinit/analyze/__main__.pyt
get_parsers^		cCs�t|�\}}tj�}|\}}}}tj|�}	tj|�}
tj|�}yZgt|�D],}|ddkrmd|dkrm|^qmd}
tj|
d�}Wn tk
r�d}tj}nXd}d	}d
}i|tj6|tj6|tj	6}||}||}i	|	d6|
d6|d
6|d6|d6|d6|d6|d6|d6}|j
||j|��|S(s�Report a list of how long different boot operations took.

    For Example:
    -- Most Recent Boot Record --
        Kernel Started at: <time>
        Kernel ended boot at: <time>
        Kernel time to boot (seconds): <time>
        Cloud-init activated by systemd at: <time>
        Time between Kernel end boot and Cloud-init activation (seconds):<time>
        Cloud-init start: <time>
    tnames
init-localsstarting searchRi����t	timestamps4Could not find init-local log-line in cloud-init.logs�Your Linux distro or container does not support this functionality.
You must be running a Kernel Telemetry supported distro.
Please check https://cloudinit.readthedocs.io/en/latest/topics/analyze.html for more information on supported distros.
s*-- Most Recent Boot Record --
    Kernel Started at: {k_s_t}
    Kernel ended boot at: {k_e_t}
    Kernel time to boot (seconds): {k_r}
    Cloud-init activated by systemd at: {ci_sysd_t}
    Time between Kernel end boot and Cloud-init activation (seconds): {bt_r}
    Cloud-init start: {ci_start}
s�-- Most Recent Container Boot Record --
    Container started at: {k_s_t}
    Cloud-init activated by systemd at: {ci_sysd_t}
    Cloud-init start: {ci_start}
tk_s_ttk_e_ttk_rtbt_rtk_etk_stci_sysdt	ci_sysd_ttci_start(tconfigure_ioRtdist_check_timestampRtutcfromtimestampt_get_eventst
IndexErrort	FAIL_CODEtCONTAINER_CODEtSUCCESS_CODEtwritetformat(R'targstinfhtoutfhtkernel_infotstatus_codetkernel_startt
kernel_endt
ci_sysd_starttkernel_start_timestamptkernel_end_timestamptci_sysd_start_timestamptetlast_init_localR1tFAILURE_MSGtSUCCESS_MSGt
CONTAINER_MSGt
status_maptkernel_runtimetbetween_process_runtimetkwargs((s>/usr/lib/python2.7/site-packages/cloudinit/analyze/__main__.pyRCsD# 

	





c	Cs�t|�\}}d}tjdtj�}x�ttjt|�|��D]f\}}tt	|j
|�dt�}|jd|d�|jdj
|�d�|jd�qLW|jd|d�dS(	szReport a list of records sorted by largest time delta.

    For example:
      30.210s (init-local) searching for datasource
       8.706s (init-network) reading and applying user-data
        166ms (modules-config) ....
        807us (modules-final) ...

    We generate event records parsing cloud-init logs, formatting the output
    and sorting by record data ('delta')
    s
     %ds (%n)s(^\s+\d+\.\d+)treverses-- Boot Record %02d --
is
s%d boot records analyzed
N(R2tretcompilet	MULTILINEt	enumerateRtshow_eventsR5tsortedtfiltertmatchRR:tjoin(	R'R<R=R>tblame_formattrtidxtrecordtsrecs((s>/usr/lib/python2.7/site-packages/cloudinit/analyze/__main__.pyR�scCs�t|�\}}xxttjt|�|j��D]U\}}|jd|d�|jd�|jd�|jdj|�d�q4W|jd|d�dS(sGenerate output records using the 'standard' format to printing events.

    Example output follows:
        Starting stage: (init-local)
          ...
        Finished stage: (init-local) 0.105195 seconds

        Starting stage: (init-network)
          ...
        Finished stage: (init-network) 0.339024 seconds

        Starting stage: (modules-config)
          ...
        Finished stage: (modules-config) 0.NNN seconds

        Starting stage: (modules-final)
          ...
        Finished stage: (modules-final) 0.NNN seconds
    s-- Boot Record %02d --
isUThe total time elapsed since completing an event is printed after the "@" character.
s>The time the event takes is printed after the "+" character.

s
s%d boot records analyzed
N(R2RTRRUR5RR:RY(R'R<R=R>R\R]((s>/usr/lib/python2.7/site-packages/cloudinit/analyze/__main__.pyR�s

cCs3t|�\}}|jtt|��d�dS(s%Dump cloud-init events in json formats
N(R2R:RR5(R'R<R=R>((s>/usr/lib/python2.7/site-packages/cloudinit/analyze/__main__.pyR�scCs@d}tj|�\}}|s<tjd|�\}}n|S(Ntrawdata(tNoneRtload_events_infileRtdump_events(RR_teventst_((s>/usr/lib/python2.7/site-packages/cloudinit/analyze/__main__.pyR5�s
cCs�|jdkrtj}nNyt|jd�}Wn5tk
rhtjjd|j�tjd�nX|jdkr�tj	}nNyt|jd�}Wn5tk
r�tjjd|j�tjd�nX||fS(s.Common parsing and setup of input/output filesRR[sCannot open file %s
itw(
RtsyststdintopentOSErrortstderrR:texitRtstdout(R<R=R>((s>/usr/lib/python2.7/site-packages/cloudinit/analyze/__main__.pyR2�s

t__main__(RRQRftcloudinit.utilRRtRRR`R&RRRRR5R2t__name__R t
parse_argsR<RR'taction_functor(((s>/usr/lib/python2.7/site-packages/cloudinit/analyze/__main__.pyt<module>s$4	K