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