HOME


Mini Shell 1.0
DIR: /usr/lib/python3/dist-packages/bcc/__pycache__/
Upload File :
Current File : //usr/lib/python3/dist-packages/bcc/__pycache__/table.cpython-312.pyc
�

f������ddlmZ	ddlmZddlmZddlZ	ddl
mZddlZddl
Z
ddlZddlZddlmZmZmZmZmZddlmZdd	lmZdZd
ZdZdZd
ZdZdZdZ dZ!dZ"dZ#dZ$dZ%dZ&dZ'dZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/d Z0d!Z1d"Z2d#Z3d$Z4d%Z5ied&�ed'�ed(�ed)�ed*�ed+�ed,�e d-�e!d.�e"d/�e#d0�e$d1�e%d2�e&d3�e'd4�e(d5�e)d6�e*d7e+d8e,d9e-d:e.d;e/d<e0d=e1d>e2d?e3d@e4dAe5dBi�Z6dCa7dDZ8dEZ9dF�Z:dxdG�Z;dxdH�Z<dI�Z=dJ�Z>dK�Z?dL�Z@dM�ZAGdN�dOe�ZBGdP�dQeB�ZCGdR�dSeC�ZDGdT�dUeB�ZEGdV�dWeE�ZFGdX�dYeE�ZGGdZ�d[�ZHGd\�d]eE�ZIGd^�d_eE�ZJGd`�daeC�ZKGdb�dceK�ZLGdd�deeE�ZMGdf�dgeB�ZNGdh�dieB�ZOGdj�dkeE�ZPGdl�dmeE�ZQGdn�doeE�ZRGdp�dqeE�ZSGdr�dseC�ZTGdt�dueB�ZUGdv�dw�ZVy#e$r
ddlmZY���wxYw)y�)�print_function)�MutableMapping)�strftimeN)�reduce�)�lib�_RAW_CB_TYPE�
_LOST_CB_TYPE�_RINGBUF_CB_TYPE�bcc_perf_buffer_opts)�get_online_cpus)�get_possible_cpus��������	�
���
�����������������HASH�ARRAY�
PROG_ARRAY�PERF_EVENT_ARRAY�PERCPU_HASH�PERCPU_ARRAY�STACK_TRACE�CGROUP_ARRAY�LRU_HASH�LRU_PERCPU_HASH�LPM_TRIE�
ARRAY_OF_MAPS�HASH_OF_MAPS�DEVMAP�SOCKMAP�CPUMAP�XSKMAP�SOCKHASH�CGROUP_STORAGE�REUSEPORT_SOCKARRAY�PERCPU_CGROUP_STORAGE�QUEUE�STACK�
SK_STORAGE�DEVMAP_HASH�
STRUCT_OPS�RINGBUF�
INODE_STORAGE�TASK_STORAGE�(�Aic�n�d}d}	|||z|zdz
kDs||dz
kDrn|dz
}|dz
}�"||kDr|dddz}|S)Nr�r�*����+�)�val�val_max�width�i�texts     �+/usr/lib/python3/dist-packages/bcc/table.py�_starsrVcsf��	�A�
�D��
����w�&�!�+�+��U�Q�Y�������	�Q���	
�
�W�}��C�R�y�3����K�c��t||d��S)N)�section_bucket)�_get_json_hist)�vals�val_typerYs   rU�
get_json_histr]os���$���>�>rWc�b�g}d}tt|��D]
}||dk7s�|}�d}d}tt|��D]O}|dk7s�	||ks�|dz}i}||d<t|�dz
|d<t||�|d<|j|�|}�Qt	d�||d�}	|r|d|	|d<|	S)	Nrrrzinterval-startzinterval-end�countz%Y-%m-%d %H:%M:%S)�tsr\�data)�range�len�int�appendr)
r[r\rY�	hist_list�max_nonzero_idxrS�index�prev�list_obj�	histograms
          rUrZrZrs����I��O�
�3�t�9�
� ����7�a�<��O� �
�E��D�
�3�t�9�
�����6�a�?�*��A�I�E��H�)-�H�%�&�'*�5�z�A�~�H�^�$� #�D��G��H�W�����X�&��D�� � 3�4�(�T]�^�I��'5�a�'8�	�.��#�$��rWc
��d}d}d}t|�D]\}}|dkDr|}||kDs�|}�|dkrd}d}	t}
nd}d}	ttd	z�}
|dkDrt||z�t	d
|d
z�D]e}d
|zd
z	}d
|zd
z
}||k(r|d
z}||}
|r$|
s�'t|	|||
|
t|
||
�fz�d}�Ht|	|||
|
t|
||
�fz��gy)N�@rMr� z#     %-19s : count     distributionz%10d -> %-10d : %-8d |%-*s|z-               %-29s : count     distributionz%20d -> %-20d : %-8d |%-*s|rrF)�	enumerate�	stars_maxrd�printrbrV)r[r\�strip_leading_zero�
log2_dist_max�idx_maxrQrS�v�header�body�stars�low�highrPs              rU�_print_log2_histr{�s+���M��G��G��$��$���1��q�5�A�'��w�;�!��$��"�}�6��,����@��,���I��M�"����{�
�f�x�� �
�1�g��k�
"�8���A�v�!�m���Q��!�|���4�K��1�H�C��1�g�����d�c�4��e�$�S�'�5�9�;�;�<�%*�"��$�#�t�S�%� ��g�u�5�7�7�
8�8rWc�D�d}d}d}t|�D]\}}|dkDr|}||kDs�|}�d}d}	t}
|dk\rt||z�td|dz�D]I}||}|r#|s�
t|	|||
t	|||
�fz�d}�-t|	|||
t	|||
�fz��Ky)NrmrMrz#     %-13s : count     distributionz        %-10d : %-8d |%-*s|rF)rorprqrbrV)r[r\rrrsrtrQrSrurvrwrxrPs            rU�_print_linear_histr}�s����M��G��G��$��$���1��q�5�A�'��w�;�!��$�3�F�(�D��E��!�|�
�f�x�� �
�1�g��k�
"�
<���1�g�����d�a��e�$�S�'�5�9�;�;�<�%*�"��d�a��e�$�S�'�5�9�;�;�<�
<rWc�4�	t|S#t$rYywxYw)Nz	<unknown>)�
map_type_name�KeyError)�ttypes rU�get_table_type_namer��s$����U�#�#������s��	�c	��idtj�dtj�dtj�dtj�dtj�dtj�dtj�dtj�d	tj
�d
tj
�dtj�dtj�d
tj�dtj�dtj�dtj�dtj�tjtjtjtjtjdztjdztjd��}tjd�}g}tj |j"j$|j&�}d}||k�r
tj(|j"j$|j&|�j+�}tj,d|�}|j/d�}|j/d�}	tj,d|	�rd
}	|j-|	�}	|rA|j1|||j/d�t3|j/d��zf�n|j1|||	f�|dz
}||kr��
t?dtj@fd|i�S#t4$r6t7d|	zt8j:��t9j<d�Y�hwxYw)N�char�s8z
unsigned char�u8zu8 *zchar *�short�s16zunsigned short�u16rd�s32�enumzunsigned int�u32�longz
unsigned longr)z	long long�s64zunsigned long long�u64�__int128zunsigned __int128zvoid *z(\S+(?: \S+)*) ?\[([0-9]+)\]$rz	(.*)#(.*)rzenum .*zGType: '%s' not recognized. Please define the data with ctypes manually.)�filerK�_fields_)!�ct�c_char�c_ubyte�c_char_p�c_short�c_ushort�c_int�c_uint�c_long�c_ulong�
c_longlong�c_ulonglong�c_void_p�re�compiler�bpf_perf_event_fields�bpf�module�_name�bpf_perf_event_field�decode�match�grouprerdr�rq�sys�stderr�exit�type�	Structure)
�	event_map�
ct_mapping�
array_type�fields�
num_fieldsrS�field�m�
field_name�
field_types
          rU�_get_event_classr��s�����b�i�i���b�i�i��	�b�j�j��	
�b�j�j�	�
	�b�k�k��	�b�k�k�
�	�b�j�j��	�b�j�j��	�b�k�k��	�b�k�k��	�b�h�h��	�b�h�h��	�b�h�h��	�b�i�i��	�b�i�i�� 	�b�i�i�!�"	�b�j�j�#�$!�m�m� �m�m� �n�n� �n�n�!�}�}�q�0�!�~�~��1� �k�k�1�J�8���<�=�J�
�F��*�*�9�=�=�+?�+?����Q�J�	�A�
�j�.��(�(����)=�)=�y���PQ�R�Y�Y�[���H�H�\�5�)���W�W�Q�Z�
��W�W�Q�Z�
�
�8�8�J�
�+��J����Z�(��
	���
�
�z�:�a�g�g�a�j�+A�C����PQ�
�O�+S�T�U��
�
�z�:�j�+A�B�C�	
�Q���+�j�.�,��R�\�\�O�j�&�%9�:�:���	�
�[���%(�Z�Z�
1��H�H�Q�K�	�s�AL�<M�Mc��tj|j|�}d}|tk(rt	|||||�}�n�|t
k(rt
|||||�}�n�|tk(rt|||||�}�n�|tk(rt||||||�}�nl|tk(rt|||||fi|��}�nQ|tk(rt|||||fi|��}�n6|tk(rt!|||||�}�n|t"k(rt%|||||�}�n|t&k(rt)|||||�}n�|t*k(rt-|||||�}n�|t.k(rt1|||||�}n�|t2k(rt5|||||�}n�|t6k(rt9|||||�}n�|t:k(rt=|||||�}nl|t>k(rtA|||||�}nS|tBk(rtE|||||�}n:|tFk(s	|tHk(rtK||||�}n|tLk(rtO||||||�}|dk(rtQd|z��|S)z|Table(bpf, map_id, map_fd, keytype, leaftype, **kwargs)

    Create a python object out of a reference to a bpf table handleNzUnknown table type %d))r�bpf_table_type_idr��BPF_MAP_TYPE_HASH�	HashTable�BPF_MAP_TYPE_ARRAY�Array�BPF_MAP_TYPE_PROG_ARRAY�	ProgArray�BPF_MAP_TYPE_PERF_EVENT_ARRAY�PerfEventArray�BPF_MAP_TYPE_PERCPU_HASH�
PerCpuHash�BPF_MAP_TYPE_PERCPU_ARRAY�PerCpuArray�BPF_MAP_TYPE_LPM_TRIE�LpmTrie�BPF_MAP_TYPE_STACK_TRACE�
StackTrace�BPF_MAP_TYPE_LRU_HASH�LruHash�BPF_MAP_TYPE_LRU_PERCPU_HASH�
LruPerCpuHash�BPF_MAP_TYPE_CGROUP_ARRAY�CgroupArray�BPF_MAP_TYPE_DEVMAP�DevMap�BPF_MAP_TYPE_CPUMAP�CpuMap�BPF_MAP_TYPE_XSKMAP�XskMap�BPF_MAP_TYPE_ARRAY_OF_MAPS�
MapInMapArray�BPF_MAP_TYPE_HASH_OF_MAPS�MapInMapHash�BPF_MAP_TYPE_QUEUE�BPF_MAP_TYPE_STACK�
QueueStack�BPF_MAP_TYPE_RINGBUF�RingBuf�	Exception)	r��map_id�map_fd�keytype�leaftype�name�kwargsr��ts	         rU�Tabler�s6��

�!�!�#�*�*�f�5�E��A��!�!��c�6�6�7�H�=��	�$�	$��#�v�v�w��9��	�)�	)��c�6�6�7�H�=��	�/�	/��3�����4�H��	�*�	*��s�F�F�G�X�H��H��	�+�	+���V�V�W�h�I�&�I��	�'�	'��C����(�;��	�*�	*��s�F�F�G�X�>��	�'�	'��C����(�;��	�.�	.��#�v�v�w��A��	�+�	+���V�V�W�h�?��	�%�	%��3�����:��	�%�	%��3�����:��	�%�	%��3�����:��	�,�	,��#�v�v�w��A��	�+�	+���f�f�g�x�@��	�$�	$��1C�(C��s�F�F�H�5��	�&�	&��C����(�D�A���D�y��/�%�7�8�8��HrWc��eZdZd"d�Zd�Zd�Zd�Zd�Zd�Zd�Z	d	�Z
d
�Zd�Zd�Z
d
�Zd�Zd�Zd#d�Zd$d�Zd�Zd"d�Zd�Zd�Zd%d�Zd�Zd�Zd�Zd�ZGd�de�Zd�Zefd�Z 		d&d�Z!			d'd �Z"			d'd!�Z#y)(�	TableBaseNc���||_||_||_||_||_tj|jj|j�|_tj|jj|j�|_
i|_||_ttj|jj|j��|_y�N)r�r�r��Key�Leafrr�r�r��bpf_table_flags_id�flags�_cbsr�rd�bpf_table_max_entries_id�max_entries)�selfr�r�r�r�r�r�s       rU�__init__zTableBase.__init__Bs�����������������	��*�*�4�8�8�?�?�D�K�K�H��
��+�+�D�H�H�O�O�T�[�[�I��
���	���
��s�;�;�D�H�H�O�O���� ���rWc��|jSr�)r��r�s rU�get_fdzTableBase.get_fdOs���{�{�rWc	�J�tjtj|j�dz�}t	j
|jj|j|t|�tj|��}|dkrtd��|jS)NrrzCould not printf key)
r��create_string_buffer�sizeofr�r�bpf_table_key_snprintfr�r�r�rc�byrefr��value)r��key�buf�ress    rU�key_sprintfzTableBase.key_sprintfRsu���%�%�b�i�i����&9�A�&=�>���(�(������$�+�+�s�),�S��2�8�8�C�=�B����7��2�3�3��y�y�rWc	�J�tjtj|j�dz�}t	j
|jj|j|t|�tj|��}|dkrtd��|jS�NrrzCould not printf leaf�
r�r�r�r�r�bpf_table_leaf_snprintfr�r�r�rcr�r�r��r��leafrrs    rU�leaf_sprintfzTableBase.leaf_sprintfZ�u���%�%�b�i�i��	�	�&:�Q�&>�?���)�)�$�(�(�/�/�4�;�;��*-�c�(�B�H�H�T�N�D����7��3�4�4��y�y�rWc���|j�}tj|jj|j
|t
j|��}|dkrtd��|S)NrzCould not scanf key)	r�r�bpf_table_key_sscanfr�r�r�r�r�r�)r��key_strr�rs    rU�	key_scanfzTableBase.key_scanfbsR���h�h�j���&�&�t�x�x������W�')�x�x��}�6����7��1�2�2��
rWc���|j�}tj|jj|j
|t
j|��}|dkrtd��|S�NrzCould not scanf leaf�	r�r�bpf_table_leaf_sscanfr�r�r�r�r�r��r��leaf_strrrs    rU�
leaf_scanfzTableBase.leaf_scanfj�R���y�y�{���'�'���������h�(*�����8����7��2�3�3��rWc���|j�}tj|jt	j
|�t	j
|��}|dkrt�|S�Nr�r�r�bpf_lookup_elemr�r�r�r��r�r�rrs    rU�__getitem__zTableBase.__getitem__rsF���y�y�{���!�!�$�+�+�r�x�x��}�b�h�h�t�n�M����7��N��rWc��tj|jtj|�tj|�d�}|dkr5tjtj��}td|z��y)NrzCould not update table: %s�	r�bpf_update_elemr�r�r��os�strerror�	get_errnor�)r�r�rr�errstrs     rU�__setitem__zTableBase.__setitem__ys]���!�!�$�+�+�r�x�x��}�b�h�h�t�n�a�P����7��[�[�����0�F��8�6�A�B�B�rWc��tj|jtj|��}|dkrt
�yr)r�bpf_delete_elemr�r�r�r�)r�r�rs   rU�__delitem__zTableBase.__delitem__s1���!�!�$�+�+�r�x�x��}�=����7��N�rWc#�HK�|D]
}	||���y#t$rY�wxYw�wr��r��r�r�s  rU�
itervalueszTableBase.itervalues�s6�����	�C�
��3�i��		��
�
��
�s�"��"�	�"��"c#�LK�|D]}	|||f���y#t$rY�wxYw�wr�r)r*s  rU�	iteritemszTableBase.iteritems�s<�����	�C�
��D��I�&�&�	���
��
�s�$�	�$�	!�$�!�$c�H�|j�D�cgc]}|��c}Scc}wr�)r-)r��items  rU�itemszTableBase.items�s��!%���!1�2���2�2��2��	c�H�|j�D�cgc]}|��c}Scc}wr��r+�r�r�s  rU�valueszTableBase.values����#'�?�?�#4�5�%��5�5��5r1c�P�|j�D]}|j|��yr�)�keysr'�r��ks  rU�clearzTableBase.clear�s%������	 �A����Q��	 rWc�&�dx}}|s|stjd�ddfS|s
|j}n|dks||jkDrtd��|r|j|z�}|r|j
|z�}tj|�||fS)a�Allocate keys and/or values arrays. Useful for in items_*_batch.

        Args:
            alloc_k (bool): True to allocate keys array, False otherwise.
            Default is False.
            alloc_v (bool): True to allocate values array, False otherwise.
            Default is False.
            count (int): number of elements in the array(s) to allocate. If
            count is None then it allocates the maximum number of elements i.e
            self.max_entries.

        Returns:
            tuple: (count, keys, values). Where count is ct.c_uint32,
            and keys and values an instance of ct.Array
        Raises:
            ValueError: If count is less than 1 or greater than
            self.max_entries.
        NrrzWrong count)r��c_uint32r��
ValueErrorr�r�)r��alloc_k�alloc_vr_r8r5s      rU�_alloc_keys_valueszTableBase._alloc_keys_values�s���&���v��w��K�K��N�D�$�/�/���$�$�E�
�Q�Y�%�$�"2�"2�2��]�+�+��$�D�H�H�u�$�'�D��'�d�i�i�%�'�*�F����E�"�D�&�1�1rWc�(�d}||fD]O}|s�t|tj�st�t	|�}|dks||j
kDs�Ft
d��|r$|r"t	|�t	|�k7rt
d��tj|�S)a�Check if the given keys or values have the right type and size.

        Args:
            keys (ct.Array): keys array to check
            values (ct.Array): values array to check
        Returns:
            ct.c_uint32 : the size of the array(s)
        Raises:
            ValueError: If length of arrays is less than 1 or greater than
            self.max_entries, or when both arrays length are different.
            TypeError: If the keys and values are not an instance of ct.Array
        rrzArray's length is wrongz(keys array length != values array length)�
isinstancer�r��	TypeErrorrcr�r>r=)r�r8r5�arr_len�elems     rU�_sanity_check_keys_valuesz#TableBase._sanity_check_keys_values�s������6�N�	@�D��!�$����1�#�O��d�)���Q�;�'�D�,<�,<�"<�$�%>�?�?�	@��F��4�y�C��K�'� �!K�L�L��{�{�7�#�#rWc#�LK�|jd��D]\}}||f���
y�w)aLook up all the key-value pairs in the map.

        Args:
            None
        Yields:
            tuple: The tuple of (key,value) for every entries that have
            been looked up.
        Notes: lookup batch on a keys subset is not supported by the kernel.
        F��deleteN��)_items_lookup_and_optionally_delete_batch�r�r:rus   rU�items_lookup_batchzTableBase.items_lookup_batch�s5�����B�B�%�B�P�	�D�A�q��Q��K�	����"$c�X�|��|j|��}tj|jt	j
|�t	j
|��}|dk7r3t
dtjt	j��z��y|j�D]}yy)a�Delete the key-value pairs related to the keys given as parameters.
        Note that if no key are given, it is faster to call
        lib.bpf_lookup_and_delete_batch than create keys array and then call
        lib.bpf_delete_batch on these keys.

        Args:
            ct_keys (ct.Array): keys array to delete. If an array of keys is
            given then it deletes all the related keys-values.
            If keys is None (default) then it deletes all entries.
        Yields:
            tuple: The tuple of (key,value) for every entries that have
            been deleted.
        Raises:
            Exception: If bpf syscall return value indicates an error.
        N)r8rz#BPF_MAP_DELETE_BATCH has failed: %s)rGr�bpf_delete_batchr�r�r�r�r r!r"�items_lookup_and_delete_batch)r��ct_keys�ct_cntr�_s     rU�items_delete_batchzTableBase.items_delete_batch�s��� ���3�3��3�A�F��&�&�t�{�{�')�x�x��'8�')�x�x��'7�)�C��q��� E�"$�+�+�b�l�l�n�"=�!>�?�?��
�7�7�9�
���
rWc�P�|j||��}tj|jt	j
|�t	j
|�t	j
|��}|dk7r3t
dtjt	j��z��y)aqUpdate all the key-value pairs in the map provided.
        The arrays must be the same length, between 1 and the maximum number
        of entries.

        Args:
            ct_keys (ct.Array): keys array to update
            ct_values (ct.Array): values array to update
        Raises:
            Exception: If bpf syscall return value indicates an error.
        )r8r5rz#BPF_MAP_UPDATE_BATCH has failed: %sN)
rGr�bpf_update_batchr�r�r�r�r r!r")r�rS�	ct_valuesrTrs     rU�items_update_batchzTableBase.items_update_batchs����/�/�W�Y�/�O���"�"�4�;�;�#%�8�8�G�#4�#%�8�8�I�#6�#%�8�8�F�#3�%��

�1�H��A� �k�k�"�,�,�.�9�:�;�
;�
rWc#�LK�|jd��D]\}}||f���
y�w)a?Look up and delete all the key-value pairs in the map.

        Args:
            None
        Yields:
            tuple: The tuple of (key,value) for every entries that have
            been looked up and deleted.
        Notes: lookup and delete batch on a keys subset is not supported by
        the kernel.
        TrINrKrMs   rUrRz'TableBase.items_lookup_and_delete_batch#s5�����B�B�$�B�O�	�D�A�q��Q��K�	��rOc#�ZK�|durtj}d}ntj}d}|jdd��\}}}t	j
d�x}}d}		|j|	z
|_||j|	rt	j|�ndt	j|�t	j|t	j|j�|	z�t	j|t	j|j�|	z�t	j|��}
t	j�}|	|jz
}	|
dk7r6|tjk7r#t|�dt!j"|�����|
dk7rn"|	|jk(rn|jdk(rn��Vt%d|	�D]h}||}
||}t'|
tj(�s|j|
�}
t'|tj(�s|j|�}|
|f���jy�w)a�Look up and optionally delete all the key-value pairs in the map.

        Args:
            delete (bool) : look up and delete the key-value pairs when True,
            else just look up.
        Yields:
            tuple: The tuple of (key,value) for every entries that have
            been looked up and deleted.
        Raises:
            Exception: If bpf syscall return value indicates an error.
        Notes: lookup and delete batch on a keys subset is not supported by
        the kernel.
        T�BPF_MAP_LOOKUP_AND_DELETE_BATCH�BPF_MAP_LOOKUP_BATCH)r?r@rNz
 has failed: )r�bpf_lookup_and_delete_batch�bpf_lookup_batchrAr�r=r�r�r�r�r�r�r"�errno�ENOENTr�r r!rbrCr�)r�rJ�	bpf_batch�bpf_cmd�ct_buf_sizerSrY�ct_out_batchrT�totalr�errcoderSr:rus               rUrLz3TableBase._items_lookup_and_optionally_delete_batch2s������T�>��7�7�I�7�G��,�,�I�,�G�+/�*A�*A�$�JN�+B�+P�'��W�i� "���A��.��v����&�,�,�u�4�F�L��D�K�K�6;�B�H�H�\�2���H�H�\�2��H�H�W�b�i�i����.A�E�.I�J��H�H�Y��	�	�$�)�)�0D�u�0L�M��H�H�V�,��C��l�l�n�G��V�\�\�!�E��q��W����4��w�79�{�{�7�7K�!M�N�N��a�x����)�)�)���|�|�q� ��1�4�q�%��	�A���
�A��!��A��a����.��H�H�Q�K���a����.��I�I�a�L���a�&�L�	�s�H)H+c�f�t|j��D]}|j�||<�yr�)�listr8r�r9s  rU�zerozTableBase.zeroos-��
�d�i�i�k�"�	"�A��i�i�k�D��G�	"rWc�,�tj|�Sr�)r��Iterr�s rU�__iter__zTableBase.__iter__ws���~�~�d�#�#rWc�"�|j�Sr��rnr�s rU�iterzTableBase.iterz�
��4�=�=�?�*rWc�"�|j�Sr�rpr�s rUr8zTableBase.keys{rrrWc�$�eZdZd�Zd�Zd�Zd�Zy)�TableBase.Iterc� �||_d|_yr�)�tabler�)r�rws  rUr�zTableBase.Iter.__init__~s���D�J��D�HrWc��|Sr�rOr�s rUrnzTableBase.Iter.__iter__�����KrWc�"�|j�Sr���nextr�s rU�__next__zTableBase.Iter.__next__�����9�9�;�rWc�n�|jj|j�|_|jSr�)rwr|r�r�s rUr|zTableBase.Iter.next�s#���z�z���t�x�x�0�D�H��8�8�OrWN��__name__�
__module__�__qualname__r�rnr}r|rOrWrUrmru}s��	�	�	�	rWrmc�z�|j�}|�Rtj|jt	j
|�t	j|j��}nGtj|jt	j
|�t	j
|��}|dkr
t��|Sr)	r�r�bpf_get_first_keyr�r�r�r��bpf_get_next_key�
StopIteration)r�r��next_keyrs    rUr|zTableBase.next�s����8�8�:���;��'�'����R�X�X�h�5G�(*�	�	�$�(�(�(;�=�C��&�&�t�{�{�B�H�H�S�M�')�x�x��'9�;�C���7��/�!��rWc�8�|jjdd}|jjdd}|dk(r>t|jj�dk(r|jjdd}|j�D]Q\}}	t	||�}
|r||
�}
|j|
dg|z�x}||
<t	||�}|	j||<�St|j��}
|r||
�}
|
D]}
|j|
��y)Nrr�__pad_1rr)
r�r�rcr0�getattr�getr�rjr8re)r��tmp�buckets�	bucket_fn�bucket_sort_fn�	index_max�f1�f2r:ru�bucketr[�slot�buckets_lsts              rU�decode_c_structzTableBase.decode_c_struct�s��
�X�X�
�
�q�
!�!�
$��
�X�X�
�
�q�
!�!�
$����?�s�4�8�8�#4�#4�5��:����"�"�1�%�a�(�B��J�J�L�	!�D�A�q��Q��^�F��"�6�*��!$����!��y��!A�A�D�3�v�;��1�b�>�D����D��J�
	!��3�8�8�:�&���(��5�K�!�	#�F��N�N�6�"�	#rWc��t|j�tj�rLi}g}|j	||||�|D].}||}	|r|||�f}
n||f}
tt
|	||
���0ydgtz}	|j�D]\}}|j|	|j<� tt
|	|��y)a.print_json_hist(val_type="value", section_header="Bucket ptr",
                                   section_print_fn=None, bucket_fn=None,
                                   bucket_sort_fn=None):

                Prints a table as a json histogram. The table must be stored as
                log2. The val_type argument is optional, and is a column header.
                If the histogram has a secondary key, the dictionary will be split by secondary key
                If section_print_fn is not None, it will be passed the bucket value
                to format into a string as it sees fit. If bucket_fn is not None,
                it will be used to produce a bucket value for the histogram keys.
                If bucket_sort_fn is not None, it will be used to sort the buckets
                before iterating them, and it is useful when there are multiple fields
                in the secondary key.
                The maximum index allowed is log2_index_max (65), which will
                accommodate any 64-bit integer in the histogram.
                rN)
rCr�r�r�r�rqrZ�log2_index_maxr0r�)
r�r\�section_header�section_print_fnr�r�r�r�r�r[rYr:rus
             rU�print_json_histzTableBase.print_json_hist�s���$�d�h�h�j�"�,�,�/��C��G�� � ��g�y�.�I�!�
F���6�{��#�&4�6F�v�6N�%O�N�&4�f�%=�N��n�T�8�^�D�E�

F��3��'�D��
�
��
(���1� !����Q�W�W�
�
(��.��x�0�1rWc	��t|j�tj�r]i}g}|j	||||�|D]?}	||	}
|rtd|�d||	����ntd|�d|	���t
|
||��Aydgtz}
|j�D]\}}|j|
|j<� t
|
||�y)a�print_log2_hist(val_type="value", section_header="Bucket ptr",
                           section_print_fn=None, bucket_fn=None,
                           strip_leading_zero=None, bucket_sort_fn=None):

        Prints a table as a log2 histogram. The table must be stored as
        log2. The val_type argument is optional, and is a column header.
        If the histogram has a secondary key, multiple tables will print
        and section_header can be used as a header description for each.
        If section_print_fn is not None, it will be passed the bucket value
        to format into a string as it sees fit. If bucket_fn is not None,
        it will be used to produce a bucket value for the histogram keys.
        If the value of strip_leading_zero is not False, prints a histogram
        that is omitted leading zeros from the beginning.
        If bucket_sort_fn is not None, it will be used to sort the buckets
        before iterating them, and it is useful when there are multiple fields
        in the secondary key.
        The maximum index allowed is log2_index_max (65), which will
        accommodate any 64-bit integer in the histogram.
        �
� = rN)
rCr�r�r�r�rqr{r�r0r��
r�r\r�r�r�rrr�r�r�r�r[r:rus
             rU�print_log2_histzTableBase.print_log2_hist�s���,�d�h�h�j�"�,�,�/��C��G�� � ��g�y�.�I�!�
E���6�{��#���(��0�2�3����@�A� ��x�1C�D�
E��3��'�D��
�
��
(���1� !����Q�W�W�
�
(��T�8�-?�@rWc	��t|j�tj�rbi}g}|j	||||t
�|D]?}	||	}
|rt
d|�d||	����nt
d|�d|	���t|
||��Aydgt
z}
|j�D]\}}	|j|
|j<�!t|
||�y#t$rtd|jt
fz��wxYw)a�print_linear_hist(val_type="value", section_header="Bucket ptr",
                           section_print_fn=None, bucket_fn=None,
                           strip_leading_zero=None, bucket_sort_fn=None)

        Prints a table as a linear histogram. This is intended to span integer
        ranges, eg, from 0 to 100. The val_type argument is optional, and is a
        column header.  If the histogram has a secondary key, multiple tables
        will print and section_header can be used as a header description for
        each.  If section_print_fn is not None, it will be passed the bucket
        value to format into a string as it sees fit. If bucket_fn is not None,
        it will be used to produce a bucket value for the histogram keys.
        If the value of strip_leading_zero is not False, prints a histogram
        that is omitted leading zeros from the beginning.
        If bucket_sort_fn is not None, it will be used to sort the buckets
        before iterating them, and it is useful when there are multiple fields
        in the secondary key.
        The maximum index allowed is linear_index_max (1025), which is hoped
        to be sufficient for integer ranges spanned.
        r�r�rz5Index in print_linear_hist() of %d exceeds max of %d.N)rCr�r�r�r��linear_index_maxrqr}r0r��
IndexErrorr�s
             rU�print_linear_histzTableBase.print_linear_hist�s��,�d�h�h�j�"�,�,�/��C��G�� � ��g�y�.�JZ�[�!�
G���6�{��#���(��0�2�3����@�A�"�4��3E�F�
G��3�)�)�D��
�
��
M���1�M�$%�G�G�D����M�
M�
�t�X�/A�B��"�M�%�'-�12���:J�0K�&L�M�M�M�s�,C�(C=r�)FFN)NN)T)r��
Bucket ptrNNN)r�r�NNNN)$r�r�r�r�r�rr	rrrr$r'r+r-r0r5r;rArGrNrVrZrRrLrkrnrqr8�objectrmr|r�r�r�r�r�rOrWrUr�r�@s����������C����3�6� �
!2�F$�<��<;�*
�;�z"�$�+�*�
�v�
��R`�#�.@L�NR�"2�H@L�FJ��&A�PBN�FJ��-CrWr�c�$��eZdZ�fd�Zd�Z�xZS)r�c�,��tt|�
|i|��yr�)�superr�r��r��argsr��	__class__s   �rUr�zHashTable.__init__+����
�i��'��8��8rWc�"�d}|D]}|dz
}�	|S�NrrrO�r�rSr:s   rU�__len__zHashTable.__len__.���
����A�q�A�v�q���rW�r�r�r�r�r��
__classcell__�r�s@rUr�r�*s
���9�rWr�c���eZdZ�fd�Z�xZS)r�c�,��tt|�
|i|��yr�)r�r�r�r�s   �rUr�zLruHash.__init__4����
�g�t�%�t�6�v�6rW�r�r�r�r�r�r�s@rUr�r�3s
���7�7rWr�c�j��eZdZ�fd�Zd�Zd�Z�fd�Z�fd�Z�fd�Zd�Z	d�Z
Gd	�d
e�Z�xZ
S)�	ArrayBasec�,��tt|�
|i|��yr�)r�r�r�r�s   �rUr�zArrayBase.__init__8r�rWc��t|t�r$|dkrt|�|z}|j|�}t|tj
�st
d��|jt|�k\rt
d��|S)Nrz#Array index must be an integer typezArray index out of range)rCrdrcr�r��_SimpleCDatar�r�r*s  rU�_normalize_keyzArrayBase._normalize_key;sh���c�3���Q�w��$�i�#�o���(�(�3�-�C��#�r���/��B�C�C��9�9��D�	�!��7�8�8��
rWc��|jSr�)r�r�s rUr�zArrayBase.__len__Fs�����rWc�L��|j|�}tt|�|�Sr�)r�r�r�r�r�r�r�s  �rUrzArrayBase.__getitem__Is%����!�!�#�&���Y��1�#�6�6rWc�P��|j|�}tt|�||�yr�)r�r�r�r$�r�r�rr�s   �rUr$zArrayBase.__setitem__Ms$����!�!�#�&��
�i��*�3��5rWc�N��|j|�}tt|�|�yr�)r�r�r�r'r�s  �rUr'zArrayBase.__delitem__Qs"����!�!�#�&��
�i��*�3�/rWc��|j|�}|j�}tj|jtj|�tj|�d�}|dkrtd��y)NrzCould not clear item)r�r�rrr�r�r�r�rs    rU�	clearitemzArrayBase.clearitemUs_���!�!�#�&���y�y�{���!�!�$�+�+�r�x�x��}�b�h�h�t�n�a�P����7��2�3�3�rWc�B�tj||j�Sr�)r�rmr�r�s rUrnzArrayBase.__iter__\s���~�~�d�D�H�H�-�-rWc�$�eZdZd�Zd�Zd�Zd�Zy)�ArrayBase.Iterc�.�||_||_d|_y�NrM)r�rwrS)r�rwr�s   rUr�zArrayBase.Iter.__init__`s���D�H��D�J��D�FrWc��|Sr�rOr�s rUrnzArrayBase.Iter.__iter__eryrWc�"�|j�Sr�r{r�s rUr}zArrayBase.Iter.__next__gr~rWc��|xjdz
c_|jt|j�k(r
t��|j	|j�S�Nr)rSrcrwr�r�r�s rUr|zArrayBase.Iter.nextis>���F�F�a�K�F��v�v��T�Z�Z��(�#�o�%��8�8�D�F�F�#�#rWNr�rOrWrUrmr�_s��	�
	�	�	$rWrm)r�r�r�r�r�r�rr$r'r�rnr�rmr�r�s@rUr�r�7s<���9�	� �7�6�0�4�.�$�v�$�$rWr�c�$��eZdZ�fd�Zd�Z�xZS)r�c�,��tt|�
|i|��yr�)r�r�r�r�s   �rUr�zArray.__init__ps���
�e�T�#�T�4�V�4rWc�&�|j|�yr��r�r*s  rUr'zArray.__delitem__s������s�rW)r�r�r�r�r'r�r�s@rUr�r�os
���5�rWr�c�(��eZdZ�fd�Z�fd�Z�xZS)r�c�,��tt|�
|i|��yr�)r�r�r�r�s   �rUr�zProgArray.__init__xr�rWc����t|t�r|j|�}t||jj�r|j|j
�}tt|�#||�yr�)	rCrdr�r��Function�fdr�r�r$r�s   �rUr$zProgArray.__setitem__{sQ����d�C� ��9�9�T�?�D��d�D�H�H�-�-�.��9�9�T�W�W�%�D�
�i��*�3��5rW�r�r�r�r�r$r�r�s@rUr�r�ws���9�6�6rWr�c�*�eZdZd�Zd�Zd�Zd�Zd�Zy)�FileDescc�6�|�|dkrtd��||_y)NrzInvalid file descriptor)r�r�)r�r�s  rUr�zFileDesc.__init__�s ���J�B��F��5�6�6���rWc��|j�7|jdk\r'tj|j�d|_yyyr)r�r �closer�s rU�clean_upzFileDesc.clean_up�s5���G�G��d�g�g��l��H�H�T�W�W���D�G�'3�rWc�$�|j�yr��r�r�s rU�__del__zFileDesc.__del__�����
�
�rWc��|Sr�rO�r�r�r�s   rU�	__enter__zFileDesc.__enter__�s���rWc�$�|j�yr�r�r�s   rU�__exit__zFileDesc.__exit__�r�rWN)r�r�r�r�r�r�r�r�rOrWrUr�r��s���
�
��rWr�c�(��eZdZ�fd�Z�fd�Z�xZS)r�c�,��tt|�
|i|��yr�)r�r�r�r�s   �rUr�zCgroupArray.__init__�s���
�k�4�)�4�:�6�:rWc���t|t�r$tt|�||j|��yt|t�rdttj|tj��5}tt|�||j|j��ddd�ytd��#1swYyxYw)Nz1Cgroup array key must be either FD or cgroup path)
rCrdr�r�r$r��strr�r �open�O_RDONLYr�r�)r�r�r�fr�s    �rUr$zCgroupArray.__setitem__�s�����d�C� ��+�t�0��d�i�i��o�F�
��c�
"��"�'�'�$����4�5�
K���k�4�4�S�$�)�)�A�D�D�/�J�
K�
K��O�P�P�
K�
K�s�3.B5�5B>r�r�s@rUr�r��s���;�Q�QrWr�c�R��eZdZ�fd�Zd�Z�fd�Zd�Zd	d�Zd�Zd
d�Z	d
d�Z
�xZS)r�c�H��tt|�
|i|��i|_d|_yr�)r�r�r��
_open_key_fds�_event_classr�s   �rUr�zPerfEventArray.__init__�s'���
�n�d�,�d�=�f�=���� ��rWc�^�t|jj��}|D]}||=�yr�)rjr�r8)r�r8r�s   rUr�zPerfEventArray.__del__�s1���D�&�&�+�+�-�.���	�C��S�	�	rWc���||jvrytt|�|�t	|�|f}||j
jvrQtj|j
j|�|j
j|=|j|=n"tj|j|�|j|=yr�)r�r�r�r'�idr��perf_buffersr�perf_reader_freer��bpf_close_perf_event_fd)r�r��key_idr�s   �rUr'zPerfEventArray.__delitem__�s�����d�(�(�(��
�n�d�/��4��T�(�C����T�X�X�*�*�*�� � ����!6�!6�v�!>�?����%�%�f�-��	�	�#��
�'�'��(:�(:�3�(?�@����s�#rWc��|jdk(rt|�|_tj|tj|j��j
S)a	event(data)

        When perf buffers are opened to receive custom perf event,
        the underlying event data struct which is defined in C in
        the BPF program can be deduced via this function. This avoids
        redundant definitions in Python.
        N�r�r�r��cast�POINTER�contents�r�ras  rU�eventzPerfEventArray.event��E������$� 0�� 6�D���w�w�t�R�Z�Z��(9�(9�:�;�D�D�DrWc�x�||dz
zdk7rtd��t�D]}|j|||||��y)azopen_perf_buffers(callback)

        Opens a set of per-cpu ring buffer to receive custom perf event
        data from the bpf program. The callback will be invoked for each
        event submitted from the kernel, up to millions per second. Use
        page_cnt to change the size of the per-cpu ring buffer. The value
        must be a power of two and defaults to 8.
        rrz+Perf buffer page_cnt must be a power of twoN)r�r
�_open_perf_buffer)r��callback�page_cnt�lost_cb�
wakeup_eventsrSs      rU�open_perf_bufferzPerfEventArray.open_perf_buffer�sK���x�!�|�$��)��I�J�J� �"�	R�A��"�"�1�h��'�=�Q�	RrWc	�,������fd�}�fd�}t|�}�rt|�ntjdt�}	t	�}
d|
_�|
_||
_tj||	d|tj|
��}|std��tj|�}|j|�||j��<||jj t#|��f<||	f|j$�<d|j&�<y)Nc���	��||�y#t$r4}|jtjk(rt�n|�Yd}~yd}~wwxYwr���IOErrorra�EPIPEr�)rUra�size�er�cpus    ��rU�raw_cb_z1PerfEventArray._open_perf_buffer.<locals>.raw_cb_�sC���
���d�D�)���
��7�7�e�k�k�)��F��G���
�s�
�	A�*A�Ac���	�|�y#t$r4}|jtjk(rt�n|�Yd}~yd}~wwxYwr�r)rU�lostrr
s   �rU�lost_cb_z2PerfEventArray._open_perf_buffer.<locals>.lost_cb_�s>���
���
���
��7�7�e�k�k�)��F��G���
�s��	A	�*A�A	rMzCould not open perf buffer)r	r
r�rr�pidrrr�bpf_open_perf_buffer_optsr�r��perf_reader_fdr�r�r�r�r�r�r�)
r�rrr	r
rrr�fn�lost_fn�opts�readerr�s
 `` `        rUrz PerfEventArray._open_perf_buffer�s����	�	��'�
"��-4�-��)�"�'�'�$�
�:V��#�%��������*����.�.�r�7�D�(�B�H�H�UY�N�[����8�9�9�
�
�
��
'��"�i�i��m��T�X�X�c�]��17������r�$�x��o�.��g���	�	�#��"$����3�rWc��tj||||�}|dkrtd��|j|�||j	|�<||j
|<y)Nrzbpf_open_perf_event failed)r�bpf_open_perf_eventr�r�r�r�)r�r�typ�configrr�s      rU�_open_perf_eventzPerfEventArray._open_perf_event�sU��
�
$�
$�S�&�#�s�
;��
��6��8�9�9�"�i�i��m��T�X�X�c�]��"$����3�rWc�J�t�D]}|j||||��y)z�open_perf_event(typ, config)

        Configures the table such that calls from the bpf program to
        table.perf_read(CUR_CPU_IDENTIFIER) will return the hardware
        counter denoted by event ev on the local cpu.
        N)r
r$)r�r"r#rrSs     rU�open_perf_eventzPerfEventArray.open_perf_events*��!�"�	7�A��!�!�!�S�&�#�6�	7rW)rNr)rM)r�r�r�r�r�r'rrrr$r&r�r�s@rUr�r��s.���!�
�
$� 
E�R�  %�D%�7rWr�c�J��eZdZ�fd�Z�fd�Zd�Z�fd�Zd�Zd�Zd�Z	�xZ
S)r�c�j��|jdd�|_tt|�|i|��|j
|_tt��|_	tj|j�dz|_|jdk(r|j|jz|_y|jtjk(r#tj|jz|_y|jtjk(r#tj |jz|_yt#d���N�reducerrrzLeaf must be aligned to 8 bytes)�popr*r�r�r�r��sLeafrcr�	total_cpur�r��	alignmentr��c_uint64r��c_int64r�r�s   �rUr�zPerCpuHash.__init__s�����z�z�)�T�2���
�j�$�(�$�9�&�9��Y�Y��
��.�0�1������4�:�:�.��2����>�>�Q���
�
�T�^�^�3�D�I��z�z�R�Y�Y�&��K�K�$�.�.�8��	����r�x�x�'��J�J����7��	� �!B�C�CrWc����tt|�|�}|jdk(r|}|S|j|j
z�}t
d|j
�D]
}||||<�|Sr)r�r�rr.r,r-rb�r�r��result�retrSr�s     �rU�getvaluezPerCpuHash.getvalue#sq����z�4�4�S�9���>�>�Q���C�
�
�/�4�:�:����.�1�C��1�d�n�n�-�
#������A��
#��
rWc��|jr%t|j|j|��S|j|�Sr��r*rr5r*s  rUrzPerCpuHash.__getitem__-s2���<�<��$�,�,��
�
�c�(:�;�;��=�=��%�%rWc�.��tt|�||�yr�)r�r�r$r�s   �rUr$zPerCpuHash.__setitem__3s���
�j�$�+�C��6rWc��t|j�tj�rt	d��|jt
|j|���S�Nz6Leaf must be an integer type for default sum functions�rCr�r�r�r�r,�sumr5r*s  rUr<zPerCpuHash.sum6�?���d�i�i�k�2�<�<�0��U�V�V��z�z�#�d�m�m�C�0�1�2�2rWc��t|j�tj�rt	d��|jt
|j|���S�Nz6Leaf must be an integer type for default max functions�rCr�r�r�r�r,�maxr5r*s  rUrAzPerCpuHash.max;r=rWc�V�|j|�}|j|jzSr��r<r�r-�r�r�r3s   rU�averagezPerCpuHash.average@�"�����#����|�|�d�n�n�,�,rW)r�r�r�r�r5rr$r<rArEr�r�s@rUr�r�s'���D�$�&�7�3�
3�
-rWr�c���eZdZ�fd�Z�xZS)r�c�,��tt|�
|i|��yr�)r�r�r�r�s   �rUr�zLruPerCpuHash.__init__E����
�m�T�+�T�<�V�<rWr�r�s@rUr�r�D�
���=�=rWr�c�P��eZdZ�fd�Z�fd�Zd�Z�fd�Zd�Zd�Zd�Z	d�Z
�xZS)	r�c�j��|jdd�|_tt|�|i|��|j
|_tt��|_	tj|j�dz|_|jdk(r|j|jz|_y|jtjk(r#tj|jz|_y|jtjk(r#tj |jz|_yt#d��r))r+r*r�r�r�r�r,rcrr-r�r�r.r�r/r�r0r�r�s   �rUr�zPerCpuArray.__init__Is�����z�z�)�T�2���
�k�4�)�4�:�6�:��Y�Y��
��.�0�1������4�:�:�.��2����>�>�Q���
�
�T�^�^�3�D�I��z�z�R�Y�Y�&��K�K�$�.�.�8��	����r�x�x�'��J�J����7��	� �!B�C�CrWc����tt|�|�}|jdk(r|}|S|j|j
z�}t
d|j
�D]
}||||<�|Sr)r�r�rr.r,r-rbr2s     �rUr5zPerCpuArray.getvalue[sq����{�D�5�c�:���>�>�Q���C�
�
�/�4�:�:����.�1�C��1�d�n�n�-�
#������A��
#��
rWc��|jr%t|j|j|��S|j|�Sr�r7r*s  rUrzPerCpuArray.__getitem__es2���L�L��$�,�,��
�
�c�(:�;�;��=�=��%�%rWc�.��tt|�||�yr�)r�r�r$r�s   �rUr$zPerCpuArray.__setitem__ks���
�k�4�,�S�$�7rWc�&�|j|�yr�r�r*s  rUr'zPerCpuArray.__delitem__nr�rWc��t|j�tj�rt	d��|jt
|j|���Sr:r;r*s  rUr<zPerCpuArray.sumrr=rWc��t|j�tj�rt	d��|jt
|j|���Sr?r@r*s  rUrAzPerCpuArray.maxwr=rWc�V�|j|�}|j|jzSr�rCrDs   rUrEzPerCpuArray.average|rFrW)r�r�r�r�r5rr$r'r<rArEr�r�s@rUr�r�Hs,���D�$�&�8��3�
3�
-rWr�c�$��eZdZ�fd�Zd�Z�xZS)r�c�,��tt|�
|i|��yr�)r�r�r�r�s   �rUr�zLpmTrie.__init__�r�rWc��t�r�)�NotImplementedErrorr�s rUr�zLpmTrie.__len__�s��!�!rWr�r�s@rUr�r��s
���7�"rWr�c�\��eZdZdZdZdZdZdZ�fd�ZGd�de	�Z
dd	�Zd
�Zd�Z
�xZS)
r��rnrrrc�,��tt|�
|i|��yr�)r�r�r�r�s   �rUr�zStackTrace.__init__�s���
�j�$�(�$�9�&�9rWc�&�eZdZdd�Zd�Zd�Zd�Zy)�StackTrace.StackWalkerNc�<�||_d|_||_||_yr�)�stack�n�resolver�)r�r^r�r`s    rUr�zStackTrace.StackWalker.__init__�s���D�J��D�F�"�D�L��D�JrWc��|Sr�rOr�s rUrnzStackTrace.StackWalker.__iter__�ryrWc�"�|j�Sr�r{r�s rUr}zStackTrace.StackWalker.__next__�r~rWc�$�|xjdz
c_|jtjk(r
t��|jtj
zrg|jj|j}|jtjk(s|jtjk(r-t��|jj|j}|dk(r
t��|jr|j|�S|S)Nrr)
r_r��	MAX_DEPTHr�r��BPF_F_STACK_BUILD_IDr^�trace�status�BPF_STACK_BUILD_ID_IP�BPF_STACK_BUILD_ID_EMPTY�ipr`)r��addrs  rUr|zStackTrace.StackWalker.next�s����F�F�a�K�F��v�v��-�-�-�#�o�%��z�z�J�;�;�;��Z�Z�%�%�d�f�f�-�d����
� @� @�@����
� C� C�C�%��'��Z�Z�]�]�4�6�6�*�d��q�y�#�o�%�)-���4�<�<��%�?�4�?rWr�r�rOrWrU�StackWalkerr\�s��	�	�	�	@rWrlc�h�tj||j|�|j|�Sr�)r�rlr�r�)r��stack_idr`s   rU�walkzStackTrace.walk�s)���%�%�d�4�8�8�H�+=�&>��
�
�G�T�TrWc�"�d}|D]}|dz
}�	|Sr�rOr�s   rUr�zStackTrace.__len__�r�rWc��yr�rOr�s rUr;zStackTrace.clear����rWr�)r�r�r�rdreri�BPF_STACK_BUILD_ID_VALIDrhr�r�rlror�r;r�r�s@rUr�r��sC����I� �� !�� ����:�@�f�@�>U��

rWr�c���eZdZ�fd�Z�xZS)r�c�,��tt|�
|i|��yr�)r�r�r�r�s   �rUr�zDevMap.__init__�����
�f�d�$�d�5�f�5rWr�r�s@rUr�r���
���6�6rWr�c���eZdZ�fd�Z�xZS)r�c�,��tt|�
|i|��yr�)r�r�r�r�s   �rUr�zCpuMap.__init__�rvrWr�r�s@rUr�r��rwrWr�c���eZdZ�fd�Z�xZS)r�c�,��tt|�
|i|��yr�)r�r�r�r�s   �rUr�zXskMap.__init__�rvrWr�r�s@rUr�r��rwrWr�c���eZdZ�fd�Z�xZS)r�c�,��tt|�
|i|��yr�)r�r�r�r�s   �rUr�zMapInMapArray.__init__�rIrWr�r�s@rUr�r��rJrWr�c���eZdZ�fd�Z�xZS)r�c�,��tt|�
|i|��yr�)r�r�r�r�s   �rUr�zMapInMapHash.__init__�s���
�l�D�*�D�;�F�;rWr�r�s@rUr�r��s
���<�<rWr�c�>��eZdZ�fd�Zd�Zd�Zd�Zd�Zdd�Z�xZ	S)r�c�H��tt|�
|i|��d|_d|_yr�)r�r�r��_ringbufr�r�s   �rUr�zRingBuf.__init__�s&���
�g�t�%�t�6�v�6���
� ��rWc��yr�rOr*s  rU�	__delitemzRingBuf.__delitem�rrrWc��yr�rOr�s rUr�zRingBuf.__del__�rrrWc��yrrOr�s rUr�zRingBuf.__len__�s��rWc��|jdk(rt|�|_tj|tj|j��j
S)aevent(data)

        When ring buffers are opened to receive custom event,
        the underlying event data struct which is defined in C in
        the BPF program can be deduced via this function. This avoids
        redundant definitions in Python.
        Nr�rs  rUrz
RingBuf.event�rrWc����fd�}t|�}|jj|j||�||jd<y)z�open_ring_buffer(callback)

        Opens a ring buffer to receive custom event data from the bpf program.
        The callback will be invoked for each event submitted from the kernel,
        up to millions per second.
        c����	�|||�}	t|�}|S#d}Y|SxYw#t$r5}|jtjk(rt	�n|�Yd}~Sd}~wwxYwr)rdrrarr�)�ctxrarr4rrs     �rU�ringbuf_cb_z-RingBuf.open_ring_buffer.<locals>.ringbuf_cb_�su���

��s�D�$�/����c�(�C��J����C��J���
��7�7�e�k�k�)��F��G���J��
�s$�
%��"�%�%�	A#�*A�A#rN)rr��_open_ring_bufferr�r�)r�rr�r�rs `   rU�open_ring_bufferzRingBuf.open_ring_buffer�s;���	�"�k�
*�����"�"�4�;�;��C�8���	�	�!�rWr�)
r�r�r�r��_RingBuf__delitemr�r�rr�r�r�s@rUr�r��s"���!�

�
��
E�rWr�c�B�eZdZdZd�Zd�Zd�Zdd�Zd�Zd�Z	d�Z
d	�Zy
)r�rc��||_||_||_||_t	j
|jj|j�|_t	j|jj|j�|_	tt	j|jj|j��|_yr�)
r�r�r�r�rr�r�r�r�r�rdr�r�)r�r�r�r�r�s     rUr�zQueueStack.__init__
s��������������	��*�*�4�8�8�?�?�D�K�K�H��
��+�+�D�H�H�O�O�T�[�[�I��
��s�;�;�D�H�H�O�O���� ���rWc	�J�tjtj|j�dz�}t	j
|jj|j|t|�tj|��}|dkrtd��|jSrrrs    rUr	zQueueStack.leaf_sprintfr
rWc���|j�}tj|jj|j
|t
j|��}|dkrtd��|Srrrs    rUrzQueueStack.leaf_scanfrrWc���tj|jdtj|�|�}|dkr5tjtj��}td|z��y)NrzCould not push to table: %sr)r�rr�rr#s     rU�pushzQueueStack.push'sU���!�!�$�+�+�t�R�X�X�d�^�U�K����7��[�[�����0�F��9�F�B�C�C�rWc��|j�}tj|jdt	j
|��}|dkrt
d��|S)NrzCould not pop from table)r�r�bpf_lookup_and_deleter�r�r�r��r�rrs   rUr+zQueueStack.pop-sE���y�y�{���'�'����T�2�8�8�D�>�J����7��5�6�6��rWc��|j�}tj|jdt	j
|��}|dkrt
d��|S)NrzCould not peek tablerr�s   rU�peekzQueueStack.peek4sE���y�y�{���!�!�$�+�+�t�R�X�X�d�^�D����7��1�2�2��rWc#�~K�|j}|r	|j���|dz}|r�yy#t$rYywxYw�wr�)r�r+r�)r��cnts  rUr+zQueueStack.itervalues;sF���������
��h�h�j�!��q������
��
�s �=�.�=�=�	:�=�:�=c�H�|j�D�cgc]}|��c}Scc}wr�r3r4s  rUr5zQueueStack.valuesEr6r1N)r)r�r�r��	BPF_EXISTr�r	rr�r+r�r+r5rOrWrUr�r�	s0���I����D����6rWr�r�)W�
__future__r�collections.abcr�ImportError�collections�timer�ctypesr��	functoolsrr rar�r��libbccrr	r
rr�utilsr
rr�r�r�r�r�r�r�r�r�r�r�r�r�r��BPF_MAP_TYPE_SOCKMAPr�r��BPF_MAP_TYPE_SOCKHASH�BPF_MAP_TYPE_CGROUP_STORAGE� BPF_MAP_TYPE_REUSEPORT_SOCKARRAY�"BPF_MAP_TYPE_PERCPU_CGROUP_STORAGEr�r��BPF_MAP_TYPE_SK_STORAGE�BPF_MAP_TYPE_DEVMAP_HASH�BPF_MAP_TYPE_STRUCT_OPSr��BPF_MAP_TYPE_INODE_STORAGE�BPF_MAP_TYPE_TASK_STORAGErrpr�r�rVr]rZr{r}r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rOrWrU�<module>r�sW��&�+�.����	��	�
�\�\�"�$������� !������������!������������������ ��#%� �%'�"�������������������v������\��"�#5�	�
�m���~�
��m���~���:��!�"3���:������~������)�� ��!�"��#�$�:��!1�$�&;�&�(?������\��m��\��)����~�;�
�@
�	�����
�?��2$8�L<�:�8;�v-
�`gC��gC�T�	��7�i�7�6$�	�6$�p�I��	6�	�	6���(Q�)�Q�i7�Y�i7�X2-��2-�h=�J�=�6-�)�6-�p"�i�"�2
��2
�h6�Y�6�6�Y�6�6�Y�6�=�I�=�<�9�<�7�i�7�r=6�=6��o'�+�*�*�+�s�G�G&�%G&