3 DaemonNcCstjdtj|_ttj|_ttj|_ tj |_ d|_ tj |_|dk r|jtjtj|_t|jtjtj|_t|jtjtj|_ |jtjtj |_ |jtjtj|_ |jtjtj |_||_|jdkrttj|_|j dkrd|_ n|j |jkr|j|_ |j |j|_tjd|j|j rJtjdtjd|j|j|jft|j d|_||_||_|jt |_!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)%logdebugconstsZCFG_DEF_DAEMON_daemonintZCFG_DEF_SLEEP_INTERVAL_sleep_intervalZCFG_DEF_UPDATE_INTERVALZ_update_intervalZCFG_DEF_DYNAMIC_TUNING_dynamic_tuningZ_recommend_commandZCFG_DEF_ROLLBACK _rollbackZget_boolZ CFG_DAEMONgetZCFG_SLEEP_INTERVALZCFG_UPDATE_INTERVALZCFG_DYNAMIC_TUNINGZCFG_RECOMMEND_COMMANDZCFG_DEF_RECOMMEND_COMMAND CFG_ROLLBACK _application _sleep_cyclesinfor_profile_recommender _unit_manager_profile_loader _init_threadsr_cmd _init_profilererror)selfZ unit_managerprofile_loader profile_namesconfigZ applicationer!/usr/lib/python3.6/daemon.py__init__sF        zDaemon.__init__cCsFd|_tj|_tj|_tj|_tj|_|jjtj|_dS)N) _thread threadingZEvent _terminate_terminate_profile_switch _not_used_sighup_processingset_profile_applied)rr!r!r"r7s     zDaemon._init_threadscCs|jddS)zARead configuration files again and load profile according to themN)r)rr!r!r"reload_profile_configCszDaemon.reload_profile_configcCsd}|jj}|dkrP|j\}}|dkrrd}|r<|d7}n|d7}tj|n"|dkrr|rhtjdn tjdd|_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_profileset_all_profiles)rrmanualpost_loaded_profilemsgr!r!r"rGs&      zDaemon._init_profilecCs|pd}|j}|jr2tjd|j||jg}x:|D]2}||jjjkr8d|}|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_changedrrloadr/r0r1rjoin)rrr4Z profile_listprofileerrstrr r!r!r"_load_profiles`s*    zDaemon._load_profilescCs2|jr"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|jdkr*d}t|n||_dS)NzYWhitespace is not allowed in profile names; only a single post-loaded profile is allowed.)r2lenr8r)r profile_namer=r!r!r"_set_post_loaded_profiles  zDaemon._set_post_loaded_profileFcCsV|jr"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"r3s   zDaemon.set_all_profilescCs|jS)N)r/)rr!r!r"r<szDaemon.profilecCs|jS)N)r0)rr!r!r"r4sz Daemon.manualcCs|jr |jSdS)N)r/r2)rr!r!r"r5szDaemon.post_loaded_profilecCs|jS)N)r)rr!r!r"profile_recommenderszDaemon.profile_recommendercCs|jS)N)r)rr!r!r"rszDaemon.profile_loadercCs |jdk rtjtj||||S)N)rrZ send_signalr ZSIGNAL_PROFILE_CHANGED)rrresultr=r!r!r"r9s zDaemon._notify_profile_changedcCsj|jjddgdgd\}}|dkr&dS|dddkr:dS|jjddgdgd\}}tjd |dkoh| S) NZ systemctlzis-system-runningr)Z no_errorsFZstoppingz list-jobsz0\b(shutdown|reboot|halt|poweroff)\.target.*start)rZexecuteresearch)rZretcodeoutr!r!r"_full_rollback_requiredszDaemon._full_rollback_requiredcCs|jdkrtd|jj|jj|jdj|j|j|j |j |jj |j j tjd|jj|jrxtjdj|j}|j|dd|jj|jr|j}x\|jj|j|js|jr|d8}|dkr|j}tjd|jjtjd |jjqW|j jd}x.|jj|j |j rD|d krD|d7}qW|j!j"rZt#j$}njt#j%}|j&svtjd nN|j'd krt#j(}tjd t#j)t#j*fn$|jrtjdt#j$}n tjd|jr|jj+||jj,dS)Nz2Cannot start the daemon without setting a profile.r7z'static tuning from profile '%s' appliedTZOKrArzupdating monitorszperforming tuningsz1terminating TuneD due to system shutdown / rebootZ not_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*rrnamer rstartr9r)clearrrwaitr&r rr Zupdate_monitorsZ update_tuningr(r'is_setr Z ROLLBACK_FULLZ ROLLBACK_SOFTrMrZ ROLLBACK_NONErZGLOBAL_CONFIG_FILEZ stop_tuningZ destroy_all)rrZ _sleep_cntiZrollbackr!r!r" _thread_codesX          "        zDaemon._thread_codecCsHy|jj||Wn0tk rB}ztjt|WYdd}~XnXdS)N)rZsave_active_profilerrrstr)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 |jjjS)z$Return all accessible plugin classes)rplugins_repositoryZload_all_plugins)rr!r!r"get_all_plugins"szDaemon.get_all_pluginsc Cs.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_documentationc Cs0y|jjj|}Wntk r&iSX|jS)zReturn 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|jjS)N)r$Zis_alive)rr!r!r"r?DszDaemon.is_runningcCs`|jr dS|jdkrdStjd|jjtj|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||jstjddS|jdkr.tjddS|jjsFtjddS|jjtjd|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_missingretr!r!r"verify_profileVs        zDaemon.verify_profilecCsB|js dStjd|r$|jj|jj|jjd|_dS)NFzstopping tuningT)r?rrr'r*r&r$r;)rZprofile_switchr!r!r"stopls    z Daemon.stop)NNN)F)F) __name__ __module__ __qualname__r#rr,rr>r@rDr3propertyr<r4r5rGrr9rMrUrErFrWr.rYr_r`rar?rPrdrer!r!r!r"rs8 &         G r)oserrnor%Z tuned.logsZtunedZtuned.exceptionsrZtuned.profiles.exceptionsrZ tuned.constsr Ztuned.utils.commandsrrZtuned.utils.profile_recommenderrrJZlogsrrobjectrr!r!r!r"s