summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <daniel.friesel@uos.de>2019-07-19 14:19:42 +0200
committerDaniel Friesel <daniel.friesel@uos.de>2019-07-19 14:19:42 +0200
commit9372ca24757ebd5dbd7ba5ae8b49472f2c2ce521 (patch)
treebc858ddfebb1d10db2c1b805aef857ee83386adf
parent29acf1f00f52235dce3dc7397cecd0127c90b22a (diff)
generate-dfa-benchmark: Add trace filter
-rwxr-xr-xbin/generate-dfa-benchmark.py34
-rw-r--r--lib/harness.py25
2 files changed, 47 insertions, 12 deletions
diff --git a/bin/generate-dfa-benchmark.py b/bin/generate-dfa-benchmark.py
index 2503097..b9790ed 100755
--- a/bin/generate-dfa-benchmark.py
+++ b/bin/generate-dfa-benchmark.py
@@ -35,6 +35,16 @@ from harness import OnboardTimerHarness
opt = {}
+def trace_matches_filter(trace: list, trace_filter: list) -> bool:
+ for allowed_trace in trace_filter:
+ if len(trace) < len(allowed_trace):
+ continue
+ different_element_count = len(list(filter(None, map(lambda x,y: x[0].name != y, trace, allowed_trace))))
+ if different_element_count == 0:
+ return True
+ return False
+
+
if __name__ == '__main__':
try:
@@ -46,6 +56,7 @@ if __name__ == '__main__':
'run= '
'sleep= '
'timer-pin= '
+ 'trace-filter= '
)
raw_opts, args = getopt.getopt(sys.argv[1:], "", optspec.split(' '))
@@ -61,6 +72,12 @@ if __name__ == '__main__':
if 'sleep' in opt:
opt['sleep'] = int(opt['sleep'])
+ if 'trace-filter' in opt:
+ trace_filter = []
+ for trace in opt['trace-filter'].split():
+ trace_filter.append(trace.split(','))
+ opt['trace-filter'] = trace_filter
+
except getopt.GetoptError as err:
print(err)
sys.exit(2)
@@ -106,14 +123,18 @@ if __name__ == '__main__':
class_prefix = '{}.'.format(pta.codegen['instance'])
num_transitions = 0
+ num_traces = 0
for run in pta.dfs(opt['depth'], with_arguments = True, with_parameters = True):
+ if 'trace-filter' in opt and not trace_matches_filter(run, opt['trace-filter']):
+ continue
outbuf.write(harness.start_run())
harness.start_trace()
param = pta.get_initial_param_dict()
for transition, arguments, parameter in run:
num_transitions += 1
harness.append_state(transition.origin.name, param)
- harness.append_transition(transition.name, param)
+ harness.append_transition(transition.name, param, arguments)
+ param = transition.get_params_after_transition(param, arguments)
outbuf.write('// {} -> {}\n'.format(transition.origin.name, transition.destination.name))
if transition.is_interrupt:
outbuf.write('// wait for {} interrupt\n'.format(transition.name))
@@ -127,11 +148,15 @@ if __name__ == '__main__':
if 'sleep' in opt:
outbuf.write('arch.delay_ms({:d});\n'.format(opt['sleep']))
- outbuf.write(harness.stop_run())
+ outbuf.write(harness.stop_run(num_traces))
outbuf.write('\n')
+ num_traces += 1
+
+ if num_transitions == 0:
+ print('DFS returned no traces -- perhaps your trace-filter is too restrictive?', file=sys.stderr)
+ sys.exit(1)
outbuf.write(harness.stop_benchmark())
- print(harness.traces)
outbuf.write('}\n')
outbuf.write('return 0;\n')
outbuf.write('}\n')
@@ -156,8 +181,7 @@ if __name__ == '__main__':
while True:
time.sleep(5)
slept += 5
- if slept < run_timeout:
- print('[MON] approx. {:.0f}% done'.format(slept * 100 / run_timeout))
+ print('[MON] approx. {:.0f}% done'.format(slept * 100 / run_timeout))
except KeyboardInterrupt:
pass
lines = monitor.get_lines()
diff --git a/lib/harness.py b/lib/harness.py
index ade42d6..529a77e 100644
--- a/lib/harness.py
+++ b/lib/harness.py
@@ -3,6 +3,7 @@ Harnesses for various types of benchmark logs.
tbd
"""
+import subprocess
import re
# TODO prepare benchmark log JSON with parameters etc.
@@ -16,6 +17,12 @@ class TransitionHarness:
self.trace_id = 1
pass
+ def start_benchmark(self):
+ pass
+
+ def stop_benchmark(self):
+ pass
+
def global_code(self):
ret = ''
if self.gpio_pin != None:
@@ -44,11 +51,12 @@ class TransitionHarness:
'parameter': param,
})
- def append_transition(self, transition_name, param):
+ def append_transition(self, transition_name, param, args = []):
self.traces[-1]['trace'].append({
'name': transition_name,
'isa': 'transition',
'parameter': param,
+ 'args' : args,
})
def start_run(self):
@@ -61,23 +69,26 @@ class TransitionHarness:
ret += 'ptalog.stopTransition();\n'
return ret
- def stop_run(self):
- return 'ptalog.dump();\n'
+ def stop_run(self, trace_id = 0):
+ return 'ptalog.dump({:d});\n'.format(trace_id)
def stop_benchmark(self):
return ''
+ def parser_cb(self, line):
+ pass
+
def parse_log(self, lines):
sync = False
for line in lines:
print(line)
- res = re.fullmatch('\[PTA\] (.*=.*)', line)
- if re.fullmatch('\[PTA\] benchmark start, id=(.*)', line):
+ res = re.fullmatch(r'\[PTA\] (.*=.*)', line)
+ if re.fullmatch(r'\[PTA\] benchmark start, id=(.*)', line):
print('> got sync')
sync = True
elif not sync:
continue
- elif re.fullmatch('\[PTA\] trace, count=(.*)', line):
+ elif re.fullmatch(r'\[PTA\] trace, count=(.*)', line):
print('> got transition')
pass
elif res:
@@ -108,4 +119,4 @@ class OnboardTimerHarness(TransitionHarness):
ret += '{}\n'.format(transition_code)
ret += 'counter.stop();\n'
ret += 'ptalog.stopTransition(counter);\n'
- return ret
+ return ret \ No newline at end of file