From 42b3f4cf9f3a7a9e547c896bf910f4ad66ffc98b Mon Sep 17 00:00:00 2001 From: Marc Bonnici Date: Thu, 2 Aug 2018 10:37:42 +0100 Subject: [PATCH] commands/create: Add special case for EnergyInstruemntBackends Previously when using the create command for adding EnergyInstruemntBackends they were treated like any other plugin and generated incorrect configuration. Now automatically add the `energy_measurement` instrument and populate it's configuration with the relevant defaults for the specified Backend. --- wa/commands/create.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/wa/commands/create.py b/wa/commands/create.py index f6c59fea..4b18ec35 100644 --- a/wa/commands/create.py +++ b/wa/commands/create.py @@ -27,6 +27,7 @@ from devlib.utils.types import identifier from wa import ComplexCommand, SubCommand, pluginloader, settings from wa.framework.target.descriptor import list_target_descriptions from wa.framework.exception import ConfigError, CommandError +from wa.instruments.energy_measurement import EnergyInstrumentBackend from wa.utils.misc import (ensure_directory_exists as _d, capitalize, ensure_file_directory_exists as _f) from wa.utils.serializer import yaml @@ -51,6 +52,7 @@ class CreateAgendaSubcommand(SubCommand): self.parser.add_argument('-o', '--output', metavar='FILE', help='Output file. If not specfied, STDOUT will be used instead.') + # pylint: disable=too-many-branches def execute(self, state, args): agenda = OrderedDict() agenda['config'] = OrderedDict(augmentations=[], iterations=args.iterations) @@ -71,7 +73,15 @@ class CreateAgendaSubcommand(SubCommand): extcls = pluginloader.get_plugin_class(name) config = pluginloader.get_default_config(name) - if extcls.kind == 'workload': + # Handle special case for EnergyInstrumentBackends + if issubclass(extcls, EnergyInstrumentBackend): + if 'energy_measurement' not in agenda['config']['augmentations']: + energy_config = pluginloader.get_default_config('energy_measurement') + agenda['config']['augmentations'].append('energy_measurement') + agenda['config']['energy_measurement'] = energy_config + agenda['config']['energy_measurement']['instrument'] = name + agenda['config']['energy_measurement']['instrument_parameters'] = config + elif extcls.kind == 'workload': entry = OrderedDict() entry['name'] = extcls.name if name != extcls.name: