3 À<×e¬ã@s~ddlZddlZddlZddlZddlZddlZddlZddlj Z ddl m Z ddl m Z ejjƒZdgZGdd„deƒZdS)éN)Ú GlobalConfig)ÚcommandsÚManagercsœeZdZdZd‡fdd„ Zedd„ƒZedd„ƒZed d „ƒZd d „Z d d„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zejfdd„Z‡ZS) rz? Manager creates plugin instances and keeps a track of them. NcsJtt|ƒjƒ||_||_||_||_g|_g|_|p:t ƒ|_ t ƒ|_ dS)N) ÚsuperrÚ__init__Ú_plugins_repositoryÚ_monitors_repositoryÚ_def_instance_priorityÚ_hardware_inventoryÚ _instancesÚ_pluginsrÚ_configrÚ_cmd)ÚselfÚplugins_repositoryZmonitors_repositoryZdef_instance_priorityZhardware_inventoryÚconfig)Ú __class__©ú/usr/lib/python3.6/manager.pyrs zManager.__init__cCs|jS)N)r )rrrrÚplugins!szManager.pluginscCs|jS)N)r )rrrrÚ instances%szManager.instancescCs|jS)N)r)rrrrr)szManager.plugins_repositorycCsF|jdkrdS|jjtjƒ}|dkr0|jjdƒ}tj|j|tj ƒdk S)NTz /proc/cpuinfo) Z cpuinfo_regexr ÚgetÚconstsZCFG_CPUINFO_STRINGrZ read_fileÚreÚsearchÚ MULTILINE)rÚunitZcpuinfo_stringrrrÚ_unit_matches_cpuinfo-s   zManager._unit_matches_cpuinfocCsH|jdkrdS|jjtjƒ}|dkr2djtjƒƒ}tj |j|tj ƒdk S)NTú ) Z uname_regexr rrZCFG_UNAME_STRINGÚjoinÚosÚunamerrr)rrZ uname_stringrrrÚ_unit_matches_uname6s  zManager._unit_matches_unamec Cs2g}x�t|jƒƒD]€\}}|js0tjd|ƒq|j|ƒsJtjd|ƒq|j|ƒsdtjd|ƒq|jjd|j ƒt |jdƒ|jd<|j |ƒqW|j dd„d�t jƒ}x"|D]}|jjdƒd||j<q´Wx¦t|jƒƒD]–\}}y$|jj|ƒ}|||<|jj |ƒWqàtjjjk �r8tjd|ƒwàYqàtk �rt} z tjd |ƒtj| ƒwàWYdd} ~ XqàXqàWg} xf|D]^}||j}|dk�r �q„tjd |j|jfƒ|j|j|j|j|j |j!|jƒ} | j | ƒ�q„Wx0| D](} | j"j#ƒ| j"j$| ƒ| j"j%| ƒ�qìW|j&j'ƒ|j(j)| ƒdS) Nzskipping disabled instance '%s'z.skipping instance '%s', cpuinfo does not matchz,skipping instance '%s', uname does not matchÚprioritycSs |jdS)Nr#)Úoptions)ÚxrrrÚPsz Manager.create..)Úkeyz2skipping plugin '%s', not supported on your systemzfailed to initialize plugin %szcreating '%s' (%s))*ÚlistÚitemsZenabledÚlogÚdebugrr"r$Ú setdefaultr ÚintÚappendÚsortÚ collectionsÚ OrderedDictÚpopÚtyperÚcreater ÚtunedrÚ exceptionsZNotSupportedPluginExceptionÚinfoÚ ExceptionÚerrorZ exceptionÚnameZcreate_instanceZdevicesZdevices_udev_regexZ script_preZ script_postÚpluginZ init_devicesZassign_free_devicesZinitialize_instancer Zstart_processing_eventsr Úextend) rZinstances_configZinstance_info_listZ instance_nameZ instance_infoZplugins_by_nameZ plugin_nameZnoner;ÚerZ new_instanceÚinstancerrrr4?s\             zManager.createcOsXy |||ŽStk rR}z,tjƒ}tjd|t|ƒfƒtj|ƒ|Sd}~XnXdS)Nz"BUG: Unhandled exception in %s: %s)r8Ú tracebackÚ format_excr*r9Ústr)rZcallerZexc_retÚfÚargsÚkwargsr=ZtracerrrÚ _try_callus  zManager._try_callcCs€x2|jD](}tjd|jƒ|jdd|jj|ƒqWx.|jD]$}tjd|jƒ|jdd|jƒqr;rrrrFs    zManager.destroy_allcCs4x.|jjD]"}tjd|ƒ|jdd|jƒq WdS)Nzupdating monitor %sÚupdate_monitors)rZmonitorsr*r+rEÚupdate)rZmonitorrrrrGŒszManager.update_monitorscCs$x|jD]}|jdd|jƒqWdS)NÚ start_tuning)r rEZ apply_tuning)rr>rrrrI‘s zManager.start_tuningcCs6d}x,|jD]"}|jdd|j|ƒ}|dkr d}q W|S)NTÚ verify_tuningF)r rErJ)rZignore_missingÚretr>ÚresrrrrJ–s  zManager.verify_tuningcCs$x|jD]}|jdd|jƒqWdS)NÚ update_tuning)r rErM)rr>rrrrMŸs zManager.update_tuningcCs4|jjƒx$t|jƒD]}|jdd|j|ƒqWdS)NÚ stop_tuning)r Zstop_processing_eventsÚreversedr rEZunapply_tuning)rZrollbackr>rrrrN¬s zManager.stop_tuning)N)Ú__name__Ú __module__Ú __qualname__Ú__doc__rÚpropertyrrrrr"r4rErFrGrIrJrMrZ ROLLBACK_SOFTrNÚ __classcell__rr)rrrs     6    )r0r rr?Ztuned.exceptionsr5Z tuned.logsZtuned.plugins.exceptionsZ tuned.constsrZtuned.utils.global_configrZtuned.utils.commandsrZlogsrr*Ú__all__ÚobjectrrrrrÚs