Your IP : 18.217.89.130


Current Path : /usr/lib/python3.6/site-packages/tuned/daemon/__pycache__/
Upload File :
Current File : //usr/lib/python3.6/site-packages/tuned/daemon/__pycache__/controller.cpython-36.opt-1.pyc

3

�@ag�4�@s�ddlmZddlZddlZddlmZddlZddljZddlm	Z	dgZ
ejj�Z
Gdd�de�ZGdd�dejjj�ZdS)	�)�exportsN)�TunedException)�commands�
Controllerc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�
TimerStorecCst�|_tj�|_dS)N)�dict�_timers�	threadingZLock�_timers_lock)�self�r� /usr/lib/python3.6/controller.py�__init__szTimerStore.__init__c
Cs |j�||j|<WdQRXdS)N)r
r)r�token�timerrrr
�store_timerszTimerStore.store_timercCsB|j�2y|j|}|j�|j|=WnYnXWdQRXdS)N)r
r�cancel)rrrrrr
�
drop_timers
zTimerStore.drop_timerc	Cs<|j�,x|jj�D]}|j�qW|jj�WdQRXdS)N)r
r�valuesr�clear)rrrrr
�
cancel_allszTimerStore.cancel_allN)�__name__�
__module__�__qualname__rrrrrrrr
r
s	rcs�eZdZdZ�fdd�Zdd�Zdd�Zdd	�Zej	d
�dd��Z
d
d�Zejdd�dUdd��Z
ejdd�dVdd��Zejdd�dWdd��ZdXdd�Zejdd�dYdd��Zejdd�dZdd ��Zd!d"�Zejdd#�d[d$d%��Zejdd#�d\d&d'��Zejdd�d]d(d)��Zejdd*�d^d+d,��Zejdd�d_d-d.��Zejdd�d`d/d0��Zejdd�dad1d2��Zejdd3�dbd4d5��Zejdd6�dcd7d8��Zejdd9�ddd:d;��Zejdd�ded<d=��Zejdd�dfd>d?��Zejdd�dgd@dA��Z ejddB�dhdCdD��Z!ejdd�didEdF��Z"ejddG�djdHdI��Z#ejdd�dkdJdK��Z$ejdLd#�dldMdN��Z%ejddO�dmdPdQ��Z&ejddR�dndSdT��Z'�Z(S)orz�
	Controller's purpose is to keep the program running, start/stop the tuning,
	and export the controller interface (currently only over D-Bus).
	cs8tt|�j�||_||_tj�|_t�|_	t
�|_dS)N)�superrr�_daemon�_global_configr	ZEvent�
_terminater�_cmdr�_timer_store)r�daemonZ
global_config)�	__class__rr
r+s
zController.__init__cCsxtjd�|j�}|jjtjtj�}|r6|r6tj�|rb|j	j
�x|jj|j	d�s`tj
�qFWtjd�|j�dS)z1
		Controller main loop. The call is blocking.
		zstarting controller�zterminating controllerN)�log�info�startr�get_bool�consts�
CFG_DAEMON�CFG_DEF_DAEMONrrrr�waitZperiod_check�stop)r�resr rrr
�run3s



zController.runcCs|jj�dS)N)r�set)rrrr
�	terminateFszController.terminatecCs0|jjj�s,|jjj�|j�s,|jjj�dS)N)rZ_sighup_processingZis_setr.�reloadr)rrrr
�sighupIszController.sighupZsbscCsdS)Nr)r�profile_name�resultZerrstrrrr
�profile_changedOszController.profile_changedcCstjj|�|jj|�dS)N)�tuned�logs�log_capture_finishrr)rrrrr
�_log_capture_abortXszController._log_capture_abortZii�sNcCsf|dkrdStjj|�}|dkr$dS|dkrVtj||j|gd�}|jj||�|j�|dkrbdS|S)N�r)�args)	r5r6�log_capture_startr	ZTimerr8rrr%)rZ	log_levelZtimeout�callerrrrrr
r<\szController.log_capture_startcCs4|dkrdStjj|�}|jj|�|dkr0dS|S)Nr:)r5r6r7rr)rrr=r,rrr
r7js
zController.log_capture_finishr:�bcCsD|dkrdS|jjtjtj�r:|jj�r,dS|jj�s:dS|jj�S)Nr:FT)	rr&r'r(r)r�
is_running�
is_enabledr%)rr=rrr
r%rs

zController.startFcCs,|jj�sd}n|jj|d�}|jj�|S)NT)�profile_switch)rr?r+rr)rrAr,rrr
�_stop}s


zController._stopcCs|dkrdS|jdd�S)Nr:F)rA)rB)rr=rrr
r+�szController.stopcCsp|dkrdS|jj�r*|jdd�}|s*dSy|jj�Wn.tk
rf}ztjd|�dSd}~XnX|j�S)Nr:FT)rAzFailed to reload TuneD: %s)rr?rBZreload_profile_configrr#�errorr%)rr=Zstop_ok�errr
r0�s
zController.reloadcCs�|jj�}d}d}d}z�y$|r,|jjdd�|jj||�Wnftjjk
r�}zFd}t|�}|r�|jjj	|kr�t
jd|�d}nt
jd|�WYdd}~XnXWd|r�|r�t
jd|�n|s�t
j
d�|jj�X||fS)	N�OKTF)rAz@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.)rr?r+Zset_profiler5�
exceptionsr�str�profile�namer#rC�warnr$r%)rr2�manualZwas_running�msg�successZreapplyrDrrr
�_switch_profile�s,
$
zController._switch_profilez(bs)cCs(|dkrdS|jj|�sdS|j|d�S)Nr:F�Unauthorized�Invalid profile_nameT)FrO)FrP)r�
is_valid_namerN)rr2r=rrr
�switch_profile�s
zController.switch_profilecCs |dkrdS|j�}|j|d�S)Nr:FrO)FrO)�recommend_profilerN)rr=r2rrr
�auto_profile�szController.auto_profilecCs*|dkrdS|jjdk	r"|jjjSdSdS)Nr:)rrHrI)rr=rrr
�active_profile�s

zController.active_profilez(ss)cCs�|dkrdS|jj}|dkrpy"|jj�\}}|dkr<|dk	}Wn0tk
rn}zd}t|�}||fSd}~XnX|rztjntj}|dfS)Nr:�unknownrO)rVrO)	rrKrZget_active_profilerrGr'ZACTIVE_PROFILE_MANUALZACTIVE_PROFILE_AUTO)rr=rKrHrD�moderCrrr
�profile_mode�szController.profile_modecCs|dkrdS|jjpdS)Nr:)r�post_loaded_profile)rr=rrr
rY�szController.post_loaded_profilecCsB|dkrdS|jj�r |jj�|jj�r>|jjddddd�dS)Nr:FT)Zsave_instantly)rr?r+r@Zset_all_profiles)rr=rrr
�disable�s


zController.disablecCs|dkrdS|jj�S)Nr:F)rr?)rr=rrr
r?�szController.is_running�ascCs|dkrgS|jjjj�S)Nr:)r�profile_loader�profile_locatorZget_known_names)rr=rrr
�profiles�szController.profilesza(ss)cCs|dkrgS|jjjj�S)Nr:)rr\r]Zget_known_names_summary)rr=rrr
�	profiles2�szController.profiles2z(bsss)cCsT|dks|jj|�rdS|dks*|dkr2|j�}t|jjjj|tj	tj
gdg��S)Nr:F)Fr:r:r:)rrQrU�tuplerr\r]Zget_profile_attrsr'ZPROFILE_ATTR_SUMMARYZPROFILE_ATTR_DESCRIPTION)rr2r=rrr
�profile_infos
zController.profile_infocCs|dkrdS|jjj�S)Nr:)rZprofile_recommenderZ	recommend)rr=rrr
rS
szController.recommend_profilecCs|dkrdS|jjdd�S)Nr:F)�ignore_missing)r�verify_profile)rr=rrr
rcszController.verify_profilecCs|dkrdS|jjdd�S)Nr:FT)rb)rrc)rr=rrr
�verify_profile_ignore_missingsz(Controller.verify_profile_ignore_missingz	a{sa{ss}}cCsz|dkriSi}xd|jj�D]V}|jjd�djdd�d}|j�}i||<x$|j�D]\}}t|�|||<qVWqW|S)zuReturn dictionary with accesible plugins

		Return:
		dictionary -- {plugin_name: {parameter_name: default_value}}
		r:�.r"�_���)r�get_all_pluginsr�splitZ_get_config_options�itemsrG)rr=ZpluginsZplugin_class�plugin_nameZconf_options�key�valrrr
rhszController.get_all_pluginscCs*|dks|jj|�rdS|jjt|��S)z"Return docstring of plugin's classr:)rrQr�get_plugin_documentationrG)rrkr=rrr
rn.sz#Controller.get_plugin_documentationza{ss}cCs*|dks|jj|�riS|jjt|��S)z�Return dictionary with plugin's parameters and their hints

		Parameters:
		plugin_name -- name of plugin

		Return:
		dictionary -- {parameter_name: hint}
		r:)rrQr�get_plugin_hintsrG)rrkr=rrr
ro5s
zController.get_plugin_hintscCsD|dks|jj|�rdS|jjr@|jjjr@|jjjj|�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
		r:FT)rrQrZ_applicationZ_unix_socket_exporterZregister_signal_path)r�pathr=rrr
�register_socket_signal_pathCs
z&Controller.register_socket_signal_pathZssc
Cs�|dkrdS|jj|�sdS|jj|�s,dSd}x2|jjjD]$}|j|kr<tjd|j�d}Pq<W|s�d|}tj|�d|fSt	|jj
|��}tjd	|jt|�f�x�|jjjD]�}|j|@}	t
|	�r�||	8}tjd
t|	�|j|jf�|jj|jjk�r6d|j|jjt|	�|j|jjf}tj|�d|fS|jj||	�|jj||	�q�Wt
|��r~dt|�}tj|�d|fSdS)Nr:FrO�Invalid devices�Invalid instance_namezFound 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'.rE)FrO)Frr)Frs)TrE)rrQr�
_unit_manager�	instancesrIr#�debugrCr.Zdevstr2devsrG�processed_devices�lenr$�pluginZ_remove_devices_nocheckZ_add_devices_nocheck)
rZdevices�
instance_namer=�foundZinstance_target�retsZdevs�instanceZdevs_movingrrr
�instance_acquire_devicesWsJ





z#Controller.instance_acquire_devicesz	(bsa(ss))cs�|dkrddgfS|jj��s(ddgfS�dkr\�|j�j�kr\d�}tj|�d|gfStdd�|jjj	�}�dkr�t�fdd�|�}d	d
t
tdd�|��fS)aReturn a list of active instances of a plugin or all active instances

		Parameters:
		plugin_name -- name of the plugin or an empty string

		Return:
		bool -- True on success
		string -- error message or "OK"
		list of string pairs -- [(instance_name, plugin_name)]
		r:FrOzInvalid plugin_namezPlugin '%s' does not existcSs|jS)N)Zactive)r}rrr
�<lambda>�sz*Controller.get_instances.<locals>.<lambda>cs|jj�kS)N)ryrI)r})rkrr
r�sTrEcSs|j|jjfS)N)rIry)r}rrr
r�s)rrQrh�keysr#rC�filterrrtru�list�map)rrkr=r|rur)rkr
�
get_instancess



zController.get_instancesz(bsas)cCsv|dkrddgfS|jj|�s(ddgfSx0|jjjD]"}|j|kr4ddtt|j��fSq4Wd|}t	j
|�d|gfS)z�Return a list of devices assigned to an instance

		Parameters:
		instance_name -- name of the instance

		Return:
		bool -- True on success
		string -- error message or "OK"
		list of strings -- device names
		r:FrOzInvalid instance_nameTrEzInstance '%s' not found)rrQrrtrurI�sortedr�rwr#rC)rrzr=r}r|rrr
�instance_get_devices�s



zController.instance_get_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)N)N))rrr�__doc__rr-r/r1r�signalr4r8Zexportr<r7r%rBr+r0rNrRrTrUrXrYrZr?r^r_rarSrcrdrhrnrorqr~r�r��
__classcell__rr)r!r
r%sv	

























'

)r5rZ
tuned.logsZtuned.exceptionsrr	Ztuned.constsr'Ztuned.utils.commandsr�__all__r6�getr#�objectrZ
interfacesZExportableInterfacerrrrr
�<module>s



?>