From 9192deb8ee13a8105742631cece3b4be095c077f Mon Sep 17 00:00:00 2001 From: Sergei Trofimov Date: Thu, 31 Aug 2017 17:38:33 +0100 Subject: [PATCH] InstrumentChannel: name is now an alias for label In addition to a label constructed form the combination of site and measurment type, channels had a name that was specified on creation. This proven to be not particularly useful (there only being one instance of the name being set to something materially different from the label); and this has lead to channels being inconsistenly referenced (some times a channel is identified by its label, and sometimes by the name). This commit removes the name from __init__ arguments, and InstrumentChannel.name is now an alias for InstrumentChannel.label. --- devlib/instrument/__init__.py | 15 ++++++--------- devlib/instrument/hwmon.py | 2 +- devlib/platform/arm.py | 32 ++++++++++++++++---------------- 3 files changed, 23 insertions(+), 26 deletions(-) diff --git a/devlib/instrument/__init__.py b/devlib/instrument/__init__.py index 74113a3..36bd4ed 100644 --- a/devlib/instrument/__init__.py +++ b/devlib/instrument/__init__.py @@ -175,14 +175,12 @@ class MeasurementsCsv(object): if entry.endswith(suffix): site = entry[:-len(suffix)] measure = mt - name = '{}_{}'.format(site, measure) break else: site = entry measure = 'unknown' - name = entry - chan = InstrumentChannel(name, site, measure) + chan = InstrumentChannel(site, measure) self.channels.append(chan) @@ -192,6 +190,8 @@ class InstrumentChannel(object): def label(self): return '{}_{}'.format(self.site, self.kind) + name = label + @property def kind(self): return self.measurement_type.name @@ -200,8 +200,7 @@ class InstrumentChannel(object): def units(self): return self.measurement_type.units - def __init__(self, name, site, measurement_type, **attrs): - self.name = name + def __init__(self, site, measurement_type, **attrs): self.site = site if isinstance(measurement_type, MeasurementType): self.measurement_type = measurement_type @@ -243,10 +242,8 @@ class Instrument(object): measure = measure.name return [c for c in self.list_channels() if c.kind == measure] - def add_channel(self, site, measure, name=None, **attrs): - if name is None: - name = '{}_{}'.format(site, measure) - chan = InstrumentChannel(name, site, measure, **attrs) + def add_channel(self, site, measure, **attrs): + chan = InstrumentChannel(site, measure, **attrs) self.channels[chan.label] = chan # initialization and teardown diff --git a/devlib/instrument/hwmon.py b/devlib/instrument/hwmon.py index ae49f40..5a9d8af 100644 --- a/devlib/instrument/hwmon.py +++ b/devlib/instrument/hwmon.py @@ -45,7 +45,7 @@ class HwmonInstrument(Instrument): measure = self.measure_map.get(ts.kind)[0] if measure: self.logger.debug('\tAdding sensor {}'.format(ts.name)) - self.add_channel(_guess_site(ts), measure, name=ts.name, sensor=ts) + self.add_channel(_guess_site(ts), measure, sensor=ts) else: self.logger.debug('\tSkipping sensor {} (unknown kind "{}")'.format(ts.name, ts.kind)) except ValueError: diff --git a/devlib/platform/arm.py b/devlib/platform/arm.py index e760eaf..76b58a4 100644 --- a/devlib/platform/arm.py +++ b/devlib/platform/arm.py @@ -210,22 +210,22 @@ class JunoEnergyInstrument(Instrument): mode = CONTINUOUS | INSTANTANEOUS _channels = [ - InstrumentChannel('sys_curr', 'sys', 'current'), - InstrumentChannel('a57_curr', 'a57', 'current'), - InstrumentChannel('a53_curr', 'a53', 'current'), - InstrumentChannel('gpu_curr', 'gpu', 'current'), - InstrumentChannel('sys_volt', 'sys', 'voltage'), - InstrumentChannel('a57_volt', 'a57', 'voltage'), - InstrumentChannel('a53_volt', 'a53', 'voltage'), - InstrumentChannel('gpu_volt', 'gpu', 'voltage'), - InstrumentChannel('sys_pow', 'sys', 'power'), - InstrumentChannel('a57_pow', 'a57', 'power'), - InstrumentChannel('a53_pow', 'a53', 'power'), - InstrumentChannel('gpu_pow', 'gpu', 'power'), - InstrumentChannel('sys_cenr', 'sys', 'energy'), - InstrumentChannel('a57_cenr', 'a57', 'energy'), - InstrumentChannel('a53_cenr', 'a53', 'energy'), - InstrumentChannel('gpu_cenr', 'gpu', 'energy'), + InstrumentChannel('sys', 'current'), + InstrumentChannel('a57', 'current'), + InstrumentChannel('a53', 'current'), + InstrumentChannel('gpu', 'current'), + InstrumentChannel('sys', 'voltage'), + InstrumentChannel('a57', 'voltage'), + InstrumentChannel('a53', 'voltage'), + InstrumentChannel('gpu', 'voltage'), + InstrumentChannel('sys', 'power'), + InstrumentChannel('a57', 'power'), + InstrumentChannel('a53', 'power'), + InstrumentChannel('gpu', 'power'), + InstrumentChannel('sys', 'energy'), + InstrumentChannel('a57', 'energy'), + InstrumentChannel('a53', 'energy'), + InstrumentChannel('gpu', 'energy'), ] def __init__(self, target):