diff options
-rwxr-xr-x | bin/generate-dfa-benchmark.py | 3 | ||||
-rw-r--r-- | lib/harness.py | 38 |
2 files changed, 33 insertions, 8 deletions
diff --git a/bin/generate-dfa-benchmark.py b/bin/generate-dfa-benchmark.py index 23aa627..62808de 100755 --- a/bin/generate-dfa-benchmark.py +++ b/bin/generate-dfa-benchmark.py @@ -138,8 +138,6 @@ def benchmark_from_runs(pta: PTA, runs: list, harness: OnboardTimerHarness, benc param = pta.get_initial_param_dict() for transition, arguments, parameter in run: num_transitions += 1 - # TODO für energytrace mode: BarCode-Library für Transition ID -> GPIO-LED-Pulse nutzen? Taugt genau so gut als sync und liefert obendrein noch - # Daten harness.append_transition(transition.name, param, arguments) harness.append_state(transition.destination.name, parameter.copy()) outbuf.write('// {} -> {}\n'.format(transition.origin.name, transition.destination.name)) @@ -255,6 +253,7 @@ def run_benchmark(application_file: str, pta: PTA, runs: list, arch: str, app: s if sync_error: for filename in monitor.get_files(): os.remove(filename) + harness.undo(i) else: files.extend(monitor.get_files()) i += 1 diff --git a/lib/harness.py b/lib/harness.py index d6594cc..7a7b898 100644 --- a/lib/harness.py +++ b/lib/harness.py @@ -7,10 +7,6 @@ import subprocess import re from pubcode import Code128 -# TODO prepare benchmark log JSON with parameters etc. -# Should be independent of PTA class, as benchmarks may also be -# generated otherwise and it should also work with AnalyticModel (which does -# not have states) class TransitionHarness: """ TODO @@ -56,6 +52,23 @@ class TransitionHarness: new_object.trace_id = self.trace_id return new_object + def undo(self, undo_from): + """ + Undo all benchmark runs starting with index `undo_from`. + + :param undo_from: index of measurements to be undone. Measurementh with a higher index (i.e., which happened later) will also be undone. + + Removes all logged results (nondeterministic parameter values and return values) + of the current benchmark iteration. Resets `done` and `synced`, + """ + for trace in self.traces: + for state_or_transition in trace['trace']: + if 'return_values' in state_or_transition: + state_or_transition['return_values'] = state_or_transition['return_values'][:undo_from] + for param_name in state_or_transition['parameter'].keys(): + if type(state_or_transition['parameter'][param_name]) is list: + state_or_transition['parameter'][param_name] = state_or_transition['parameter'][param_name][:undo_from] + def reset(self): """ Reset harness for a new benchmark. @@ -202,7 +215,6 @@ class TransitionHarness: self.trace_id = int(res.group(1)) self.trace_length = int(res.group(2)) self.current_transition_in_trace = 0 - #print('[HARNESS] trace {:d} contains {:d} transitions. Expecting {:d} transitions.'.format(self.trace_id, self.trace_length, len(self.traces[self.trace_id]['trace']) // 2)) if self.log_return_values: res = re.match(r'\[PTA\] transition=(\S+) return=(\S+)', line) else: @@ -270,6 +282,21 @@ class OnboardTimerHarness(TransitionHarness): new_harness.trace_id = self.trace_id return new_harness + def undo(self, undo_from): + """ + Undo all benchmark runs starting with index `undo_from`. + + :param undo_from: index of measurements to be undone. Measurementh with a higher index (i.e., which happened later) will also be undone. + + Removes all logged results (durations, nondeterministic parameter values, return values) + of the current benchmark iteration. Resets `done` and `synced`, + """ + super().undo(undo_from) + for trace in self.traces: + for state_or_transition in trace['trace']: + if 'offline_aggregates' in state_or_transition: + state_or_transition['offline_aggregates']['duration'] = state_or_transition['offline_aggregates']['duration'][:undo_from] + def global_code(self): ret = '#include "driver/counter.h"\n' ret += '#define PTALOG_TIMING\n' @@ -322,7 +349,6 @@ class OnboardTimerHarness(TransitionHarness): self.trace_id = int(res.group(1)) self.trace_length = int(res.group(2)) self.current_transition_in_trace = 0 - #print('[HARNESS] trace {:d} contains {:d} transitions. Expecting {:d} transitions.'.format(self.trace_id, self.trace_length, len(self.traces[self.trace_id]['trace']) // 2)) if self.log_return_values: res = re.match(r'\[PTA\] transition=(\S+) cycles=(\S+)/(\S+) return=(\S+)', line) else: |