a ”ˆ«h4ã@sŽddlZddlZddlZddlZddlmZddlmZddl m Z ddl m Z ddlm Z ddlmZddlZej ¡ZGdd„deƒZdS) éN)ÚTunedException)ÚInvalidProfileException)Úcommands)Úexports)ÚProfileRecommenderc@seZdZd;dd„Zdd„Zdd„Zdd „Zd d „Zd d „Zdd„Z dÚDaemonNc CsÎt d¡tj|_ttjƒ|_ttjƒ|_ tj |_ d|_ tj |_|dur¼| tjtj¡|_t| tjtj¡ƒ|_t| tjtj¡ƒ|_ | tjtj ¡|_ | tjtj¡|_ | tjtj ¡|_||_|jdkrØttjƒ|_|j dkrêd|_ n|j |jkrþ|j|_ |j |j|_t d|j¡|j rJt d¡t d|j|j|jf¡t|j d|_||_||_| ¡t ƒ|_!z| "|¡WnDt#yÈ}z*t $d |¡|js´t#d ƒ‚WYd}~n d}~00dS) 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: %szŸszDaemon.profilecCs|jSr#)r2r-r r r!r6£sz Daemon.manualcCs|jr |jSdSr#)r1r4r-r r r!r7§szDaemon.post_loaded_profilecCs|jSr#)rr-r r r!Úprofile_recommender­szDaemon.profile_recommendercCs|jSr#)rr-r r r!r±szDaemon.profile_loadercCs |jdurt tj|||¡|Sr#)rrZ send_signalr ZSIGNAL_PROFILE_CHANGED)rrÚresultr?r r r!r;·s zDaemon._notify_profile_changedcCsj|jjddgdgd\}}|dkr&dS|dd…dkr:dS|jjddgdgd\}}t d |¡duoh| 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Ü|jdurtdƒ‚|j |jj¡| d |j¡|j¡|  |j ¡|j  ¡|j   ¡t d|jj¡|jrxt ¡d |j¡}| |dd¡|j ¡|jr|j}|j |j|j¡s|jrª|d8}|dkrª|j}t d¡|j ¡t d ¡|j ¡qª|j  ¡d}|j |j |j¡s<|d kr<|d7}q|j! "¡rPt#j$}njt#j%}| &¡slt d ¡nN|j'd kr–t#j(}t d t#j)t#j*f¡n$|jr°t d¡t#j$}n t d¡|jrÎ|j +|¡|j ,¡dS)Nz2Cannot start the daemon without setting a profile.r9z'static tuning from profile '%s' appliedTZOKrDrzupdating monitorszperforming tuningséz1terminating 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)-r1rrZcreateZunitsrHr=r3r2rIr4Z start_tuningr,r+rrÚnamer rÚstartr;r*ÚclearrrÚwaitr'r rr Zupdate_monitorsZ update_tuningr)r(Úis_setr Z ROLLBACK_FULLZ ROLLBACK_SOFTrQrZ ROLLBACK_NONErZGLOBAL_CONFIG_FILEZ stop_tuningZ destroy_all)rrZ _sleep_cntÚiZrollbackr r r!Ú _thread_codeÅsZ ÿ                   zDaemon._thread_codec CsJz|j ||¡Wn2tyD}zt t|ƒ¡WYd}~n d}~00dSr#)rZsave_active_profilerrrÚstr)rrr6rr r r!rH szDaemon._save_active_profilec CsHz|j |¡Wn2tyB}zt t|ƒ¡WYd}~n d}~00dSr#)rZsave_post_loaded_profilerrrrZ)rrFrr r r!rIsz Daemon._save_post_loaded_profilecCs&t d¡|j ¡}t d|¡|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|j ¡\}}|dur|du}|s*| ¡}||fSr#)rZget_active_profiler[)rr>r6r r r!r0s zDaemon._get_startup_profilecCs |jj ¡S)z$Return all accessible plugin classes)rÚplugins_repositoryZload_all_classesr-r r r!Úget_all_plugins&szDaemon.get_all_pluginscCs.z|jj |¡}Wnty&YdS0|jS)zReturn plugin class docstringr/)rr\Ú load_classÚ ImportErrorÚ__doc__©rZ plugin_nameZ plugin_classr r r!Úget_plugin_documentation*sÿ zDaemon.get_plugin_documentationcCs2z|jj |¡}Wnty(iYS0| ¡S)zŒReturn plugin's parameters and their hints Parameters: plugin_name -- plugins name Return: dictionary -- {parameter_name: hint} )rr\r^r_Zget_config_options_hintsrar r r!Úget_plugin_hints4s ÿ  zDaemon.get_plugin_hintscCs |jduSr#rJr-r r r!Ú is_enabledEszDaemon.is_enabledcCs|jduo|j ¡Sr#)r$Úis_aliver-r r r!rBHszDaemon.is_runningcCs`| ¡r dS|jdurdSt d¡|j ¡tj|jd|_ |j   ¡|j   ¡|j   ¡dS)NFzstarting tuning)ÚtargetT)rBr1rrr)r+r%ÚThreadrYr$r(rUr'rTr-r r r!rTKs      z Daemon.startcCs|| ¡st d¡dS|jdur.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) rBrrr1r,rWr)rUrrSrZ verify_tuningr+)rZignore_missingÚretr r r!Úverify_profileZs        zDaemon.verify_profilecCsB| ¡s dSt d¡|r$|j ¡|j ¡|j ¡d|_dS)NFzstopping tuningT)rBrrr(r+r'r$r=)rZprofile_switchr r r!Ústopps    z Daemon.stop)NNN)F)F) Ú__name__Ú __module__Ú __qualname__r"rr.rr@rCrGr5Úpropertyr>r6r7rKrr;rQrYrHrIr[r0r]rbrcrdrBrTrirjr r r r!rsD (  ÿ       G r)ÚosÚerrnor%Z tuned.logsZtunedZtuned.exceptionsrZtuned.profiles.exceptionsrZ tuned.constsr Ztuned.utils.commandsrrZtuned.utils.profile_recommenderrrNZlogsrrÚobjectrr r r r!Ús