Edit File: daemon.cpython-36.opt-1.pyc
3 ��cY0������������������@���s����d�dl�Z�d�dlZd�dlZd�dlZd�dlmZ�d�dlmZ�d�dl j Z d�dlmZ�d�dlm Z �d�dlmZ�d�dlZejj��ZG�dd��de�ZdS�) �����N)�TunedException)�InvalidProfileException)�commands)�exports)�ProfileRecommenderc���������������@���s��e�Zd�Zd;dd�Zdd��Zdd��Zdd ��Zd d��Zdd ��Zdd��Z d<dd�Z edd���Zedd���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�)>�DaemonNc�������������C���s���t�jd��tj|�_ttj�|�_ttj�|�_ tj |�_d|�_|d�k r�|j tjtj�|�_t|jtjtj��|�_t|jtjtj��|�_ |j tjtj �|�_|j tjtj�|�_||�_|�jdkr�ttj�|�_|�j dkr�d|�_n|�j |�jk�r�|�j|�_ |�j |�j�|�_t�jd|�j���|�j�r0t�jd��t�jd|�j|�j�|�jf���t|�j�d�|�_||�_||�_|�j���t��|�_y|�j|��W�n2�t k �r��}�zt�j!d |���W�Y�d�d�}~X�nX�d�S�) Nzinitializing daemonTr���Fz$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))Zis_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_commandZget_boolZ CFG_DAEMON�getZCFG_SLEEP_INTERVALZCFG_UPDATE_INTERVALZCFG_DYNAMIC_TUNINGZCFG_RECOMMEND_COMMANDZCFG_DEF_RECOMMEND_COMMAND�_application� _sleep_cycles�infor����_profile_recommender� _unit_manager�_profile_loader� _init_threadsr����_cmd� _init_profiler����error)�selfZunit_manager�profile_loader� profile_names�configZapplication�e��r����/usr/lib/python3.6/daemon.py�__init__���sB���� zDaemon.__init__c�������������C���s<���d�|�_�tj��|�_tj��|�_tj��|�_|�jj���tj��|�_d�S�)N)�_thread� threadingZEvent� _terminate�_terminate_profile_switch� _not_used�set�_profile_applied)r���r���r���r ���r���5���s���� zDaemon._init_threadsc�������������C���s���|�j�d��dS�)zARead configuration files again and load profile according to themN)r���)r���r���r���r ����reload_profile_config?���s����zDaemon.reload_profile_configc�������������C���s����d}|�j�j��}|d�krP|�j��\}}|d�krrd}|r<|d7�}n|d7�}tj|��n"|dkrr|rhtjd��n tjd��d�|�_d�|�_g�|�_d�|�_|�j |||��d�S�)NTz.No profile is preset, running in manual mode. z(Only post-loaded profile will be enabledzNo profile will be enabled.��) r���Zget_post_loaded_profile�_get_startup_profiler���r����_profile�_manual�_active_profiles�_post_loaded_profile�set_all_profiles)r���r����manual�post_loaded_profile�msgr���r���r ���r���C���s&���� zDaemon._init_profilec�������������C���s����|pd}|j���}|�jr2tjd|�j���||�jg�}x:|D�]2}||�jjj��kr8d|�}|�j|d|��t|��q8W�y.|r�|�j j |�|�_nd�|�_||�_|j���|�_ W�nJ�tk r��}�z.ddj|�|f�}|�j|d|��t|��W�Y�d�d�}~X�nX�d�S�)Nr*���zUsing post-loaded profile '%s'z%Requested profile '%s' doesn't exist.FzCannot load profile(s) '%s': %s� )�splitr/���r���r���r���Zprofile_locatorZget_known_names�_notify_profile_changedr���r����loadr,���r-���r.���r����join)r���r���r1���Zprofile_list�profile�errstrr���r���r���r ����_load_profiles\���s*���� zDaemon._load_profilesc�������������C���s2���|�j���r"d}|�j|d|��t|��|�j||��d�S�)Nz/Cannot set profile while the daemon is running.F)� is_runningr6���r���r;���)r���r���r1���r:���r���r���r ����set_profilev���s����zDaemon.set_profilec�������������C���s4���|sd�|�_�n$t|j���dkr*d}t|��n||�_�d�S�)N����zYWhitespace is not allowed in profile names; only a single post-loaded profile is allowed.)r/����lenr5���r���)r����profile_namer:���r���r���r ����_set_post_loaded_profile���s���� zDaemon._set_post_loaded_profileFc�������������C���sV���|�j���r"d}|�j|d|��t|��|�j|��|�j||��|rR|�j||��|�j|��d�S�)Nz/Cannot set profile while the daemon is running.F)r<���r6���r���rA���r;����_save_active_profile�_save_post_loaded_profile)r���Zactive_profilesr1���r2���Zsave_instantlyr:���r���r���r ���r0�������s���� zDaemon.set_all_profilesc�������������C���s���|�j�S�)N)r,���)r���r���r���r ���r9�������s����zDaemon.profilec�������������C���s���|�j�S�)N)r-���)r���r���r���r ���r1�������s����z Daemon.manualc�������������C���s���|�j�r|�jS�d�S�)N)r,���r/���)r���r���r���r ���r2�������s����zDaemon.post_loaded_profilec�������������C���s���|�j�S�)N)r���)r���r���r���r ����profile_recommender����s����zDaemon.profile_recommenderc�������������C���s���|�j�S�)N)r���)r���r���r���r ���r�������s����zDaemon.profile_loaderc�������������C���s ���|�j�d�k rtjtj|||��|S�)N)r���r���Zsend_signalr ���ZSIGNAL_PROFILE_CHANGED)r���r����resultr:���r���r���r ���r6�������s���� zDaemon._notify_profile_changedc�������������C���sj���|�j�jddgdgd�\}}|dk�r&dS�|d�d��dkr:dS�|�j�jddgdgd�\}}tjd |�d�koh|�S�) NZ systemctlzis-system-runningr���)Z no_errorsF����Zstoppingz list-jobsz0\b(shutdown|reboot|halt|poweroff)\.target.*start)r���Zexecute�re�search)r���Zretcode�outr���r���r ����_full_rollback_required����s����zDaemon._full_rollback_requiredc�������������C���s���|�j�d�krtd��|�jj|�j�j��|�jdj|�j�|�j��|�j |�j ��|�jj���|�jj ���tjd|�j�j���|�jrxtj���dj|�j�}|�j|dd��|�jr�|�j}xZ|�jj|�j|�j�s�|�jr�|d8�}|dkr�|�j}tjd��|�jj���tjd ��|�jj���q�W�|�jj���d}x.|�jj|�j|�j���r6|d k��r6|d7�}�q W�|�j j!���rJd}n<d}|�j"���r||�j�rptjd��d}n tjd ��n tjd��|�j�r�|�jj#|��|�jj$���d�S�)Nz2Cannot start the daemon without setting a profile.r4���z'static tuning from profile '%s' appliedTZOKr>���r���zupdating monitorszperforming tunings����Fz+terminating TuneD, rolling back all changesz"terminating TuneD in one-shot modez1terminating TuneD due to system shutdown / reboot)%r,���r���r���ZcreateZunitsrB���r8���r.���r-���rC���r/���Zstart_tuningr(���r'���r���r����namer���r����startr6���r���r����waitr$���r ���r���r ���Zupdate_monitorsZ update_tuning�clearr&���r%����is_setrJ���Zstop_tuningZdestroy_all)r���r���Z _sleep_cnt�iZ full_rollbackr���r���r ����_thread_code����sP���� " zDaemon._thread_codec�������������C���sH���y|�j�j||��W�n0�tk rB�}�ztjt|���W�Y�d�d�}~X�nX�d�S�)N)r���Zsave_active_profiler���r���r����str)r���r���r1���r���r���r���r ���rB�������s����zDaemon._save_active_profilec�������������C���sF���y|�j�j|��W�n0�tk r@�}�ztjt|���W�Y�d�d�}~X�nX�d�S�)N)r���Zsave_post_loaded_profiler���r���r���rS���)r���r@���r���r���r���r ���rC�����s����z Daemon._save_post_loaded_profilec�������������C���s&���t�jd��|�jj��}t�jd|���|S�)NzWRunning in automatic mode, checking what profile is recommended for your configuration.zUsing '%s' profile)r���r���r���Z recommend)r���r9���r���r���r ����_get_recommended_profile��s���� zDaemon._get_recommended_profilec�������������C���s2���|�j�j��\}}|d�kr|d�k }|s*|�j��}||fS�)N)r���Zget_active_profilerT���)r���r9���r1���r���r���r ���r+��� ��s����zDaemon._get_startup_profilec�������������C���s���|�j�jj��S�)z$Return all accessible plugin classes)r����plugins_repositoryZload_all_plugins)r���r���r���r ����get_all_plugins��s����zDaemon.get_all_pluginsc�������������C���s.���y|�j�jj|�}W�n�tk r&���dS�X�|jS�)zReturn plugin class docstringr*���)r���rU����load_plugin�ImportError�__doc__)r����plugin_name�plugin_classr���r���r ����get_plugin_documentation��s���� zDaemon.get_plugin_documentationc�������������C���s0���y|�j�jj|�}W�n�tk r&���i�S�X�|j��S�)z�Return plugin's parameters and their hints Parameters: plugin_name -- plugins name Return: dictionary -- {parameter_name: hint} )r���rU���rW���rX���Zget_config_options_hints)r���rZ���r[���r���r���r ����get_plugin_hints#��s���� zDaemon.get_plugin_hintsc�������������C���s ���|�j�d�k S�)N)r,���)r���r���r���r ���� is_enabled4��s����zDaemon.is_enabledc�������������C���s���|�j�d�k o|�j�j��S�)N)r"���Zis_alive)r���r���r���r ���r<���7��s����zDaemon.is_runningc�������������C���s`���|�j���rdS�|�jd�krdS�tjd��|�jj���tj|�jd�|�_ |�j j���|�jj���|�j j ���dS�)NFzstarting tuning)�targetT)r<���r,���r���r���r&���r'���r#���ZThreadrR���r"���r%���rO���r$���rM���)r���r���r���r ���rM���:��s���� zDaemon.startc�������������C���s|���|�j���stjd��dS�|�jd�kr.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<���r���r���r,���r(���rP���r&���rO���r���rL���r���Z verify_tuningr'���)r���Zignore_missing�retr���r���r ����verify_profileI��s���� zDaemon.verify_profilec�������������C���sB���|�j���sdS�tjd��|r$|�jj���|�jj���|�jj���d�|�_dS�)NFzstopping tuningT)r<���r���r���r%���r'���r$���r"���r8���)r���Zprofile_switchr���r���r ����stop_��s���� zDaemon.stop)NNN)F)F) �__name__� __module__�__qualname__r!���r���r)���r���r;���r=���rA���r0����propertyr9���r1���r2���rD���r���r6���rJ���rR���rB���rC���rT���r+���rV���r\���r]���r^���r<���rM���ra���rb���r���r���r���r ���r������s8��� $ > r���)�os�errnor#���Z tuned.logsZtunedZtuned.exceptionsr���Ztuned.profiles.exceptionsr���Ztuned.constsr ���Ztuned.utils.commandsr���r���Ztuned.utils.profile_recommenderr���rG���Zlogsr���r����objectr���r���r���r���r ����<module>���s���