U
    id                     @   s2   d dl mZmZmZ d dlZG dd deeZdS )    )PluginIndependentPlugin	PluginOptNc                   @   sB   e Zd ZdZdZdZeddeddgZdd	 Z	d
d Z
dd ZdS )Ebpfz	eBPF toolZebpf)systemZkernelZnetwork
namespacesNz0Number of namespaces to collect, 0 for unlimited)defaultZval_typeZdescc              
   C   s   g }zt |}W n8 tk
rJ } z| d|  | W Y S d }~X Y nX tt|D ]"}d|| krX||| d  qX|S )Nz-Could not parse bpftool prog list as JSON: %sidjsonloads	ExceptionZ	_log_inforangelenappend)selfZ	prog_jsonoutZ	prog_dataeitem r   9/usr/lib/python3/dist-packages/sos/report/plugins/ebpf.pyget_bpftool_prog_ids   s    zEbpf.get_bpftool_prog_idsc              
   C   s   g }zt |}W n8 tk
rJ } z| d|  | W Y S d }~X Y nX tt|D ]"}d|| krX||| d  qX|S )Nz,Could not parse bpftool map list as JSON: %sr	   r
   )r   Zmap_jsonr   Zmap_datar   r   r   r   r   get_bpftool_map_ids$   s    zEbpf.get_bpftool_map_idsc           
      C   s   |  d}| |d D ] }dD ]}| d||f  q q|  d}| |d D ]}| d|  qR| ddd	d
dg d}| d}| j|dD ]}|| d }	| |	d
  qd S )Nzbpftool -j prog listoutput)ZxlatedZjitedzbpftool prog dump %s id %szbpftool -j map listzbpftool map dump id %szbpftool prog listzbpftool map listzbpftool cgroup treezbpftool net listzbpftool struct_ops dumpzip netns exec r   )Zns_max )Zcollect_cmd_outputr   Zadd_cmd_outputr   Z
get_optionZget_network_namespaces)
r   ZprogsZprog_idZdumpcmdmapsZmap_idZ
cmd_prefixZnsps	namespaceZns_cmd_prefixr   r   r   setup0   s*    



z
Ebpf.setup)__name__
__module____qualname__Z
short_descZplugin_nameZprofilesr   intZoption_listr   r   r   r   r   r   r   r      s   r   )Zsos.report.pluginsr   r   r   r   r   r   r   r   r   <module>	   s   