3 \me% @ s d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZmZ d dl m Z dddZdd Zd d Z dd Zdd Zdd Zdd ZeddddZedkre Zej Zej\ZZeee dS ) N)datetime)IO)dumpshow) json_dumpsc C sh | st jddd} | jddd}d|_|jdd d }|jddd dddd |jddd dddd |jdtfd |jddd }|jddd dddd |jddd dddd |jddd dddd |jdtfd |jd d!d }|jddd ddd"d |jddd dddd |jd t fd |jd#d$d }|jddd ddd"d |jddd dddd |jd#t fd | S )%Nzcloudinit-analyzez,Devel tool: Analyze cloud-init logs and data)progdescriptionZSubcommandsZ subcommand)titledestTZblamez5Print list of executed stages ordered by time to init)helpz-iz--infileZstoreinfilez/var/log/cloud-init.logzspecify where to read input.)actionr defaultr z-oz --outfileoutfile-zspecify where to write output. )r r z.Print list of in-order events during executionz-fz--formatprint_formatz%I%D @%Es +%dszspecify formatting of output.zspecify where to write output.r z%Dump cloud-init events in JSON formatzspecify where to read input. Zbootz2Print list of boot times for kernel and cloud-init)argparseArgumentParserZadd_subparsersZrequiredZ add_parseradd_argumentZset_defaults analyze_blameanalyze_showanalyze_dumpanalyze_boot)parserZ subparsersZparser_blameZparser_showZparser_dumpZparser_boot r /usr/lib/python3.6/__init__.py get_parser s r c C s t |\}}tj }|\}}}}tj|} tj|} tj|}y(dd t|D d }tj|d } W n tk r d} tj}Y nX d}d}d}tj|tj|tj |i}|| }|| }| | ||||||| d }|j || jf | t|| |S )a Report a list of how long different boot operations took. For Example: -- Most Recent Boot Record -- Kernel Started at: