HEX
Server: Apache
System: Linux insrv.serversdaddy.com 5.14.0-362.24.2.el9_3.x86_64 #1 SMP PREEMPT_DYNAMIC Sat Mar 30 14:11:54 EDT 2024 x86_64
User: jsaha (1066)
PHP: 8.3.6
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib/python3.9/site-packages/tuned/daemon/__pycache__/controller.cpython-39.opt-1.pyc
a

Y��du,�@s�ddlmZddlZddlZddlmZddlZddlmZddlm	Z	dgZ
ej��Z
Gdd�de�ZGdd�dejjj�ZdS)	�)�exportsN)�TunedException)�commands�
Controllerc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�
TimerStorecCst�|_t��|_dS�N)�dict�_timers�	threading�Lock�_timers_lock��self�r�;/usr/lib/python3.9/site-packages/tuned/daemon/controller.py�__init__szTimerStore.__init__cCs4|j�||j|<Wd�n1s&0YdSr)rr	�r�token�timerrrr�store_timerszTimerStore.store_timercCsV|j�<z|j|}|��|j|=WnYn0Wd�n1sH0YdSr)rr	�cancelrrrr�
drop_timers
zTimerStore.drop_timercCsL|j�2|j��D]}|��q|j��Wd�n1s>0YdSr)rr	�valuesr�clear)rrrrr�
cancel_alls
zTimerStore.cancel_allN)�__name__�
__module__�__qualname__rrrrrrrrr
s	rcs^eZdZdZ�fdd�Zdd�Zdd�Zdd	�Ze�	d
�dd��Z
d
d�Ze�dd�dOdd��Z
e�dd�dPdd��Ze�dd�dQdd��ZdRdd�Ze�dd�dSdd��Ze�dd�dTdd ��Zd!d"�Ze�dd#�dUd$d%��Ze�dd#�dVd&d'��Ze�dd�dWd(d)��Ze�dd*�dXd+d,��Ze�dd�dYd-d.��Ze�dd�dZd/d0��Ze�dd�d[d1d2��Ze�dd3�d\d4d5��Ze�dd6�d]d7d8��Ze�dd9�d^d:d;��Ze�dd�d_d<d=��Ze�dd�d`d>d?��Ze�dd�dad@dA��Z e�ddB�dbdCdD��Z!e�dd�dcdEdF��Z"e�ddG�dddHdI��Z#e�dd�dedJdK��Z$e�dLd#�dfdMdN��Z%�Z&S)grz�
	Controller's purpose is to keep the program running, start/stop the tuning,
	and export the controller interface (currently only over D-Bus).
	cs8tt|���||_||_t��|_t�|_	t
�|_dSr)�superrr�_daemon�_global_configr
�Event�
_terminater�_cmdr�_timer_store)r�daemonZ
global_config��	__class__rrr+s
zController.__init__cCsrt�d�|��}|j�tjtj�}|s4|r4t��|r\|j	�
�|j�|j	d�s\t�
�qBt�d�|��dS)z1
		Controller main loop. The call is blocking.
		zstarting controller�zterminating controllerN)�log�info�startr �get_bool�consts�
CFG_DAEMON�CFG_DEF_DAEMONrr"rr#�waitZperiod_check�stop)r�resr%rrr�run3s



zController.runcCs|j��dSr)r"�setr
rrr�	terminateFszController.terminatecCs0|jj��s,|jj��|��s,|jj��dSr)rZ_sighup_processing�is_setr4�reloadrr
rrr�sighupIszController.sighupZsbscCsdSrr)r�profile_name�resultZerrstrrrr�profile_changedOszController.profile_changedcCstj�|�|j�|�dSr��tuned�logs�log_capture_finishr$r)rrrrr�_log_capture_abortXszController._log_capture_abort�ii�sNcCsf|dkrdStj�|�}|dur$dS|dkrVtj||j|gd�}|j�||�|��|durbdS|S)N�r)�args)	r=r>�log_capture_startr
�Timerr@r$rr+)rZ	log_level�timeout�callerrrrrrrE\s�zController.log_capture_startcCs4|dkrdStj�|�}|j�|�|dur0dS|S�NrCr<)rrrHr2rrrr?js
zController.log_capture_finishrC�bcCsD|dkrdS|j�tjtj�r:|j��r,dS|j��s:dS|j��S)NrCFT)	r r,r-r.r/r�
is_running�
is_enabledr+�rrHrrrr+rs

zController.startFcCs,|j��sd}n|jj|d�}|j��|S)NT��profile_switch)rrKr1r$r)rrOr2rrr�_stop}s


zController._stopcCs|dkrdS|jdd�S)NrCFrN)rPrMrrrr1�szController.stopc
Csv|dkrdS|j��r*|jdd�}|s*dSz|j��Wn4tyl}zt�d|�WYd}~dSd}~00|��S)NrCFTrNzFailed to reload TuneD: %s)rrKrPZreload_profile_configrr)�errorr+)rrHZstop_ok�errrr7�s
zController.reloadc
Cs|j��}d}d}d}z�z$|r,|jjdd�|j�||�Wnhtjjy�}zLd}t|�}|r�|jjj	|kr�t
�d|�d}nt
�d|�WYd}~n
d}~00W|r�|r�t
�d|�n|s�t
�
d�|j��n6|�r|r�t
�d|�n|�st
�
d�|j��0||fS)	N�OKTFrNz@Failed to reapply profile '%s'. Did it change on disk and break?zFailed to apply profile '%s'z>Applying previously applied (possibly out-dated) profile '%s'.z$Applying previously applied profile.)rrKr1Zset_profiler=�
exceptionsr�str�profile�namer)rQ�warnr*r+)rr9�manualZwas_running�msg�successZreapplyrRrrr�_switch_profile�s8
&
�
zController._switch_profilez(bs)cCs|dkrdS|�|d�S)NrC�F�UnauthorizedT)r\�rr9rHrrr�switch_profile�szController.switch_profilecCs |dkrdS|��}|�|d�S)NrCr]F)�recommend_profiler\)rrHr9rrr�auto_profile�szController.auto_profilecCs*|dkrdS|jjdur"|jjjSdSdSrI)rrVrWrMrrr�active_profile�s

zController.active_profilez(ss)c
Cs�|dkrdS|jj}|durxz"|j��\}}|dur<|du}Wn8tyv}z d}t|�}||fWYd}~Sd}~00|r�tjntj}|dfS)NrC)�unknownr^rd)	rrYr#Zget_active_profilerrUr-ZACTIVE_PROFILE_MANUALZACTIVE_PROFILE_AUTO)rrHrYrVrR�moderQrrr�profile_mode�szController.profile_modecCs|dkrdS|jjpdSrI)r�post_loaded_profilerMrrrrg�szController.post_loaded_profilecCsB|dkrdS|j��r |j��|j��r>|jjddddd�dS)NrCFT)Zsave_instantly)rrKr1rLZset_all_profilesrMrrr�disable�s


�zController.disablecCs|dkrdS|j��S�NrCF)rrKrMrrrrK�szController.is_running�ascCs|dkrgS|jjj��SrI)r�profile_loader�profile_locatorZget_known_namesrMrrr�profiles�szController.profilesza(ss)cCs|dkrgS|jjj��SrI)rrkrlZget_known_names_summaryrMrrr�	profiles2�szController.profiles2z(bsss)cCsP|dkrtdddd�S|dus&|dkr.|��}t|jjj�|tjtjgdg��Sri)	�tuplercrrkrlZget_profile_attrsr-ZPROFILE_ATTR_SUMMARYZPROFILE_ATTR_DESCRIPTIONr_rrr�profile_infos
zController.profile_infocCs|dkrdS|jj��SrI)rZprofile_recommenderZ	recommendrMrrrraszController.recommend_profilecCs|dkrdS|jjdd�S)NrCF�Zignore_missing�r�verify_profilerMrrrrsszController.verify_profilecCs|dkrdS|jjdd�S)NrCFTrqrrrMrrr�verify_profile_ignore_missingsz(Controller.verify_profile_ignore_missingz	a{sa{ss}}cCsr|dkrdSi}|j��D]R}|j�d�d�dd�d}|��}i||<|��D]\}}t|�|||<qRq|S)zuReturn dictionary with accesible plugins

		Return:
		dictionary -- {plugin_name: {parameter_name: default_value}}
		rCF�.����_r()r�get_all_pluginsr�splitZ_get_config_options�itemsrU)rrHZpluginsZplugin_class�plugin_nameZconf_options�key�valrrrrxszController.get_all_pluginscCs|dkrdS|j�t|��S)z"Return docstring of plugin's classrCF)r�get_plugin_documentationrU�rr{rHrrrr~,sz#Controller.get_plugin_documentationza{ss}cCs|dkrdS|j�t|��S)z�Return dictionary with plugin's parameters and their hints

		Parameters:
		plugin_name -- name of plugin

		Return:
		dictionary -- {parameter_name: hint}
		rCF)r�get_plugin_hintsrUrrrrr�3s
zController.get_plugin_hintscCs6|dkrdS|jjr2|jjjr2|jjj�|�dSdS)z�Allows to dynamically add sockets to send signals to

		Parameters:
		path -- path to socket to register for sending signals

		Return:
		bool -- True on success
		rCFT)rZ_applicationZ_unix_socket_exporterZregister_signal_path)r�pathrHrrr�register_socket_signal_pathAs
z&Controller.register_socket_signal_path�ssc
Cs`|dkrdSd}|jjjD]&}|j|krt�d|j�d}qBq|s`d|}t�|�d|fSt|j�	|��}t�d|jt
|�f�|jjjD]�}|j|@}	t|	�r�||	8}t�
dt
|	�|j|jf�|jj|jjk�rd	|j|jjt
|	�|j|jjf}t�|�d|fS|j�||	�|j�||	�q�t|��r\d
t
|�}t�
|�d|fSdS)NrCr]FzFound instance '%s'.TzInstance '%s' not foundz-Instance '%s' trying to acquire devices '%s'.z8Moving devices '%s' from instance '%s' to instance '%s'.ztTarget instance '%s' is of type '%s', but devices '%s' are currently handled by instance '%s' which is of type '%s'.z2Ignoring devices not handled by any instance '%s'.)TrS)rZ
_unit_managerZ	instancesrWr)�debugrQr4r#Zdevstr2devsrUZprocessed_devices�lenr*ZpluginZ_remove_devices_nocheckZ_add_devices_nocheck)
rZdevicesZ
instance_namerH�foundZinstance_targetZretsZdevs�instanceZdevs_movingrrr�instance_acquire_devicesUsH


���


z#Controller.instance_acquire_devices)N)N)N)F)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)'rrr�__doc__rr3r5r8r�signalr;r@ZexportrEr?r+rPr1r7r\r`rbrcrfrgrhrKrmrnrprarsrtrxr~r�r�r��
__classcell__rrr&rr%sp


























)r=rZ
tuned.logsZtuned.exceptionsrr
Ztuned.constsr-Ztuned.utils.commandsr�__all__r>�getr)�objectrZ
interfacesZExportableInterfacerrrrr�<module>s