
    x[h,+                         S SK r 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SSSS	S
SSSSS.r	Sr
SrSr\SSS4rS rS rS rS rS rS rS rS rS rS r " S S5      rS  rS! rS" r S&S# jrS$ rS% rg)'    N)subputil)uses_systemddeltadescriptionelapsed
event_typeindentlevelnameoriginresult	timestamp
total_time)z%dz%Dz%Ez%ez%Iz%lz%nz%oz%rz%tz%T
successfulfailure	containerc                     [         R                  5        H>  u  p#X ;   d  M  US;   a  U R                  USU-  5      n M)  U R                  USU-  5      n M@     U R                  " S0 UD6$ )N)r   r   r   z
{%s:08.5f}z{%s} )
format_keyitemsreplaceformat)msgeventijs       8/usr/lib/python3/dist-packages/cloudinit/analyze/show.pyformat_recordr    6   sb      "855kk!\A%56kk!VaZ0 # ::    c                 4    U (       a  U R                  S5      $ g )Nr   getr   s    r   
event_namer&   A   s    yy  r!   c                 4    U (       a  U R                  S5      $ g )Nr	   r#   r%   s    r   r	   r	   G   s    yy&&r!   c                 L    U (       a  [        U 5      R                  S5      S   $ g )N/r   )r&   splitr%   s    r   event_parentr+   M   s#    % &&s+A..r!   c                 6    [        U R                  S5      5      $ Nr   )floatr$   r%   s    r   event_timestampr/   S   s    ;'((r!   c                     [         R                   R                  [        U 5      [         R                  R                  5      $ N)datetimefromtimestampr/   timezoneutcr%   s    r   event_datetimer6   W   s1    ** 1 1 5 5 r!   c                 &    X-
  R                  5       $ r1   )total_seconds)t1t2s     r   delta_secondsr;   ]   s    G""$$r!   c                 >    [        [        U 5      [        U5      5      $ r1   )r;   r6   )startfinishs     r   event_durationr?   a   s    .v0FGGr!   c           	          UR                  5       nUR                  [        X5      [        U [	        U5      5      SS[        U5      R                  S5      S-
  -  -   S-   S.5        U$ )N| r)      z`->)r   r   r
   )copyupdater?   r;   r6   r&   count)
start_timer=   r>   records       r   event_recordrI   e   sc    [[]F
MM#E2$Z1FGC:e#4#:#:3#?!#CDDuL	
 Mr!   c                     SU -  $ )NzTotal Time: %3.5f seconds
r   )r   s    r   total_time_recordrK   r   s    (:55r!   c                   .    \ rS rSrSrSS jrS rS rSrg)	SystemctlReaderv   zI
Class for dealing with all systemctl subp calls in a consistent manner.
Nc                     S U l         [        R                  " S5      S/U l        U(       a  U R                  R	                  U5        U R                  R                  SU/5        U R                  5       U l        g )N	systemctlshowz-p)epochr   whichargsappendextendr   )selfproperty	parameters      r   __init__SystemctlReader.__init__{   sY    
ZZ,f5	IIY'		$)* yy{r!   c                      [         R                   " U R                  SS9u  pU(       a  U$ Xl        g! [         a  nUs SnA$ SnAff = f)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   rT   rR   	Exception)rW   valueerrsystemctl_fails       r   r   SystemctlReader.subp   sC    	"499d;JE
J 	"!!	"s   )3 3 
A	AA	A	c                     U R                   (       a$  [        SR                  U R                   5      5      eU R                  R	                  S5      S   n[        U5      S-  $ )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 ({})=rC   i@B )r   RuntimeErrorr   rR   r*   r.   )rW   r   s     r   parse_epoch_as_float$SystemctlReader.parse_epoch_as_float   sV     <<,,2F4<<,@  JJ$$S)!,	Y'))r!   )rT   rR   r   r1   )	__name__
__module____qualname____firstlineno____doc__rZ   r   rg   __static_attributes__r   r!   r   rM   rM   v   s    	#" *r!   rM   c                      [        5       (       a
  [        5       $ [        R                  " 5       (       d*  S[        R                  " 5       S   R                  5       ;   a
  [        5       $ [        $ )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_timestamprx      sR     ~~.00 H(8(8(:8(D(J(J(LL,.. r!   c                      [         R                   " S/SS9u  pU S   R                  5       nU H  nUR                  S5      R                  S5      S:w  d  M)  UR                  S5      R	                  5       nUS   R                  S	5      n[        U5      n[        [        R                  " 5       5      [        [        R                  " 5       5      -
  nXv-   n[        XxU4s  $    [        $ ! [         a     [        $ f = f)
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]   r   zUTF-8userr   rC   ])r   
splitlinesdecodefindr*   stripr.   timer   uptimeSUCCESS_CODEr_   rw   )	data_split_entriesr   splitupstrippeduser_space_timestampkernel_start
kernel_ends	            r   rv   rv      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* "C* *
C<;C<c                     [        [        R                  " 5       5      [        [        R                  " 5       5      -
  n  [	        S5      R                  5       n[	        SS5      R                  5       nU n[        n[        R                  " 5       (       a  [        nX1-   nX2-   nX@XV4$ ! [         a  n[        U5        [        s SnA$ SnAff = f)z
Gather timestamps that corresponds to kernel begin initialization,
kernel finish initialization. and cloud-init systemd unit activation

:return: the three timestamps
UserspaceTimestampMonotonicInactiveExitTimestampMonotoniczcloud-init-localN)r.   r   r   r   rM   rg   r   is_containerCONTAINER_CODEr_   printrw   )r   delta_k_end
delta_ci_s	base_timestatusr   cloudinit_sysdes           r   rr   rr      s     %dkkm(<<L!%)



  	 %,.@



  	 !	 #F,
"/ ;;  ! 	a  !s   A#B& &
C0C CCc                    [        U S S9n/ nSnSn0 n/ n/ n[        [        U5      5       GH  n	X	   n
 X	S-      n[	        U
5      S:X  a  U(       aF  U
R                  S5      S:X  a1  UR                  [        U5      5        UR                  U5        / nSnSnUc  [        U
5      nXF[        U
5      '   [        U
5      [        U5      :X  a8  [	        U5      S	:X  a'  UR                  [        U[        XJU5      5      5        M  M  UR                  S
U
R                  S5      -  5        UR                  U
5        GM  UR                  5       n[        U
5      [        U5      :X  a@  [        XLU
5      nUR                  [        SU5      S-   5        X]R                  S5      -  nGMv  UR                  U5        GM     UR                  [        U5      5        UR                  U5        U$ ! [         a    Sn GNf = f)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                     U S   $ r-   r   )xs    r   <lambda>"generate_records.<locals>.<lambda>  s    ;r!   )keyNg        rC   r=   r   z
init-localr>   zStarting stage: %szFinished stage: (%n) %d seconds
r   )sortedrangelen
IndexErrorr	   r$   rU   rK   r6   r+   r&   r    rI   pop)eventsprint_formatsorted_eventsrecordsrG   r   stage_start_timeboot_recordsunprocessedr   r   next_evtprev_evtrH   s                 r   generate_recordsr     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NN%((HE 4 3eii6GGH""5)"(H% Jx$88%jEB!"CVL jj11
 ""8,Y '\ NN$Z01 Y  	H	s   G%%G54G5c                     [        XS9$ )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   K  s     F>>r!   c                 *   U R                  5       nUR                  5       (       dB  [        R                  R	                  SU R
                  -  5        [        R                  " S5         [        R                  " U5      U4$ ! [         a    SU4s $ f = f)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
rC   N)
readr   sysstderrwriter   exitjsonloads
ValueError)infiler   s     r   load_events_infiler   X  ss     ;;=D::<<

*V[[89zz$%% Tzs   )B BB)z(%n) %d seconds in %I%D)r2   r   r   r   	cloudinitr   r   cloudinit.distrosr   r   r   	FAIL_CODEr   rw   r    r&   r	   r+   r/   r6   r;   r?   rI   rK   rM   rx   rv   rr   r   r   r   r   r!   r   <module>r      s      
    *, 










 	B+ )%H
62* 2*j,><F +GT
?r!   