f>/ ddlZddlZddlZddlZddlZddlmZmZddlm Z dddddd d d d d dd Z dje jDcgc]'\}}dj|jdd|)c}}ZdZdZdZedddfZdZdZdZdZdZdZdZdZd Zd!ZGd"d#Zd$Zd%Z d&Z! d*d'Z"d(Z#d)Z$ycc}}w)+N)subputil) uses_systemddelta descriptionelapsed event_typeindentlevelnameoriginresult timestamp total_time) z%dz%Dz%Ez%ez%Iz%lz%nz%oz%rz%tz%T z{0}: {1}%z%% 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":sm  "11 855kk!\A%56kk!VaZ0 1 3::  c*|r|jdSy)Nr getrs r! event_namer(Es yy  r#c*|r|jdSy)Nr r%r's r!r r Ks yy&& r#cB|rt|jddSy)N/r)r(splitr's r! event_parentr-Qs# % &&s+A.. r#c6t|jdSNr)floatr&r's r!event_timestampr1Ws ;' ((r#cRtjjt|SN)datetimeutcfromtimestampr1r's r!event_datetimer6[s    - -oe.D EEr#c(||z jSr3) total_seconds)t1t2s r! delta_secondsr;_s G " " $$r#c>tt|t|Sr3)r;r6)startfinishs r!event_durationr?cs .v0F GGr#c |j}|jt||t|t |ddt |j ddz zzdzd|S)N|rr+z`->)rrr )copyupdater?r;r6r(count) start_timer=r>records r! event_recordrHgse [[]F MM#E62$Z1FGC:e#4#:#:3#?!#CDDuL  Mr#c d|zS)NzTotal Time: %3.5f seconds r)rs r!total_time_recordrJts (: 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)rrRrP Exception)rUvalueerrsystemctl_fails r!rzSystemctlReader.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 ({})=rBi@B)r RuntimeErrorrrPr,r0)rUrs r!parse_epoch_as_floatz$SystemctlReader.parse_epoch_as_floatsV <<,,2F4<<,@  JJ$$S)!, Y'))r#r3)__name__ __module__ __qualname____doc__rXrrcrr#r!rLrLxs #" *r#rLctr 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#r!dist_check_timestamprqsM~.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 dmesgTrZrzUTF-8userrrB]) r splitlinesdecodefindr,stripr0timeruptime SUCCESS_CODEr\rp) data_ split_entriesrsplitupstrippeduser_space_timestamp kernel_start kernel_ends r!roros ))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 }tjrcttjttjz } tjd}|j}t}||z}||z}||||fS#t$r }tdj||d}~wwxYw#t $r} t#| t$cYd} ~ 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-localz/proc/1/cmdlinezBCould not determine container boot time from /proc/1/cmdline. ({})N)r0rzrr{rLrcr| is_container monotonicosstatst_atimeOSErrorrbrCONTAINER_CODEr\printrp) r delta_k_end delta_ci_s base_timestatus file_statr^rcloudinit_sysdes r!rkrks8%dkkm(<>3C-DDI GG$56 (11 $F, "Z/ <^ ;; "66z"generate_records..%s ;r#)keyNgrBr=r z init-localr>zStarting stage: %szFinished stage: (%n) %d seconds r)sortedrangelen IndexErrorr r&rSrJr6r-r(r"rHpop)events blame_sort print_format dump_files log_datafiles sorted_eventsrecordsrFrstage_start_time boot_records unprocessedrrnext_evtprev_evtrGs r!generate_recordsrs*6'?@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_eventsr`s 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 rBN) readrysysstderrwriter exitjsonloads ValueError)infiler}s r!load_events_infilermsq ;;=D ::< *V[[89  zz$%% Tzs#A:: B  B )Fz(%n) %d seconds in %I%DFF)%r4rrrrz cloudinitrrcloudinit.distrosrrjoinrrrformatting_helpr| FAIL_CODErrpr"r(r r-r1r6r;r?rHrJrLrqrorkrrr)kvs00r!rs *,             ((+<`* M` ?w Ps,C