<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
        integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
</html>
3
<e                 @   s~   d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlj	Z	d dl
mZ d dlmZ ejj ZdgZG dd deZdS )    N)GlobalConfig)commandsManagerc                   s   e Zd ZdZd fdd	Zedd Zedd Zed	d
 Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd ZejfddZ  ZS ) r   z?
	Manager creates plugin instances and keeps a track of them.
	Nc                sJ   t t| j  || _|| _|| _|| _g | _g | _|p:t	 | _
t | _d S )N)superr   __init___plugins_repository_monitors_repository_def_instance_priority_hardware_inventory
_instances_pluginsr   _configr   _cmd)selfplugins_repositoryZmonitors_repositoryZdef_instance_priorityZhardware_inventoryconfig)	__class__ /usr/lib/python3.6/manager.pyr      s    zManager.__init__c             C   s   | j S )N)r   )r   r   r   r   plugins!   s    zManager.pluginsc             C   s   | j S )N)r   )r   r   r   r   	instances%   s    zManager.instancesc             C   s   | j S )N)r   )r   r   r   r   r   )   s    zManager.plugins_repositoryc             C   sF   |j d krdS | jjtj}|d kr0| jjd}tj|j |tj	d k	S )NTz/proc/cpuinfo)
Zcpuinfo_regexr   getconstsZCFG_CPUINFO_STRINGr   Z	read_fileresearch	MULTILINE)r   unitZcpuinfo_stringr   r   r   _unit_matches_cpuinfo-   s    

zManager._unit_matches_cpuinfoc             C   sH   |j d krdS | jjtj}|d kr2djtj }tj	|j |tj
d k	S )NT )Zuname_regexr   r   r   ZCFG_UNAME_STRINGjoinosunamer   r   r   )r   r   Zuname_stringr   r   r   _unit_matches_uname6   s    

zManager._unit_matches_unamec             C   s2  g }xt |j D ]\}}|js0tjd|  q| j|sJtjd|  q| j|sdtjd|  q|jjd| j	 t
|jd |jd< |j| qW |jdd d tj }x"|D ]}|jjd d ||j< qW xt |j D ]\}}y$| jj|}|||< | jj| W q tjjjk
r8   tjd|  wY q tk
rt }	 z tjd	|  tj|	 wW Y d d }	~	X qX qW g }
xf|D ]^}||j }|d krqtjd
|j|jf  |j|j|j|j|j |j!|j}|
j| qW x0|
D ](}|j"j#  |j"j$| |j"j%| qW | j&j'  | j(j)|
 d S )Nzskipping disabled instance '%s'z.skipping instance '%s', cpuinfo does not matchz,skipping instance '%s', uname does not matchpriorityc             S   s
   | j d S )Nr#   )options)xr   r   r   <lambda>P   s    z Manager.create.<locals>.<lambda>)keyz2skipping plugin '%s', not supported on your systemzfailed to initialize plugin %szcreating '%s' (%s))*listitemsZenabledlogdebugr   r"   r$   
setdefaultr	   intappendsortcollectionsOrderedDictpoptyper   creater   tunedr   
exceptionsZNotSupportedPluginExceptioninfo	ExceptionerrorZ	exceptionnameZcreate_instanceZdevicesZdevices_udev_regexZ
script_preZscript_postpluginZinit_devicesZassign_free_devicesZinitialize_instancer
   Zstart_processing_eventsr   extend)r   Zinstances_configZinstance_info_listZinstance_nameZinstance_infoZplugins_by_nameZplugin_nameZnoner;   er   Znew_instanceinstancer   r   r   r4   ?   s\    









zManager.createc             O   sX   y
|||S  t k
rR } z,tj }tjd|t|f  tj| |S d }~X nX d S )Nz"BUG: Unhandled exception in %s: %s)r8   	traceback
format_excr*   r9   str)r   ZcallerZexc_retfargskwargsr=   Ztracer   r   r   	_try_callu   s    

zManager._try_callc             C   s   x2| j D ](}tjd|j  | jdd |jj| qW x.| jD ]$}tjd|j  | jdd |j q<W | jd d = | j d d = d S )Nzdestroying instance %sdestroy_allzcleaning plugin '%s')	r   r*   r+   r:   rE   r;   Zdestroy_instancer   Zcleanup)r   r>   r;   r   r   r   rF      s    
zManager.destroy_allc             C   s4   x.| j jD ]"}tjd|  | jdd |j q
W d S )Nzupdating monitor %supdate_monitors)r   Zmonitorsr*   r+   rE   update)r   Zmonitorr   r   r   rG      s    zManager.update_monitorsc             C   s$   x| j D ]}| jdd |j qW d S )Nstart_tuning)r   rE   Zapply_tuning)r   r>   r   r   r   rI      s    zManager.start_tuningc             C   s6   d}x,| j D ]"}| jdd|j|}|dkrd}qW |S )NTverify_tuningF)r   rE   rJ   )r   Zignore_missingretr>   resr   r   r   rJ      s    
zManager.verify_tuningc             C   s$   x| j D ]}| jdd |j qW d S )Nupdate_tuning)r   rE   rM   )r   r>   r   r   r   rM      s    zManager.update_tuningc             C   s4   | j j  x$t| jD ]}| jdd |j| qW d S )Nstop_tuning)r
   Zstop_processing_eventsreversedr   rE   Zunapply_tuning)r   Zrollbackr>   r   r   r   rN      s    
zManager.stop_tuning)N)__name__
__module____qualname____doc__r   propertyr   r   r   r   r"   r4   rE   rF   rG   rI   rJ   rM   r   ZROLLBACK_SOFTrN   __classcell__r   r   )r   r   r      s   		6
	)r0   r    r   r?   Ztuned.exceptionsr5   Z
tuned.logsZtuned.plugins.exceptionsZtuned.constsr   Ztuned.utils.global_configr   Ztuned.utils.commandsr   Zlogsr   r*   __all__objectr   r   r   r   r   <module>   s   

