diff options
author | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-04-21 13:28:38 -0400 |
---|---|---|
committer | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-04-21 13:28:38 -0400 |
commit | fbd1df6f63eb551b99f71330d2370c570ff323f5 (patch) | |
tree | ca0db4599365bf8f4de7cd247c6363ef0ffba288 /run_exps.py | |
parent | daa0e3a92e03a89baf7ea3750df374df79123245 (diff) |
Scripts read directories created by other scripts if no arguments.
With no arguments, all scripts first try to load the current directory. If the
current directory has no data, the scripts search for the output of the previous
scripts in the toolchain, e.g. parse_exps.py loads run-data/*, created by
run_exps.py.
This commit also switched messages to stderr where they belong, and adds in
missing lock and unlock overheads.
Diffstat (limited to 'run_exps.py')
-rwxr-xr-x | run_exps.py | 73 |
1 files changed, 49 insertions, 24 deletions
diff --git a/run_exps.py b/run_exps.py index 905d033..d7a06b5 100755 --- a/run_exps.py +++ b/run_exps.py | |||
@@ -2,13 +2,13 @@ | |||
2 | from __future__ import print_function | 2 | from __future__ import print_function |
3 | 3 | ||
4 | import common as com | 4 | import common as com |
5 | import config.config as conf | ||
6 | import os | 5 | import os |
7 | import re | 6 | import re |
8 | import shutil | 7 | import shutil |
9 | import sys | 8 | import sys |
10 | import run.tracer as trace | 9 | import run.tracer as trace |
11 | 10 | ||
11 | from config.config import PARAMS,DEFAULTS | ||
12 | from collections import namedtuple | 12 | from collections import namedtuple |
13 | from optparse import OptionParser | 13 | from optparse import OptionParser |
14 | from run.executable.executable import Executable | 14 | from run.executable.executable import Executable |
@@ -56,12 +56,13 @@ def parse_args(): | |||
56 | parser.add_option('-d', '--duration', dest='duration', type='int', | 56 | parser.add_option('-d', '--duration', dest='duration', type='int', |
57 | help='duration (seconds) of tasks') | 57 | help='duration (seconds) of tasks') |
58 | parser.add_option('-o', '--out-dir', dest='out_dir', | 58 | parser.add_option('-o', '--out-dir', dest='out_dir', |
59 | help='directory for data output', default=("%s/run-data"%os.getcwd())) | 59 | help='directory for data output', |
60 | default=DEFAULTS['out-run']) | ||
60 | parser.add_option('-p', '--params', dest='param_file', | 61 | parser.add_option('-p', '--params', dest='param_file', |
61 | help='file with experiment parameters') | 62 | help='file with experiment parameters') |
62 | parser.add_option('-c', '--schedule-file', dest='sched_file', | 63 | parser.add_option('-c', '--schedule-file', dest='sched_file', |
63 | help='name of schedule files within directories', | 64 | help='name of schedule files within directories', |
64 | default=conf.DEFAULTS['sched_file']) | 65 | default=DEFAULTS['sched_file']) |
65 | parser.add_option('-f', '--force', action='store_true', default=False, | 66 | parser.add_option('-f', '--force', action='store_true', default=False, |
66 | dest='force', help='overwrite existing data') | 67 | dest='force', help='overwrite existing data') |
67 | parser.add_option('-j', '--jabber', metavar='username@domain', | 68 | parser.add_option('-j', '--jabber', metavar='username@domain', |
@@ -96,7 +97,7 @@ def convert_data(data): | |||
96 | proc = (loc, match.group("CONTENT")) | 97 | proc = (loc, match.group("CONTENT")) |
97 | procs.append(proc) | 98 | procs.append(proc) |
98 | else: | 99 | else: |
99 | prog = match.group("PROG") or conf.DEFAULTS['prog'] | 100 | prog = match.group("PROG") or DEFAULTS['prog'] |
100 | spin = (prog, match.group("ARGS")) | 101 | spin = (prog, match.group("ARGS")) |
101 | tasks.append(spin) | 102 | tasks.append(spin) |
102 | 103 | ||
@@ -184,10 +185,10 @@ def verify_environment(exp_params): | |||
184 | def run_parameter(exp_dir, out_dir, params, param_name): | 185 | def run_parameter(exp_dir, out_dir, params, param_name): |
185 | '''Run an executable (arguments optional) specified as a configurable | 186 | '''Run an executable (arguments optional) specified as a configurable |
186 | @param_name in @params.''' | 187 | @param_name in @params.''' |
187 | if conf.PARAMS[param_name] not in params: | 188 | if PARAMS[param_name] not in params: |
188 | return | 189 | return |
189 | 190 | ||
190 | script_params = params[conf.PARAMS[param_name]] | 191 | script_params = params[PARAMS[param_name]] |
191 | 192 | ||
192 | # Split into arguments and program name | 193 | # Split into arguments and program name |
193 | if type(script_params) != type([]): | 194 | if type(script_params) != type([]): |
@@ -210,22 +211,22 @@ def get_exp_params(cmd_scheduler, cmd_duration, file_params): | |||
210 | '''Return ExpParam with configured values of all hardcoded params.''' | 211 | '''Return ExpParam with configured values of all hardcoded params.''' |
211 | kernel = copts = "" | 212 | kernel = copts = "" |
212 | 213 | ||
213 | scheduler = cmd_scheduler or file_params[conf.PARAMS['sched']] | 214 | scheduler = cmd_scheduler or file_params[PARAMS['sched']] |
214 | duration = cmd_duration or file_params[conf.PARAMS['dur']] or\ | 215 | duration = cmd_duration or file_params[PARAMS['dur']] or\ |
215 | conf.DEFAULTS['duration'] | 216 | DEFAULTS['duration'] |
216 | 217 | ||
217 | # Experiments can specify required kernel name | 218 | # Experiments can specify required kernel name |
218 | if conf.PARAMS['kernel'] in file_params: | 219 | if PARAMS['kernel'] in file_params: |
219 | kernel = file_params[conf.PARAMS['kernel']] | 220 | kernel = file_params[PARAMS['kernel']] |
220 | 221 | ||
221 | # Or required config options | 222 | # Or required config options |
222 | if conf.PARAMS['copts'] in file_params: | 223 | if PARAMS['copts'] in file_params: |
223 | copts = file_params[conf.PARAMS['copts']] | 224 | copts = file_params[PARAMS['copts']] |
224 | 225 | ||
225 | # Or required tracers | 226 | # Or required tracers |
226 | requested = [] | 227 | requested = [] |
227 | if conf.PARAMS['trace'] in file_params: | 228 | if PARAMS['trace'] in file_params: |
228 | requested = file_params[conf.PARAMS['trace']] | 229 | requested = file_params[PARAMS['trace']] |
229 | tracers = trace.get_tracer_types(requested) | 230 | tracers = trace.get_tracer_types(requested) |
230 | 231 | ||
231 | # But only these two are mandatory | 232 | # But only these two are mandatory |
@@ -250,7 +251,7 @@ def load_experiment(sched_file, cmd_scheduler, cmd_duration, | |||
250 | 251 | ||
251 | # Load parameter file | 252 | # Load parameter file |
252 | param_file = param_file or \ | 253 | param_file = param_file or \ |
253 | "%s/%s" % (dir_name, conf.DEFAULTS['params_file']) | 254 | "%s/%s" % (dir_name, DEFAULTS['params_file']) |
254 | if os.path.isfile(param_file): | 255 | if os.path.isfile(param_file): |
255 | file_params = com.load_params(param_file) | 256 | file_params = com.load_params(param_file) |
256 | else: | 257 | else: |
@@ -277,19 +278,36 @@ def load_experiment(sched_file, cmd_scheduler, cmd_duration, | |||
277 | 278 | ||
278 | # Save parameters used to run experiment in out_dir | 279 | # Save parameters used to run experiment in out_dir |
279 | out_params = dict(file_params.items() + | 280 | out_params = dict(file_params.items() + |
280 | [(conf.PARAMS['sched'], exp_params.scheduler), | 281 | [(PARAMS['sched'], exp_params.scheduler), |
281 | (conf.PARAMS['tasks'], len(execs)), | 282 | (PARAMS['tasks'], len(execs)), |
282 | (conf.PARAMS['dur'], exp_params.duration)]) | 283 | (PARAMS['dur'], exp_params.duration)]) |
283 | 284 | ||
284 | # Feather-trace clock frequency saved for accurate overhead parsing | 285 | # Feather-trace clock frequency saved for accurate overhead parsing |
285 | ft_freq = com.ft_freq() | 286 | ft_freq = com.ft_freq() |
286 | if ft_freq: | 287 | if ft_freq: |
287 | out_params[conf.PARAMS['cycles']] = ft_freq | 288 | out_params[PARAMS['cycles']] = ft_freq |
288 | 289 | ||
289 | with open("%s/%s" % (out_dir, conf.DEFAULTS['params_file']), 'w') as f: | 290 | with open("%s/%s" % (out_dir, DEFAULTS['params_file']), 'w') as f: |
290 | f.write(str(out_params)) | 291 | f.write(str(out_params)) |
291 | 292 | ||
292 | 293 | ||
294 | def get_exps(opts, args): | ||
295 | if args: | ||
296 | return args | ||
297 | |||
298 | # Default to sched_file > generated dirs | ||
299 | if os.path.exists(opts.sched_file): | ||
300 | sys.stderr.write("Reading schedule from %s.\n" % opts.sched_file) | ||
301 | return [opts.sched_file] | ||
302 | elif os.path.exists(DEFAULTS['out-gen']): | ||
303 | sys.stderr.write("Reading schedules from %s/*.\n" % DEFAULTS['out-gen']) | ||
304 | sched_dirs = os.listdir(DEFAULTS['out-gen']) | ||
305 | return ['%s/%s' % (DEFAULTS['out-gen'], d) for d in sched_dirs] | ||
306 | else: | ||
307 | sys.stderr.write("Run with -h to view options.\n"); | ||
308 | sys.exit(1) | ||
309 | |||
310 | |||
293 | def setup_jabber(target): | 311 | def setup_jabber(target): |
294 | try: | 312 | try: |
295 | from run.jabber import Jabber | 313 | from run.jabber import Jabber |
@@ -300,6 +318,7 @@ def setup_jabber(target): | |||
300 | "Disabling instant messages.\n") | 318 | "Disabling instant messages.\n") |
301 | return None | 319 | return None |
302 | 320 | ||
321 | |||
303 | def setup_email(target): | 322 | def setup_email(target): |
304 | try: | 323 | try: |
305 | from run.emailer import Emailer | 324 | from run.emailer import Emailer |
@@ -313,6 +332,7 @@ def setup_email(target): | |||
313 | sys.stderr.write(message + " Disabling email message.\n") | 332 | sys.stderr.write(message + " Disabling email message.\n") |
314 | return None | 333 | return None |
315 | 334 | ||
335 | |||
316 | def main(): | 336 | def main(): |
317 | opts, args = parse_args() | 337 | opts, args = parse_args() |
318 | 338 | ||
@@ -321,7 +341,7 @@ def main(): | |||
321 | param_file = opts.param_file | 341 | param_file = opts.param_file |
322 | out_base = os.path.abspath(opts.out_dir) | 342 | out_base = os.path.abspath(opts.out_dir) |
323 | 343 | ||
324 | args = args or [opts.sched_file] | 344 | exps = get_exps(opts, args) |
325 | 345 | ||
326 | created = False | 346 | created = False |
327 | if not os.path.exists(out_base): | 347 | if not os.path.exists(out_base): |
@@ -335,9 +355,9 @@ def main(): | |||
335 | invalid = 0 | 355 | invalid = 0 |
336 | 356 | ||
337 | jabber = setup_jabber(opts.jabber) if opts.jabber else None | 357 | jabber = setup_jabber(opts.jabber) if opts.jabber else None |
338 | email = setup_email(opts.email) if opts.email else None | 358 | email = setup_email(opts.email) if opts.email else None |
339 | 359 | ||
340 | for exp in args: | 360 | for exp in exps: |
341 | path = "%s/%s" % (os.getcwd(), exp) | 361 | path = "%s/%s" % (os.getcwd(), exp) |
342 | out_dir = "%s/%s" % (out_base, os.path.split(exp.strip('/'))[1]) | 362 | out_dir = "%s/%s" % (out_base, os.path.split(exp.strip('/'))[1]) |
343 | 363 | ||
@@ -374,6 +394,7 @@ def main(): | |||
374 | 394 | ||
375 | ran += 1 | 395 | ran += 1 |
376 | 396 | ||
397 | # Clean out directory if it failed immediately | ||
377 | if not os.listdir(out_base) and created and not succ: | 398 | if not os.listdir(out_base) and created and not succ: |
378 | os.rmdir(out_base) | 399 | os.rmdir(out_base) |
379 | 400 | ||
@@ -385,6 +406,10 @@ def main(): | |||
385 | 406 | ||
386 | print(message) | 407 | print(message) |
387 | 408 | ||
409 | if succ: | ||
410 | sys.stderr.write("Successful experiment data saved in %s.\n" % | ||
411 | opts.out_dir) | ||
412 | |||
388 | if email: | 413 | if email: |
389 | email.send(message) | 414 | email.send(message) |
390 | email.close() | 415 | email.close() |