diff options
author | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-04-10 14:35:37 -0400 |
---|---|---|
committer | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-04-10 14:35:37 -0400 |
commit | 4162cc0c57de22566efa6e2dab224909279f2a47 (patch) | |
tree | a8628096c4161e658c385b07b026371a2ef5e3c4 /run_exps.py | |
parent | 37a410ab7d4ba991a075a3b2f4d24a656f4544ca (diff) |
run_exps will run any command whose last argument is the duration.
Diffstat (limited to 'run_exps.py')
-rwxr-xr-x | run_exps.py | 71 |
1 files changed, 30 insertions, 41 deletions
diff --git a/run_exps.py b/run_exps.py index 6043931..77c9631 100755 --- a/run_exps.py +++ b/run_exps.py | |||
@@ -79,13 +79,13 @@ def convert_data(data): | |||
79 | r"(?P<HEADER>/proc/[\w\-]+?/)?" | 79 | r"(?P<HEADER>/proc/[\w\-]+?/)?" |
80 | r"(?P<ENTRY>[\w\-\/]+)" | 80 | r"(?P<ENTRY>[\w\-\/]+)" |
81 | r"\s*{\s*(?P<CONTENT>.*?)\s*?}$)|" | 81 | r"\s*{\s*(?P<CONTENT>.*?)\s*?}$)|" |
82 | r"(?P<SPIN>^" | 82 | r"(?P<TASK>^" |
83 | r"(?:(?P<TYPE>[^\d\-\s]\w*?) )?\s*" | 83 | r"(?:(?P<PROG>[^\d\-\s][\w\.]*?) )?\s*" |
84 | r"(?P<ARGS>[\w\-_\d\. \=]+)\s*$)", | 84 | r"(?P<ARGS>[\w\-_\d\. \=]+)\s*$)", |
85 | re.S|re.I|re.M) | 85 | re.S|re.I|re.M) |
86 | 86 | ||
87 | procs = [] | 87 | procs = [] |
88 | spins = [] | 88 | tasks = [] |
89 | 89 | ||
90 | for match in regex.finditer(data): | 90 | for match in regex.finditer(data): |
91 | if match.group("PROC"): | 91 | if match.group("PROC"): |
@@ -94,16 +94,16 @@ def convert_data(data): | |||
94 | proc = (loc, match.group("CONTENT")) | 94 | proc = (loc, match.group("CONTENT")) |
95 | procs.append(proc) | 95 | procs.append(proc) |
96 | else: | 96 | else: |
97 | prog = match.group("TYPE") or "rtspin" | 97 | prog = match.group("PROG") or conf.DEFAULTS['prog'] |
98 | spin = (prog, match.group("ARGS")) | 98 | spin = (prog, match.group("ARGS")) |
99 | spins.append(spin) | 99 | tasks.append(spin) |
100 | 100 | ||
101 | return {'proc' : procs, 'spin' : spins} | 101 | return {'proc' : procs, 'task' : tasks} |
102 | 102 | ||
103 | 103 | ||
104 | def fix_paths(schedule, exp_dir, sched_file): | 104 | def fix_paths(schedule, exp_dir, sched_file): |
105 | '''Replace relative paths of command line arguments with absolute ones.''' | 105 | '''Replace relative paths of command line arguments with absolute ones.''' |
106 | for (idx, (spin, args)) in enumerate(schedule['spin']): | 106 | for (idx, (task, args)) in enumerate(schedule['task']): |
107 | for arg in re.split(" +", args): | 107 | for arg in re.split(" +", args): |
108 | abspath = "%s/%s" % (exp_dir, arg) | 108 | abspath = "%s/%s" % (exp_dir, arg) |
109 | if os.path.exists(abspath): | 109 | if os.path.exists(abspath): |
@@ -113,7 +113,7 @@ def fix_paths(schedule, exp_dir, sched_file): | |||
113 | print("WARNING: non-existent file '%s' may be referenced:\n\t%s" | 113 | print("WARNING: non-existent file '%s' may be referenced:\n\t%s" |
114 | % (arg, sched_file)) | 114 | % (arg, sched_file)) |
115 | 115 | ||
116 | schedule['spin'][idx] = (spin, args) | 116 | schedule['task'][idx] = (task, args) |
117 | 117 | ||
118 | 118 | ||
119 | def load_schedule(name, fname, duration): | 119 | def load_schedule(name, fname, duration): |
@@ -126,48 +126,43 @@ def load_schedule(name, fname, duration): | |||
126 | except: | 126 | except: |
127 | schedule = convert_data(data) | 127 | schedule = convert_data(data) |
128 | 128 | ||
129 | sched_dir = os.path.split(fname)[0] | ||
130 | |||
129 | # Make paths relative to the file's directory | 131 | # Make paths relative to the file's directory |
130 | fix_paths(schedule, os.path.split(fname)[0], fname) | 132 | fix_paths(schedule, sched_dir, fname) |
131 | 133 | ||
132 | proc_entries = [] | 134 | proc_entries = [] |
133 | executables = [] | 135 | executables = [] |
134 | 136 | ||
135 | # Create proc entries | 137 | # Create proc entries |
136 | for entry_conf in schedule['proc']: | 138 | for entry_conf in schedule['proc']: |
137 | path = entry_conf[0] | 139 | proc_entries += [ProcEntry(*entry_conf)] |
138 | data = entry_conf[1] | ||
139 | 140 | ||
140 | if not os.path.exists(path): | 141 | # Create executables |
141 | raise IOError("Invalid proc path %s: %s" % (path, name)) | 142 | for task_conf in schedule['task']: |
143 | if len(task_conf) != 2: | ||
144 | raise Exception("Invalid task conf %s: %s" % (task_conf, name)) | ||
142 | 145 | ||
143 | proc_entries += [ProcEntry(path, data)] | 146 | (task, args) = (task_conf[0], task_conf[1]) |
144 | 147 | ||
145 | # Create executables | 148 | real_task = com.get_executable(task, sched_dir) |
146 | for spin_conf in schedule['spin']: | ||
147 | if isinstance(spin_conf, str): | ||
148 | # Just a string defaults to default spin | ||
149 | (spin, args) = (conf.DEFAULTS['spin'], spin_conf) | ||
150 | else: | ||
151 | # Otherwise its a pair, the type and the args | ||
152 | if len(spin_conf) != 2: | ||
153 | raise IOError("Invalid spin conf %s: %s" % (spin_conf, name)) | ||
154 | (spin, args) = (spin_conf[0], spin_conf[1]) | ||
155 | 149 | ||
156 | real_spin = com.get_executable(spin, "") | 150 | # Last argument must always be duration |
157 | real_args = args.split() | 151 | real_args = args.split() + [duration] |
158 | if re.match(".*spin", real_spin): | ||
159 | real_args = ['-w'] + real_args + [duration] | ||
160 | 152 | ||
161 | if not com.is_executable(real_spin): | 153 | # All spins take a -w flag |
162 | raise OSError("Cannot run spin %s: %s" % (real_spin, name)) | 154 | if re.match(".*spin$", real_task) and '-w' not in real_args: |
155 | real_args = ['-w'] + real_args | ||
163 | 156 | ||
164 | executables += [Executable(real_spin, real_args)] | 157 | executables += [Executable(real_task, real_args)] |
165 | 158 | ||
166 | return proc_entries, executables | 159 | return proc_entries, executables |
167 | 160 | ||
168 | 161 | ||
169 | def verify_environment(exp_params): | 162 | def verify_environment(exp_params): |
170 | if exp_params.kernel and not com.uname_matches(exp_params.kernel): | 163 | '''Raise an exception if the current system doesn't match that required |
164 | by @exp_params.''' | ||
165 | if exp_params.kernel and not re.match(exp_params.kernel, com.kernel()): | ||
171 | raise InvalidKernel(exp_params.kernel) | 166 | raise InvalidKernel(exp_params.kernel) |
172 | 167 | ||
173 | if exp_params.config_options: | 168 | if exp_params.config_options: |
@@ -197,15 +192,7 @@ def run_parameter(exp_dir, out_dir, params, param_name): | |||
197 | script_params = [script_params] | 192 | script_params = [script_params] |
198 | script_name = script_params.pop(0) | 193 | script_name = script_params.pop(0) |
199 | 194 | ||
200 | cwd_name = "%s/%s" % (exp_dir, script_name) | 195 | script = com.get_executable(script_name, cwd=exp_dir) |
201 | if os.path.isfile(cwd_name): | ||
202 | script = cwd_name | ||
203 | else: | ||
204 | script = com.get_executable(script_name, optional=True) | ||
205 | |||
206 | if not script: | ||
207 | raise Exception("Cannot find executable %s-script: %s" % | ||
208 | (param_name, script_name)) | ||
209 | 196 | ||
210 | out = open('%s/%s-out.txt' % (out_dir, param_name), 'w') | 197 | out = open('%s/%s-out.txt' % (out_dir, param_name), 'w') |
211 | prog = Executable(script, script_params, | 198 | prog = Executable(script, script_params, |
@@ -219,6 +206,7 @@ def run_parameter(exp_dir, out_dir, params, param_name): | |||
219 | 206 | ||
220 | 207 | ||
221 | def get_exp_params(cmd_scheduler, cmd_duration, file_params): | 208 | def get_exp_params(cmd_scheduler, cmd_duration, file_params): |
209 | '''Return ExpParam with configured values of all hardcoded params.''' | ||
222 | kernel = copts = "" | 210 | kernel = copts = "" |
223 | 211 | ||
224 | scheduler = cmd_scheduler or file_params[conf.PARAMS['sched']] | 212 | scheduler = cmd_scheduler or file_params[conf.PARAMS['sched']] |
@@ -267,6 +255,7 @@ def load_experiment(sched_file, cmd_scheduler, cmd_duration, | |||
267 | else: | 255 | else: |
268 | file_params = {} | 256 | file_params = {} |
269 | 257 | ||
258 | # Create input needed by Experiment | ||
270 | exp_params = get_exp_params(cmd_scheduler, cmd_duration, file_params) | 259 | exp_params = get_exp_params(cmd_scheduler, cmd_duration, file_params) |
271 | procs, execs = load_schedule(exp_name, sched_file, exp_params.duration) | 260 | procs, execs = load_schedule(exp_name, sched_file, exp_params.duration) |
272 | 261 | ||