+
    i&                     >   ^ RI t ^ RIt^ RIt^ RIHtHt ^ RIHtHtHtH	t	H
t
Ht ^ RIHtHt ^ RIHt RR R lltR R	 ltR
 R ltR R ltR R ltR R ltR R ltR R lt]R8X  d2   ]! 4       t]P7                  4       t]P:                  w  tt]! ]]4       R# R# )    N)datetimetimezone)IODictListOptionalTupleUnion)dumpshow)
json_dumpsc                n    V ^8  d   QhR\         \        P                  ,          R\        P                  /# )   parserreturn)r   argparseArgumentParser)formats   "</usr/lib/python3/dist-packages/cloudinit/analyze/__init__.py__annotate__r      s1     d dX,,-dd    c           	      p   V '       g   \         P                  ! R RR7      p V P                  RRR7      pRVn        VP	                  RRR	7      pVP                  R
RRRRRR7       VP                  RRRRRRR7       VP                  R\        3R7       VP	                  RRR	7      pVP                  RRRRRRR7       VP                  R
RRRRRR7       VP                  RRRRRRR7       VP                  R\        3R7       VP	                  RR R	7      pVP                  R
RRRRR!R7       VP                  RRRRRRR7       VP                  R\        3R7       VP	                  R"R#R	7      pVP                  R
RRRRR!R7       VP                  RRRRRRR7       VP                  R"\        3R7       V # )$z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)r   r   add_subparsersrequired
add_parseradd_argumentset_defaultsanalyze_blameanalyze_showanalyze_dumpanalyze_boot)r   
subparsersparser_blameparser_showparser_dumpparser_boots   &     r   
get_parserr7      sl    (($F
 &&]&NJJ((M ) L )+   .   g}%=>''E ( K  ,   )+   -   V\$:;''< ( K ),   .   V\$:;''I ( K ),   -   V\$:;Mr   c                P    V ^8  d   QhR\         R\        P                  R\         /# )r   nameargsr   )strr   	Namespace)r   s   "r   r   r   v   s,     T Ts T("4"4 T Tr   c                   \        V4      w  r#\        P                  ! 4       pVw  rVrx\        P                  ! V\
        P                  4      p	\        P                  ! V\
        P                  4      p
\        P                  ! V\
        P                  4      p \        V4       Uu. uF.  pVR,          R8X  g   K  R\        VR,          4      9   g   K,  VNK0  	  upR,          p\        P                  ! \        VR,          4      \
        P                  4      pRpRpR	p\        P                  V\        P                  V\        P                  V/pWv,
          pW,
          pR
V	RV
RVRVRVRVRVRVRV/	pVP                  VV,          P                  ! R/ VB 4       \!        W#4       V# u upi   \         d    Rp\        P                  p Li ; i)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>
r9   z
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_eventsr;   float
IndexError	FAIL_CODECONTAINER_CODESUCCESS_CODEwriter   clean_io)r9   r:   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_localrG   FAILURE_MSGSUCCESS_MSGCONTAINER_MSG
status_mapkernel_runtimebetween_process_runtimekwargss   &&                    r   r1   r1   v   s    t$KD++-K;F8Kz%33L(,,O#11*hllK&44x||% !&
&yL(  "S=)9%:: A&

  *2)?)?/+./*
	. 	- 	-  	];J  .N+8 	'%~'z|=,H
F 
KK
;'..889T
  %Inn%s0   F. %F):F)F)?F. )F. .GGc                <    V ^8  d   QhR\         P                  RR/# r   r:   r   Nr   r<   )r   s   "r   r   r      s       h00 T r   c                   \        V4      w  r#Rp\        P                  ! R\        P                  4      p^ p\	        \
        P                  ! \        V4      V4      4       F}  w  rg\        \        VP                  V4      RR7      pVP                  RV^,           ,          4       VP                  RP                  V4      R,           4       VP                  R4       K  	  VP                  RV^,           ,          4       \        W#4       R# )	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+)T)reverse-- Boot Record %02d --

%d boot records analyzed
N)rJ   recompile	MULTILINE	enumerater   show_eventsrN   sortedfiltermatchrT   joinrU   )	r9   r:   rV   rW   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                <    V ^8  d   QhR\         P                  RR/# rj   rk   )r   s   "r   r   r      s      " "X// "D "r   c                   \        V4      w  r#\        \        P                  ! \	        V4      VP
                  4      4       Fm  w  rEVP                  RV^,           ,          4       VP                  R4       VP                  R4       VP                  RP                  V4      R,           4       Ko  	  VP                  RX^,           ,          4       \        W#4       R# )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
rn   zUThe total time elapsed since completing an event is printed after the "@" character.
z>The time the event takes is printed after the "+" character.

ro   rp   N)	rJ   rt   r   ru   rN   r'   rT   ry   rU   )r9   r:   rV   rW   r|   r}   s   &&    r   r/   r/      s    ( t$KD T*D,=,=> 	.#':;2	
 	N	
 	DIIf%,- 
KK,a89Tr   c                <    V ^8  d   QhR\         P                  RR/# rj   rk   )r   s   "r   r   r     s       X// D r   c                    \        V4      w  r#VP                  \        \        V4      4      R,           4       \	        W#4       R# )z%Dump cloud-init events in json formatro   N)rJ   rT   r   rN   rU   )r9   r:   rV   rW   s   &&  r   r0   r0     s1    t$KD	KK
;t,-45Tr   c          	          V ^8  d   QhR\         R\        \        \        \        \        \
        3,          3,          ,          /# )r   r"   r   )r   r   r   r;   r
   rO   )r   s   "r   r   r     s2       tDeCJ.?)?$@A r   c                 |    R p\         P                  ! V 4      w  r!V'       g   \        P                  ! VR7      w  r#V# )N)rawdata)r   load_events_infiler   dump_events)r"   r   events_s   &   r   rN   rN     s3    G--f5OF$$W5	Mr   c                f    V ^8  d   QhR\         P                  R\        \        \        3,          /# )r   r:   r   )r   r<   r	   r   )r   s   "r   r   r     s(      x)) eBFm r   c                V   V P                   R8X  d   \        P                  pM \        V P                   R4      pV P                  R8X  d   \        P                  pXV3#  \        V P                  R4      pXV3#   \         dJ    \        P
                  P                  RT P                   ,          4       \        P                  ! ^4        Li ; i  \         dM    \        P
                  P                  RT P                  ,          4       \        P                  ! ^4        XX3# i ; i)z.Common parsing and setup of input/output filesr&   r{   zCannot open file %s
w)
r"   sysstdinopenOSErrorstderrrT   exitr%   stdout)r:   rV   rW   s   &  r   rJ   rJ     s    {{cyy	S)D
 ||s

 ;	s+E
 ;  	JJ4t{{BCHHQK	  	JJ4t||CDHHQK;		s%   A:  C :ACCAD('D(c                (    V ^8  d   QhR\         RR/# )r   file_handlesr   N)r   )r   s   "r   r   r   3  s      B 4 r   c                     V  F:  pV\         P                  \         P                  39   d   K*  VP                  4        K<  	  R# )zclose filehandlesN)r   r   r   close)r   file_handles   * r   rU   rU   3  s0    #399cjj11 $r   __main__)N) r   rq   r   r   r   typingr   r   r   r   r	   r
   cloudinit.analyzer   r   cloudinit.atomic_helperr   r7   r1   r.   r/   r0   rN   rJ   rU   __name__r   
parse_argsr:   r#   r9   action_functorrI   r   r   <module>r      s   
  	 
 ' 9 9 ( .dNTn6"J. z\FD![[T>4	 r   