plugins: cleanup, accept devices list
This commit is contained in:
parent
25480d46c4
commit
421b1474d9
5 changed files with 29 additions and 10 deletions
|
|
@ -1,6 +1,8 @@
|
|||
import base
|
||||
import repository
|
||||
|
||||
__all__ = ["repository", "get_repository", "Plugin"]
|
||||
|
||||
def get_repository():
|
||||
return repository.PluginRepository.get_instance()
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,24 @@
|
|||
class Plugin(object):
|
||||
"""
|
||||
Base class for all plugins.
|
||||
|
||||
Plugins change various system settings in order to get desired performance or power
|
||||
saving. Plugins use Monitor objects to get information from the running system.
|
||||
|
||||
Methods requiring reimplementation:
|
||||
- update_tuning(self)
|
||||
"""
|
||||
|
||||
# class methods
|
||||
|
||||
@classmethod
|
||||
def _get_default_options(cls):
|
||||
return {}
|
||||
|
||||
def __init__(self, options = None):
|
||||
# instance methods
|
||||
|
||||
def __init__(self, devices = None, options = None):
|
||||
self._devices = devices
|
||||
self._options = self._get_default_options()
|
||||
if options is not None:
|
||||
self._merge_options(options)
|
||||
|
|
|
|||
|
|
@ -1,18 +1,20 @@
|
|||
import tuned.plugins
|
||||
import tuned.monitors
|
||||
|
||||
import os
|
||||
import struct
|
||||
|
||||
class CPULatencyPlugin(tuned.plugins.Plugin):
|
||||
def __init__(self, options = None):
|
||||
"""
|
||||
"""
|
||||
|
||||
def __init__(self, devices = None, options = None):
|
||||
"""
|
||||
"""
|
||||
super(self.__class__, self).__init__(options)
|
||||
super(self.__class__, self).__init__(options, None, options)
|
||||
|
||||
self._latency = None
|
||||
self._cpu_latency_fd = os.open("/dev/cpu_dma_latency", os.O_WRONLY)
|
||||
self._load_monitor = tuned.monitors.get_repository().create("load")
|
||||
self._load_monitor = tuned.monitors.get_repository().create("load", devices)
|
||||
|
||||
@classmethod
|
||||
def _get_default_options(cls):
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
import tuned.monitors
|
||||
|
||||
class TestPlugin(tuned.plugins.Plugin):
|
||||
def __init__(self, options = None):
|
||||
def __init__(self, devices = None, options = None):
|
||||
"""
|
||||
"""
|
||||
super(self.__class__, self).__init__(options)
|
||||
|
||||
self._monitors = [
|
||||
tuned.monitors.get_repository().create("load"),
|
||||
tuned.monitors.get_repository().create("disk")
|
||||
tuned.monitors.get_repository().create("load", None),
|
||||
tuned.monitors.get_repository().create("disk", None)
|
||||
]
|
||||
|
||||
def cleanup(self):
|
||||
|
|
|
|||
|
|
@ -12,11 +12,11 @@ class PluginRepository(tuned.patterns.Singleton):
|
|||
self._loader = tuned.utils.PluginLoader("tuned.plugins", "plugin_", tuned.plugins.Plugin)
|
||||
self._plugins = set()
|
||||
|
||||
def create(self, plugin_name):
|
||||
def create(self, plugin_name, devices, options):
|
||||
log.debug("creating plugin %s" % plugin_name)
|
||||
try:
|
||||
plugin_cls = self._loader.load(plugin_name)
|
||||
plugin_instance = plugin_cls()
|
||||
plugin_instance = plugin_cls(devices, options)
|
||||
self._plugins.add(plugin_instance)
|
||||
return plugin_instance
|
||||
except Exception as exception:
|
||||
|
|
|
|||
Loading…
Reference in a new issue