1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
"""
Harnesses for various types of benchmark logs.
tbd
"""
import subprocess
import re
# 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:
def __init__(self, gpio_pin = None):
self.gpio_pin = gpio_pin
self.traces = []
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:
ret += '#define PTALOG_GPIO {}\n'.format(self.gpio_pin)
ret += '#include "object/ptalog.h"\n'
if self.gpio_pin != None:
ret += 'PTALog ptalog({});\n'.format(self.gpio_pin)
else:
ret += 'PTALog ptalog;\n'
return ret
def start_benchmark(self):
return 'ptalog.startBenchmark(0);\n'
def start_trace(self):
self.traces.append({
'id' : self.trace_id,
'trace' : list(),
})
self.trace_id += 1
def append_state(self, state_name, param):
self.traces[-1]['trace'].append({
'name': state_name,
'isa': 'state',
'parameter': 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):
return 'ptalog.reset();\n'
def pass_transition(self, transition_id, transition_code, transition: object = None, parameter: dict = dict()):
ret = 'ptalog.passTransition({:d});\n'.format(transition_id)
ret += 'ptalog.startTransition();\n'
ret += '{}\n'.format(transition_code)
ret += 'ptalog.stopTransition();\n'
return ret
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(r'\[PTA\] (.*=.*)', line)
if re.fullmatch(r'\[PTA\] benchmark start, id=(.*)', line):
print('> got sync')
sync = True
elif not sync:
continue
elif re.fullmatch(r'\[PTA\] trace, count=(.*)', line):
print('> got transition')
pass
elif res:
print(dict(map(lambda x: x.split('='), res.group(1).split())))
pass
class OnboardTimerHarness(TransitionHarness):
def __init__(self, gpio_pin = None):
super().__init__(gpio_pin = gpio_pin)
def global_code(self):
ret = '#include "driver/counter.h"\n'
ret += '#define PTALOG_TIMING\n'
ret += super().global_code()
return ret
def start_benchmark(self):
ret = 'counter.start();\n'
ret += 'counter.stop();\n'
ret += 'ptalog.passNop(counter);\n'
ret += super().start_benchmark()
return ret
def pass_transition(self, transition_id, transition_code, transition: object = None, parameter: dict = dict()):
ret = 'ptalog.passTransition({:d});\n'.format(transition_id)
ret += 'ptalog.startTransition();\n'
ret += 'counter.start();\n'
ret += '{}\n'.format(transition_code)
ret += 'counter.stop();\n'
ret += 'ptalog.stopTransition(counter);\n'
return ret
|