+
    i+7                        ^ RI t ^ RIt^ RIt^ RIt^ RIHtHt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RR	R
RRRRRRRRRRRRRRRR/tRtRtRt]R@R@R@3t]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, R- ltR. R/ lt R0 R1 lt! ! R2 R34      t"R4 R5 lt#R6 R7 lt$R8 R9 lt%RAR: R; llt&R< R= lt'R> R? lt(R# )B    N)IOAnyDictListOptionalTupleUnioncast)subputil)uses_systemdz%ddeltaz%Ddescriptionz%Eelapsedz%e
event_typez%Iindentz%llevelz%nnamez%ooriginz%rresultz%t	timestampz%T
total_time
successfulfailure	containerc                <    V ^8  d   QhR\         R\        R\         /# )   msgeventreturn)strEvent)formats   "8/usr/lib/python3/dist-packages/cloudinit/analyze/show.py__annotate__r%   9   s!      s 5 S     c                     \         P                  4        FH  w  r#W 9   g   K  VR9   d   V P                  VRV,          4      p K/  V P                  VRV,          4      p KJ  	  V P                  ! R/ VB # )r   z
{%s:08.5f}z{%s})r   r   r    )
format_keyitemsreplacer#   )r   r   ijs   &&  r$   format_recordr.   9   sb      "855kk!\A%56kk!VaZ0 # ::r&   c                \    V ^8  d   QhR\         \        ,          R\         \        ,          /# r   r   r    r   r"   r!   )r#   s   "r$   r%   r%   D   "      huo (3- r&   c                 8    V '       d   V P                  R 4      # R# )r   Ngetr   s   &r$   
event_namer7   D   s    yy  r&   c                \    V ^8  d   QhR\         \        ,          R\         \        ,          /# r0   r1   )r#   s   "r$   r%   r%   J   r2   r&   c                 8    V '       d   V P                  R 4      # R# )r   Nr4   r6   s   &r$   r   r   J   s    yy&&r&   c                \    V ^8  d   QhR\         \        ,          R\         \        ,          /# r0   r1   )r#   s   "r$   r%   r%   P   s"       HSM r&   c                 \    \        V 4      pV'       d   VP                  R 4      ^ ,          # R# )/N)r7   split)r   r   s   & r$   event_parentr>   P   s%    eDzz#q!!r&   c                0    V ^8  d   QhR\         R\        /# r0   r"   float)r#   s   "r$   r%   r%   W   s      5 U r&   c                 X    V P                  R 4      pVf   \        R4      h\        V4      # )r   zEvent is missing a 'timestamp')r5   
ValueErrorrA   )r   tss   & r$   event_timestamprE   W   s+    	;	B	z9::9r&   c                D    V ^8  d   QhR\         R\        P                  /# r0   )r"   datetime)r#   s   "r$   r%   r%   ^   s       % H$5$5 r&   c                     \         P                   P                  \        V 4      \         P                  P                  4      # N)rG   fromtimestamprE   timezoneutcr6   s   &r$   event_datetimerM   ^   s1    ** 1 1 5 5 r&   c                d    V ^8  d   QhR\         P                   R\         P                   R\        /# )r   t1t2r    )rG   rA   )r#   s   "r$   r%   r%   d   s-     % %h'' %X->-> %5 %r&   c                 .    W,
          P                  4       # rI   )total_seconds)rO   rP   s   &&r$   delta_secondsrS   d   s    G""$$r&   c                <    V ^8  d   QhR\         R\         R\        /# )r   startfinishr    r@   )r#   s   "r$   r%   r%   h   s&     H H% H H5 Hr&   c                 >    \        \        V 4      \        V4      4      # rI   )rS   rM   )rU   rV   s   &&r$   event_durationrX   h   s    .v0FGGr&   c                \    V ^8  d   QhR\         P                   R\        R\        R\        /# )r   
start_timerU   rV   r    )rG   r"   )r#   s   "r$   r%   r%   l   s6      !!  	r&   c                    VP                  4       p\        V4      pR pV'       d.   VRVP                  R4      ^,
          ,          R,           ,          pVP                  R\	        W4      R\        V \        V4      4      RV/4       V# )| r<   z`->r   r   r   )copyr7   countupdaterX   rS   rM   )rZ   rU   rV   recordr   r   s   &&&   r$   event_recordrb   l   sz    
 [[]FeDF#C1,-55
MM^E2}Z1FGf	
 Mr&   c                0    V ^8  d   QhR\         R\        /# )r   r   r    )rA   r!   )r#   s   "r$   r%   r%      s     6 6% 6C 6r&   c                     R V ,          # )zTotal Time: %3.5f seconds
r(   )r   s   &r$   total_time_recordre      s    (:55r&   c                   ^   a  ] tR t^t o RtR
V 3R lR lltV 3R lR ltV 3R lR ltR	tV t	R# )SystemctlReaderzI
Class for dealing with all systemctl subp calls in a consistent manner.
Nc                6   < V ^8  d   QhRS[ RS[S[ ,          /# )r   property	parameter)r!   r   )r#   __classdict__s   "r$   r%   SystemctlReader.__annotate__   s     $ $ $# $r&   c                    R V n         \        P                  ! R4      R.V n        V'       d   V P                  P	                  V4       V P                  P                  RVR.4       V P                  4       V n        R # )N	systemctlshowz-pz--timestamp=us+utc)stdoutr   whichargsappendextend_subpr   )selfri   rj   s   &&&r$   __init__SystemctlReader.__init__   s^    %)**[16:	IIY' 			$*>?@
 zz|r&   c                F   < V ^8  d   QhRS[ S[S[S[3,          ,          /# r   r    )r   r	   r!   	Exception)r#   rk   s   "r$   r%   rl      s"     " "xc9n 56 "r&   c                     \         P                   ! V P                  RR7      w  rV'       d   V# Wn        R#   \         d   pTu Rp?# Rp?ii ; i)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captureN)r   rr   rp   r{   )rv   valueerrsystemctl_fails   &   r$   ru   SystemctlReader._subp   sC    	"499d;JE
K 	"!!	"s   -8 8 AA
A
Ac                    < V ^8  d   QhRS[ /# rz   )rA   )r#   rk   s   "r$   r%   rl      s     + +e +r&   c                   V P                   '       d%   \        RP                  V P                   4      4      hV P                  f   \        R4      hV P                  P	                  R4      ^,          P                  4       pVP                  4       '       d   \        V4      R,          pV# \        P                  P                  VR4      P                  \        P                  P                  R7      P                  4       pV# )zc
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 ({})z.stdout of subprocess call to systemctl is None=i@B z%a %Y-%m-%d %H:%M:%S.%f %Z)tzinfo)r   RuntimeErrorr#   rp   r=   strip	isnumericrA   rG   strptimer+   rK   rL   r   )rv   valr   s   &  r$   convert_val_to_float$SystemctlReader.convert_val_to_float   s     <<<,,2F4<<,@  ;;@  kk$Q'--/==?? c
W,I  !!**30LM 1 1 5 56  r&   )rr   r   rp   rI   )
__name__
__module____qualname____firstlineno____doc__rw   ru   r   __static_attributes____classdictcell__)rk   s   @r$   rg   rg      s(     $ $$" " + +r&   rg   c                Z    V ^8  d   QhR\         \        \        \        \        3,          /# rz   r   r!   rA   )r#   s   "r$   r%   r%      s!      eCu$<= r&   c                     \        4       '       d   \        4       # \        P                  ! 4       '       g0   R\        P                  ! 4       R,          P                  4       9   d   \        4       # \        # )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.
gentoosystem)r   gather_timestamps_using_systemdr   
is_FreeBSDsystem_infolowergather_timestamps_using_dmesgTIMESTAMP_UNKNOWNr(   r&   r$   dist_check_timestampr      sR     ~~.00 H(8(8(:8(D(J(J(LL,.. r&   c                Z    V ^8  d   QhR\         \        \        \        \        3,          /# rz   r   )r#   s   "r$   r%   r%      s!      uS%-E'F r&   c                 (    \         P                   ! R.RR7      w  rV ^ ,          P                  4       pV F  pVP                  R4      P                  R4      R8w  g   K*  VP                  R4      P	                  4       pV^,          P                  R4      p\        V4      p\        \        P                  ! 4       4      \        \        P                  ! 4       4      ,
          pWv,           p\        WxV3u # 	  \        #   \         d	     \        # i ; i)z
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
dmesgTr}   zUTF-8user])r   
splitlinesdecodefindr=   r   rA   timer   uptimeSUCCESS_CODEr{   r   )	data_split_entriesr,   splitupstrippeduser_space_timestampkernel_start
kernel_ends	            r$   r   r      s    ))WIt4Q**,Axx %%f-3((7+113"1:++C0 (-X$$TYY[1E$++-4HH)@
 $\zII "   s   AC>  BC> 6C> >DDc                Z    V ^8  d   QhR\         \        \        \        \        3,          /# rz   r   )r#   s   "r$   r%   r%     s!     6 6sE5%/G)H 6r&   c                 J    \         P                  ! 4       '       d4   \        R4      P                  4       p \        R4      P                  4       pM2\        R4      P                  4       p \        R4      P                  4       p\        R4      P                  4       V,
          p\        RR4      P                  4       V,
          p\         P                  ! 4       '       d   \        M\        pTT Y,           Y,           3#   \         d   p\        T4       \        u Rp?# Rp?ii ; i)z
Gather timestamps that corresponds to kernel begin initialization,
kernel finish initialization. and cloud-init systemd unit activation

:return: the three timesread_propertystamps
UserspaceTimestampUserspaceTimestampMonotonicKernelTimestampKernelTimestampMonotonicInactiveExitTimestampMonotoniczcloud-init-localN)	r   is_containerrg   r   r{   printr   CONTAINER_CODEr   )r   monotonic_offsetr   cloudinit_sysdestatuss         r$   r   r     s#   &!  +$""$   /- ""$  +!""$   /* ""$  -""$ 	 02D""$ 	  $0022^F 	!%	   ! 	a  !s#   C< B&C< <D"DD"D"c                ~    V ^8  d   QhR\         \        ,          R\        R\         \         \        ,          ,          /# r   eventsprint_formatr    r   r"   r!   )r#   s   "r$   r%   r%   H  s7     M MKMM 
$s)_Mr&   c                   \        V R R7      p. pRpRp/ p. p. p\        \        V4      4       EF  p	W	,          p
 W	^,           ,          p\	        V
4      R8X  Ed	   V'       dH   V
P                  R4      R8X  d2   VP                  \        V4      4       VP                  V4       . pRpRpVf   \        V
4      pWF\        V
4      &   \        V
4      \        V4      8X  dJ   \	        V4      R8X  d8   \        \        V4      pVP                  \        V\        WJV4      4      4       K  K  VP                  R	V
P                  R4      ,          4       VP                  V
4       EK5  VP                  4       p\        V
4      \        V4      8X  d^   V'       dS   \        WLV
4      pVP                  \        R
V4      R,           4       Y]P                  R4      ;'       g    R,          pEK  EK  VP                  V4       EK  	  VP                  \        V4      4       VP                  V4       V#   \         d    Rp ELi ; i)aW  
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
c                     V R ,          # )r   r(   )xs   &r$   <lambda>"generate_records.<locals>.<lambda>W  s    ;r&   )keyNg        rU   r   z
init-localrV   zStarting stage: %szFinished stage: (%n) %d seconds
r   )sortedrangelen
IndexErrorr   r5   rs   re   rM   r>   r7   r
   r   r.   rb   pop)r   r   sorted_eventsrecordsrZ   r   stage_start_timeboot_recordsunprocessedr   r   next_evtprev_evtra   s   &&            r$   generate_recordsr   H  s    6'?@MGJJLK3}%&		!e}H e'599V,<0<=##G,!
 
!+E2
8Be!45 % Jx$88h'83  $D(3HNN%((HE	 4 3eii6GGH""5)"(H% Jx$88)*FFNN%=v  **W"5"<"<<J  ""8,e 'h NN$Z01 e  	H	s   H--H>=H>c                ~    V ^8  d   QhR\         \        ,          R\        R\         \         \        ,          ,          /# r   r   )r#   s   "r$   r%   r%     s-     
? 
?U 
?3 
?4S	? 
?r&   c                    \        WR7      # )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   s   &&r$   show_eventsr     s     F>>r&   c                h    V ^8  d   QhR\         R\        \        \        ,          \        3,          /# )r   infiler    )r   r   r   r   r!   )r#   s   "r$   r%   r%     s(      r eHSM3,>&? r&   c                6   V P                  4       pVP                  4       '       gG   \        P                  P	                  RV P
                  ,          4       \        P                  ! ^4        \        P                  ! V4      V3#   \         d    RT3u # i ; i)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
zEmpty file %s
N)
readr   sysstderrwriter   exitjsonloadsrC   )r   r   s   & r$   load_events_infiler     ss     ;;=D::<<

*V[[89zz$%% Tzs   .B BBr   )z(%n) %d seconds in %I%D))rG   r   r   r   typingr   r   r   r   r   r   r	   r
   	cloudinitr   r   cloudinit.distrosr   r)   r   	FAIL_CODEr   r   r"   r.   r7   r   r>   rE   rM   rS   rX   rb   re   rg   r   r   r   r   r   r   r(   r&   r$   <module>r      s      
  D D D   *, 	'-),('&((+,
 	B+ %H*6R Rj,>6rM`
?r&   