܍~cm0 jddlZddlZddlZddlZddlZddlmZmZddlm Z dddddd d d d d dd Z d de DZ dZdZdZedddfZdZdZdZdZdZdZdZdZdZdZd ZGd!d"Zd#Zd$Zd%Z d+d(Z!d)Z"d*Z#dS),N)subputil) uses_systemddelta descriptionelapsed event_typeindentlevelnameoriginresult timestamp total_time) z%dz%Dz%Ez%ez%Iz%lz%nz%oz%rz%tz%T chg|]/\}}d|dd|0S)z{0}: {1}%z%%)formatreplace.0kvs 8/usr/lib/python3/dist-packages/cloudinit/analyze/show.py r2s:OOODAqZqyyd++Q//OOO successfulfailure containerctD]@\}}||vr7|dvr||d|z}'||d|z}A|jdi|S)N)rrrz {%s:08.5f}z{%s}) format_keyitemsrr)msgeventijs r format_recordr):s  ""111 88555kk!\A%566kk!VaZ00 3:    rcvtd|D}|d}g}|D]}|d}tj|}t j|dd}tj ||| ||S)Nc3,K|]\}}|dv ||fVdS))contentNr"rs r z#dump_event_files..Fs4LLdaq 7K7KAq67K7K7K7KLLrfilespathr,ascii) dictr$osr/basenamebase64 b64decodedecoder write_fileappend)r&r,r.savedffnamefn_localfcontents rdump_event_filesr>EsLLekkmmLLLLLG G E E & 7##E**#AiL1188AA (+++ X Lrc4|r|dSdS)Nr getr&s r event_namerCSs! !yy   4rc4|r|dSdS)Nr r@rBs rr r Ys! 'yy&&& 4rcZ|r(t|ddSdS)N/r)rCsplitrBs r event_parentrH_s0 /%  &&s++A.. 4rcFt|dSNr)floatrArBs revent_timestamprLes ;'' ( ((rcZtjt|SN)datetimeutcfromtimestamprLrBs revent_datetimerQis!   - -oe.D.D E EErc0||z SrN) total_seconds)t1t2s r delta_secondsrVms G " " $ $$rcVtt|t|SrN)rVrQ)startfinishs revent_durationrZqs" ..v0F0F G GGrc  |}|t||t|t |ddt |ddz zzdzd|S)N|rrFz`->)rrr )copyupdaterZrVrQrCcount) start_timerXrYrecords r event_recordrcus [[]]F MM#E622$Z1F1FGGC:e#4#4#:#:3#?#?!#CDDuL   Mrc d|zS)NzTotal Time: %3.5f seconds r")rs rtotal_time_recordres (: 55rc&eZdZdZddZdZdZdS)SystemctlReaderzQ Class for dealing with all systemctl subp calls in a consistent manner. Ncd|_tjddg|_|r|j||jd|g||_dS)N systemctlshowz-p)epochrwhichargsr8extendr)selfproperty parameters r__init__zSystemctlReader.__init__sm Z ,,f5  ( I  Y ' ' ' $)***yy{{ rc tj|jd\}}|r|S||_dS#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)rrmrk Exception)rovalueerrsystemctl_fails rrzSystemctlReader.subpsn "49d;;;JE3  DJ4 " " "! ! ! ! ! ! ! "s!-- A>AAc|jr'td|j|jdd}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 ({})=r]i@B)r RuntimeErrorrrkrGrK)rors rparse_epoch_as_floatz$SystemctlReader.parse_epoch_as_floatsc < ,,2F4<,@,@  J$$S))!, Y'))rrN)__name__ __module__ __qualname____doc__rrrr}r"rrrgrgsP # # # #""" *****rrgctrtStjs-dtjdvrt 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_UNKNOWNr"rrdist_check_timestamprsf~~1.000 /H(8(:(:8(D(J(J(L(LLL,... rcF tjdgd\}}|d}|D]}|dddkr|d}|dd }t |}t tjt tj z }||z}t|||fcSn#t$rYnwxYwtS) 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 dmesgTrtrzUTF-8userr r]]) r splitlinesr6findrGstriprKtimeruptime SUCCESS_CODErvr) data_ split_entriesr'splitupstrippeduser_space_timestamp kernel_start kernel_ends rrrs) )WIt444aQ**,,  J JAxx  %%f--33((7++1133"1:++C00(-X$$TY[[11E$+--4H4HH ),@@ $\:zIIII4 J      sDD D DDcttjttjz } t d}t dd}|}t }tjrttjttjz } tj d}|j }n5#t$r(}td||d}~wwxYwt}||z}||z}n-#t $r } t#| t$cYd} ~ Sd} ~ wwxYw||||fS)z Gather timestamps that corresponds to kernel begin initialization, kernel finish initialization. and cloud-init systemd unit activation :return: the three timestamps UserspaceTimestampMonotonicInactiveExitTimestampMonotoniczcloud-init-localz/proc/1/cmdlinezBCould not determine container boot time from /proc/1/cmdline. ({})N)rKrrrrgr}r is_container monotonicr2statst_atimeOSErrorr|rCONTAINER_CODErvprintr) r delta_k_end delta_ci_s base_timestatus file_statrxrcloudinit_sysdes rrrs%%dkmm(<(<3C3C-D-DDI G$566 (1    "66z"generate_records..3s ;r)keyNgrr]rXr z init-localrYzStarting stage: %szFinished stage: (%n) %d seconds r)sortedrangelen IndexErrorr rAr8rerQrHrCr)rcpop)events blame_sort print_format dump_files log_datafiles sorted_eventsrecordsrarstage_start_time boot_records unprocessedrr&next_evtprev_evtrbs rgenerate_recordsrs*6'?'?@@@MGJJLK 1c-(( ) ),-,-q  a!e}HH   HHH  e   ' ' !599V,, <<0<<===##G,,,!  !+E22 8B e!4!45%  Jx$8$888h''833NN%((UHEE3eii6G6GGHHH""5)))"((H%  Jx$8$888%j(EBB!"CVLLfjj111 ""8,,,, NN$Z00111   s A A#"A#c$t||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_eventsrns F > > >>rc|} 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 N)readjsonloads ValueError)infilers rload_events_infiler{sV ;;==Dz$%% Tzs ,==)FrFF)$r4rOrr2r cloudinitrrcloudinit.distrosrr#joinr$formatting_helpr FAIL_CODErrr)r>rCr rHrLrQrVrZrcrergrrrrrrr"rrrs0  ******,              ((OOJ+<+<+<`* MMMM` ? ? ?     r