summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniel Friesel <daniel.friesel@uos.de>2019-08-14 15:03:28 +0200
committerDaniel Friesel <daniel.friesel@uos.de>2019-08-14 15:03:28 +0200
commit830705b59483181eb5577173318c2df6255518af (patch)
treea20713527b61c213163ef3a325434a8d80b46f21 /lib
parent680e7498a128c752e6eb43156ee990807c042769 (diff)
add support for a posteriori parameters (e.g. TX success / retry count)
Diffstat (limited to 'lib')
-rwxr-xr-xlib/automata.py11
-rwxr-xr-xlib/dfatool.py13
-rw-r--r--lib/harness.py30
3 files changed, 45 insertions, 9 deletions
diff --git a/lib/automata.py b/lib/automata.py
index de40eb4..d26c0bc 100755
--- a/lib/automata.py
+++ b/lib/automata.py
@@ -185,6 +185,10 @@ class Transition:
self.set_param = set_param
self.return_value_handlers = return_value_handlers
+ for handler in self.return_value_handlers:
+ if 'formula' in handler:
+ handler['formula'] = NormalizationFunction(handler['formula'])
+
def get_duration(self, param_dict: dict = {}, args: list = []) -> float:
u"""
Return transition duration in µs.
@@ -310,6 +314,11 @@ class PTA:
if not 'UNINITIALIZED' in state_names:
self.state['UNINITIALIZED'] = State('UNINITIALIZED')
+ if self.parameter_normalization:
+ for normalization_spec in self.parameter_normalization.values():
+ if 'formula' in normalization_spec:
+ normalization_spec['formula'] = NormalizationFunction(normalization_spec['formula'])
+
def normalize_parameters(self, param_dict):
if self.parameter_normalization is None:
return param_dict.copy()
@@ -319,7 +328,7 @@ class PTA:
if 'enum' in self.parameter_normalization[parameter] and value in self.parameter_normalization[parameter]['enum']:
normalized_param[parameter] = self.parameter_normalization[parameter]['enum'][value]
if 'formula' in self.parameter_normalization[parameter]:
- normalization_formula = NormalizationFunction(self.parameter_normalization[parameter]['formula'])
+ normalization_formula = self.parameter_normalization[parameter]['formula']
normalized_param[parameter] = normalization_formula.eval(value)
return normalized_param
diff --git a/lib/dfatool.py b/lib/dfatool.py
index 1dc2291..e318e81 100755
--- a/lib/dfatool.py
+++ b/lib/dfatool.py
@@ -519,13 +519,18 @@ class TimingData:
trace['id'] = i
for log_entry in trace['trace']:
paramkeys = sorted(log_entry['parameter'].keys())
- paramvalues = [soft_cast_int(log_entry['parameter'][x]) for x in paramkeys]
- if arg_support_enabled and 'args' in log_entry:
- paramvalues.extend(map(soft_cast_int, log_entry['args']))
if not 'param' in log_entry['offline_aggregates']:
log_entry['offline_aggregates']['param'] = list()
if 'duration' in log_entry['offline_aggregates']:
for i in range(len(log_entry['offline_aggregates']['duration'])):
+ paramvalues = list()
+ for paramkey in paramkeys:
+ if type(log_entry['parameter'][paramkey]) is list:
+ paramvalues.append(soft_cast_int(log_entry['parameter'][paramkey][i]))
+ else:
+ paramvalues.append(soft_cast_int(log_entry['parameter'][paramkey]))
+ if arg_support_enabled and 'args' in log_entry:
+ paramvalues.extend(map(soft_cast_int, log_entry['args']))
log_entry['offline_aggregates']['param'].append(paramvalues)
def _preprocess_0(self):
@@ -537,7 +542,7 @@ class TimingData:
def get_preprocessed_data(self, verbose = True):
"""
- Return a list of DFA traces annotated with timing, and parameter data.
+ Return a list of DFA traces annotated with timing and parameter data.
Suitable for the PTAModel constructor.
See PTAModel(...) docstring for format details.
diff --git a/lib/harness.py b/lib/harness.py
index 8f48d00..cad7b06 100644
--- a/lib/harness.py
+++ b/lib/harness.py
@@ -135,6 +135,11 @@ class OnboardTimerHarness(TransitionHarness):
ret += 'ptalog.stopTransition(counter);\n'
return ret
+ def _append_nondeterministic_parameter_value(self, log_data_target, parameter_name, parameter_value):
+ if log_data_target['parameter'][parameter_name] is None:
+ log_data_target['parameter'][parameter_name] = list()
+ log_data_target['parameter'][parameter_name].append(parameter_value)
+
def parser_cb(self, line):
#print('[HARNESS] got line {}'.format(line))
if re.match(r'\[PTA\] benchmark start, id=(\S+)', line):
@@ -178,12 +183,29 @@ class OnboardTimerHarness(TransitionHarness):
if self.log_return_values and len(transition.return_value_handlers):
for handler in transition.return_value_handlers:
if 'parameter' in handler:
- print('got return value {:x} for transition {}, which has a handler. whoop whoop.'.format(int(res.group(4)), transition.name))
- # TODO handle value.
- #print('[HARNESS] Logging data for transition {}'.format(log_data_target['name']))
+ parameter_value = return_value = int(res.group(4))
+
+ if 'return_values' not in log_data_target:
+ log_data_target['return_values'] = list()
+ log_data_target['return_values'].append(return_value)
+
+ if 'formula' in handler:
+ parameter_value = handler['formula'].eval(return_value)
+
+ print('append current')
+ self._append_nondeterministic_parameter_value(log_data_target, handler['parameter'], parameter_value)
+ print('append following')
+ for following_log_data_target in self.traces[self.trace_id]['trace'][(self.current_transition_in_trace * 2 + 1) :]:
+ self._append_nondeterministic_parameter_value(following_log_data_target, handler['parameter'], parameter_value)
+ print('append preceding')
+ if 'apply_from' in handler and any(map(lambda x: x['name'] == handler['apply_from'], self.traces[self.trace_id]['trace'][: (self.current_transition_in_trace * 2 + 1)])):
+ for preceding_log_data_target in reversed(self.traces[self.trace_id]['trace'][: (self.current_transition_in_trace * 2)]):
+ self._append_nondeterministic_parameter_value(preceding_log_data_target, handler['parameter'], parameter_value)
+ if preceding_log_data_target['name'] == handler['apply_from']:
+ break
if 'offline_aggregates' not in log_data_target:
log_data_target['offline_aggregates'] = {
'duration' : list()
}
log_data_target['offline_aggregates']['duration'].append(duration_us)
- self.current_transition_in_trace += 1 \ No newline at end of file
+ self.current_transition_in_trace += 1