summaryrefslogtreecommitdiff
path: root/bin/workload.py
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2019-12-13 14:19:16 +0100
committerDaniel Friesel <derf@finalrewind.org>2019-12-13 14:19:16 +0100
commit6dea5e30f9023b7748d9249f80aaeeded6011bc1 (patch)
tree1e4c41363c150b2862274493a952816bba3db9d9 /bin/workload.py
parentde382bd34807a32af948a017164f0fb91cb2e6cb (diff)
Add Parser and Lexer for timed sequences (words with loops); use them in workload
Diffstat (limited to 'bin/workload.py')
-rwxr-xr-xbin/workload.py62
1 files changed, 34 insertions, 28 deletions
diff --git a/bin/workload.py b/bin/workload.py
index e294b95..d2e5b34 100755
--- a/bin/workload.py
+++ b/bin/workload.py
@@ -1,37 +1,43 @@
#!/usr/bin/env python3
from automata import PTA
-import re
import sys
-from utils import soft_cast_int, human_readable
+from utils import human_readable
+from lex import TimedSequence, TimedWord, Workload
ptafile, raw_word = sys.argv[1:]
+# TODO loops im raw_word:
+# init(); repeat { foo(); sleep(5m); bar(); ... } o.ä.
+# - Zeitangaben mit Einheit in sleep
+# - Ausgabe in Gesamt, Init und Schleifeninhalt aufdröseln
+
pta = PTA.from_file(ptafile)
+timedword = TimedSequence(raw_word)
+
+print('Input: {}\n'.format(timedword))
+
+prev_state = 'UNINITIALIZED'
+prev_param = None
+for trace_part in timedword:
+ print('Trace Part {}'.format(trace_part))
+ if type(trace_part) is TimedWord:
+ result = pta.simulate(trace_part, orig_state=prev_state)
+ elif type(trace_part) is Workload:
+ result = pta.simulate(trace_part.word, orig_state=prev_state)
+ if prev_state != result.end_state:
+ print('Warning: loop starts in state {}, but terminates in {}'.format(prev_state, result.end_state.name))
+ if prev_param != result.parameters:
+ print('Warning: loop starts with parameters {}, but terminates with {}'.format(prev_param, result.parameters))
+
+ print(' Duration: ' + human_readable(result.duration, 's'))
+ if result.duration_mae:
+ print(u' ± {} / {:.0f}%'.format(human_readable(result.duration_mae, 's'), result.duration_mape))
+ print(' Energy: ' + human_readable(result.energy, 'J'))
+ if result.energy_mae:
+ print(u' ± {} / {:.0f}%'.format(human_readable(result.energy_mae, 'J'), result.energy_mape))
+ print(' Mean Power: ' + human_readable(result.mean_power, 'W'))
+ print('')
-trace = list()
-for raw_symbol in raw_word.split(';'):
- match = re.fullmatch(r' *([^(]+)\((.*)\) *', raw_symbol)
- if match:
- function_name = match.group(1).strip()
- if match.group(2) == '':
- raw_args = list()
- else:
- raw_args = match.group(2).split(',')
- if function_name == 'sleep':
- function_name = None
- word = [function_name]
- for raw_arg in raw_args:
- word.append(soft_cast_int(raw_arg.strip()))
- trace.append(word)
-
-print(trace)
-result = pta.simulate(trace)
-
-print('Duration: ' + human_readable(result.duration, 's'))
-if result.duration_mae:
- print(u' ± {} / {:.0f}%'.format(human_readable(result.duration_mae, 's'), result.duration_mape))
-print('Energy: ' + human_readable(result.energy, 'J'))
-if result.energy_mae:
- print(u' ± {} / {:.0f}%'.format(human_readable(result.energy_mae, 'J'), result.energy_mape))
-print('Mean Power: ' + human_readable(result.mean_power, 'W'))
+ prev_state = result.end_state
+ prev_param = result.parameters