diff options
author | Jonathan Herman <hermanjl@cs.unc.edu> | 2012-10-12 01:56:20 -0400 |
---|---|---|
committer | Jonathan Herman <hermanjl@cs.unc.edu> | 2012-10-12 01:56:20 -0400 |
commit | d66aa52d719cf7edad8cac20b711e4c16d2899de (patch) | |
tree | 167415c66fa78c045fc0a793fe655ffba4b24cfa /run_exps.py | |
parent | 5d97a6baf6166b74355c6e744e010949a46fd625 (diff) |
Bug fixes from mixed-criticality experiments
Diffstat (limited to 'run_exps.py')
-rwxr-xr-x | run_exps.py | 49 |
1 files changed, 20 insertions, 29 deletions
diff --git a/run_exps.py b/run_exps.py index 8f72adb..19dbad1 100755 --- a/run_exps.py +++ b/run_exps.py | |||
@@ -1,14 +1,11 @@ | |||
1 | #!/usr/bin/env python | 1 | #!/usr/bin/env python |
2 | from __future__ import print_function | 2 | from __future__ import print_function |
3 | """ | ||
4 | TODO: no -f flag, instead allow individual schedules to be passed in. | ||
5 | -f flag now forced, which removes old data directories | ||
6 | """ | ||
7 | 3 | ||
8 | import config.config as conf | 4 | import config.config as conf |
9 | import experiment.litmus_util as lu | 5 | import experiment.litmus_util as lu |
10 | import os | 6 | import os |
11 | import re | 7 | import re |
8 | import shutil | ||
12 | import traceback | 9 | import traceback |
13 | 10 | ||
14 | from common import load_params | 11 | from common import load_params |
@@ -22,19 +19,21 @@ def InvalidKernel(Exception): | |||
22 | self.kernel = kernel | 19 | self.kernel = kernel |
23 | 20 | ||
24 | def parse_args(): | 21 | def parse_args(): |
25 | parser = OptionParser("usage: %prog [options] [sched_file]... [exp_dir]...]") | 22 | parser = OptionParser("usage: %prog [options] [sched_file]... [exp_dir]...") |
26 | 23 | ||
27 | parser.add_option('-s', '--scheduler', dest='scheduler', | 24 | parser.add_option('-s', '--scheduler', dest='scheduler', |
28 | help='scheduler for all experiments') | 25 | help='scheduler for all experiments') |
29 | parser.add_option('-d', '--duration', dest='duration', type='int', | 26 | parser.add_option('-d', '--duration', dest='duration', type='int', |
30 | help='duration (seconds) of tasks') | 27 | help='duration (seconds) of tasks') |
31 | parser.add_option('-o', '--out-dir', dest='out_dir', | 28 | parser.add_option('-o', '--out-dir', dest='out_dir', |
32 | help='directory for data output', default=os.getcwd()) | 29 | help='directory for data output', default="run-data") |
33 | parser.add_option('-p', '--params', dest='param_file', | 30 | parser.add_option('-p', '--params', dest='param_file', |
34 | help='file with experiment parameters') | 31 | help='file with experiment parameters') |
35 | parser.add_option('-f', '--schedule-file', dest='sched_file', | 32 | parser.add_option('-c', '--schedule-file', dest='sched_file', |
36 | help='name of schedule files', | 33 | help='name of schedule files within directories', |
37 | default=conf.DEFAULTS['sched_file']) | 34 | default=conf.DEFAULTS['sched_file']) |
35 | parser.add_option('-f', '--force', action='store_true', default=False, | ||
36 | dest='force', help='overwrite existing data') | ||
38 | 37 | ||
39 | return parser.parse_args() | 38 | return parser.parse_args() |
40 | 39 | ||
@@ -67,33 +66,21 @@ def convert_data(data): | |||
67 | 66 | ||
68 | return {'proc' : procs, 'spin' : spins} | 67 | return {'proc' : procs, 'spin' : spins} |
69 | 68 | ||
70 | def fix_paths(schedule, exp_dir): | 69 | def fix_paths(schedule, exp_dir, sched_file): |
71 | for (idx, (spin, args)) in enumerate(schedule['spin']): | 70 | for (idx, (spin, args)) in enumerate(schedule['spin']): |
72 | # Replace relative paths (if present) with absolute ones | 71 | # Replace relative paths (if present) with absolute ones |
73 | for arg in args.split(" "): | 72 | for arg in re.split(" +", args): |
74 | abspath = "%s/%s" % (exp_dir, arg) | 73 | abspath = "%s/%s" % (exp_dir, arg) |
75 | if os.path.exists(abspath): | 74 | if os.path.exists(abspath): |
76 | args = args.replace(arg, abspath) | 75 | args = args.replace(arg, abspath) |
77 | break | 76 | break |
77 | elif re.match(r'.*\w+\.\w+', arg): | ||
78 | print("WARNING: non-existent file '%s' may be referenced:\n\t%s" | ||
79 | % (arg, sched_file)) | ||
78 | 80 | ||
79 | schedule['spin'][idx] = (spin, args) | 81 | schedule['spin'][idx] = (spin, args) |
80 | 82 | ||
81 | def get_dirs(sched_file, out_base_dir): | 83 | def load_experiment(sched_file, scheduler, duration, param_file, out_dir): |
82 | sched_leaf_dir = re.findall(r".*/([\w_-]+)/.*?$", sched_file)[0] | ||
83 | sched_full_dir = os.path.split(sched_file)[0] | ||
84 | |||
85 | work_dir = "%s/tmp" % sched_full_dir | ||
86 | |||
87 | if sched_full_dir == out_base_dir: | ||
88 | out_dir = "%s/data" % sched_full_dir | ||
89 | else: | ||
90 | # Put it under the base output dir with the same directory name | ||
91 | out_dir = "%s/%s" % (out_base_dir, sched_leaf_dir) | ||
92 | |||
93 | return (work_dir, out_dir) | ||
94 | |||
95 | |||
96 | def load_experiment(sched_file, scheduler, duration, param_file, out_base): | ||
97 | if not os.path.isfile(sched_file): | 84 | if not os.path.isfile(sched_file): |
98 | raise IOError("Cannot find schedule file: %s" % sched_file) | 85 | raise IOError("Cannot find schedule file: %s" % sched_file) |
99 | 86 | ||
@@ -121,8 +108,8 @@ def load_experiment(sched_file, scheduler, duration, param_file, out_base): | |||
121 | 108 | ||
122 | # Parse schedule file's intentions | 109 | # Parse schedule file's intentions |
123 | schedule = load_schedule(sched_file) | 110 | schedule = load_schedule(sched_file) |
124 | (work_dir, out_dir) = get_dirs(sched_file, out_base) | 111 | work_dir = "%s/tmp" % dirname |
125 | fix_paths(schedule, os.path.split(sched_file)[0]) | 112 | fix_paths(schedule, os.path.split(sched_file)[0], sched_file) |
126 | 113 | ||
127 | run_exp(sched_file, schedule, scheduler, kernel, duration, work_dir, out_dir) | 114 | run_exp(sched_file, schedule, scheduler, kernel, duration, work_dir, out_dir) |
128 | 115 | ||
@@ -209,15 +196,19 @@ def main(): | |||
209 | 196 | ||
210 | for exp in args: | 197 | for exp in args: |
211 | path = "%s/%s" % (os.getcwd(), exp) | 198 | path = "%s/%s" % (os.getcwd(), exp) |
199 | out_dir = "%s/%s" % (out_base, exp) | ||
212 | 200 | ||
213 | if not os.path.exists(path): | 201 | if not os.path.exists(path): |
214 | raise IOError("Invalid experiment: %s" % path) | 202 | raise IOError("Invalid experiment: %s" % path) |
215 | 203 | ||
204 | if opts.force and os.path.exists(out_dir): | ||
205 | shutil.rmtree(out_dir) | ||
206 | |||
216 | if os.path.isdir(exp): | 207 | if os.path.isdir(exp): |
217 | path = "%s/%s" % (path, opts.sched_file) | 208 | path = "%s/%s" % (path, opts.sched_file) |
218 | 209 | ||
219 | try: | 210 | try: |
220 | load_experiment(path, scheduler, duration, param_file, out_base) | 211 | load_experiment(path, scheduler, duration, param_file, out_dir) |
221 | succ += 1 | 212 | succ += 1 |
222 | except ExperimentDone: | 213 | except ExperimentDone: |
223 | done += 1 | 214 | done += 1 |