Skip to content
Snippets Groups Projects
Commit 7a1719cf authored by Georges Da Costa's avatar Georges Da Costa
Browse files

Adds capability to run code in background and updates MojitO/S monitor to use it

parent 95d8f03a
Branches
Tags
No related merge requests found
......@@ -112,11 +112,11 @@ Here is an example of a simple benchmark in a file **demo_monitor.py**
def start(self):
'Starts the monitoring right before the benchmark'
self.executor.hosts(self.cmdline)
self.process = self.executor.hosts(self.cmdline, background=True)
def stop(self):
'Stops the monitoring right before the benchmark'
self.executor.hosts('killall monitor')
self.process.kill()
def save(self, experiment, benchname, beg_time):
'Save the results when time is no more critical'
......
......@@ -53,30 +53,42 @@ class Executor:
self.hosts(f'mkdir -p {self.tmp_dir}')
def local(self, cmd, shell=True, root=False):
def local_start(self, cmd, shell=True, root=False):
"""Executes the cmd command and returns stdout after cmd exits"""
if root:
cmd = self.sudo+' '+cmd
print('DEBUG:', cmd)
proc = Process(cmd, shell=shell)
proc.run()
proc.start()
return proc
def wait_result(self, proc):
proc.wait()
return proc.stdout
def mpi(self, cmd, host_file, nb_processes, root=False):
def local(self, cmd, shell=True, root=False, background=False):
proc = self.local_start(cmd, shell=shell, root=root)
print('DEBUG: local', background, root, shell, cmd)
if background:
return proc
else:
return self.wait_result(proc)
def mpi(self, cmd, host_file, nb_processes, root=False, background=False):
'Executes mpi cmd and returns stdout'
if root:
cmd = self.sudo+' '+cmd
mpi_cmd = 'mpirun %s -np %s --machinefile %s %s' % \
(self.mpi_options, nb_processes, host_file, cmd)
return self.local(mpi_cmd)
return self.local(mpi_cmd, background=background)
def hosts(self, cmd, root=False):
def hosts(self, cmd, root=False, background=False):
"""Executes cmd on each host, returns rank=0 stdout"""
return self.mpi(cmd, self.mpi_host_file, self.nbhosts, root)
return self.mpi(cmd, self.mpi_host_file, self.nbhosts, root, background)
def cores(self, cmd):
def cores(self, cmd, root=False, background=False):
"""Executes cmd on each core, returns rank=0 stdout"""
return self.mpi(cmd, self.mpi_core_file, self.nbcores)
return self.mpi(cmd, self.mpi_core_file, self.nbcores, root, background)
def sync(self, directory):
'Synchronize one directory accross all nodes of the experiment'
......
......@@ -35,11 +35,11 @@ class Lperf:
def start(self):
'Starts the monitoring right before the benchmark'
self.executor.hosts(self.cmdline)
self.proc = self.executor.hosts(self.cmdline, background=True)
def stop(self):
'Stops the monitoring right before the benchmark'
self.executor.hosts('killall lperf')
self.proc.kill()
def save(self, experiment, benchname, beg_time):
'Save the results when time is no more critical'
......
......@@ -110,11 +110,11 @@ class Mojitos:
def start(self):
'Starts the monitoring right before the benchmark'
self.executor.hosts(self.cmdline)
self.proc = self.executor.hosts(self.cmdline, background=True)
def stop(self):
'Stops the monitoring right before the benchmark'
self.executor.hosts('killall mojitos')
self.proc.kill()
def save(self, experiment, benchname, beg_time):
'Save the results when time is no more critical'
......
......@@ -30,14 +30,14 @@ class Power:
if self.g5k:
self.start_time = int(time.time())
else:
self.executor.local(self.local_script)
self.proc = self.executor.local(self.local_script, background=True)
def stop(self):
'Stops the monitoring right after the benchmark'
if self.g5k:
self.end_time = int(time.time())
else:
self.executor.local('killall laptop_power_monitor.py')
self.proc.kill()
def save(self, experiment, benchname, beg_time):
'Save the results when time is no more critical'
......
......@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
setuptools.setup(
name="expetator",
version="0.3.26",
version="0.3.27",
author="Georges Da Costa",
author_email="georges.da-costa@irit.fr",
description="A framework for monitoring HPC applications using DVFS",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment