8889841có oBú]c@säddlZddlZddlZddlZddlZddlZddlmZddlm Z i dd6dd6dd 6d d 6d d 6dd6dd6dd6dd6dd6dd6Z dj ge j ƒD]*\Z Zdje jddƒeƒ^q΃ZdZdZd ZedddfZd!„Zd"„Zd#„Zd$„Zd%„Zd&„Zd'„Zd(„Zd)„Zd*„Zd+„Z d,e!fd-„ƒYZ"d.„Z#d/„Z$d0„Z%e&d1e&e&d2„Z'd3„Z(d4„Z)dS(5iÿÿÿÿN(tutil(t uses_systemdtdeltas%dt descriptions%Dtelapseds%Et event_types%etindents%Itlevels%ltnames%ntorigins%otresults%rt timestamps%tt total_times%Tt s{0}: {1}t%s%%t successfultfailuret containercCstxdtjƒD]V\}}||kr |dkrJ|j|d|ƒ}qc|j|d|ƒ}q q W|j|S(NRRR s {%s:08.5f}s{%s}(RRs timestamp(t format_keytitemstreplacetformat(tmsgteventtitj((s:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pyt format_record=s   cCs–td„|jƒDƒƒ}|d}g}xc|D][}|d}tjj|ƒ}tj|dƒjdƒ}tj ||ƒ|j |ƒq3W|S(Ncss-|]#\}}|dkr||fVqdS(tcontentN(scontent((t.0tktv((s:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pys IstfilestpathRtascii( tdictRtosR tbasenametbase64t b64decodetdecodeRt write_filetappend(RRRtsavedtftfnametfn_localtfcontent((s:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pytdump_event_filesHs   cCs|r|jdƒSdS(NR(tgettNone(R((s:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pyt event_nameVs cCs|r|jdƒSdS(NR(R0R1(R((s:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pyR\s cCs!|rt|ƒjdƒdSdS(Nt/i(R2tsplitR1(R((s:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pyt event_parentbscCst|jdƒƒS(NR (tfloatR0(R((s:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pytevent_timestamphscCstjjt|ƒƒS(N(tdatetimetutcfromtimestampR7(R((s:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pytevent_datetimelscCs||jƒS(N(t total_seconds(tt1tt2((s:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pyt delta_secondspscCstt|ƒt|ƒƒS(N(R>R:(tstarttfinish((s:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pytevent_durationtscCsi|jƒ}|jit||ƒd6t|t|ƒƒd6ddt|ƒjdƒddd6ƒ|S( NRRt|R R3is`->R(tcopytupdateRAR>R:R2tcount(t start_timeR?R@trecord((s:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pyt event_recordxs   *cCsd|S(NsTotal Time: %3.5f seconds ((R ((s:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pyttotal_time_recordƒstSystemctlReadercBs,eZdZdd„Zd„Zd„ZRS(sQ Class for dealing with all systemctl subp calls in a consistent manner. cCsZd|_ddg|_|r1|jj|ƒn|jjd|gƒ|jƒ|_dS(Ns/bin/systemctltshows-p(R1tepochtargsR)textendtsubpR(tselftpropertyt parameter((s:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pyt__init__‹s  cCsTy9tj|jdtƒ\}}|r+|S||_dSWntk rO}|SXdS(sœ Make a subp call based on set args and handle errors by setting failure code :return: whether the subp call failed or not tcaptureN(RRORMtTrueRLR1t Exception(RPtvalueterrtsystemctl_fail((s:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pyRO–s cCsH|jr$tdj|jƒƒ‚n|jjdƒd}t|ƒdS(s{ If subp call succeeded, return the timestamp from subp as a float. :return: timestamp as a float sBSubprocess call to systemctl has failed, returning error code ({})t=ii@B(Rt RuntimeErrorRRLR4R6(RPR ((s:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pytparse_epoch_as_float¦s  N(t__name__t __module__t__doc__R1RSROR\(((s:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pyRJ‡s cCsCtƒrtƒStjƒs8dtjƒdjƒkr?tƒStS(s2 Determine which init system a particular linux distro is using. Each init system (systemd, upstart, 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. tgentootsystem(Rtgather_timestamps_using_systemdRt is_FreeBSDt system_infotlowertgather_timestamps_using_dmesgtTIMESTAMP_UNKNOWN(((s:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pytdist_check_timestampºs c CséyÑtjdgdtƒ\}}|djƒ}xœ|D]”}|jdƒjdƒdkr8|jdƒjƒ}|djdƒ}t|ƒ}tt j ƒƒttj ƒƒ}||}t |||fSq8WWnt k ränXt S( s 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 tdmesgRTisUTF-8tuseriÿÿÿÿit](RRORUt splitlinesR'tfindR4tstripR6ttimetuptimet SUCCESS_CODERVRg( tdatat_t split_entriesRtsplituptstrippedtuser_space_timestampt kernel_startt kernel_end((s:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pyRfÑs  "   c Cs/ttjƒƒttjƒƒ}yátdƒjƒ}tddƒjƒ}|}t}tjƒrîtj dkråttjƒƒttj ƒƒ}yt j dƒ}|j }Wn(tk rÛ}tdj|ƒƒ‚nXt}qît}n||}||}Wntk r} | GHtSX||||fS(s¸ Gather timestamps that corresponds to kernel begin initialization, kernel finish initialization. and cloud-init systemd unit activation :return: the three timestamps tUserspaceTimestampMonotonictInactiveExitTimestampMonotonicscloud-init-localis/proc/1/cmdlinesBCould not determine container boot time from /proc/1/cmdline. ({})(ii(R6RoRRpRJR\Rqt is_containertsyst version_infot monotonicR#tstattst_atimetOSErrorR[RtCONTAINER_CODEt FAIL_CODERVRg( Rxt delta_k_endt delta_ci_st base_timetstatust file_statRXRytcloudinit_sysdte((s:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pyRbñs0" "     s(%n) %d seconds in %I%DcCsNt|dd„ƒ}g}d }d}i} g} g} g} xètdt|ƒƒD]Ñ} || }y|| d}Wntk rd }nXt|ƒdkr³|jdƒ| krí|jt|ƒƒ| j|ƒg}d }d}n|d krg} t |ƒ}|| t |ƒ1sgiiR?RR@sStarting stage: %ssFinished stage: (%n) %d secondss RN(tsortedR1trangetlent IndexErrorRR0R)RIR:R5R2RRHtpop(teventst blame_sortt print_formatt dump_filest log_datafilest sorted_eventstrecordsRFR tstage_start_timet stages_seent boot_recordst unprocessedR‹Rtnext_evttprev_evtRG((s:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pytgenerate_records sZ            cCst|d|ƒS(s< 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:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pyt show_eventsls cCsB|jƒ}ytj|ƒ|fSWntk r=d|fSXdS(s˜ 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(treadtjsontloadst ValueErrorR1(tinfileRr((s:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pytload_events_infileys   (*R%R8R¤R#RoR}t cloudinitRtcloudinit.distrosRRtjoinRRRRRtformatting_helpRqR„RƒRgRR/R2RR5R7R:R>RARHRItobjectRJRhRfRbtFalseR¡R¢R¨(((s:/usr/lib/python2.7/site-packages/cloudinit/analyze/show.pytsZ        =         3  /J