Commit 3745dcb4 authored by Antoine Kaufmann's avatar Antoine Kaufmann
Browse files

experiments: default to non-verbose and add --verbose switch

parent 9031dc48
......@@ -182,7 +182,8 @@ async def run_cmdlist(label, cmds, verbose=True):
await cmdC.start()
await cmdC.wait()
async def await_file(path, delay=0.05):
print('await_file(%s)' % path)
async def await_file(path, delay=0.05, verbose=False):
if verbose:
print('await_file(%s)' % path)
while not os.path.exists(path):
await asyncio.sleep(delay)
......@@ -25,32 +25,36 @@ class Experiment(object):
def add_network(self, sim):
self.networks.append(sim)
async def prepare(self, env):
async def prepare(self, env, verbose=False):
# generate config tars
for host in self.hosts:
path = env.cfgtar_path(host)
print('preparing config tar:', path)
if verbose:
print('preparing config tar:', path)
host.node_config.make_tar(path)
# prepare all simulators in parallel
sims = []
for sim in self.hosts + self.nics + self.networks:
prep_cmds = [pc for pc in sim.prep_cmds(env)]
sims.append(exectools.run_cmdlist('prepare_' + self.name, prep_cmds))
sims.append(exectools.run_cmdlist('prepare_' + self.name, prep_cmds,
verbose=verbose))
await asyncio.wait(sims)
async def run(self, env):
async def run(self, env, verbose=False):
running = []
sockets = []
out = ExpOutput(self)
try:
out.set_start()
print('%s: starting NICS' % self.name)
if verbose:
print('%s: starting NICS' % self.name)
for nic in self.nics:
print('start NIC:', nic.run_cmd(env))
if verbose:
print('start NIC:', nic.run_cmd(env))
sc = exectools.SimpleComponent(nic.full_name(),
shlex.split(nic.run_cmd(env)))
shlex.split(nic.run_cmd(env)), verbose=verbose)
await sc.start()
running.append((nic, sc))
......@@ -58,31 +62,38 @@ class Experiment(object):
sockets.append(env.nic_eth_path(nic))
sockets.append(env.nic_shm_path(nic))
print('%s: waiting for sockets' % self.name)
if verbose:
print('%s: waiting for sockets' % self.name)
for s in sockets:
await exectools.await_file(s)
await exectools.await_file(s, verbose=verbose)
# start networks
for net in self.networks:
print('start Net:', net.run_cmd(env))
if verbose:
print('start Net:', net.run_cmd(env))
sc = exectools.SimpleComponent(net.full_name(),
shlex.split(net.run_cmd(env)))
shlex.split(net.run_cmd(env)), verbose=verbose)
await sc.start()
running.append((net, sc))
# start hosts
wait_hosts = []
for host in self.hosts:
print('start Host:', host.run_cmd(env))
if verbose:
print('start Host:', host.run_cmd(env))
sc = exectools.SimpleComponent(host.full_name(),
shlex.split(host.run_cmd(env)))
shlex.split(host.run_cmd(env)), verbose=verbose)
await sc.start()
running.append((host,sc))
if host.wait:
wait_hosts.append(sc)
print('%s: waiting for hosts to terminate' % self.name)
if verbose:
print('%s: waiting for hosts to terminate' % self.name)
for sc in wait_hosts:
await sc.wait()
# wait for necessary hosts to terminate
......@@ -93,7 +104,8 @@ class Experiment(object):
out.set_end()
# shut things back down
print('%s: cleaning up' % self.name)
if verbose:
print('%s: cleaning up' % self.name)
scs = []
for _,sc in running:
scs.append(sc.int_term_kill())
......@@ -188,6 +200,6 @@ class ExpOutput(object):
def run_exp_local(exp, env):
asyncio.run(exp.prepare(env))
return asyncio.run(exp.run(env))
def run_exp_local(exp, env, verbose=False):
asyncio.run(exp.prepare(env, verbose=verbose))
return asyncio.run(exp.run(env, verbose=verbose))
......@@ -16,28 +16,33 @@ class Runtime(object):
def start(self):
pass
class LocalSimpleRuntime(Runtime):
def __init__(self):
def __init__(self, verbose=False):
self.runnable = []
self.complete = []
self.verbose = verbose
def add_run(self, run):
self.runnable.append(run)
def start(self):
for run in self.runnable:
run.output = exp.run_exp_local(run.experiment, run.env)
run.output = exp.run_exp_local(run.experiment, run.env,
verbose=self.verbose)
self.complete.append(run)
with open(run.outpath, 'w') as f:
f.write(run.output.dumps())
class LocalParallelRuntime(Runtime):
def __init__(self, cores, mem=None):
def __init__(self, cores, mem=None, verbose=False):
self.runnable = []
self.complete = []
self.cores = cores
self.mem = mem
self.verbose = verbose
def add_run(self, run):
if run.experiment.resreq_cores() > self.cores:
......@@ -50,14 +55,13 @@ class LocalParallelRuntime(Runtime):
async def do_run(self, run):
''' actually starts a run '''
await run.experiment.prepare(run.env)
await run.experiment.prepare(run.env, verbose=self.verbose)
print('starting run ', run)
run.output = await run.experiment.run(run.env)
run.output = await run.experiment.run(run.env, verbose=self.verbose)
with open(run.outpath, 'w') as f:
f.write(run.output.dumps())
print('finished run ', run)
return run
#await self.completions.put(run)
async def wait_completion(self):
''' wait for any run to terminate and return '''
......
......@@ -16,6 +16,9 @@ parser.add_argument('experiments', metavar='EXP', type=str, nargs='+',
help='An experiment file to run')
parser.add_argument('--runs', metavar='N', type=int, default=1,
help='Number of repetition for each experiment')
parser.add_argument('--verbose', action='store_const', const=True,
default=False,
help='Verbose output')
g_env = parser.add_argument_group('Environment')
g_env.add_argument('--repo', metavar='DIR', type=str,
......@@ -54,9 +57,10 @@ mkdir_if_not_exists(args.workdir)
mkdir_if_not_exists(args.outdir)
if args.runtime == 'parallel':
rt = runtime.LocalParallelRuntime(cores=args.cores, mem=args.mem)
rt = runtime.LocalParallelRuntime(cores=args.cores, mem=args.mem,
verbose=args.verbose)
else:
rt = runtime.LocalSimpleRuntime()
rt = runtime.LocalSimpleRuntime(verbose=args.verbose)
for e in experiments:
workdir_base = '%s/%s' % (args.workdir, e.name)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment