x[h,+ ddlZddlZddlZddlZddlmZmZddlmZdddddd d d d d dd Z dZ dZ dZ e dddfZ dZdZdZdZdZdZdZdZdZdZGddZd Zd!Zd"Z d&d#Zd$Zd%Zy)'N)subputil) uses_systemddelta descriptionelapsed event_typeindentlevelnameoriginresult timestamp total_time) z%dz%Dz%Ez%ez%Iz%lz%nz%oz%rz%tz%T successfulfailure containerctjD]9\}}||vs |dvr|j|d|z}%|j|d|z};|jdi|S)N)rrrz {%s:08.5f}z{%s}) format_keyitemsreplaceformat)msgeventijs 8/usr/lib/python3/dist-packages/cloudinit/analyze/show.py format_recordr 6sm  "11 855kk!\A%56kk!VaZ0 1 3::  c*|r|jdSy)Nr getrs r event_namer&As yy  r!c*|r|jdSy)Nr r#r%s rr r Gs yy&& r!cB|rt|jddSy)N/r)r&splitr%s r event_parentr+Ms# % &&s+A.. r!c6t|jdSNr)floatr$r%s revent_timestampr/Ss ;' ((r!ctjjt|tjjSN)datetime fromtimestampr/timezoneutcr%s revent_datetimer6Ws1    * * 1 1 5 5 r!c(||z jSr1) total_seconds)t1t2s r delta_secondsr;]s G " " $$r!c>tt|t|Sr1)r;r6)startfinishs revent_durationr?as .v0F GGr!c |j}|jt||t|t |ddt |j ddz zzdzd|S)N| r)z`->)rrr )copyupdater?r;r6r&count) start_timer=r>records r event_recordrIese [[]F MM#E62$Z1FGC:e#4#:#:3#?!#CDDuL  Mr!c d|zS)NzTotal Time: %3.5f seconds r)rs rtotal_time_recordrKrs (: 55r!c$eZdZdZddZdZdZy)SystemctlReaderzQ Class for dealing with all systemctl subp calls in a consistent manner. Ncd|_tjddg|_|r|jj ||jj d|g|j|_y)N systemctlshowz-p)epochrwhichargsappendextendr)selfproperty parameters r__init__zSystemctlReader.__init__{sY ZZ ,f5  II  Y ' $)*yy{ r!c tj|jd\}}|r|S||_y#t$r }|cYd}~Sd}~wwxYw)z Make a subp call based on set args and handle errors by setting failure code :return: whether the subp call failed or not TcaptureN)rrSrQ Exception)rVvalueerrsystemctl_fails rrzSystemctlReader.subpsG "499d;JE3 DJ "! ! "s'22 AAAAc|jr$tdj|j|jj dd}t |dz S)z{ 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 ({})=rCi@B)r RuntimeErrorrrQr*r.)rVrs rparse_epoch_as_floatz$SystemctlReader.parse_epoch_as_floatsV <<,,2F4<<,@  JJ$$S)!, Y'))r!r1)__name__ __module__ __qualname____doc__rYrrdrr!rrMrMvs #" *r!rMctr tStjs'dtjdj vr t StS)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. gentoosystem)rgather_timestamps_using_systemdr is_FreeBSD system_infolowergather_timestamps_using_dmesgTIMESTAMP_UNKNOWNrr!rdist_check_timestamprrsM~.00 H(8(8(:8(D(J(J(LL,.. r!c tjdgd\}}|dj}|D]}|jdjddk7s'|jdj }|dj d }t |}t tjt tjz }||z}t|||fcS tS#t$rYtSwxYw) a 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[rzUTF-8userrrC]) r splitlinesdecodefindr*stripr.timeruptime SUCCESS_CODEr]rq) data_ split_entriesrsplitupstrippeduser_space_timestamp kernel_start kernel_ends rrprps ))WIt4aQ**,  JAxx %%f-3((7+113"1:++C0(-X$$TYY[1E$++-4HH ),@@ $\:zII J"     sAC+B C+#C++ C<;C<cttjttjz } t dj }t ddj }|}t }tjrt}||z}||z}||||fS#t$r}t|tcYd}~Sd}~wwxYw)z Gather timestamps that corresponds to kernel begin initialization, kernel finish initialization. and cloud-init systemd unit activation :return: the three timestamps UserspaceTimestampMonotonicInactiveExitTimestampMonotoniczcloud-init-localN) r.r{rr|rMrdr} is_containerCONTAINER_CODEr]printrq)r delta_k_end delta_ci_s base_timestatusrcloudinit_sysdes rrlrls%dkkm(<z"generate_records..s ;r!)keyNgrCr=r z init-localr>zStarting stage: %szFinished stage: (%n) %d seconds r)sortedrangelen IndexErrorr r$rTrKr6r+r&r rIpop)events print_format sorted_eventsrecordsrGrstage_start_time boot_records unprocessedrrnext_evtprev_evtrHs rgenerate_recordsrs6'?@MGJJLK 3}% &,-q  a!e}H e  '599V, <0<=##G,!  !+E2 8B e!45% Jx$88h'83NN%((UHE3eii6GGH""5)"(H% Jx$88%j(EB!"CVLfjj11 ""8,Y,-\ NN$Z01 Y H sG G,+G,ct||S)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)rrs r show_eventsrKs F >>r!c|j}|jsAtjj d|j ztj d tj||fS#t$rd|fcYSwxYw)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 zEmpty file %s rCN) readrzsysstderrwriter exitjsonloads ValueError)infiler~s rload_events_infilerXsq ;;=D ::< *V[[89  zz$%% Tzs#A:: B  B )z(%n) %d seconds in %I%D)r2rrr{ cloudinitrrcloudinit.distrosrrr} FAIL_CODErrqr r&r r+r/r6r;r?rIrKrMrrrprlrrrrr!rrs *,               B+   ) %H 62*2*j,>