From 906c1e0c71c8ad58934990ebe686adf7496e0dce Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 8 Jul 2020 13:45:39 +0200 Subject: Add harness.energytrace_sync="led" for LA / Timing based sync --- bin/generate-dfa-benchmark.py | 3 +++ lib/harness.py | 4 ++++ lib/runner.py | 5 ++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/bin/generate-dfa-benchmark.py b/bin/generate-dfa-benchmark.py index 1410c28..fdfac35 100755 --- a/bin/generate-dfa-benchmark.py +++ b/bin/generate-dfa-benchmark.py @@ -636,8 +636,10 @@ if __name__ == "__main__": elif "energytrace" in opt: # Use barcode sync by default gpio_mode = "bar" + energytrace_sync = None if "sync" in opt["energytrace"] and opt["energytrace"]["sync"] != "bar": gpio_mode = "around" + energytrace_sync = "led" harness = OnboardTimerHarness( gpio_pin=timer_pin, gpio_mode=gpio_mode, @@ -645,6 +647,7 @@ if __name__ == "__main__": counter_limits=runner.get_counter_limits_us(opt["arch"]), log_return_values=need_return_values, repeat=1, + energytrace_sync=energytrace_sync, ) elif "timing" in opt: harness = OnboardTimerHarness( diff --git a/lib/harness.py b/lib/harness.py index ae9c28c..fe6cb9a 100644 --- a/lib/harness.py +++ b/lib/harness.py @@ -33,6 +33,7 @@ class TransitionHarness: log_return_values=False, repeat=0, post_transition_delay_us=0, + energytrace_sync=None, ): """ Create a new TransitionHarness @@ -53,6 +54,7 @@ class TransitionHarness: self.log_return_values = log_return_values self.repeat = repeat self.post_transition_delay_us = post_transition_delay_us + self.energytrace_sync = energytrace_sync self.reset() def copy(self): @@ -63,6 +65,7 @@ class TransitionHarness: log_return_values=self.log_return_values, repeat=self.repeat, post_transition_delay_us=self.post_transition_delay_us, + energytrace_sync=self.energytrace_sync, ) new_object.traces = self.traces.copy() new_object.trace_id = self.trace_id @@ -373,6 +376,7 @@ class OnboardTimerHarness(TransitionHarness): pta=self.pta, log_return_values=self.log_return_values, repeat=self.repeat, + energytrace_sync=self.energytrace_sync, ) new_harness.traces = self.traces.copy() new_harness.trace_id = self.trace_id diff --git a/lib/runner.py b/lib/runner.py index 0d4d449..def9c8f 100644 --- a/lib/runner.py +++ b/lib/runner.py @@ -172,12 +172,15 @@ class EnergyTraceMonitor(SerialMonitor): def get_files(self) -> list: return [self._output] - # + # Benchmark-Konfiguration. Hier: Die (konstante) Spannung. + # MSP430FR5969: 3,6V (wird aktuell nicht unterstützt) + # MSP430FR5994: 3,3V (default) def get_config(self) -> dict: return { "voltage": self._voltage, } + class EnergyTraceLogicAnalyzerMonitor(EnergyTraceMonitor): """EnergyTraceLogicAnalyzerMonitor captures EnergyTrace energy data and LogicAnalyzer timing output.""" -- cgit v1.2.3 From 0bda106da0af4b9ba72f31930669fb5da1311d28 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 8 Jul 2020 16:06:51 +0200 Subject: Add dummy loader for EnergyTraceWithLogicAnalyzer. Data is not analyzed. Instead, everything takes as long as planned and everything costs 23 mW --- lib/loader.py | 137 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 133 insertions(+), 4 deletions(-) diff --git a/lib/loader.py b/lib/loader.py index c35eb4c..65d497b 100644 --- a/lib/loader.py +++ b/lib/loader.py @@ -107,7 +107,14 @@ def _preprocess_mimosa(measurement): def _preprocess_etlog(measurement): setup = measurement["setup"] - etlog = EnergyTraceLog( + + energytrace_class = EnergyTraceWithBarcode + if measurement["sync_mode"] == "la": + energytrace_class = EnergyTraceWithLogicAnalyzer + elif measurement["sync_mode"] == "timer": + energytrace_class = EnergyTraceWithTimer + + etlog = energytrace_class( float(setup["voltage"]), int(setup["state_duration"]), measurement["transition_names"], @@ -406,7 +413,7 @@ class RawData: processed_data["error"] = "; ".join(processed_data["datasource_errors"]) return False - # Note that the low-level parser (EnergyTraceLog) already checks + # Note that the low-level parser (EnergyTraceWithBarcode) already checks # whether the transition count is correct return True @@ -909,6 +916,10 @@ class RawData: new_filenames = list() with tarfile.open(filename) as tf: ptalog = self.ptalog + if "sync" in ptalog["opt"]["energytrace"]: + sync_mode = ptalog["opt"]["energytrace"]["sync"] + else: + sync_mode = "bar" # Benchmark code may be too large to be executed in a single # run, so benchmarks (a benchmark is basically a list of DFA runs) @@ -968,6 +979,7 @@ class RawData: offline_data.append( { "content": tf.extractfile(member).read(), + "sync_mode": sync_mode, "fileno": j, "info": member, "setup": self.setup_by_fileno[j], @@ -1161,7 +1173,7 @@ def pta_trace_to_aggregate(traces, ignore_trace_indexes=[]): return by_name, parameter_names, arg_count -class EnergyTraceLog: +class EnergyTraceWithBarcode: """ EnergyTrace log loader for DFA traces. @@ -1184,7 +1196,7 @@ class EnergyTraceLog: with_traces=False, ): """ - Create a new EnergyTraceLog object. + Create a new EnergyTraceWithBarcode object. :param voltage: supply voltage [V], usually 3.3 V :param state_duration: state duration [ms] @@ -1599,6 +1611,123 @@ class EnergyTraceLog: return None, None, None, None +class EnergyTraceWithLogicAnalyzer: + def __init__( + self, + voltage: float, + state_duration: int, + transition_names: list, + with_traces=False, + ): + """ + Create a new EnergyTraceWithLogicAnalyzer object. + + :param voltage: supply voltage [V], usually 3.3 V + :param state_duration: state duration [ms] + :param transition_names: list of transition names in PTA transition order. + Needed to map barcode synchronization numbers to transitions. + """ + self.voltage = voltage + self.state_duration = state_duration * 1e-3 + self.transition_names = transition_names + self.with_traces = with_traces + self.errors = list() + + def load_data(self, log_data): + # TODO Daten laden + pass + + def analyze_states(self, traces, offline_index: int): + u""" + Split log data into states and transitions and return duration, energy, and mean power for each element. + + :param traces: expected traces, needed to synchronize with the measurement. + traces is a list of runs, traces[*]['trace'] is a single run + (i.e. a list of states and transitions, starting with a transition + and ending with a state). + :param offline_index: This function uses traces[*]['trace'][*]['online_aggregates']['duration'][offline_index] to find sync codes + + :param charges: raw charges (each element describes the charge in pJ transferred during 10 µs) + :param trigidx: "charges" indexes corresponding to a trigger edge, see `trigger_edges` + :param ua_func: charge(pJ) -> current(µA) function as returned by `calibration_function` + + :returns: returns list of states and transitions, starting with a transition and ending with astate + Each element is a dict containing: + * `isa`: 'state' or 'transition' + * `W_mean`: Mittelwert der Leistungsaufnahme + * `W_std`: Standardabweichung der Leistungsaufnahme + * `s`: Dauer + if isa == 'transition, it also contains: + * `W_mean_delta_prev`: Differenz zwischen W_mean und W_mean des vorherigen Zustands + * `W_mean_delta_next`: Differenz zwischen W_mean und W_mean des Folgezustands + """ + + # TODO Tatsächlich Daten auswerten + + energy_trace = list() + + expected_transitions = list() + for trace_number, trace in enumerate(traces): + for state_or_transition_number, state_or_transition in enumerate( + trace["trace"] + ): + if state_or_transition["isa"] == "transition": + try: + expected_transitions.append( + ( + state_or_transition["name"], + state_or_transition["online_aggregates"]["duration"][ + offline_index + ] + * 1e-6, + ) + ) + except IndexError: + self.errors.append( + 'Entry #{} ("{}") in trace #{} has no duration entry for offline_index/repeat_id {}'.format( + state_or_transition_number, + state_or_transition["name"], + trace_number, + offline_index, + ) + ) + return energy_trace + + for name, duration in expected_transitions: + transition = { + "isa": "transition", + "W_mean": max(np.random.normal(0.023, 0.002), 0), + "W_std": 0.0001, + "s": duration, + } + + energy_trace.append(transition) + + if len(energy_trace) > 1: + energy_trace[-1]["W_mean_delta_prev"] = ( + energy_trace[-1]["W_mean"] - energy_trace[-2]["W_mean"] + ) + + state = { + "isa": "state", + "W_mean": max(np.random.normal(0.023, 0.002), 0), + "W_std": 0.0001, + "s": self.state_duration, + } + + energy_trace.append(state) + + energy_trace[-2]["W_mean_delta_next"] = ( + energy_trace[-2]["W_mean"] - energy_trace[-1]["W_mean"] + ) + + return energy_trace + + +class EnergyTraceWithTimer(EnergyTraceWithLogicAnalyzer): + pass + + class MIMOSA: """ MIMOSA log loader for DFA traces with auto-calibration. -- cgit v1.2.3 From 54ce41f2c7710b1bfbc884ce141140dc268710c5 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Thu, 9 Jul 2020 11:05:57 +0200 Subject: OnboardTimerHarness: Log state duration as well --- lib/harness.py | 123 +++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 93 insertions(+), 30 deletions(-) diff --git a/lib/harness.py b/lib/harness.py index ae9c28c..c251ec8 100644 --- a/lib/harness.py +++ b/lib/harness.py @@ -175,21 +175,16 @@ class TransitionHarness: """Return C++ code used to start a new run/trace.""" return "ptalog.reset();\n" - def _pass_transition_call(self, transition_id): - if self.gpio_mode == "bar": - barcode_bits = Code128("T{}".format(transition_id), charset="B").modules - if len(barcode_bits) % 8 != 0: - barcode_bits.extend([1] * (8 - (len(barcode_bits) % 8))) - barcode_bytes = [ - 255 - int("".join(map(str, reversed(barcode_bits[i : i + 8]))), 2) - for i in range(0, len(barcode_bits), 8) - ] - inline_array = "".join(map(lambda s: "\\x{:02x}".format(s), barcode_bytes)) - return 'ptalog.startTransition("{}", {});\n'.format( - inline_array, len(barcode_bytes) - ) - else: - return "ptalog.startTransition();\n" + def _get_barcode(self, transition_id): + barcode_bits = Code128("T{}".format(transition_id), charset="B").modules + if len(barcode_bits) % 8 != 0: + barcode_bits.extend([1] * (8 - (len(barcode_bits) % 8))) + barcode_bytes = [ + 255 - int("".join(map(str, reversed(barcode_bits[i : i + 8]))), 2) + for i in range(0, len(barcode_bits), 8) + ] + inline_array = "".join(map(lambda s: "\\x{:02x}".format(s), barcode_bytes)) + return inline_array, len(barcode_bytes) def pass_transition( self, transition_id, transition_code, transition: object = None @@ -201,7 +196,12 @@ class TransitionHarness: `post_transition_delay_us` is set. """ ret = "ptalog.passTransition({:d});\n".format(transition_id) - ret += self._pass_transition_call(transition_id) + if self.gpio_mode == "bar": + ret += """ptalog.startTransition("{}", {});\n""".format( + *self._get_barcode(transition_id) + ) + else: + ret += "ptalog.startTransition();\n" if ( self.log_return_values and transition @@ -398,15 +398,12 @@ class OnboardTimerHarness(TransitionHarness): ] def global_code(self): - ret = '#include "driver/counter.h"\n' - ret += "#define PTALOG_TIMING\n" + ret = "#define PTALOG_TIMING\n" ret += super().global_code() return ret def start_benchmark(self, benchmark_id=0): - ret = "counter.start();\n" - ret += "counter.stop();\n" - ret += "ptalog.passNop(counter);\n" + ret = "ptalog.passNop();\n" ret += super().start_benchmark(benchmark_id) return ret @@ -414,8 +411,12 @@ class OnboardTimerHarness(TransitionHarness): self, transition_id, transition_code, transition: object = None ): ret = "ptalog.passTransition({:d});\n".format(transition_id) - ret += self._pass_transition_call(transition_id) - ret += "counter.start();\n" + if self.gpio_mode == "bar": + ret += """ptalog.startTransition("{}", {});\n""".format( + *self._get_barcode(transition_id) + ) + else: + ret += "ptalog.startTransition();\n" if ( self.log_return_values and transition @@ -424,14 +425,13 @@ class OnboardTimerHarness(TransitionHarness): ret += "transition_return_value = {}\n".format(transition_code) else: ret += "{}\n".format(transition_code) - ret += "counter.stop();\n" if ( self.log_return_values and transition and len(transition.return_value_handlers) ): ret += "ptalog.logReturn(transition_return_value);\n" - ret += "ptalog.stopTransition(counter);\n" + ret += "ptalog.stopTransition();\n" return ret def _append_nondeterministic_parameter_value( @@ -453,11 +453,26 @@ class OnboardTimerHarness(TransitionHarness): res.group(1), res.group(2) ) ) - if re.match(r"\[PTA\] benchmark stop", line): + match = re.match(r"\[PTA\] benchmark stop, cycles=(\S+)/(\S+)", line) + if match: self.repetitions += 1 self.synced = False if self.repeat > 0 and self.repetitions == self.repeat: self.done = True + prev_state_cycles = int(match.group(1)) + prev_state_overflow = int(match.group(2)) + prev_state_duration_us = ( + prev_state_cycles * self.one_cycle_in_us + + prev_state_overflow * self.one_overflow_in_us + - self.nop_cycles * self.one_cycle_in_us + ) + final_state = self.traces[self.trace_id]["trace"][-1] + if "offline_aggregates" not in final_state: + final_state["offline_aggregates"] = {"duration": list()} + final_state["offline_aggregates"]["duration"].append( + prev_state_duration_us + ) + print("[HARNESS] done") return # May be repeated, e.g. if the device is reset shortly after start by @@ -473,14 +488,20 @@ class OnboardTimerHarness(TransitionHarness): self.current_transition_in_trace = 0 if self.log_return_values: res = re.match( - r"\[PTA\] transition=(\S+) cycles=(\S+)/(\S+) return=(\S+)", line + r"\[PTA\] transition=(\S+) prevcycles=(\S+)/(\S+) cycles=(\S+)/(\S+) return=(\S+)", + line, ) else: - res = re.match(r"\[PTA\] transition=(\S+) cycles=(\S+)/(\S+)", line) + res = re.match( + r"\[PTA\] transition=(\S+) prevcycles=(\S+)/(\S+) cycles=(\S+)/(\S+)", + line, + ) if res: transition_id = int(res.group(1)) - cycles = int(res.group(2)) - overflow = int(res.group(3)) + prev_state_cycles = int(res.group(2)) + prev_state_overflow = int(res.group(3)) + cycles = int(res.group(4)) + overflow = int(res.group(5)) if overflow >= self.counter_max_overflow: self.abort = True raise RuntimeError( @@ -493,11 +514,28 @@ class OnboardTimerHarness(TransitionHarness): transition_id, ) ) + if prev_state_overflow >= self.counter_max_overflow: + self.abort = True + raise RuntimeError( + "Counter overflow ({:d}/{:d}) in benchmark id={:d} trace={:d}: state before transition #{:d} (ID {:d})".format( + prev_state_cycles, + prev_state_overflow, + 0, + self.trace_id, + self.current_transition_in_trace, + transition_id, + ) + ) duration_us = ( cycles * self.one_cycle_in_us + overflow * self.one_overflow_in_us - self.nop_cycles * self.one_cycle_in_us ) + prev_state_duration_us = ( + prev_state_cycles * self.one_cycle_in_us + + prev_state_overflow * self.one_overflow_in_us + - self.nop_cycles * self.one_cycle_in_us + ) if duration_us < 0: duration_us = 0 # self.traces contains transitions and states, UART output only contains transitions -> use index * 2 @@ -505,6 +543,14 @@ class OnboardTimerHarness(TransitionHarness): log_data_target = self.traces[self.trace_id]["trace"][ self.current_transition_in_trace * 2 ] + if self.current_transition_in_trace > 0: + prev_state_data = self.traces[self.trace_id]["trace"][ + self.current_transition_in_trace * 2 - 1 + ] + elif self.current_transition_in_trace == 0 and self.trace_id > 0: + prev_state_data = self.traces[self.trace_id - 1]["trace"][-1] + else: + prev_state_data = None except IndexError: transition_name = None if self.pta: @@ -531,6 +577,17 @@ class OnboardTimerHarness(TransitionHarness): log_data_target["isa"], ) ) + if prev_state_data and prev_state_data["isa"] != "state": + self.abort = True + raise RuntimeError( + "Log mismatch in benchmark id={:d} trace={:d}: state before transition #{:d} (ID {:d}): Expected state, got {:s}".format( + 0, + self.trace_id, + self.current_transition_in_trace, + transition_id, + prev_state_data["isa"], + ) + ) if self.pta: transition = self.pta.transitions[transition_id] if transition.name != log_data_target["name"]: @@ -601,4 +658,10 @@ class OnboardTimerHarness(TransitionHarness): if "offline_aggregates" not in log_data_target: log_data_target["offline_aggregates"] = {"duration": list()} log_data_target["offline_aggregates"]["duration"].append(duration_us) + if prev_state_data is not None: + if "offline_aggregates" not in prev_state_data: + prev_state_data["offline_aggregates"] = {"duration": list()} + prev_state_data["offline_aggregates"]["duration"].append( + prev_state_duration_us + ) self.current_transition_in_trace += 1 -- cgit v1.2.3 From b5f7fd47d1ee66f20af50fae145990d4665b56c3 Mon Sep 17 00:00:00 2001 From: Lennart Date: Mon, 13 Jul 2020 13:06:11 +0200 Subject: Added first version, kinda working but some tweaks needed. src directory of repository 'ba-lennart-kaiser' needs to in the python execution path --- lib/harness.py | 33 ++++++++++++++++++++++++++++++++- lib/runner.py | 31 ++++++++++++++++++++++++++++++- 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/lib/harness.py b/lib/harness.py index fe6cb9a..3b9db89 100644 --- a/lib/harness.py +++ b/lib/harness.py @@ -405,15 +405,46 @@ class OnboardTimerHarness(TransitionHarness): ret = '#include "driver/counter.h"\n' ret += "#define PTALOG_TIMING\n" ret += super().global_code() + if self.energytrace_sync == "led": + #TODO Make nicer + ret += """\nvoid runLASync(){ + // ======================= LED SYNC ================================ + ptalog.passTransition(0); + ptalog.startTransition(); + gpio.led_toggle(0); + gpio.led_toggle(1); + ptalog.stopTransition(counter); + + for (unsigned char i = 0; i < 4; i++) { + arch.sleep_ms(250); + } + + ptalog.passTransition(0); + ptalog.startTransition(); + gpio.led_toggle(0); + gpio.led_toggle(1); + ptalog.stopTransition(counter); + // ======================= LED SYNC ================================ + arch.sleep_ms(250); +}\n\n""" return ret def start_benchmark(self, benchmark_id=0): - ret = "counter.start();\n" + ret = "" + if self.energytrace_sync == "led": + ret += "runLASync();\n" + ret += "counter.start();\n" ret += "counter.stop();\n" ret += "ptalog.passNop(counter);\n" ret += super().start_benchmark(benchmark_id) return ret + def stop_benchmark(self): + ret = super().stop_benchmark() + if self.energytrace_sync == "led": + ret += "runLASync();\n" + return ret + def pass_transition( self, transition_id, transition_code, transition: object = None ): diff --git a/lib/runner.py b/lib/runner.py index def9c8f..3a201fc 100644 --- a/lib/runner.py +++ b/lib/runner.py @@ -9,7 +9,7 @@ Functions: get_monitor -- return Monitor class suitable for the selected multipass arch get_counter_limits -- return arch-specific multipass counter limits (max value, max overflow) """ - +import json import os import re import serial @@ -17,6 +17,7 @@ import serial.threaded import subprocess import sys import time +from data.timing.SigrokCLIInterface import SigrokCLIInterface class SerialReader(serial.threaded.Protocol): @@ -156,6 +157,7 @@ class EnergyTraceMonitor(SerialMonitor): self._start_energytrace() def _start_energytrace(self): + print("EnergyTrace Start") cmd = ["msp430-etv", "--save", self._output, "0"] self._logger = subprocess.Popen( cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True @@ -187,6 +189,33 @@ class EnergyTraceLogicAnalyzerMonitor(EnergyTraceMonitor): def __init__(self, port: str, baud: int, callback=None, voltage=3.3): super().__init__(port=port, baud=baud, callback=callback, voltage=voltage) + #TODO get length + options = {'length': 90, 'fake': False, 'sample_rate': 1_000_000} + self.log_file = 'logic_output_log_%s.json' % (time.strftime("%Y%m%d-%H%M%S")) + + # Initialization of Interfaces + self.sig = SigrokCLIInterface(sample_rate=options['sample_rate'], + sample_count=options['length'] * options['sample_rate'], fake=options['fake']) + + # Start Measurements + print("[ET LA] START MEASURE") + self.sig.runMeasureAsynchronous() + + def close(self): + super().close() + # Read measured data + print("[ET LA] Wait MEASURE") + self.sig.waitForAsynchronousMeasure() + print("[ET LA] WRITE MEASURE") + sync_data = self.sig.getData() + print("[ET LA] MEASURE LEN", len(sync_data.timestamps)) + with open(self.log_file, 'w') as fp: + json.dump(sync_data.getDict(), fp) + + def get_files(self) -> list: + print("[ET LA] FILE REQUEST") + return [self.log_file] + class MIMOSAMonitor(SerialMonitor): """MIMOSAMonitor captures serial output and MIMOSA energy data for a specific amount of time.""" -- cgit v1.2.3 From 427f80213e915cb3a7f5fa63eab910ed7fcb0fe0 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Tue, 14 Jul 2020 11:20:33 +0200 Subject: Make black(1) happy --- lib/runner.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/runner.py b/lib/runner.py index 0d4d449..aeb8600 100644 --- a/lib/runner.py +++ b/lib/runner.py @@ -178,6 +178,7 @@ class EnergyTraceMonitor(SerialMonitor): "voltage": self._voltage, } + class EnergyTraceLogicAnalyzerMonitor(EnergyTraceMonitor): """EnergyTraceLogicAnalyzerMonitor captures EnergyTrace energy data and LogicAnalyzer timing output.""" -- cgit v1.2.3 From 0a7917342cf27f18f553afdf4a65d6377f671aad Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Tue, 14 Jul 2020 16:49:27 +0200 Subject: support more than one logfile per measurement run --- bin/generate-dfa-benchmark.py | 4 ++-- lib/loader.py | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/bin/generate-dfa-benchmark.py b/bin/generate-dfa-benchmark.py index fdfac35..6540702 100755 --- a/bin/generate-dfa-benchmark.py +++ b/bin/generate-dfa-benchmark.py @@ -393,7 +393,7 @@ def run_benchmark( os.remove(filename) harness.undo(i) else: - files.extend(monitor.get_files()) + files.append(monitor.get_files()) i += 1 harness.restart() @@ -680,7 +680,7 @@ if __name__ == "__main__": "files": list(map(lambda x: x[3], results)), "configs": list(map(lambda x: x[2].get_config(), results)), } - extra_files = flatten(json_out["files"]) + extra_files = flatten(map(flatten, json_out["files"])) if "instance" in pta.codegen: output_prefix = ( opt["data"] + time.strftime("/%Y%m%d-%H%M%S-") + pta.codegen["instance"] diff --git a/lib/loader.py b/lib/loader.py index 65d497b..4934316 100644 --- a/lib/loader.py +++ b/lib/loader.py @@ -974,14 +974,16 @@ class RawData: "state_duration": ptalog["opt"]["sleep"], } ) - for repeat_id, etlog_file in enumerate(ptalog["files"][j]): - member = tf.getmember(etlog_file) + for repeat_id, etlog_files in enumerate(ptalog["files"][j]): + members = list(map(tf.getmember, etlog_files)) offline_data.append( { - "content": tf.extractfile(member).read(), + "content": list( + map(lambda f: tf.extractfile(f).read(), members) + ), "sync_mode": sync_mode, "fileno": j, - "info": member, + "info": members[0], "setup": self.setup_by_fileno[j], "repeat_id": repeat_id, "expected_trace": ptalog["traces"][j], @@ -1238,7 +1240,7 @@ class EnergyTraceWithBarcode: ) return list() - lines = log_data.decode("ascii").split("\n") + lines = log_data[0].decode("ascii").split("\n") data_count = sum(map(lambda x: len(x) > 0 and x[0] != "#", lines)) data_lines = filter(lambda x: len(x) > 0 and x[0] != "#", lines) -- cgit v1.2.3 From 2389623346d6b81477b8775635a0627baa90e31f Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Tue, 14 Jul 2020 16:59:14 +0200 Subject: Add --no-cache option --- bin/analyze-archive.py | 9 +++++++-- lib/loader.py | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/bin/analyze-archive.py b/bin/analyze-archive.py index 5c7c97e..10fe304 100755 --- a/bin/analyze-archive.py +++ b/bin/analyze-archive.py @@ -104,6 +104,9 @@ Options: --export-energymodel= Export energy model. Works out of the box for v1 and v2 logfiles. Requires --hwmodel for v0 logfiles. + +--no-cache + Do not load cached measurement results """ import getopt @@ -304,7 +307,7 @@ if __name__ == "__main__": try: optspec = ( - "info " + "info no-cache " "plot-unparam= plot-param= plot-traces= show-models= show-quality= " "ignored-trace-indexes= discard-outliers= function-override= " "export-traces= " @@ -369,7 +372,9 @@ if __name__ == "__main__": sys.exit(2) raw_data = RawData( - args, with_traces=("export-traces" in opt or "plot-traces" in opt) + args, + with_traces=("export-traces" in opt or "plot-traces" in opt), + skip_cache=("no-cache" in opt), ) if "info" in opt: diff --git a/lib/loader.py b/lib/loader.py index 4934316..438bbdb 100644 --- a/lib/loader.py +++ b/lib/loader.py @@ -249,7 +249,7 @@ class RawData: file system, making subsequent loads near-instant. """ - def __init__(self, filenames, with_traces=False): + def __init__(self, filenames, with_traces=False, skip_cache=False): """ Create a new RawData object. @@ -328,7 +328,7 @@ class RawData: self.pta = self.ptalog["pta"] self.set_cache_file() - if not with_traces: + if not with_traces and not skip_cache: self.load_cache() def set_cache_file(self): -- cgit v1.2.3 From 12a46eeee142233a205cac571e276a68af503e77 Mon Sep 17 00:00:00 2001 From: Lennart Date: Tue, 14 Jul 2020 17:17:09 +0200 Subject: Tested more --- .gitignore | 1 + lib/loader.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 25b1be5..91b6250 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ *.pyc /htmlcov/ /.coverage* +.idea/ diff --git a/lib/loader.py b/lib/loader.py index 438bbdb..c0a1694 100644 --- a/lib/loader.py +++ b/lib/loader.py @@ -1637,6 +1637,8 @@ class EnergyTraceWithLogicAnalyzer: def load_data(self, log_data): # TODO Daten laden + print("########################") + print(log_data[0].split("\n")[0]) pass def analyze_states(self, traces, offline_index: int): -- cgit v1.2.3 From e250e8fb30901a910cc22023a0bb99879e2c71b9 Mon Sep 17 00:00:00 2001 From: Lennart Date: Tue, 14 Jul 2020 22:52:21 +0200 Subject: Added into runner.py --- lib/harness.py | 3 +- lib/loader.py | 158 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- lib/runner.py | 17 ++++--- 3 files changed, 163 insertions(+), 15 deletions(-) diff --git a/lib/harness.py b/lib/harness.py index 3b9db89..7c99f5d 100644 --- a/lib/harness.py +++ b/lib/harness.py @@ -440,9 +440,10 @@ class OnboardTimerHarness(TransitionHarness): return ret def stop_benchmark(self): - ret = super().stop_benchmark() + ret = "" if self.energytrace_sync == "led": ret += "runLASync();\n" + ret += super().stop_benchmark() return ret def pass_transition( diff --git a/lib/loader.py b/lib/loader.py index c0a1694..38d59fc 100644 --- a/lib/loader.py +++ b/lib/loader.py @@ -1621,6 +1621,7 @@ class EnergyTraceWithLogicAnalyzer: transition_names: list, with_traces=False, ): + """ Create a new EnergyTraceWithLogicAnalyzer object. @@ -1636,9 +1637,13 @@ class EnergyTraceWithLogicAnalyzer: self.errors = list() def load_data(self, log_data): - # TODO Daten laden - print("########################") - print(log_data[0].split("\n")[0]) + from data.timing.SigrokInterface import SigrokResult + from data.energy.EnergyInterface import EnergyInterface + + # Daten laden + self.sync_data = SigrokResult.fromString(log_data[0]) + self.energy_data = EnergyInterface.getDataFromString(str(log_data[1])) + pass def analyze_states(self, traces, offline_index: int): @@ -1666,7 +1671,89 @@ class EnergyTraceWithLogicAnalyzer: * `W_mean_delta_next`: Differenz zwischen W_mean und W_mean des Folgezustands """ - # TODO Tatsächlich Daten auswerten + # Tatsächlich Daten auswerten + # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + # remove Dirty Data from previously running program (happens if logic Analyzer Measurement starts earlier than + # the HW Reset from energytrace) + use_data_after_index = 0 + for x in range(1, len(self.sync_data.timestamps)): + if self.sync_data.timestamps[x] - self.sync_data.timestamps[x - 1] > 1.3: + use_data_after_index = x + break + + time_stamp_data = self.sync_data.timestamps[use_data_after_index:] + + start_offset = None + start_timestamp = None + end_offset = None + end_timestamp = None + + last_values = [] # maybe needed to flatten the data + plot_data_x = [] + plot_data_y = [] + last_data = [0, 0, 0, 0] + + power_sync_watt = 0.0162 + + # MAIN ENERGY DATA ITERATION + for energytrace_dataset in self.energy_data: + usedtime = energytrace_dataset[0] - last_data[0] + usedenergy = energytrace_dataset[3] - last_data[3] + power = usedenergy / usedtime * 10 ** -3 # in watts + + if power > 0: + if power > power_sync_watt and start_offset is None: + # automatic START offset calculation + start_offset = energytrace_dataset[0] / 1_000_000 - time_stamp_data[0] + start_timestamp = energytrace_dataset[0] / 1_000_000 + if power > power_sync_watt and start_offset is not None: # TODO BETTER + # automatic END offset calculation (Drift) + end_offset = energytrace_dataset[0] / 1_000_000 - time_stamp_data[-1] - start_offset + end_timestamp = energytrace_dataset[0] / 1_000_000 + if len(last_values) > 10: + last_values.pop(0) + last_values.append(power) + # print("%s \tUsed Energy: %i \tUsed Time: %i \tPower: %f \t l_10: %f" % (now_data[0], usedenergy, usedtime, power, sum(last_values) / len(last_values))) + plot_data_x.append(energytrace_dataset[0] / 1_000_000) + plot_data_y.append(power) + + last_data = energytrace_dataset + + # -------------------- + # add start offset to the data + modified_timestamps_with_offset = [] + for x in time_stamp_data: + if x + start_offset >= 0: + modified_timestamps_with_offset.append(x + start_offset) + + # -------------------- + # Add drift to datapoints + modified_timestamps_with_drift = [] + endFactor = (end_timestamp + end_offset - start_timestamp) / (end_timestamp - start_timestamp) + for x in modified_timestamps_with_offset: + modified_timestamps_with_drift.append(((x - start_timestamp) * endFactor) + start_timestamp) + + self.start_offset = 0 + def getPowerBetween(start, end): + first_index = 0 + all_power = 0 + all_power_count = 0 + for ind in range(self.start_offset, len(plot_data_x)): + first_index = ind + if plot_data_x[ind] > start: + break + + for ind in range(first_index, len(plot_data_x)): + all_power += plot_data_y[ind] + all_power_count += 1 + if plot_data_x[ind] > end: + self.start_offset = ind - 1 + break + return all_power / all_power_count + + # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ energy_trace = list() @@ -1697,7 +1784,65 @@ class EnergyTraceWithLogicAnalyzer: ) return energy_trace - for name, duration in expected_transitions: + + # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + end_transition_ts = None + timestamps_sync_start = 0 + energy_trace_new = list() + + for ts_index in range(0 + timestamps_sync_start, int(len(modified_timestamps_with_drift) / 2)): + start_transition_ts = modified_timestamps_with_drift[ts_index * 2] + if end_transition_ts is not None: + power = getPowerBetween(end_transition_ts, start_transition_ts) + #print("STATE", end_transition_ts * 10 ** 6, start_transition_ts * 10 ** 6, (start_transition_ts - end_transition_ts) * 10 ** 6, power) + if (start_transition_ts - end_transition_ts) * 10 ** 6 > 900_000 and power > power_sync_watt * 0.9 and ts_index > 10: + #remove last transition and stop (upcoming data only sync) + del energy_trace_new[-1] + break + pass + + state = { + "isa": "state", + "W_mean": power, + "W_std": 0.0001, + "s": (start_transition_ts - end_transition_ts), #* 10 ** 6, + } + energy_trace_new.append(state) + + energy_trace_new[-2]["W_mean_delta_next"] = ( + energy_trace_new[-2]["W_mean"] - energy_trace_new[-1]["W_mean"] + ) + + # get energy end_transition_ts + end_transition_ts = modified_timestamps_with_drift[ts_index * 2 + 1] + power = getPowerBetween(start_transition_ts, end_transition_ts) + #print("TRANS", start_transition_ts * 10 ** 6, end_transition_ts * 10 ** 6, (end_transition_ts - start_transition_ts) * 10 ** 6, power) + transition = { + "isa": "transition", + "W_mean": power, + "W_std": 0.0001, + "s": (end_transition_ts - start_transition_ts), #* 10 ** 6, + } + + if (end_transition_ts - start_transition_ts) * 10 ** 6 > 2_000_000: + # TODO Last data set corrupted? HOT FIX!!!!!!!!!!!! REMOVE LATER + for x in range(4): + del energy_trace_new[-1] + break + pass + + energy_trace_new.append(transition) + # print(start_transition_ts, "-", end_transition_ts, "-", end_transition_ts - start_transition_ts) + + # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + energy_trace_new = energy_trace_new[4:] + + for number, item in enumerate(expected_transitions): + name, duration = item transition = { "isa": "transition", "W_mean": max(np.random.normal(0.023, 0.002), 0), @@ -1725,7 +1870,8 @@ class EnergyTraceWithLogicAnalyzer: energy_trace[-2]["W_mean"] - energy_trace[-1]["W_mean"] ) - return energy_trace + #print(len(energy_trace_new), " - ", len(energy_trace), " - ", ",".join([str(x["s"]) for x in energy_trace_new[-6:]]), " - ", ",".join([str(x["s"]) for x in energy_trace[-6:]])) + return energy_trace_new class EnergyTraceWithTimer(EnergyTraceWithLogicAnalyzer): diff --git a/lib/runner.py b/lib/runner.py index 3a201fc..3092d5a 100644 --- a/lib/runner.py +++ b/lib/runner.py @@ -165,6 +165,7 @@ class EnergyTraceMonitor(SerialMonitor): # Benchmark fertig -> externe Hilfsprogramme beenden def close(self): + print("EnergyTrace Close") super().close() self._logger.send_signal(subprocess.signal.SIGINT) stdout, stderr = self._logger.communicate(timeout=15) @@ -172,6 +173,7 @@ class EnergyTraceMonitor(SerialMonitor): # Zusätzliche Dateien, die mit dem Benchmark-Log und -Plan abgespeichert werden sollen # (hier: Die von msp430-etv generierten Logfiles) def get_files(self) -> list: + print("EnergyTrace Get Files") return [self._output] # Benchmark-Konfiguration. Hier: Die (konstante) Spannung. @@ -189,7 +191,7 @@ class EnergyTraceLogicAnalyzerMonitor(EnergyTraceMonitor): def __init__(self, port: str, baud: int, callback=None, voltage=3.3): super().__init__(port=port, baud=baud, callback=callback, voltage=voltage) - #TODO get length + #TODO Max length options = {'length': 90, 'fake': False, 'sample_rate': 1_000_000} self.log_file = 'logic_output_log_%s.json' % (time.strftime("%Y%m%d-%H%M%S")) @@ -198,23 +200,22 @@ class EnergyTraceLogicAnalyzerMonitor(EnergyTraceMonitor): sample_count=options['length'] * options['sample_rate'], fake=options['fake']) # Start Measurements - print("[ET LA] START MEASURE") self.sig.runMeasureAsynchronous() def close(self): super().close() # Read measured data - print("[ET LA] Wait MEASURE") - self.sig.waitForAsynchronousMeasure() - print("[ET LA] WRITE MEASURE") + #self.sig.waitForAsynchronousMeasure() + self.sig.forceStopMeasure() + time.sleep(0.2) sync_data = self.sig.getData() - print("[ET LA] MEASURE LEN", len(sync_data.timestamps)) with open(self.log_file, 'w') as fp: json.dump(sync_data.getDict(), fp) def get_files(self) -> list: - print("[ET LA] FILE REQUEST") - return [self.log_file] + files = [self.log_file] + files.extend(super().get_files()) + return files class MIMOSAMonitor(SerialMonitor): -- cgit v1.2.3 From 15be4345defa588e512626800ad9e1764160dfab Mon Sep 17 00:00:00 2001 From: Lennart Date: Mon, 20 Jul 2020 23:11:50 +0200 Subject: Added UART version and changed max power. --- lib/loader.py | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 81 insertions(+), 6 deletions(-) diff --git a/lib/loader.py b/lib/loader.py index 531559f..e9bd7d1 100644 --- a/lib/loader.py +++ b/lib/loader.py @@ -1694,7 +1694,7 @@ class EnergyTraceWithLogicAnalyzer: plot_data_y = [] last_data = [0, 0, 0, 0] - power_sync_watt = 0.0162 + power_sync_watt = 0.015 # MAIN ENERGY DATA ITERATION for energytrace_dataset in self.energy_data: @@ -1735,7 +1735,7 @@ class EnergyTraceWithLogicAnalyzer: modified_timestamps_with_drift.append(((x - start_timestamp) * endFactor) + start_timestamp) self.start_offset = 0 - def getPowerBetween(start, end, base_power=0.001469): + def getPowerBetween(start, end, base_power=0): #0.001469): first_index = 0 all_power = 0 all_power_count = 0 @@ -1841,7 +1841,44 @@ class EnergyTraceWithLogicAnalyzer: energy_trace_new = energy_trace_new[4:] - + # ******************************************************************** + # ******************************************************************** + # ******************************************************************** + # _____ _ ____ _______ _______ _____ _ _ _____ + # | __ \| | / __ \__ __|__ __|_ _| \ | |/ ____| + # | |__) | | | | | | | | | | | | | \| | | __ + # | ___/| | | | | | | | | | | | | . ` | | |_ | + # | | | |___| |__| | | | | | _| |_| |\ | |__| | + # |_| |______\____/ |_| |_| |_____|_| \_|\_____| + # + # ******************************************************************** + # ******************************************************************** + # ******************************************************************** + def calculateRectangleCurve(timestamps, min_value=0, max_value=0.160): + import numpy as np + data = [] + for ts in timestamps: + data.append(ts) + data.append(ts) + + a = np.empty((len(data),)) + a[1::4] = max_value + a[2::4] = max_value + a[3::4] = min_value + a[4::4] = min_value + return data, a # plotting by columns + + import matplotlib.pyplot as plt + rectCurve_with_drift = calculateRectangleCurve(modified_timestamps_with_drift, max_value=max(plot_data_y)) + + plt.plot(plot_data_x, plot_data_y, label='Energy') # plotting by columns + plt.plot(rectCurve_with_drift[0], rectCurve_with_drift[1], '-g', label='With calculated Driftfactor') + leg = plt.legend() + plt.show() + + # ******************************************************************** + # ******************************************************************** + # ******************************************************************** for number, item in enumerate(expected_transitions): name, duration = item @@ -1876,9 +1913,10 @@ class EnergyTraceWithLogicAnalyzer: st = "" for i, x in enumerate(energy_trace_new[-10:]): - st += "(%s|%s|%s)" % (energy_trace[i-10]["name"],x['W_mean'],x['s']) + #st += "(%s|%s|%s)" % (energy_trace[i-10]["name"],x['W_mean'],x['s']) + st += "(%s|%s|%s)\n" % (energy_trace[i-10]["s"], x['s'], x['W_mean']) - #print(st) + #print(st, "\n_______________________") print(len(self.sync_data.timestamps), " - ", len(energy_trace_new), " - ", len(energy_trace), " - ", ",".join([str(x["s"]) for x in energy_trace_new[-6:]]), " - ", ",".join([str(x["s"]) for x in energy_trace[-6:]])) if len(energy_trace_new) < len(energy_trace): return None @@ -1886,8 +1924,45 @@ class EnergyTraceWithLogicAnalyzer: class EnergyTraceWithTimer(EnergyTraceWithLogicAnalyzer): - pass + def __init__( + self, + voltage: float, + state_duration: int, + transition_names: list, + with_traces=False, + ): + + """ + Create a new EnergyTraceWithLogicAnalyzer object. + :param voltage: supply voltage [V], usually 3.3 V + :param state_duration: state duration [ms] + :param transition_names: list of transition names in PTA transition order. + Needed to map barcode synchronization numbers to transitions. + """ + + self.voltage = voltage + self.state_duration = state_duration * 1e-3 + self.transition_names = transition_names + self.with_traces = with_traces + self.errors = list() + + super().__init__(voltage, state_duration, transition_names, with_traces) + + def load_data(self, log_data): + from data.timing.SigrokInterface import SigrokResult + from data.energy.EnergyInterface import EnergyInterface + + # Daten laden + self.sync_data = None + self.energy_data = EnergyInterface.getDataFromString(str(log_data[1])) + + pass + + def analyze_states(self, traces, offline_index: int): + from data.timing.SigrokInterface import SigrokResult + self.sync_data = SigrokResult.fromTraces(traces) + return super().analyze_states(traces, offline_index) class MIMOSA: """ -- cgit v1.2.3 From 1f2f18c5b3ecb37ec8b2e4e9e57749d11ad0bba1 Mon Sep 17 00:00:00 2001 From: Lennart Date: Tue, 18 Aug 2020 17:43:35 +0200 Subject: Updated to Dataprocessor --- lib/loader.py | 234 +++++++++++----------------------------------------------- 1 file changed, 44 insertions(+), 190 deletions(-) diff --git a/lib/loader.py b/lib/loader.py index e9bd7d1..bd6a49d 100644 --- a/lib/loader.py +++ b/lib/loader.py @@ -11,6 +11,8 @@ import struct import tarfile import hashlib from multiprocessing import Pool + +from data.processing.DataProcessor import DataProcessor from .utils import running_mean, soft_cast_int logger = logging.getLogger(__name__) @@ -1671,97 +1673,24 @@ class EnergyTraceWithLogicAnalyzer: * `W_mean_delta_next`: Differenz zwischen W_mean und W_mean des Folgezustands """ - # Tatsächlich Daten auswerten - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - # remove Dirty Data from previously running program (happens if logic Analyzer Measurement starts earlier than - # the HW Reset from energytrace) - use_data_after_index = 0 - for x in range(1, len(self.sync_data.timestamps)): - if self.sync_data.timestamps[x] - self.sync_data.timestamps[x - 1] > 1.3: - use_data_after_index = x - break - - time_stamp_data = self.sync_data.timestamps[use_data_after_index:] - - start_offset = None - start_timestamp = None - end_offset = None - end_timestamp = None - - last_values = [] # maybe needed to flatten the data - plot_data_x = [] - plot_data_y = [] - last_data = [0, 0, 0, 0] - - power_sync_watt = 0.015 - - # MAIN ENERGY DATA ITERATION - for energytrace_dataset in self.energy_data: - usedtime = energytrace_dataset[0] - last_data[0] - usedenergy = energytrace_dataset[3] - last_data[3] - power = usedenergy / usedtime * 10 ** -3 # in watts - - if power > 0: - if power > power_sync_watt and start_offset is None: - # automatic START offset calculation - start_offset = energytrace_dataset[0] / 1_000_000 - time_stamp_data[0] - start_timestamp = energytrace_dataset[0] / 1_000_000 - if power > power_sync_watt and start_offset is not None: # TODO BETTER - # automatic END offset calculation (Drift) - end_offset = energytrace_dataset[0] / 1_000_000 - time_stamp_data[-1] - start_offset - end_timestamp = energytrace_dataset[0] / 1_000_000 - if len(last_values) > 10: - last_values.pop(0) - last_values.append(power) - # print("%s \tUsed Energy: %i \tUsed Time: %i \tPower: %f \t l_10: %f" % (now_data[0], usedenergy, usedtime, power, sum(last_values) / len(last_values))) - plot_data_x.append(energytrace_dataset[0] / 1_000_000) - plot_data_y.append(power) - - last_data = energytrace_dataset - - # -------------------- - # add start offset to the data - modified_timestamps_with_offset = [] - for x in time_stamp_data: - if x + start_offset >= 0: - modified_timestamps_with_offset.append(x + start_offset) - - # -------------------- - # Add drift to datapoints - modified_timestamps_with_drift = [] - endFactor = (end_timestamp + end_offset - start_timestamp) / (end_timestamp - start_timestamp) - for x in modified_timestamps_with_offset: - modified_timestamps_with_drift.append(((x - start_timestamp) * endFactor) + start_timestamp) - - self.start_offset = 0 - def getPowerBetween(start, end, base_power=0): #0.001469): - first_index = 0 - all_power = 0 - all_power_count = 0 - for ind in range(self.start_offset, len(plot_data_x)): - first_index = ind - if plot_data_x[ind] > start: - break - - for ind in range(first_index, len(plot_data_x)): - all_power += plot_data_y[ind] - all_power_count += 1 - if plot_data_x[ind] > end: - self.start_offset = ind - 1 - break - return (all_power / all_power_count) - base_power - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + names = [] + for trace_number, trace in enumerate(traces): + for state_or_transition in trace["trace"]: + names.append(state_or_transition["name"]) + print(names[:15]) + dp = DataProcessor(sync_data=self.sync_data, energy_data=self.energy_data) + dp.run() + energy_trace_new = list() + energy_trace_new.extend(dp.getStatesdfatool()) + #dp.plot() + #dp.plot(names) + energy_trace_new = energy_trace_new[4:] energy_trace = list() - expected_transitions = list() for trace_number, trace in enumerate(traces): - for state_or_transition_number, state_or_transition in enumerate( - trace["trace"] - ): + for state_or_transition_number, state_or_transition in enumerate(trace["trace"]): if state_or_transition["isa"] == "transition": try: expected_transitions.append( @@ -1785,100 +1714,6 @@ class EnergyTraceWithLogicAnalyzer: return energy_trace - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - - end_transition_ts = None - timestamps_sync_start = 0 - energy_trace_new = list() - - for ts_index in range(0 + timestamps_sync_start, int(len(modified_timestamps_with_drift) / 2)): - start_transition_ts = modified_timestamps_with_drift[ts_index * 2] - if end_transition_ts is not None: - power = getPowerBetween(end_transition_ts, start_transition_ts) - #print("STATE", end_transition_ts * 10 ** 6, start_transition_ts * 10 ** 6, (start_transition_ts - end_transition_ts) * 10 ** 6, power) - if (start_transition_ts - end_transition_ts) * 10 ** 6 > 900_000 and power > power_sync_watt * 0.9 and ts_index > 10: - #remove last transition and stop (upcoming data only sync) - del energy_trace_new[-1] - break - pass - - state = { - "isa": "state", - "W_mean": power, - "W_std": 0.0001, - "s": (start_transition_ts - end_transition_ts), #* 10 ** 6, - } - energy_trace_new.append(state) - - energy_trace_new[-2]["W_mean_delta_next"] = ( - energy_trace_new[-2]["W_mean"] - energy_trace_new[-1]["W_mean"] - ) - - # get energy end_transition_ts - end_transition_ts = modified_timestamps_with_drift[ts_index * 2 + 1] - power = getPowerBetween(start_transition_ts, end_transition_ts) - #print("TRANS", start_transition_ts * 10 ** 6, end_transition_ts * 10 ** 6, (end_transition_ts - start_transition_ts) * 10 ** 6, power) - transition = { - "isa": "transition", - "W_mean": power, - "W_std": 0.0001, - "s": (end_transition_ts - start_transition_ts), #* 10 ** 6, - } - - if (end_transition_ts - start_transition_ts) * 10 ** 6 > 2_000_000: - # TODO Last data set corrupted? HOT FIX!!!!!!!!!!!! REMOVE LATER - #for x in range(4): - # del energy_trace_new[-1] - #break - pass - - energy_trace_new.append(transition) - # print(start_transition_ts, "-", end_transition_ts, "-", end_transition_ts - start_transition_ts) - - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - - energy_trace_new = energy_trace_new[4:] - - # ******************************************************************** - # ******************************************************************** - # ******************************************************************** - # _____ _ ____ _______ _______ _____ _ _ _____ - # | __ \| | / __ \__ __|__ __|_ _| \ | |/ ____| - # | |__) | | | | | | | | | | | | | \| | | __ - # | ___/| | | | | | | | | | | | | . ` | | |_ | - # | | | |___| |__| | | | | | _| |_| |\ | |__| | - # |_| |______\____/ |_| |_| |_____|_| \_|\_____| - # - # ******************************************************************** - # ******************************************************************** - # ******************************************************************** - def calculateRectangleCurve(timestamps, min_value=0, max_value=0.160): - import numpy as np - data = [] - for ts in timestamps: - data.append(ts) - data.append(ts) - - a = np.empty((len(data),)) - a[1::4] = max_value - a[2::4] = max_value - a[3::4] = min_value - a[4::4] = min_value - return data, a # plotting by columns - - import matplotlib.pyplot as plt - rectCurve_with_drift = calculateRectangleCurve(modified_timestamps_with_drift, max_value=max(plot_data_y)) - - plt.plot(plot_data_x, plot_data_y, label='Energy') # plotting by columns - plt.plot(rectCurve_with_drift[0], rectCurve_with_drift[1], '-g', label='With calculated Driftfactor') - leg = plt.legend() - plt.show() - - # ******************************************************************** - # ******************************************************************** - # ******************************************************************** for number, item in enumerate(expected_transitions): name, duration = item @@ -1894,7 +1729,7 @@ class EnergyTraceWithLogicAnalyzer: if len(energy_trace) > 1: energy_trace[-1]["W_mean_delta_prev"] = ( - energy_trace[-1]["W_mean"] - energy_trace[-2]["W_mean"] + energy_trace[-1]["W_mean"] - energy_trace[-2]["W_mean"] ) state = { @@ -1908,18 +1743,37 @@ class EnergyTraceWithLogicAnalyzer: energy_trace.append(state) energy_trace[-2]["W_mean_delta_next"] = ( - energy_trace[-2]["W_mean"] - energy_trace[-1]["W_mean"] + energy_trace[-2]["W_mean"] - energy_trace[-1]["W_mean"] ) - st = "" - for i, x in enumerate(energy_trace_new[-10:]): - #st += "(%s|%s|%s)" % (energy_trace[i-10]["name"],x['W_mean'],x['s']) - st += "(%s|%s|%s)\n" % (energy_trace[i-10]["s"], x['s'], x['W_mean']) + for number, item in enumerate(energy_trace): + name = item["name"] + #print(energy_trace[number - 1]["name"]) + #if name == "state" and "switchTo3K3" in energy_trace[number - 1]["name"]: + #print(name, energy_trace_new[number]["W_mean"]) + + # add next/prev state W_mean_delta + for number, item in enumerate(energy_trace_new): + if item['isa'] == 'transition' and number > 0 and number < len(energy_trace_new) - 1: + item['W_mean_delta_prev'] = energy_trace_new[number - 1] + item['W_mean_delta_next'] = energy_trace_new[number + 1] + + for number, item in enumerate(energy_trace): + name = energy_trace[number]['name'] + + if energy_trace_new[number]['isa'] == 'transition': + print(name, energy_trace_new[number]['count_dp'], energy_trace_new[number]["W_mean"]) + + #st = "" + #for i, x in enumerate(energy_trace_new[-10:]): + # #st += "(%s|%s|%s)" % (energy_trace[i-10]["name"],x['W_mean'],x['s']) + # st += "(%s|%s|%s)\n" % (energy_trace[i-10]["s"], x['s'], x['W_mean']) #print(st, "\n_______________________") - print(len(self.sync_data.timestamps), " - ", len(energy_trace_new), " - ", len(energy_trace), " - ", ",".join([str(x["s"]) for x in energy_trace_new[-6:]]), " - ", ",".join([str(x["s"]) for x in energy_trace[-6:]])) - if len(energy_trace_new) < len(energy_trace): - return None + #print(len(self.sync_data.timestamps), " - ", len(energy_trace_new), " - ", len(energy_trace), " - ", ",".join([str(x["s"]) for x in energy_trace_new[-6:]]), " - ", ",".join([str(x["s"]) for x in energy_trace[-6:]])) + #if len(energy_trace_new) < len(energy_trace): + # return None + return energy_trace_new @@ -1955,7 +1809,7 @@ class EnergyTraceWithTimer(EnergyTraceWithLogicAnalyzer): # Daten laden self.sync_data = None - self.energy_data = EnergyInterface.getDataFromString(str(log_data[1])) + self.energy_data = EnergyInterface.getDataFromString(str(log_data[0])) pass -- cgit v1.2.3 From ae154071f9da8105bfa0ca9c20948d471d38e8cd Mon Sep 17 00:00:00 2001 From: Lennart Date: Thu, 20 Aug 2020 13:39:15 +0200 Subject: Added state duration --- lib/loader.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/loader.py b/lib/loader.py index bd6a49d..d14680e 100644 --- a/lib/loader.py +++ b/lib/loader.py @@ -1678,11 +1678,11 @@ class EnergyTraceWithLogicAnalyzer: for trace_number, trace in enumerate(traces): for state_or_transition in trace["trace"]: names.append(state_or_transition["name"]) - print(names[:15]) + #print(names[:15]) dp = DataProcessor(sync_data=self.sync_data, energy_data=self.energy_data) dp.run() energy_trace_new = list() - energy_trace_new.extend(dp.getStatesdfatool()) + energy_trace_new.extend(dp.getStatesdfatool(state_sleep=self.state_duration)) #dp.plot() #dp.plot(names) energy_trace_new = energy_trace_new[4:] -- cgit v1.2.3 From b55d5aabeeca7020bbcad34925592ed0eee88d3c Mon Sep 17 00:00:00 2001 From: Lennart Date: Mon, 7 Sep 2020 18:30:53 +0200 Subject: Changed sync Slightly & Black --- lib/harness.py | 10 ++++------ lib/loader.py | 61 +++++++++++++++++++++++++++++++--------------------------- lib/runner.py | 6 +++--- 3 files changed, 40 insertions(+), 37 deletions(-) diff --git a/lib/harness.py b/lib/harness.py index 833807e..f0f2837 100644 --- a/lib/harness.py +++ b/lib/harness.py @@ -141,9 +141,7 @@ class TransitionHarness: def start_trace(self): """Prepare a new trace/run in the internal `.traces` structure.""" - self.traces.append( - {"id": self.trace_id, "trace": list(),} - ) + self.traces.append({"id": self.trace_id, "trace": list()}) self.trace_id += 1 def append_state(self, state_name, param): @@ -154,7 +152,7 @@ class TransitionHarness: :param param: parameter dict """ self.traces[-1]["trace"].append( - {"name": state_name, "isa": "state", "parameter": param,} + {"name": state_name, "isa": "state", "parameter": param} ) def append_transition(self, transition_name, param, args=[]): @@ -405,7 +403,7 @@ class OnboardTimerHarness(TransitionHarness): ret = "#define PTALOG_TIMING\n" ret += super().global_code() if self.energytrace_sync == "led": - #TODO Make nicer + # TODO Make nicer ret += """\nvoid runLASync(){ // ======================= LED SYNC ================================ ptalog.passTransition(0); @@ -424,7 +422,7 @@ class OnboardTimerHarness(TransitionHarness): gpio.led_toggle(1); ptalog.stopTransition(); // ======================= LED SYNC ================================ - arch.sleep_ms(250); + //arch.sleep_ms(250); }\n\n""" return ret diff --git a/lib/loader.py b/lib/loader.py index d14680e..4ae883e 100644 --- a/lib/loader.py +++ b/lib/loader.py @@ -1648,7 +1648,7 @@ class EnergyTraceWithLogicAnalyzer: pass - def analyze_states(self, traces, offline_index: int): + def analyze_states(self, traces, offline_index: int, timer_measurement=False): u""" Split log data into states and transitions and return duration, energy, and mean power for each element. @@ -1673,24 +1673,25 @@ class EnergyTraceWithLogicAnalyzer: * `W_mean_delta_next`: Differenz zwischen W_mean und W_mean des Folgezustands """ - names = [] for trace_number, trace in enumerate(traces): for state_or_transition in trace["trace"]: names.append(state_or_transition["name"]) - #print(names[:15]) + # print(names[:15]) dp = DataProcessor(sync_data=self.sync_data, energy_data=self.energy_data) - dp.run() + dp.run(timer_measurement) energy_trace_new = list() energy_trace_new.extend(dp.getStatesdfatool(state_sleep=self.state_duration)) - #dp.plot() - #dp.plot(names) + dp.plot() + # dp.plot(names) energy_trace_new = energy_trace_new[4:] energy_trace = list() expected_transitions = list() for trace_number, trace in enumerate(traces): - for state_or_transition_number, state_or_transition in enumerate(trace["trace"]): + for state_or_transition_number, state_or_transitistddevon in enumerate( + trace["trace"] + ): if state_or_transition["isa"] == "transition": try: expected_transitions.append( @@ -1713,8 +1714,6 @@ class EnergyTraceWithLogicAnalyzer: ) return energy_trace - - for number, item in enumerate(expected_transitions): name, duration = item transition = { @@ -1729,7 +1728,7 @@ class EnergyTraceWithLogicAnalyzer: if len(energy_trace) > 1: energy_trace[-1]["W_mean_delta_prev"] = ( - energy_trace[-1]["W_mean"] - energy_trace[-2]["W_mean"] + energy_trace[-1]["W_mean"] - energy_trace[-2]["W_mean"] ) state = { @@ -1743,35 +1742,39 @@ class EnergyTraceWithLogicAnalyzer: energy_trace.append(state) energy_trace[-2]["W_mean_delta_next"] = ( - energy_trace[-2]["W_mean"] - energy_trace[-1]["W_mean"] + energy_trace[-2]["W_mean"] - energy_trace[-1]["W_mean"] ) for number, item in enumerate(energy_trace): name = item["name"] - #print(energy_trace[number - 1]["name"]) - #if name == "state" and "switchTo3K3" in energy_trace[number - 1]["name"]: - #print(name, energy_trace_new[number]["W_mean"]) + # print(energy_trace[number - 1]["name"]) + # if name == "state" and "switchTo3K3" in energy_trace[number - 1]["name"]: + # print(name, energy_trace_new[number]["W_mean"]) # add next/prev state W_mean_delta for number, item in enumerate(energy_trace_new): - if item['isa'] == 'transition' and number > 0 and number < len(energy_trace_new) - 1: - item['W_mean_delta_prev'] = energy_trace_new[number - 1] - item['W_mean_delta_next'] = energy_trace_new[number + 1] + if item["isa"] == "transition" and 0 < number < len(energy_trace_new) - 1: + item["W_mean_delta_prev"] = energy_trace_new[number - 1] + item["W_mean_delta_next"] = energy_trace_new[number + 1] + """ for number, item in enumerate(energy_trace): - name = energy_trace[number]['name'] - - if energy_trace_new[number]['isa'] == 'transition': - print(name, energy_trace_new[number]['count_dp'], energy_trace_new[number]["W_mean"]) - - #st = "" - #for i, x in enumerate(energy_trace_new[-10:]): + name = energy_trace[number]["name"] + if energy_trace_new[number]["isa"] == "transition": + print( + name, + energy_trace_new[number]["count_dp"], + energy_trace_new[number]["W_mean"], + ) + """ + # st = "" + # for i, x in enumerate(energy_trace_new[-10:]): # #st += "(%s|%s|%s)" % (energy_trace[i-10]["name"],x['W_mean'],x['s']) # st += "(%s|%s|%s)\n" % (energy_trace[i-10]["s"], x['s'], x['W_mean']) - #print(st, "\n_______________________") - #print(len(self.sync_data.timestamps), " - ", len(energy_trace_new), " - ", len(energy_trace), " - ", ",".join([str(x["s"]) for x in energy_trace_new[-6:]]), " - ", ",".join([str(x["s"]) for x in energy_trace[-6:]])) - #if len(energy_trace_new) < len(energy_trace): + # print(st, "\n_______________________") + # print(len(self.sync_data.timestamps), " - ", len(energy_trace_new), " - ", len(energy_trace), " - ", ",".join([str(x["s"]) for x in energy_trace_new[-6:]]), " - ", ",".join([str(x["s"]) for x in energy_trace[-6:]])) + # if len(energy_trace_new) < len(energy_trace): # return None return energy_trace_new @@ -1815,8 +1818,10 @@ class EnergyTraceWithTimer(EnergyTraceWithLogicAnalyzer): def analyze_states(self, traces, offline_index: int): from data.timing.SigrokInterface import SigrokResult + self.sync_data = SigrokResult.fromTraces(traces) - return super().analyze_states(traces, offline_index) + return super().analyze_states(traces, offline_index, timer_measurement=True) + class MIMOSA: """ diff --git a/lib/runner.py b/lib/runner.py index 3092d5a..8093a55 100644 --- a/lib/runner.py +++ b/lib/runner.py @@ -157,7 +157,7 @@ class EnergyTraceMonitor(SerialMonitor): self._start_energytrace() def _start_energytrace(self): - print("EnergyTrace Start") + print("[%s] Starting Measurement" % type(self).__name__) cmd = ["msp430-etv", "--save", self._output, "0"] self._logger = subprocess.Popen( cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True @@ -165,15 +165,15 @@ class EnergyTraceMonitor(SerialMonitor): # Benchmark fertig -> externe Hilfsprogramme beenden def close(self): - print("EnergyTrace Close") super().close() self._logger.send_signal(subprocess.signal.SIGINT) stdout, stderr = self._logger.communicate(timeout=15) + print("[%s] Stopped Measurement" % type(self).__name__) # Zusätzliche Dateien, die mit dem Benchmark-Log und -Plan abgespeichert werden sollen # (hier: Die von msp430-etv generierten Logfiles) def get_files(self) -> list: - print("EnergyTrace Get Files") + print("[%s] Getting files" % type(self).__name__) return [self._output] # Benchmark-Konfiguration. Hier: Die (konstante) Spannung. -- cgit v1.2.3 From b5cd0911fd986666b229aadce48f3d372f4b7e13 Mon Sep 17 00:00:00 2001 From: Lennart Date: Mon, 7 Sep 2020 18:44:04 +0200 Subject: test --- lib/harness.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/harness.py b/lib/harness.py index f0f2837..ed6cdac 100644 --- a/lib/harness.py +++ b/lib/harness.py @@ -422,7 +422,7 @@ class OnboardTimerHarness(TransitionHarness): gpio.led_toggle(1); ptalog.stopTransition(); // ======================= LED SYNC ================================ - //arch.sleep_ms(250); + arch.sleep_ms(200); }\n\n""" return ret -- cgit v1.2.3 From aa0a56a8f1ba32235e1b2664835e35b6641a5715 Mon Sep 17 00:00:00 2001 From: Lennart Date: Wed, 9 Sep 2020 13:20:43 +0200 Subject: changed stuff --- lib/harness.py | 2 +- lib/loader.py | 81 +++++----------------------------------------------------- 2 files changed, 8 insertions(+), 75 deletions(-) diff --git a/lib/harness.py b/lib/harness.py index ed6cdac..51013e1 100644 --- a/lib/harness.py +++ b/lib/harness.py @@ -422,7 +422,7 @@ class OnboardTimerHarness(TransitionHarness): gpio.led_toggle(1); ptalog.stopTransition(); // ======================= LED SYNC ================================ - arch.sleep_ms(200); + arch.sleep_ms(250); }\n\n""" return ret diff --git a/lib/loader.py b/lib/loader.py index 4ae883e..b4b2127 100644 --- a/lib/loader.py +++ b/lib/loader.py @@ -1648,7 +1648,7 @@ class EnergyTraceWithLogicAnalyzer: pass - def analyze_states(self, traces, offline_index: int, timer_measurement=False): + def analyze_states(self, traces, offline_index: int): u""" Split log data into states and transitions and return duration, energy, and mean power for each element. @@ -1679,7 +1679,7 @@ class EnergyTraceWithLogicAnalyzer: names.append(state_or_transition["name"]) # print(names[:15]) dp = DataProcessor(sync_data=self.sync_data, energy_data=self.energy_data) - dp.run(timer_measurement) + dp.run() energy_trace_new = list() energy_trace_new.extend(dp.getStatesdfatool(state_sleep=self.state_duration)) dp.plot() @@ -1688,68 +1688,11 @@ class EnergyTraceWithLogicAnalyzer: energy_trace = list() expected_transitions = list() - for trace_number, trace in enumerate(traces): - for state_or_transition_number, state_or_transitistddevon in enumerate( - trace["trace"] - ): - if state_or_transition["isa"] == "transition": - try: - expected_transitions.append( - ( - state_or_transition["name"], - state_or_transition["online_aggregates"]["duration"][ - offline_index - ] - * 1e-6, - ) - ) - except IndexError: - self.errors.append( - 'Entry #{} ("{}") in trace #{} has no duration entry for offline_index/repeat_id {}'.format( - state_or_transition_number, - state_or_transition["name"], - trace_number, - offline_index, - ) - ) - return energy_trace - for number, item in enumerate(expected_transitions): - name, duration = item - transition = { - "isa": "transition", - "W_mean": max(np.random.normal(0.023, 0.002), 0), - "W_std": 0.0001, - "s": duration, - "name": name, - } - - energy_trace.append(transition) - - if len(energy_trace) > 1: - energy_trace[-1]["W_mean_delta_prev"] = ( - energy_trace[-1]["W_mean"] - energy_trace[-2]["W_mean"] - ) - - state = { - "isa": "state", - "W_mean": max(np.random.normal(0.023, 0.002), 0), - "W_std": 0.0001, - "s": self.state_duration, - "name": "state", - } - - energy_trace.append(state) - - energy_trace[-2]["W_mean_delta_next"] = ( - energy_trace[-2]["W_mean"] - energy_trace[-1]["W_mean"] - ) - - for number, item in enumerate(energy_trace): - name = item["name"] - # print(energy_trace[number - 1]["name"]) - # if name == "state" and "switchTo3K3" in energy_trace[number - 1]["name"]: - # print(name, energy_trace_new[number]["W_mean"]) + # Print for debug purposes + # for number, name in enumerate(names): + # if "P15_8MW" in name: + # print(name, energy_trace_new[number]["W_mean"]) # add next/prev state W_mean_delta for number, item in enumerate(energy_trace_new): @@ -1757,16 +1700,6 @@ class EnergyTraceWithLogicAnalyzer: item["W_mean_delta_prev"] = energy_trace_new[number - 1] item["W_mean_delta_next"] = energy_trace_new[number + 1] - """ - for number, item in enumerate(energy_trace): - name = energy_trace[number]["name"] - if energy_trace_new[number]["isa"] == "transition": - print( - name, - energy_trace_new[number]["count_dp"], - energy_trace_new[number]["W_mean"], - ) - """ # st = "" # for i, x in enumerate(energy_trace_new[-10:]): # #st += "(%s|%s|%s)" % (energy_trace[i-10]["name"],x['W_mean'],x['s']) @@ -1820,7 +1753,7 @@ class EnergyTraceWithTimer(EnergyTraceWithLogicAnalyzer): from data.timing.SigrokInterface import SigrokResult self.sync_data = SigrokResult.fromTraces(traces) - return super().analyze_states(traces, offline_index, timer_measurement=True) + return super().analyze_states(traces, offline_index) class MIMOSA: -- cgit v1.2.3 From f8cf50af8564094e145124af08e5e12e13ed352f Mon Sep 17 00:00:00 2001 From: Lennart Date: Tue, 22 Sep 2020 00:03:23 +0200 Subject: Changed code import and black formatted --- lib/loader.py | 3 ++- lib/runner.py | 27 ++++++++++++--------------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/lib/loader.py b/lib/loader.py index b4b2127..ea2b183 100644 --- a/lib/loader.py +++ b/lib/loader.py @@ -12,7 +12,6 @@ import tarfile import hashlib from multiprocessing import Pool -from data.processing.DataProcessor import DataProcessor from .utils import running_mean, soft_cast_int logger = logging.getLogger(__name__) @@ -1678,6 +1677,8 @@ class EnergyTraceWithLogicAnalyzer: for state_or_transition in trace["trace"]: names.append(state_or_transition["name"]) # print(names[:15]) + from data.processing.DataProcessor import DataProcessor + dp = DataProcessor(sync_data=self.sync_data, energy_data=self.energy_data) dp.run() energy_trace_new = list() diff --git a/lib/runner.py b/lib/runner.py index 8093a55..4cab9ed 100644 --- a/lib/runner.py +++ b/lib/runner.py @@ -180,9 +180,7 @@ class EnergyTraceMonitor(SerialMonitor): # MSP430FR5969: 3,6V (wird aktuell nicht unterstützt) # MSP430FR5994: 3,3V (default) def get_config(self) -> dict: - return { - "voltage": self._voltage, - } + return {"voltage": self._voltage} class EnergyTraceLogicAnalyzerMonitor(EnergyTraceMonitor): @@ -191,13 +189,16 @@ class EnergyTraceLogicAnalyzerMonitor(EnergyTraceMonitor): def __init__(self, port: str, baud: int, callback=None, voltage=3.3): super().__init__(port=port, baud=baud, callback=callback, voltage=voltage) - #TODO Max length - options = {'length': 90, 'fake': False, 'sample_rate': 1_000_000} - self.log_file = 'logic_output_log_%s.json' % (time.strftime("%Y%m%d-%H%M%S")) + # TODO Max length + options = {"length": 90, "fake": False, "sample_rate": 1_000_000} + self.log_file = "logic_output_log_%s.json" % (time.strftime("%Y%m%d-%H%M%S")) # Initialization of Interfaces - self.sig = SigrokCLIInterface(sample_rate=options['sample_rate'], - sample_count=options['length'] * options['sample_rate'], fake=options['fake']) + self.sig = SigrokCLIInterface( + sample_rate=options["sample_rate"], + sample_count=options["length"] * options["sample_rate"], + fake=options["fake"], + ) # Start Measurements self.sig.runMeasureAsynchronous() @@ -205,11 +206,11 @@ class EnergyTraceLogicAnalyzerMonitor(EnergyTraceMonitor): def close(self): super().close() # Read measured data - #self.sig.waitForAsynchronousMeasure() + # self.sig.waitForAsynchronousMeasure() self.sig.forceStopMeasure() time.sleep(0.2) sync_data = self.sig.getData() - with open(self.log_file, 'w') as fp: + with open(self.log_file, "w") as fp: json.dump(sync_data.getDict(), fp) def get_files(self) -> list: @@ -293,11 +294,7 @@ class MIMOSAMonitor(SerialMonitor): return [self.mim_file] def get_config(self) -> dict: - return { - "offset": self._offset, - "shunt": self._shunt, - "voltage": self._voltage, - } + return {"offset": self._offset, "shunt": self._shunt, "voltage": self._voltage} class ShellMonitor: -- cgit v1.2.3