Current File : //usr/lib/python3/dist-packages/cloudinit/analyze/__pycache__/__init__.cpython-312.pyc |
�
ӇgZ% � � � d dl Z d dlZd dlZd dlmZmZ d dlmZ d dlmZm Z d dl
mZ dd�Zd� Z
d� Zd � Zd
� Zd� Zd� Zd
eddfd�Zedk( r0 e� Zej- � Zej0 \ ZZ eee� yy)� N)�datetime�timezone)�IO)�dump�show)�
json_dumpsc �b � | st j dd�� } | j dd�� }d|_ |j dd �
� }|j ddd
ddd�� |j ddd
ddd�� |j
dt f�� |j dd�
� }|j ddd
ddd�� |j ddd
ddd�� |j ddd
ddd�� |j
dt f�� |j d d!�
� }|j ddd
ddd"�� |j ddd
ddd�� |j
d t f�� |j d#d$�
� }|j ddd
ddd"�� |j ddd
ddd�� |j
d#t f�� | S )%Nzcloudinit-analyzez,Devel tool: Analyze cloud-init logs and data)�prog�description�Subcommands�
subcommand)�title�destT�blamez5Print list of executed stages ordered by time to init)�helpz-iz--infile�store�infilez/var/log/cloud-init.logzspecify where to read input.)�actionr �defaultr z-oz --outfile�outfile�-zspecify where to write output. )r r z.Print list of in-order events during executionz-fz--format�print_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. �bootz2Print list of boot times for kernel and cloud-init)�argparse�ArgumentParser�add_subparsers�required�
add_parser�add_argument�set_defaults�
analyze_blame�analyze_show�analyze_dump�analyze_boot)�parser�
subparsers�parser_blame�parser_show�parser_dump�parser_boots �</usr/lib/python3/dist-packages/cloudinit/analyze/__init__.py�
get_parserr, sj � ���(�(�$�F�
�� �&�&�]��&�N�J��J���(�(��M� )� �L� ������
�)�
+�
� � ������
��
.�
� � ���g�}�%=��>��'�'��E� (� �K� ������
� �
,�
� � ������
�)�
+�
� � ������
��
-�
� � ���V�\�$:��;��'�'��<� (� �K� ������
�)�
,�
� � ������
��
.�
� � ���V�\�$:��;��'�'��I� (� �K� ������
�)�
,�
� � ������
��
-�
� � ���V�\�$:��;��M� c
� � t |� \ }}t j � }|\ }}}}t j |t
j � } t j |t
j � }
t j |t
j � } t |� D �cg c] }|d dk( r d|d v r|�� c}d }
t j |
d t
j � }d}d }d
}t j |t j |t j |i}||z
}||z
}| |
|||||||d� }|j || j di |��� t ||� |S c c}w # t $ r d}t j }Y ��w xY w)
a� Report a list of how long different boot operations took.
For Example:
-- Most Recent Boot Record --
Kernel Started at: <time>
Kernel ended boot at: <time>
Kernel time to boot (seconds): <time>
Cloud-init activated by systemd at: <time>
Time between Kernel end boot and Cloud-init activation (seconds):<time>
Cloud-init start: <time>
�namez
init-localzstarting searchr ���� timestampz4Could not find init-local log-line in cloud-init.logz�Your Linux distro or container does not support this functionality.
You must be running a Kernel Telemetry supported distro.
Please check https://docs.cloud-init.io/en/latest/topics/analyze.html for more information on supported distros.
a* -- Most Recent Boot Record --
Kernel Started at: {k_s_t}
Kernel ended boot at: {k_e_t}
Kernel time to boot (seconds): {k_r}
Cloud-init activated by systemd at: {ci_sysd_t}
Time between Kernel end boot and Cloud-init activation (seconds): {bt_r}
Cloud-init start: {ci_start}
z�-- Most Recent Container Boot Record --
Container started at: {k_s_t}
Cloud-init activated by systemd at: {ci_sysd_t}
Cloud-init start: {ci_start}
) �k_s_t�k_e_t�k_r�bt_r�k_e�k_s�ci_sysd� ci_sysd_t�ci_start� )�configure_ior �dist_check_timestampr �
fromtimestampr �utc�_get_events�
IndexError� FAIL_CODE�CONTAINER_CODE�SUCCESS_CODE�write�format�clean_io)r/ �args�infh�outfh�kernel_info�status_code�kernel_start�
kernel_end�
ci_sysd_start�kernel_start_timestamp�kernel_end_timestamp�ci_sysd_start_timestamp�e�last_init_localr: �FAILURE_MSG�SUCCESS_MSG�
CONTAINER_MSG�
status_map�kernel_runtime�between_process_runtime�kwargss r+ r$ r$ t s� � � �t�$�K�D�%��+�+�-�K�;F�8�K��z�=�%�3�3�L�(�,�,�O��#�1�1�*�h�l�l�K��&�4�4��x�|�|���%� !��&�
����y�L�(�!�Q�}�%5�5�
�
�
��� �)�)��K�(�(�,�,�
�� .� � -� � -� �
�������]����;��J� �,�.�N�+�j�8�� (�%��'��� �,��
�F�
�K�K�.�
�;�'�.�.�8��8�9��T�5�����
�� � %�I���n�n��%�s$ �
E. �$E)�<-E. �)E. �.F�Fc �� � t |� \ }}d}t j dt j � }d}t t j t |� |� � D ]q \ }}t t |j |� d�� }|j d|dz z � |j dj |� dz � |j d� �s |j d |dz z � t ||� y
)az Report a list of records sorted by largest time delta.
For example:
30.210s (init-local) searching for datasource
8.706s (init-network) reading and applying user-data
166ms (modules-config) ....
807us (modules-final) ...
We generate event records parsing cloud-init logs, formatting the output
and sorting by record data ('delta')
z
%ds (%n)z(^\s+\d+\.\d+)r T)�reverse�-- Boot Record %02d --
� �
�%d boot records analyzed
N)r<