ok

Mini Shell

Direktori : /lib/python3.6/site-packages/tuned/daemon/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/tuned/daemon/__pycache__/daemon.cpython-36.pyc

3

�<�e�3�@s�ddlZddlZddlZddlZddlmZddlmZddl	j
Z
ddlmZddlm
Z
ddlmZddlZejj�ZGdd�de�ZdS)	�N)�TunedException)�InvalidProfileException)�commands)�exports)�ProfileRecommenderc@seZdZd;dd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	d<dd�Z
edd��Zedd��Z
edd��Zedd��Zedd��Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd=d9d:�ZdS)>�DaemonNcCs�tjd�tj|_ttj�|_ttj�|_	tj
|_d|_tj
|_|dk	r�|jtjtj�|_t|jtjtj��|_t|jtjtj��|_	|jtjtj
�|_|jtjtj�|_|jtjtj
�|_||_|jdkr�ttj�|_|j	dkr�d|_n|j	|jkr�|j|_	|j	|j|_tjd|j�|j�rJtjd�tjd|j|j|jf�t|jd�|_||_||_|j�t �|_!y|j"|�Wn2t#k
�r�}ztj$d	|�WYdd}~XnXdS)
Nzinitializing daemonTrFz$using sleep interval of %d second(s)z8dynamic tuning is enabled (can be overridden by plugins)zFusing update interval of %d second(s) (%d times of the sleep interval))Zis_hardcodedz:Cannot set initial profile. No tunings will be enabled: %s)%�log�debug�constsZCFG_DEF_DAEMON�_daemon�intZCFG_DEF_SLEEP_INTERVAL�_sleep_intervalZCFG_DEF_UPDATE_INTERVALZ_update_intervalZCFG_DEF_DYNAMIC_TUNING�_dynamic_tuningZ_recommend_commandZCFG_DEF_ROLLBACK�	_rollbackZget_boolZ
CFG_DAEMON�getZCFG_SLEEP_INTERVALZCFG_UPDATE_INTERVALZCFG_DYNAMIC_TUNINGZCFG_RECOMMEND_COMMANDZCFG_DEF_RECOMMEND_COMMAND�CFG_ROLLBACK�_application�
_sleep_cycles�infor�_profile_recommender�
_unit_manager�_profile_loader�
_init_threadsr�_cmd�
_init_profiler�error)�selfZunit_manager�profile_loader�
profile_names�configZapplication�e�r!�/usr/lib/python3.6/daemon.py�__init__sF



zDaemon.__init__cCsFd|_tj�|_tj�|_tj�|_tj�|_|jj�tj�|_dS)N)	�_thread�	threadingZEvent�
_terminate�_terminate_profile_switch�	_not_used�_sighup_processing�set�_profile_applied)rr!r!r"r7s




zDaemon._init_threadscCs|jd�dS)zARead configuration files again and load profile according to themN)r)rr!r!r"�reload_profile_configCszDaemon.reload_profile_configcCs�d}|jj�}|dkrP|j�\}}|dkrrd}|r<|d7}n|d7}tj|�n"|dkrr|rhtjd�n
tjd�d|_d|_g|_d|_|j	|||�dS)NTz.No profile is preset, running in manual mode. z(Only post-loaded profile will be enabledzNo profile will be enabled.�)
rZget_post_loaded_profile�_get_startup_profilerr�_profile�_manual�_active_profiles�_post_loaded_profile�set_all_profiles)rr�manual�post_loaded_profile�msgr!r!r"rGs&


zDaemon._init_profilecCs�|pd}|j�}|jr2tjd|j�||jg}x:|D]2}||jjj�kr8d|}|j|d|�t|��q8Wy.|r�|j	j
|�|_nd|_||_|j�|_
WnJtk
r�}z.ddj|�|f}|j|d|�t|��WYdd}~XnXdS)Nr-zUsing post-loaded profile '%s'z%Requested profile '%s' doesn't exist.FzCannot load profile(s) '%s': %s� )�splitr2rrrZprofile_locatorZget_known_names�_notify_profile_changedrr�loadr/r0r1r�join)rrr4Zprofile_list�profile�errstrr r!r!r"�_load_profiles`s*

zDaemon._load_profilescCs2|j�r"d}|j|d|�t|��|j||�dS)Nz/Cannot set profile while the daemon is running.F)�
is_runningr9rr>)rrr4r=r!r!r"�set_profilezszDaemon.set_profilecCs4|sd|_n$t|j��dkr*d}t|��n||_dS)N�zYWhitespace is not allowed in profile names; only a single post-loaded profile is allowed.)r2�lenr8r)r�profile_namer=r!r!r"�_set_post_loaded_profile�s
zDaemon._set_post_loaded_profileFcCsV|j�r"d}|j|d|�t|��|j|�|j||�|rR|j||�|j|�dS)Nz/Cannot set profile while the daemon is running.F)r?r9rrDr>�_save_active_profile�_save_post_loaded_profile)rZactive_profilesr4r5Zsave_instantlyr=r!r!r"r3�s
zDaemon.set_all_profilescCs|jS)N)r/)rr!r!r"r<�szDaemon.profilecCs|jS)N)r0)rr!r!r"r4�sz
Daemon.manualcCs|jr|jSdS)N)r/r2)rr!r!r"r5�szDaemon.post_loaded_profilecCs|jS)N)r)rr!r!r"�profile_recommender�szDaemon.profile_recommendercCs|jS)N)r)rr!r!r"r�szDaemon.profile_loadercCs |jdk	rtjtj|||�|S)N)rrZsend_signalr
ZSIGNAL_PROFILE_CHANGED)rr�resultr=r!r!r"r9�s
zDaemon._notify_profile_changedcCsj|jjddgdgd�\}}|dkr&dS|dd�dkr:dS|jjddgdgd�\}}tjd	|�dkoh|S)
NZ	systemctlzis-system-runningr)Z	no_errorsF�Zstoppingz	list-jobsz0\b(shutdown|reboot|halt|poweroff)\.target.*start)rZexecute�re�search)rZretcode�outr!r!r"�_full_rollback_required�szDaemon._full_rollback_requiredcCs�|jdkrtd��|jj|jj�|jdj|j�|j�|j	|j
�|jj�|jj
�tjd|jj�|jrxtj�dj|j�}|j|dd�|jj�|j�r|j}x\|jj|j|j��s|jr�|d8}|dkr�|j}tjd�|jj�tjd	�|jj�q�W|jj�d}x.|jj|j |j��rD|d
k�rD|d7}�qW|j!j"��rZt#j$}njt#j%}|j&��svtjd�nN|j'dk�r�t#j(}tjd
t#j)t#j*f�n$|j�r�tjd�t#j$}n
tjd�|j�r�|jj+|�|jj,�dS)Nz2Cannot start the daemon without setting a profile.r7z'static tuning from profile '%s' appliedTZOKrArzupdating monitorszperforming tunings�z1terminating TuneD due to system shutdown / rebootZnot_on_exitzMterminating TuneD and not rolling back any changes due to '%s' option in '%s'z+terminating TuneD, rolling back all changesz"terminating TuneD in one-shot mode)-r/rrZcreateZunitsrEr;r1r0rFr2Zstart_tuningr+r*rr�namerr�startr9r)�clearrr�waitr&r
rr	Zupdate_monitorsZ
update_tuningr(r'�is_setr
Z
ROLLBACK_FULLZ
ROLLBACK_SOFTrMrZ
ROLLBACK_NONErZGLOBAL_CONFIG_FILEZstop_tuningZdestroy_all)rrZ
_sleep_cnt�iZrollbackr!r!r"�_thread_code�sX







"



zDaemon._thread_codecCsHy|jj||�Wn0tk
rB}ztjt|��WYdd}~XnXdS)N)rZsave_active_profilerrr�str)rrr4r r!r!r"rEszDaemon._save_active_profilecCsFy|jj|�Wn0tk
r@}ztjt|��WYdd}~XnXdS)N)rZsave_post_loaded_profilerrrrV)rrCr r!r!r"rFsz Daemon._save_post_loaded_profilecCs&tjd�|jj�}tjd|�|S)NzWRunning in automatic mode, checking what profile is recommended for your configuration.zUsing '%s' profile)rrrZ	recommend)rr<r!r!r"�_get_recommended_profiles

zDaemon._get_recommended_profilecCs2|jj�\}}|dkr|dk	}|s*|j�}||fS)N)rZget_active_profilerW)rr<r4r!r!r"r.szDaemon._get_startup_profilecCs|jjj�S)z$Return all accessible plugin classes)r�plugins_repositoryZload_all_plugins)rr!r!r"�get_all_plugins"szDaemon.get_all_pluginscCs.y|jjj|�}Wntk
r&dSX|jS)zReturn plugin class docstringr-)rrX�load_plugin�ImportError�__doc__)r�plugin_name�plugin_classr!r!r"�get_plugin_documentation&s
zDaemon.get_plugin_documentationcCs0y|jjj|�}Wntk
r&iSX|j�S)z�Return plugin's parameters and their hints

		Parameters:
		plugin_name -- plugins name

		Return:
		dictionary -- {parameter_name: hint}
		)rrXrZr[Zget_config_options_hints)rr]r^r!r!r"�get_plugin_hints0s	
zDaemon.get_plugin_hintscCs
|jdk	S)N)r/)rr!r!r"�
is_enabledAszDaemon.is_enabledcCs|jdk	o|jj�S)N)r$Zis_alive)rr!r!r"r?DszDaemon.is_runningcCs`|j�rdS|jdkrdStjd�|jj�tj|jd�|_	|j
j�|jj�|j	j
�dS)NFzstarting tuning)�targetT)r?r/rrr(r*r%ZThreadrUr$r'rQr&rP)rr!r!r"rPGs





zDaemon.startcCs||j�stjd�dS|jdkr.tjd�dS|jj�sFtjd�dS|jj�tjd|jj	�|j
j|�}|jj�|S)NzTuneD is not runningFzno profile is setzprofile is not appliedzverifying profile(s): %s)
r?rrr/r+rSr(rQrrOrZ
verify_tuningr*)rZignore_missing�retr!r!r"�verify_profileVs






zDaemon.verify_profilecCsB|j�sdStjd�|r$|jj�|jj�|jj�d|_dS)NFzstopping tuningT)r?rrr'r*r&r$r;)rZprofile_switchr!r!r"�stopls



zDaemon.stop)NNN)F)F) �__name__�
__module__�__qualname__r#rr,rr>r@rDr3�propertyr<r4r5rGrr9rMrUrErFrWr.rYr_r`rar?rPrdrer!r!r!r"rs8
&	

	G
r)�os�errnor%Z
tuned.logsZtunedZtuned.exceptionsrZtuned.profiles.exceptionsrZtuned.constsr
Ztuned.utils.commandsrrZtuned.utils.profile_recommenderrrJZlogsrr�objectrr!r!r!r"�<module>s



Zerion Mini Shell 1.0