관리-도구
편집 파일: daemon.cpython-39.opt-1.pyc
a ����,�g4����������������������@���s����d�dl�Z�d�dlZd�dlZd�dlZd�dlmZ�d�dlmZ�d�dl m Z �d�dlmZ�d�dlm Z �d�dlmZ�d�dlZej���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��d��tj|�_ttj�|�_ttj�|�_ tj |�_d|�_tj |�_|d�ur�|�tjtj�|�_t|�tjtj��|�_t|�tjtj��|�_ |�tjtj �|�_|�tjtj�|�_|�tjtj �|�_||�_|�jdkr�ttj�|�_|�j dkr�d|�_n|�j |�jk�r�|�j|�_ |�j |�j�|�_t��d|�j���|�j�rJt��d��t��d|�j|�j�|�jf���t|�j�d�|�_||�_||�_|�����t ��|�_!z|��"|��W�n4�t#�y��}�zt��$d |���W�Y�d�}~n d�}~0�0�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_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)�selfZunit_manager�profile_loader� profile_namesZconfigZapplication�e��r ����7/usr/lib/python3.9/site-packages/tuned/daemon/daemon.py�__init__���sF���� zDaemon.__init__c�����������������C���sP���d�|�_�t���|�_t���|�_t���|�_t���|�_t���|�_|�j����t���|�_ d�S��N) �_thread� threading�Event� _terminate�_terminate_profile_switch� _not_used�_sighup_processingZ_sighup_pending�set�_profile_applied�r���r ���r ���r!���r���7���s���� zDaemon._init_threadsc�����������������C���s���|���d��dS�)zARead configuration files again and load profile according to themN)r���r-���r ���r ���r!����reload_profile_configE���s����zDaemon.reload_profile_configc�����������������C���s����d}|�j����}|d�u�rP|����\}}|d�u�rrd}|r<|d7�}n|d7�}t�|��n"|dkrr|rht�d��n t�d��d�|�_d�|�_g�|�_d�|�_|�� |||��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���I���s&���� zDaemon._init_profilec�������������� ���C���s����|pd}|����}|�jr2t�d|�j���||�jg�}|D�]2}||�jj���vr6d|�}|��|d|��t|��q6z.|r�|�j � |�|�_nd�|�_||�_|����|�_ W�nL�ty��}�z4dd�|�|f�}|��|d|��t|��W�Y�d�}~n d�}~0�0�d�S�)Nr/���zUsing post-loaded profile '%s'z%Requested profile '%s' doesn't exist.FzCannot load profile(s) '%s': %s� )�splitr4���r���r���r���Zprofile_locatorZget_known_names�_notify_profile_changedr���r����loadr1���r2���r3���r����join)r���r���r6���Zprofile_list�profile�errstrr���r ���r ���r!����_load_profilesb���s,����� zDaemon._load_profilesc�����������������C���s2���|�����r"d}|��|d|��t|��|��||��d�S��Nz/Cannot set profile while the daemon is running.F)� is_runningr;���r���r@���)r���r���r6���r?���r ���r ���r!����set_profile|���s�����zDaemon.set_profilec�����������������C���s4���|sd�|�_�n$t|����dkr*d}t|��n||�_�d�S�)N����zYWhitespace is not allowed in profile names; only a single post-loaded profile is allowed.)r4����lenr:���r���)r����profile_namer?���r ���r ���r!����_set_post_loaded_profile����s���� zDaemon._set_post_loaded_profileFc�����������������C���sV���|�����r"d}|��|d|��t|��|��|��|��||��|rR|��||��|��|��d�S�rA���)rB���r;���r���rG���r@����_save_active_profile�_save_post_loaded_profile)r���Zactive_profilesr6���r7���Zsave_instantlyr?���r ���r ���r!���r5�������s����� zDaemon.set_all_profilesc�����������������C���s���|�j�S�r#����r1���r-���r ���r ���r!���r>�������s����zDaemon.profilec�����������������C���s���|�j�S�r#���)r2���r-���r ���r ���r!���r6�������s����z Daemon.manualc�����������������C���s���|�j�r|�jS�d�S�r#���)r1���r4���r-���r ���r ���r!���r7�������s����zDaemon.post_loaded_profilec�����������������C���s���|�j�S�r#���)r���r-���r ���r ���r!����profile_recommender����s����zDaemon.profile_recommenderc�����������������C���s���|�j�S�r#���)r���r-���r ���r ���r!���r�������s����zDaemon.profile_loaderc�����������������C���s ���|�j�d�urt�tj|||��|S�r#���)r���r���Zsend_signalr ���ZSIGNAL_PROFILE_CHANGED)r���r����resultr?���r ���r ���r!���r;�������s���� zDaemon._notify_profile_changedc�����������������C���sj���|�j�jddgdgd�\}}|dk�r&dS�|d�d��dkr:dS�|�j�jddgdgd�\}}t�d |�d�u�oh|�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�u�rtd��|�j�|�j�j��|��d�|�j�|�j��|�� |�j ��|�j����|�j� ���t�d|�j�j���|�jrxt����d�|�j�}|��|dd��|�j����|�j�r|�j}|�j�|�j|�j��s|�jr�|d8�}|dkr�|�j}t�d��|�j����t�d ��|�j����q�|�j����d}|�j�|�j |�j��s<|d k��r<|d7�}�q|�j!�"���rPt#j$}njt#j%}|��&���slt�d��nN|�j'dk�r�t#j(}t�d t#j)t#j*f���n$|�j�r�t�d��t#j$}n t�d��|�j�r�|�j�+|��|�j�,���d�S�)Nz2Cannot start the daemon without setting a profile.r9���z'static tuning from profile '%s' appliedTZOKrD���r���zupdating 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)-r1���r���r���ZcreateZunitsrH���r=���r3���r2���rI���r4���Zstart_tuningr,���r+���r���r����namer���r����startr;���r*����clearr���r����waitr'���r ���r���r ���Zupdate_monitorsZ update_tuningr)���r(����is_setr ���Z ROLLBACK_FULLZ ROLLBACK_SOFTrQ���r���Z ROLLBACK_NONEr���ZGLOBAL_CONFIG_FILEZstop_tuningZdestroy_all)r���r���Z _sleep_cnt�iZrollbackr ���r ���r!����_thread_code����sZ���� � zDaemon._thread_codec�������������� ���C���sJ���z|�j��||��W�n2�tyD�}�zt�t|���W�Y�d�}~n d�}~0�0�d�S�r#���)r���Zsave_active_profiler���r���r����str)r���r���r6���r���r ���r ���r!���rH��� ��s����zDaemon._save_active_profilec�������������� ���C���sH���z|�j��|��W�n2�tyB�}�zt�t|���W�Y�d�}~n d�}~0�0�d�S�r#���)r���Zsave_post_loaded_profiler���r���r���rZ���)r���rF���r���r ���r ���r!���rI�����s����z Daemon._save_post_loaded_profilec�����������������C���s&���t��d��|�j���}t��d|���|S�)NzWRunning in automatic mode, checking what profile is recommended for your configuration.zUsing '%s' profile)r���r���r���Z recommend)r���r>���r ���r ���r!����_get_recommended_profile��s���� zDaemon._get_recommended_profilec�����������������C���s2���|�j����\}}|d�u�r|d�u}|s*|����}||fS�r#���)r���Zget_active_profiler[���)r���r>���r6���r ���r ���r!���r0�����s����zDaemon._get_startup_profilec�����������������C���s���|�j�j���S�)z$Return all accessible plugin classes)r����plugins_repositoryZload_all_classesr-���r ���r ���r!����get_all_plugins$��s����zDaemon.get_all_pluginsc�����������������C���s.���z|�j�j�|�}W�n�ty&���Y�dS�0�|jS�)zReturn plugin class docstringr/���)r���r\���� load_class�ImportError�__doc__�r���Zplugin_nameZplugin_classr ���r ���r!����get_plugin_documentation(��s�����zDaemon.get_plugin_documentationc�����������������C���s2���z|�j�j�|�}W�n�ty(���i��Y�S�0�|���S�)z�Return plugin's parameters and their hints Parameters: plugin_name -- plugins name Return: dictionary -- {parameter_name: hint} )r���r\���r^���r_���Zget_config_options_hintsra���r ���r ���r!����get_plugin_hints2��s���� � zDaemon.get_plugin_hintsc�����������������C���s ���|�j�d�uS�r#���rJ���r-���r ���r ���r!���� is_enabledC��s����zDaemon.is_enabledc�����������������C���s���|�j�d�uo|�j����S�r#���)r$����is_aliver-���r ���r ���r!���rB���F��s����zDaemon.is_runningc�����������������C���s`���|�����rdS�|�jd�u�rdS�t�d��|�j����tj|�jd�|�_ |�j ����|�j����|�j � ���dS�)NFzstarting tuning)�targetT)rB���r1���r���r���r)���r+���r%����ThreadrY���r$���r(���rU���r'���rT���r-���r ���r ���r!���rT���I��s���� zDaemon.startc�����������������C���s|���|�����st�d��dS�|�jd�u�r.t�d��dS�|�j���sFt�d��dS�|�j����t�d|�jj ���|�j �|�}|�j����|S�)NzTuneD is not runningFzno profile is setzprofile is not appliedzverifying profile(s): %s) rB���r���r���r1���r,���rW���r)���rU���r���rS���r���Z verify_tuningr+���)r���Zignore_missing�retr ���r ���r!����verify_profileX��s���� zDaemon.verify_profilec�����������������C���sB���|�����sdS�t�d��|r$|�j����|�j����|�j����d�|�_dS�)NFzstopping tuningT)rB���r���r���r(���r+���r'���r$���r=���)r���Zprofile_switchr ���r ���r!����stopn��s���� zDaemon.stop)NNN)F)F) �__name__� __module__�__qualname__r"���r���r.���r���r@���rC���rG���r5����propertyr>���r6���r7���rK���r���r;���rQ���rY���rH���rI���r[���r0���r]���rb���rc���rd���rB���rT���ri���rj���r ���r ���r ���r!���r������sD��� & �� G r���)�os�errnor%���Z tuned.logsZtunedZtuned.exceptionsr���Ztuned.profiles.exceptionsr���Ztuned.constsr ���Ztuned.utils.commandsr���r���Ztuned.utils.profile_recommenderr���rN���Zlogsr���r����objectr���r ���r ���r ���r!����<module>���s���