summaryrefslogtreecommitdiff
path: root/bin/workload.py
diff options
context:
space:
mode:
authorDaniel Friesel <daniel.friesel@uos.de>2019-12-11 11:23:59 +0100
committerDaniel Friesel <daniel.friesel@uos.de>2019-12-11 11:23:59 +0100
commit2f134105ee9ae414ac99bc69365658da7d4d8643 (patch)
tree4c63807cf0e42bf7858a024718adff56fd9065e3 /bin/workload.py
parent3642def010396d46757fb2bc19445c45f9db1c55 (diff)
add basic workload energy/power/duration simulation tool
Diffstat (limited to 'bin/workload.py')
-rwxr-xr-xbin/workload.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/bin/workload.py b/bin/workload.py
new file mode 100755
index 0000000..ef89b0d
--- /dev/null
+++ b/bin/workload.py
@@ -0,0 +1,33 @@
+#!/usr/bin/env python3
+
+from automata import PTA
+import re
+import sys
+from utils import soft_cast_int, human_readable
+
+ptafile, raw_word = sys.argv[1:]
+
+pta = PTA.from_file(ptafile)
+
+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'))
+print('Energy: ' + human_readable(result.energy, 'J'))
+print('Mean Power: ' + human_readable(result.mean_power, 'W'))