ó æ ”\c@sÄddlZddlZddlZddlZddlmZddlmZddl j Z ddl m Z ddlm Z ddlmZddlZejjƒZdefd„ƒYZdS( iÿÿÿÿN(tTunedException(tInvalidProfileException(tcommands(texports(tProfileRecommendertDaemoncBsïeZdddd„Zd„Zd„Zd„Zed„Ze d„ƒZ e d„ƒZ e d„ƒZ d„Z d „Zd „Zd „Zd „Zd „Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zed„ZRS(cCs%tjdƒtj|_ttjƒ|_ttjƒ|_ tj |_ t |_ |dk rô|jtjtjƒ|_t|jtjtjƒƒ|_t|jtjtjƒƒ|_ |jtjtj ƒ|_ |jtjtjƒ|_ n||_|jdkr!ttjƒ|_n|j dkr<t|_ n!|j |jkr]|j|_ n|j |j|_tjd|jƒ|j rÁtjdƒtjd|j|j|jfƒn||_||_|jƒtƒ|_y|j |ƒWn$t!k r }tj"d|ƒnXdS(Nsinitializing daemonis$using sleep interval of %d second(s)s8dynamic tuning is enabled (can be overridden by plugins)sFusing update interval of %d second(s) (%d times of the sleep interval)s:Cannot set initial profile. No tunings will be enabled: %s(#tlogtdebugtconststCFG_DEF_DAEMONt_daemontinttCFG_DEF_SLEEP_INTERVALt_sleep_intervaltCFG_DEF_UPDATE_INTERVALt_update_intervaltCFG_DEF_DYNAMIC_TUNINGt_dynamic_tuningtTruet_recommend_commandtNonetget_boolt CFG_DAEMONtgettCFG_SLEEP_INTERVALtCFG_UPDATE_INTERVALtCFG_DYNAMIC_TUNINGtCFG_RECOMMEND_COMMANDtCFG_DEF_RECOMMEND_COMMANDt _applicationtFalset _sleep_cyclestinfot _unit_managert_profile_loadert _init_threadsRt_cmdt _init_profileRterror(tselft unit_managertprofile_loadert profile_namestconfigt applicationte((s7/usr/lib/python2.7/site-packages/tuned/daemon/daemon.pyt__init__s@     !!    '    cCsVd|_tjƒ|_tjƒ|_tjƒ|_|jjƒtjƒ|_dS(N( Rt_threadt threadingtEventt _terminatet_terminate_profile_switcht _not_usedtsett_profile_applied(R'((s7/usr/lib/python2.7/site-packages/tuned/daemon/daemon.pyR#4s   cCs|jdƒdS(sARead configuration files again and load profile according to themN(R%R(R'((s7/usr/lib/python2.7/site-packages/tuned/daemon/daemon.pytreload_profile_config>scCs…t}|dkrC|jƒ\}}|dkr_tjdƒq_n|dkr_tjdƒnd|_d|_|j||ƒdS(NsINo profile is preset, running in manual mode. No profile will be enabled.tsNo profile will be enabled.(RRt_get_startup_profileRR t_profilet_manualt set_profile(R'R*tmanual((s7/usr/lib/python2.7/site-packages/tuned/daemon/daemon.pyR%Bs     cCs=|jƒr*t|j|tdƒƒ‚n|dksB|dkrWd|_||_n´|jƒ}xH|D]@}||jj j ƒkrjt|j|td|ƒƒ‚qjqjWy"|j j |ƒ|_||_Wn8t k r }t|j|td||fƒƒ‚nX|r9|dkr&d}n|j||ƒndS(Ns/Cannot set profile while the daemon is running.R8s%Requested profile '%s' doesn't exist.sCannot load profile(s) '%s': %s(t is_runningRt_notify_profile_changedRRR:R;tsplitR)tprofile_locatortget_known_namesR"tloadRt_save_active_profile(R'R*R=tsave_instantlyt profile_listtprofileR-((s7/usr/lib/python2.7/site-packages/tuned/daemon/daemon.pyR<Ps(       )  cCs|jS(N(R:(R'((s7/usr/lib/python2.7/site-packages/tuned/daemon/daemon.pyRGiscCs|jS(N(R;(R'((s7/usr/lib/python2.7/site-packages/tuned/daemon/daemon.pyR=mscCs|jS(N(R"(R'((s7/usr/lib/python2.7/site-packages/tuned/daemon/daemon.pyR)qscCsG|jdk rC|jjdk rC|jjjtj|||ƒn|S(N(RRt_dbus_exportert send_signalRtDBUS_SIGNAL_PROFILE_CHANGED(R'R*tresultterrstr((s7/usr/lib/python2.7/site-packages/tuned/daemon/daemon.pyR?ws!"cCsˆ|jjddgddgƒ\}}|dkr7tS|d dkrKtS|jjddgddgƒ\}}tjd|ƒdkS( Nt systemctlsis-system-runningt no_errorsiitstoppings list-jobss0\b(shutdown|reboot|halt|poweroff)\.target.*start(R$texecuteRtretsearchR(R'tretcodetout((s7/usr/lib/python2.7/site-packages/tuned/daemon/daemon.pyt_full_rollback_required|s' 'cCs%|jdkrtdƒ‚n|jj|jjƒ|j|jj|jƒ|jj ƒ|j j ƒt j d|jjƒ|jr”tjƒn|j|jjtdƒ|jrF|j}x„|jj|j|jƒsB|jrÂ|d8}|dkr?|j}t jdƒ|jjƒt jdƒ|jjƒq?qÂqÂWn|j jƒd}x6|jj|j|jƒ r‘|dkr‘|d7}q\W|jjƒrªt}nNt }|j!ƒrë|jrÛt j d ƒt}qøt j d ƒn t j d ƒ|jr|jj"|ƒn|jj#ƒdS( Ns2Cannot start the daemon without setting a profile.s'static tuning from profile '%s' appliedtOKiisupdating monitorssperforming tuningsis+terminating Tuned, rolling back all changess"terminating Tuned in one-shot modes1terminating Tuned due to system shutdown / reboot($R:RRR!tcreatetunitsRDtnameR;t start_tuningR6R5RR R RtstartR?RRR$twaitR2R RRtupdate_monitorst update_tuningtclearR4R3tis_setRRUt stop_tuningt destroy_all(R't _sleep_cnttit full_rollback((s7/usr/lib/python2.7/site-packages/tuned/daemon/daemon.pyt _thread_code…sJ              +       cCsDy|jj||ƒWn&tk r?}tjt|ƒƒnXdS(N(R$tsave_active_profileRRR&tstr(R'R*R=R-((s7/usr/lib/python2.7/site-packages/tuned/daemon/daemon.pyRDÀscCs;tjdƒtƒjd|j ƒ}tjd|ƒ|S(NsWRunning in automatic mode, checking what profile is recommended for your configuration.t hardcodedsUsing '%s' profile(RR Rt recommendR(R'RG((s7/usr/lib/python2.7/site-packages/tuned/daemon/daemon.pyt_get_recommended_profileÆs cCsO|jjƒ\}}|dkr0|dk }n|sE|jƒ}n||fS(N(R$tget_active_profileRRk(R'RGR=((s7/usr/lib/python2.7/site-packages/tuned/daemon/daemon.pyR9Ìs  cCs|jjjƒS(s$Return all accessible plugin classes(R!tplugins_repositorytload_all_plugins(R'((s7/usr/lib/python2.7/site-packages/tuned/daemon/daemon.pytget_all_pluginsÔscCs5y|jjj|ƒ}Wntk r-dSX|jS(sReturn plugin class docstringR8(R!Rmt load_plugint ImportErrort__doc__(R't plugin_namet plugin_class((s7/usr/lib/python2.7/site-packages/tuned/daemon/daemon.pytget_plugin_documentationØs    cCs8y|jjj|ƒ}Wntk r-iSX|jƒS(sŒReturn plugin's parameters and their hints Parameters: plugin_name -- plugins name Return: dictionary -- {parameter_name: hint} (R!RmRpRqtget_config_options_hints(R'RsRt((s7/usr/lib/python2.7/site-packages/tuned/daemon/daemon.pytget_plugin_hintsâs    cCs |jdk S(N(R:R(R'((s7/usr/lib/python2.7/site-packages/tuned/daemon/daemon.pyt is_enabledóscCs|jdk o|jjƒS(N(R/Rtis_alive(R'((s7/usr/lib/python2.7/site-packages/tuned/daemon/daemon.pyR>öscCs€|jƒrtS|jdkr#tStjdƒ|jjƒtj d|j ƒ|_ |j j ƒ|jj ƒ|j jƒtS(Nsstarting tuningttarget(R>RR:RRR R4R5R0tThreadRfR/R3R_R2R[R(R'((s7/usr/lib/python2.7/site-packages/tuned/daemon/daemon.pyR[ùs      cCs¤|jƒstjdƒtS|jdkr=tjdƒtS|jjƒs]tjdƒtS|jj ƒtj d|jj ƒ|j j |ƒ}|jjƒ|S(Nstuned is not runningsno profile is setsprofile is not appliedsverifying profile(s): %s(R>RR&RR:RR6R`R4R_R RYR!t verify_tuningR5(R'tignore_missingtret((s7/usr/lib/python2.7/site-packages/tuned/daemon/daemon.pytverify_profiles      cCsZ|jƒstStjdƒ|r3|jjƒn|jjƒ|jjƒd|_t S(Nsstopping tuning( R>RRR R3R5R2R/tjoinRR(R'tprofile_switch((s7/usr/lib/python2.7/site-packages/tuned/daemon/daemon.pytstops     N(t__name__t __module__RR.R#R7R%RR<tpropertyRGR=R)R?RURfRDRkR9RoRuRwRxR>R[RR‚(((s7/usr/lib/python2.7/site-packages/tuned/daemon/daemon.pyRs,#     ;         (tosterrnoR0t tuned.logsttunedttuned.exceptionsRttuned.profiles.exceptionsRt tuned.constsRttuned.utils.commandsRRttuned.utils.profile_recommenderRRQtlogsRRtobjectR(((s7/usr/lib/python2.7/site-packages/tuned/daemon/daemon.pyts