o
    id{                     @   s:   d dl Z d dlZd dlmZmZmZ G dd deeZdS )    N)PluginIndependentPlugin	PluginOptc                
   @   sl   e Zd ZdZdZdZeddddedd	d
dedd	ddeddeddeddeddgZdd Z	dd Z
dS )Processzprocess informationprocess)systemlsofTzcollect info on all open files)defaultdesclsof-threadsFz,collect threads' open file info if supportedsmapszcollect /proc/*/smaps filessamples   z"number of iotop samples to collect)r	   val_typer
   numprocsi   z*number of process to collect /proc data ofc              	   C   sX  d}d}d}|d7 }|  ddg dd | d	D }| d
r)|d | d
 }|D ]}|  d| d| d| d| d| g q+| drL|  d | jddg ddd | jddd | drm| jdddddd | drz| jd ddd! | jd"d#gd$d% | d&||f d&||f g | d'r| jd(| d' d)d* | d+d,g d S )-Nzps axoz3pid,ppid,user,group,lwp,nlwp,start_time,comm,cgroupz2flags,state,uid,pid,ppid,pgid,sid,cls,pri,addr,sz,zwchan:20,lstart,tty,time,cmdz/proc/sched_debugz
/proc/statc                 S   s   g | ]
}t d |r|qS )z[0-9])rematch).0p r   </usr/lib/python3/dist-packages/sos/report/plugins/process.py
<listcomp>-   s    z!Process.setup.<locals>.<listcomp>z/procr   z/proc/%s/statusz/proc/%s/cpusetz/proc/%s/oom_*z/proc/%s/stackz/proc/%s/limitsr   z/proc/[0-9]*/smapsz
ps auxwwwmps)ps_auxps_auxww	ps_auxwww
ps_auxwwwm	ps_auxcww   )root_symlinktagspriorityz
pstree -lppstree)r   r   zlsof +M -n -l -c ''   2   )r   timeoutr!   r    r   zlsof +M -n -l)r%   r!   z	ps alxwwwzps -elfLT)
cmd_as_tagz%s %sr   ziotop -b -o -d 0.5 -t -n %sd   )r!   z#pidstat -p ALL -rudvwsRU --human -hzpidstat -tl)add_copy_speclistdir
get_optionadd_cmd_output)selfps_axops_group_optsps_sched_optsprocsprocr   r   r   setup!   sh   








zProcess.setupc                 C   s  |  d{}| jjjs|d 	 W d    d S | d}i }i }|d dks;|d|d   	 W d    d S |d  D ],}|  }|d }|d }| 	|sWqA||vrd| jj
|||< ||| d	||< qA|tj|dd
 W d    d S 1 sw   Y  d S )Nzpids_to_packages.jsonz/Package manager not configured for path querieszps --no-headers aexstatusr   zUnable to get process list: output   )pathpackage)indent)collection_filepolicypackage_managerquery_path_commandwriteexec_cmd
splitlinesstripsplitpath_existspkg_by_pathjsondumps)r,   pfile_pspidpkgpathsr1   pidr6   r   r   r   collect]   s.   




"zProcess.collectN)__name__
__module____qualname__
short_descplugin_nameprofilesr   intoption_listr2   rK   r   r   r   r   r      s$    <r   )rD   r   sos.report.pluginsr   r   r   r   r   r   r   r   <module>   s   