܍~c%ddlZddlZddlZddlmZddlmZddlmZmZddl m Z ddZ dZ dZ d Zd Zd Zd Zd eddfdZedkr6e ZeZej\ZZeeedSdS)N)datetime)IO)dumpshow) json_dumpsc|stjdd}|dd}d|_|dd }|d d d ddd|ddd ddd|dtf|dd }|ddd ddd|d d d ddd|ddd ddd|dtf|d d! }|d d d ddd"|ddd ddd|d tf|d#d$ }|d d d ddd"|ddd ddd|d#tf|S)%Nzcloudinit-analyzez,Devel tool: Analyze cloud-init logs and data)prog description Subcommands subcommand)titledestTblamez5Print list of executed stages ordered by time to init)helpz-iz--infilestoreinfilez/var/log/cloud-init.logzspecify where to read input.)actionrdefaultrz-oz --outfileoutfile-zspecify where to write output. )rrz.Print list of in-order events during executionz-fz--format print_formatz%I%D @%Es +%dszspecify formatting of output.zspecify where to write output.rz%Dump cloud-init events in JSON formatzspecify where to read input. bootz2Print list of boot times for kernel and cloud-init) argparseArgumentParseradd_subparsersrequired add_parser add_argument set_defaults analyze_blame analyze_show analyze_dump analyze_boot)parser subparsers parser_blame parser_show parser_dump parser_boots >>''E(K   ,   ) +    - V\$:;;;''<(K  ) ,    . V\$:;;;''I(K  ) ,    - V\$:;;; Mc xt|\}}tj}|\}}}}tj|} tj|} tj|} dt |Dd} tj| d} n#t $rd} tj}YnwxYwd}d}d}tj|tj|tj |i}||z }||z }| | |||||| | d }| ||j d i|t|||S) aReport a list of how long different boot operations took. For Example: -- Most Recent Boot Record -- Kernel Started at: