%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/cloudinit/analyze/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/cloudinit/analyze/__pycache__/__init__.cpython-312.pyc

�

�f%���ddlZddlZddlZddlmZddlmZddlmZmZddl	m
Z
dd�Zd�Zd�Z
d	�Zd
�Zd�Zd�Zd
eddfd�Zedk(r0e�Zej+�Zej.\ZZeee�yy)�N)�datetime)�IO)�dump�show)�
json_dumpsc�b�|stjdd��}|jdd��}d|_|j	dd	�
�}|jddd
ddd��|jddd
ddd��|j
dtf��|j	dd�
�}|jddd
ddd��|jddd
ddd��|jddd
ddd��|j
dtf��|j	d d!�
�}|jddd
ddd"��|jddd
ddd��|j
d tf��|j	d#d$�
�}|jddd
ddd"��|jddd
ddd��|j
d#tf��|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�defaultrz-oz	--outfile�outfile�-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)�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|�\}}tj�}|\}}}}tj|�}	tj|�}
tj|�}	t|�D�cgc]}|ddk(r	d|dvr|��c}d}
tj|
d�}d}d	}d
}tj|tj|tj|i}||z
}||z
}|	|
|||||||d�	}|j||jdi|���t||�|Scc}w#t$rd}tj}Y��wxYw)
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://cloudinit.readthedocs.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�utcfromtimestamp�_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_localr9�FAILURE_MSG�SUCCESS_MSG�
CONTAINER_MSG�
status_map�kernel_runtime�between_process_runtime�kwargss                      r*r#r#ts����t�$�K�D�%��+�+�-�K�;F�8�K��z�=�%�6�6�|�D��#�4�4�Z�@��&�7�7�
�F��
%�!��&�
����y�L�(�!�Q�}�%5�5�
�
�

����,�,�_�[�-I�J��	.��	-��	-��	
�������]����;��J� �,�.�N�+�j�8��(�%��'��� �,��
�F�
�K�K�.�
�;�'�.�.�8��8�9��T�5�����{
���%�I���n�n��%�s$�*
D2�7D-�D2�-D2�2E�Ec���t|�\}}d}tjdtj�}d}t	tjt|�|��D]q\}}tt|j|�d��}|jd|dzz�|jdj|�dz�|jd��s|jd	|dzz�t||�y
)azReport 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+)rT)�reverse�-- Boot Record %02d --
��
�%d boot records analyzed
N)r;�re�compile�	MULTILINE�	enumerater�show_eventsr>�sorted�filter�matchrC�joinrE)	r.rFrGrH�blame_format�r�idx�record�srecss	         r*r r �s����t�$�K�D�%�"�L�
�
�
�$�b�l�l�3�A�
�C� �����T�*�L�9�����V��v�a�g�g�v�.��=��
���.�#��'�:�;�
���D�I�I�e�$�t�+�,�
���D��
�
�K�K�,��a��8�9��T�5�r,c��t|�\}}ttjt	|�|j
��D]a\}}|j
d|dzz�|j
d�|j
d�|j
dj|�dz��c|j
ddzz�t||�y)aGenerate output records using the 'standard' format to printing events.

    Example output follows:
        Starting stage: (init-local)
          ...
        Finished stage: (init-local) 0.105195 seconds

        Starting stage: (init-network)
          ...
        Finished stage: (init-network) 0.339024 seconds

        Starting stage: (modules-config)
          ...
        Finished stage: (modules-config) 0.NNN seconds

        Starting stage: (modules-final)
          ...
        Finished stage: (modules-final) 0.NNN seconds
    r\r]zUThe total time elapsed since completing an event is printed after the "@" character.
z>The time the event takes is printed after the "+" character.

r^r_N)	r;rcrrdr>rrCrhrE)r.rFrGrHrkrls      r*r!r!�s���(�t�$�K�D�%� �����T�*�D�,=�,=�>��.���V�	���.�#��'�:�;�
���
2�	
�	���N�	
�	���D�I�I�f�%��,�-�.�
�K�K�,��a��8�9��T�5�r,c��t|�\}}|jtt|��dz�t	||�y)z%Dump cloud-init events in json formatr^N)r;rCrr>rE)r.rFrGrHs    r*r"r"s5���t�$�K�D�%�	�K�K�
�;�t�,�-��4�5��T�5�r,c�p�d}tj|�\}}|stj|��\}}|S)N)�rawdata)r�load_events_infiler�dump_events)rrq�events�_s    r*r>r>s7���G��-�-�f�5�O�F�G���$�$�W�5�	����Mr,c�2�|jdk(rtj}n	t|jd�}|jdk(rtj}|fS	t|jd�}|fS#t$rDtj
j
d|jz�tjd�Y��wxYw#t$rGtj
j
d|jz�tjd�YfSwxYw)z.Common parsing and setup of input/output filesrrjzCannot open file %s
r]�w)
r�sys�stdin�open�OSError�stderrrC�exitr�stdout)rFrGrHs   r*r;r;s����{�{�c���y�y��	�����S�)�D�
�|�|�s���
�
����;��
	�����s�+�E�
��;����	��J�J���4�t�{�{�B�C��H�H�Q�K�	���	��J�J���4�t�|�|�C�D��H�H�Q�K���;��		�s%�A6�C�6A
C�C�A
D�D�file_handles�returnc�x�|D]5}|tjtjfvr�&|j��7y)zclose filehandlesN)rxryr~�close)r�file_handles  r*rErE-s5��#����3�9�9�c�j�j�1�1������r,�__main__)N)rr`rxr�typingr�cloudinit.analyzerr�cloudinit.atomic_helperrr+r#r r!r"r>r;rE�__name__r$�
parse_argsrFrr.�action_functorr:r,r*�<module>r�s���
�	�
���(�.�b�JP�f�6"�J���.�B��4���z��
�\�F�����D�!�[�[��T�>��4���	r,

Zerion Mini Shell 1.0