aboutsummaryrefslogtreecommitdiff
path: root/tools/scriptgenerator.py
diff options
context:
space:
mode:
authorMarco Capitani <[email protected]>2018-02-22 10:18:10 +0100
committerMarco Capitani <[email protected]>2018-03-16 14:07:24 +0100
commite174aaf3650c23331c757921b1af9b152f53c6e5 (patch)
tree281a859419b20e34605e310c9572668d6f545734 /tools/scriptgenerator.py
parentade6bd4cda44c88b555f521641c6e01326ab0060 (diff)
downloadrumba-e174aaf3650c23331c757921b1af9b152f53c6e5.tar.gz
rumba-e174aaf3650c23331c757921b1af9b152f53c6e5.zip
storyboard: add replayability
implements #27
Diffstat (limited to 'tools/scriptgenerator.py')
-rw-r--r--tools/scriptgenerator.py88
1 files changed, 88 insertions, 0 deletions
diff --git a/tools/scriptgenerator.py b/tools/scriptgenerator.py
new file mode 100644
index 0000000..059163e
--- /dev/null
+++ b/tools/scriptgenerator.py
@@ -0,0 +1,88 @@
+import argparse
+import importlib.machinery as mach
+
+from rumba.storyboard import *
+import rumba.log as log
+from rumba.utils import ExperimentManager, PAUSE_SWAPOUT
+
+client1 = Client(
+ "rinaperf",
+ options="-t perf -s 1000 -c 0",
+ c_id='rinaperf_^C' # To differentiate
+)
+
+
+client2 = Client(
+ "rinaperf",
+ options="-t perf -s 1000 -D <duration>",
+ shutdown="",
+ c_id='rinaperf_-D' # To differentiate
+)
+
+
+server = Server(
+ "rinaperf",
+ options="-l",
+ arrival_rate=0.5,
+ mean_duration=5,
+ clients=[client1, client2]
+)
+
+
+def main(duration, exp, run=False, script='generated_script.txt'):
+ story = StoryBoard(duration)
+ story.set_experiment(exp)
+ story.add_server_on_node(server, exp.nodes[0])
+ client1.add_node(exp.nodes[1])
+ if len(exp.nodes) == 2:
+ third_n = exp.nodes[1]
+ else:
+ third_n = exp.nodes[2]
+ client2.add_node(third_n)
+ story.generate_script()
+
+ with open(script, 'w') as f:
+ f.write('################################################\n')
+ f.write('# SCRIPT GENERATED WITH RUMBA SCRIPT GENERATOR #\n')
+ f.write('################################################\n')
+ story.script.write(f)
+
+ if run:
+ with ExperimentManager(exp, swap_out_strategy=PAUSE_SWAPOUT):
+ exp.swap_in()
+ exp.bootstrap_prototype()
+ story.start()
+
+
+if __name__ == '__main__':
+
+ description = "Storyboard generator for Rumba scripts"
+ epilog = "2018 Marco Capitani <[email protected]>"
+
+ parser = argparse.ArgumentParser(description=description,
+ epilog=epilog)
+ parser.add_argument('exp', metavar='EXPERIMENT', type=str,
+ help='The experiment file.')
+ parser.add_argument('-O', '--object', metavar='OBJECT', type=str,
+ default='exp',
+ help='The Python variable name of '
+ 'the experiment object defined in the file')
+ parser.add_argument('d', metavar='DURATION', type=float,
+ help='The required duration of the storyboard')
+ parser.add_argument('-R', '--run', action='store_true',
+ help='Run the storyboard after script generation.')
+ parser.add_argument('-S', '--script', type=str,
+ default='generated_script.txt',
+ help='Name of the output script.')
+
+ args = parser.parse_args()
+
+ try:
+ exp_module = mach.SourceFileLoader('exp', args.exp).load_module()
+ experiment = getattr(exp_module, args.object)
+ main(args.d, experiment, args.run, args.script)
+ except AttributeError:
+ logger.error('Module %s has no attribute %s', args.exp, args.object)
+ except Exception as e:
+ logger.error('Could not load file %s. %s.', args.exp, str(e))
+ log.flush_log()