HOME


Mini Shell 1.0
Redirecting to https://devs.lapieza.net/iniciar-sesion Redirecting to https://devs.lapieza.net/iniciar-sesion.
DIR: /proc/1991111/cwd/lib/python3/dist-packages/cloudinit/analyze/__pycache__/
Upload File :
Current File : //proc/1991111/cwd/lib/python3/dist-packages/cloudinit/analyze/__pycache__/__main__.cpython-311.pyc
�

܍~c%���ddlZddlZddlZddlmZddlmZddlmZmZddl	m
Z
dd�Zd�Zd�Z
d	�Zd
�Zd�Zd�Zd
eddfd�Zedkr6e��Ze���Zej\ZZeee��dSdS)�N)�datetime)�IO)�dump�show)�
json_dumpsc��|stjdd���}|�dd���}d|_|�dd	�
��}|�ddd
ddd���|�ddd
ddd���|�dtf���|�dd�
��}|�ddd
ddd���|�ddd
ddd���|�ddd
ddd���|�dtf���|�d d!�
��}|�ddd
ddd"���|�ddd
ddd���|�d tf���|�d#d$�
��}|�ddd
ddd"���|�ddd
ddd���|�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/__main__.py�
get_parserr+s����
��(�$�F�
�
�
���&�&�]��&�N�N�J��J���(�(��M�)���L�������
�)�
+�
����������
��
.�
�������g�}�%=��>�>�>��'�'��E�(���K�������
� �
,�
����������
�)�
+�
����������
��
-�
�������V�\�$:��;�;�;��'�'��<�(���K�������
�)�
,�
����������
��
.�
�������V�\�$:��;�;�;��'�'��I�(���K�������
�)�
,�
����������
��
-�
�������V�\�$:��;�;�;��M�c
�x�t|��\}}tj��}|\}}}}tj|��}	tj|��}
tj|��}	d�t|��D��d}tj|d��}
n#t$rd}
tj}YnwxYwd}d}d}tj|tj|tj	|i}||z
}||z
}|	|
|||||||
d�	}|�
||jd	i|����t||��|S)
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>
    c�>�g|]}|ddkrd|dv�|��S)�namez
init-localzstarting searchr
�)�.0�es  r*�
<listcomp>z analyze_boot.<locals>.<listcomp>�sC��
�
�
����y�L�(�(�!�Q�}�%5�5�5�
�6�5�5r,����	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_startr0)
�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�last_init_localr>�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�|�D�D��#�4�Z�@�@��&�7�
�F�F��
%�
�
� ��&�&�
�
�
�

����,�_�[�-I�J�J�����%�%�%�I���n����%����
	.��	-��	-��	
�����]���;��J� �,�.�N�+�j�8��(�%��'��� �,��
�
�F�
�K�K�.�
�;�'�.�8�8��8�8�9�9�9��T�5�����s�*9B$�$B?�>B?c�*�t|��\}}d}tjdtj��}t	tjt|��|����D]�\}}tt|j
|��d���}|�d|dzz��|�d�|��dz��|�d����|�d|dzz��t||��d	S)
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+)T)�reverse�-- Boot Record %02d --
��
�%d boot records analyzed
N)r?�re�compile�	MULTILINE�	enumerater�show_eventsrB�sorted�filter�matchrG�joinrI)	r/rJrKrL�blame_format�r�idx�record�srecss	         r*r r �s	��!��&�&�M�T�5�"�L�
�
�$�b�l�3�3�A� ����T�*�*�L�9�9�������V��v�a�g�v�.�.��=�=�=��
���.�#��'�:�;�;�;�
���D�I�I�e�$�$�t�+�,�,�,�
���D�����	�K�K�,��a��8�9�9�9��T�5�����r,c���t|��\}}ttjt	|��|j����D]u\}}|�d|dzz��|�d��|�d��|�d�|��dz���v|�d|dzz��t||��dS)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.

rarbN)	r?rfrrgrBrrGrkrI)r/rJrKrLrnros      r*r!r!�s���(!��&�&�M�T�5� ����T�*�*�D�,=�>�>���.�.���V�	���.�#��'�:�;�;�;�
���
2�	
�	
�	
�	���N�	
�	
�	
�	���D�I�I�f�%�%��,�-�-�-�-�	�K�K�,��a��8�9�9�9��T�5�����r,c��t|��\}}|�tt|����dz��t	||��dS)z%Dump cloud-init events in json formatraN)r?rGrrBrI)r/rJrKrLs    r*r"r"sP�� ��&�&�M�T�5�	�K�K�
�;�t�,�,�-�-��4�5�5�5��T�5�����r,c�l�d}tj|��\}}|stj|���\}}|S)N)�rawdata)r�load_events_infiler�dump_events)rrt�events�_s    r*rBrB
s?���G��-�f�5�5�O�F�G��6��$�W�5�5�5�	����Mr,c���|jdkr
tj}nb	t|jd��}nK#t$r>tj�d|jz��tjd��YnwxYw|jdkr
tj	}nb	t|jd��}nK#t$r>tj�d|jz��tjd��YnwxYw||fS)z.Common parsing and setup of input/output filesrrmzCannot open file %s
r`�w)
r�sys�stdin�open�OSError�stderrrG�exitr�stdout)rJrKrLs   r*r?r?s���{�c����y���	����S�)�)�D�D���	�	�	��J���4�t�{�B�C�C�C��H�Q�K�K�K�K�K�	�����|�s����
���	����s�+�+�E�E���	�	�	��J���4�t�|�C�D�D�D��H�Q�K�K�K�K�K�	����
�%�=�s#�0�AA8�7A8�B*�*AC2�1C2�file_handles�returnc�n�|D]1}|tjtjfvr�|����2dS)zclose filehandlesN)r{r|r��close)r��file_handles  r*rIrI,sG��#�����3�9�c�j�1�1�1����������r,�__main__)N)rrcr{r�typingr�cloudinit.analyzerr�cloudinit.utilrr+r#r r!r"rBr?rI�__name__r$�
parse_argsrJrr/�action_functorr0r,r*�<module>r�s_��
����	�	�	�	�
�
�
�
�������������(�(�(�(�(�(�(�(�%�%�%�%�%�%�b�b�b�b�JP�P�P�f���4"�"�"�J���������.�B��4������z���
�Z�\�\�F������D�!�[��T�>��N�4�������	�r,