
    x[hZ%                         S SK r S SKrS SKrS SKJrJr  S SKJr  S SKJrJ	r	  S SK
Jr  SS jrS rS rS	 rS
 rS rS rS\SS4S jr\S:X  a0  \" 5       r\R-                  5       r\R0                  u  rr\" \\5        gg)    N)datetimetimezone)IO)dumpshow)
json_dumpsc           	         U (       d  [         R                  " SSS9n U R                  SSS9nSUl        UR	                  SS	S
9nUR                  SSSSSSS9  UR                  SSSSSSS9  UR                  S[        4S9  UR	                  SSS
9nUR                  SSSSSSS9  UR                  SSSSSSS9  UR                  SSSSSSS9  UR                  S[        4S9  UR	                  S S!S
9nUR                  SSSSSS"S9  UR                  SSSSSSS9  UR                  S [        4S9  UR	                  S#S$S
9nUR                  SSSSSS"S9  UR                  SSSSSSS9  UR                  S#[        4S9  U $ )%Nzcloudinit-analyzez,Devel tool: Analyze cloud-init logs and data)progdescriptionSubcommands
subcommand)titledestTblamez5Print list of executed stages ordered by time to init)helpz-iz--infilestoreinfilez/var/log/cloud-init.logzspecify where to read input.)actionr   defaultr   z-oz	--outfileoutfile-zspecify where to write output. )r   r   z.Print list of in-order events during executionz-fz--formatprint_formatz%I%D @%Es +%dszspecify formatting of output.zspecify where to write output.r   z%Dump cloud-init events in JSON formatzspecify where to read input. bootz2Print list of boot times for kernel and cloud-init)argparseArgumentParseradd_subparsersrequired
add_parseradd_argumentset_defaultsanalyze_blameanalyze_showanalyze_dumpanalyze_boot)parser
subparsersparser_blameparser_showparser_dumpparser_boots         </usr/lib/python3/dist-packages/cloudinit/analyze/__init__.py
get_parserr,      sj   (($F
 &&]&NJJ((M ) L )+   .   g}%=>''E ( K  ,   )+   -   V\$:;''< ( K ),   .   V\$:;''I ( K ),   -   V\$:;M    c           
      2   [        U5      u  p#[        R                  " 5       nUu  pVpx[        R                  " U[
        R                  5      n	[        R                  " U[
        R                  5      n
[        R                  " U[
        R                  5      n [        U5       Vs/ s H  nUS   S:X  d  M  SUS   ;   d  M  UPM     snS   n[        R                  " US   [
        R                  5      nSnS	nS
n[        R                  U[        R                  U[        R                  U0nXv-
  nX-
  nU	U
UUUUUUUS.	nUR                  UU   R                  " S0 UD65        [        X#5        U$ s  snf ! [         a    Sn[        R                  n Nf = f)ag  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>
namez
init-localzstarting searchr   	timestampz4Could not find init-local log-line in cloud-init.logzYour Linux distro or container does not support this functionality.
You must be running a Kernel Telemetry supported distro.
Please check https://docs.cloud-init.io/en/latest/topics/analyze.html for more information on supported distros.
a*  -- 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}
z-- 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}
)	k_s_tk_e_tk_rbt_rk_ek_sci_sysd	ci_sysd_tci_start )configure_ior   dist_check_timestampr   fromtimestampr   utc_get_events
IndexError	FAIL_CODECONTAINER_CODESUCCESS_CODEwriteformatclean_io)r/   argsinfhoutfhkernel_infostatus_codekernel_start
kernel_endci_sysd_startkernel_start_timestampkernel_end_timestampci_sysd_start_timestampelast_init_localr:   FAILURE_MSGSUCCESS_MSGCONTAINER_MSG
status_mapkernel_runtimebetween_process_runtimekwargss                         r+   r$   r$   t   s    t$KD++-K;F8Kz%33L(,,O#11*hllK&44x||% !&
&yL(  "Q}%55 &

  ))K((,,
	. 	- 	-  	];J  .N+8 (%' ,
F 
KK
;'..889T
  %Inn%s0   E7 %E26E2E2.E7 2E7 7FFc                    [        U5      u  p#Sn[        R                  " S[        R                  5      nSn[	        [
        R                  " [        U5      U5      5       Hn  u  pg[        [        UR                  U5      SS9nUR                  SUS-   -  5        UR                  SR                  U5      S-   5        UR                  S5        Mp     UR                  S	US-   -  5        [        X#5        g
)aZ  Report 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')
z     %ds (%n)z(^\s+\d+\.\d+)r   T)reverse-- Boot Record %02d --
   
%d boot records analyzed
N)r<   recompile	MULTILINE	enumerater   show_eventsr@   sortedfiltermatchrE   joinrG   )	r/   rH   rI   rJ   blame_formatridxrecordsrecss	            r+   r!   r!      s     t$KD"L


$bll3A
C T*L9 vaggv.=.#':;DIIe$t+,D 
KK,a89Tr-   c                    [        U5      u  p#[        [        R                  " [	        U5      UR
                  5      5       Ha  u  pEUR                  SUS-   -  5        UR                  S5        UR                  S5        UR                  SR                  U5      S-   5        Mc     UR                  SWS-   -  5        [        X#5        g)a  Generate 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
r^   r_   zUThe total time elapsed since completing an event is printed after the "@" character.
z>The time the event takes is printed after the "+" character.

r`   ra   N)	r<   re   r   rf   r@   r   rE   rj   rG   )r/   rH   rI   rJ   rm   rn   s         r+   r"   r"      s    ( t$KD T*D,=,=> 	.#':;2	
 	N	
 	DIIf%,- 
KK,a89Tr-   c                     [        U5      u  p#UR                  [        [        U5      5      S-   5        [	        X#5        g)z%Dump cloud-init events in json formatr`   N)r<   rE   r   r@   rG   )r/   rH   rI   rJ   s       r+   r#   r#     s1    t$KD	KK
;t,-45Tr-   c                 t    S n[         R                  " U 5      u  p!U(       d  [        R                  " US9u  p#U$ )N)rawdata)r   load_events_infiler   dump_events)r   rs   events_s       r+   r@   r@     s3    G--f5OF$$W5	Mr-   c                 >   U R                   S:X  a  [        R                  nO [        U R                   S5      nU R                  S:X  a  [        R                  nWU4$  [        U R                  S5      nWU4$ ! [         aE    [        R
                  R                  SU R                   -  5        [        R                  " S5         Nf = f! [         aH    [        R
                  R                  SU R                  -  5        [        R                  " S5         WW4$ f = f)z.Common parsing and setup of input/output filesr   rl   zCannot open file %s
r_   w)
r   sysstdinopenOSErrorstderrrE   exitr   stdout)rH   rI   rJ   s      r+   r<   r<     s    {{cyy	S)D
 ||s

 ;	s+E
 ;  	JJ4t{{BCHHQK	  	JJ4t||CDHHQK;		s%   A8 C
 8ACC
ADDfile_handlesreturnc                      U  H9  nU[         R                  [         R                  4;   a  M)  UR                  5         M;     g)zclose filehandlesN)rz   r{   r   close)r   file_handles     r+   rG   rG   1  s0    #399cjj11 $r-   __main__)N)r   rb   rz   r   r   typingr   cloudinit.analyzer   r   cloudinit.atomic_helperr   r,   r$   r!   r"   r#   r@   r<   rG   __name__r%   
parse_argsrH   r   r/   action_functorr;   r-   r+   <module>r      s   
  	 
 '  ( .bJTn6"J.B 4  z\FD![[T>4	 r-   