aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fl.fischer@fau.de>2020-02-09 15:08:54 +0100
committerFlorian Fischer <florian.fl.fischer@fau.de>2020-02-09 15:08:54 +0100
commit3a419eb8e62449bee59f62154cdc359c82957384 (patch)
tree87fa431fe1f2dca475204f9798504ff19b097004
parent241cec136189fbb22cdfa79e99e0001120a699c4 (diff)
downloadallocbench-3a419eb8e62449bee59f62154cdc359c82957384.tar.gz
allocbench-3a419eb8e62449bee59f62154cdc359c82957384.zip
unify the use of LD_PRELOAD between server and non-server commands
Always use exec to start a measured cmd overwriting LD_PRELOAD. Exec overwrites LD_PRELOAD using this format: print_status_on_exit.so sig_handlers.so <allocator LD_PRELOAD> <orignal LD_PRELOAD> With this change our LD_PRELOAD is only active for the measured process and not for the measuring cmd.
-rw-r--r--src/benchmark.py89
1 files changed, 47 insertions, 42 deletions
diff --git a/src/benchmark.py b/src/benchmark.py
index 68e83ea..e3986d7 100644
--- a/src/benchmark.py
+++ b/src/benchmark.py
@@ -257,7 +257,41 @@ class Benchmark:
if is_fixed:
yield perm
- def start_servers(self, env=None, alloc_name="None", alloc={"cmd_prefix": ""}):
+ def prepare_argv(self, cmd, env={}, alloc={}, substitutions={}, prepend=True):
+ """Prepare an complete argv list for benchmarking"""
+ argv = []
+ if prepend:
+ if "cmd_prefix" in alloc:
+ prefix_argv = alloc["cmd_prefix"].format(**substitutions).split()
+ argv.extend(prefix_argv)
+
+ if self.measure_cmd != "":
+ measure_argv = self.measure_cmd.format(**substitutions)
+ measure_argv = src.util.prefix_cmd_with_abspath(measure_argv).split()
+ argv.extend(measure_argv)
+
+ argv.extend([f"{src.globalvars.builddir}/exec"])
+
+ ld_preload = f"{src.globalvars.builddir}/print_status_on_exit.so"
+ ld_preload += f" {src.globalvars.builddir}/sig_handlers.so"
+
+ if "LD_PRELOAD" in env or alloc.get("LD_PRELOAD", ""):
+ ld_preload += f" {alloc.get('LD_PRELOAD', '')}"
+ ld_preload += " " + env.get('LD_PRELOAD', '')
+
+ argv.extend(["-p", ld_preload])
+
+ if "LD_LIBRARY_PATH" in env or alloc.get("LD_LIBRARY_PATH", ""):
+ argv.extend(["-l", f"{alloc.get('LD_LIBRARY_PATH', '')} {env.get('LD_LIBRARY_PATH', '')}"])
+
+ cmd_argv = cmd.format(**substitutions)
+ cmd_argv = src.util.prefix_cmd_with_abspath(cmd_argv).split()
+
+ argv.extend(cmd_argv)
+
+ return argv
+
+ def start_servers(self, env={}, alloc_name="None", alloc={"cmd_prefix": ""}):
"""Start Servers
Servers are not allowed to deamonize because then they can't
@@ -274,15 +308,10 @@ class Benchmark:
server_name = server.get("name", "Server")
print_info(f"Starting {server_name} for {alloc_name}")
- server_cmd = src.util.prefix_cmd_with_abspath(server["cmd"])
- server_cmd = "{} {} {}".format(self.measure_cmd,
- alloc["cmd_prefix"],
- server_cmd)
+ argv = self.prepare_argv(server["cmd"], env, alloc, substitutions)
+ print_debug(argv)
- server_cmd = server_cmd.format(**substitutions)
- print_debug(server_cmd)
-
- proc = subprocess.Popen(server_cmd.split(), env=env,
+ proc = subprocess.Popen(argv, env=env,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True)
@@ -370,20 +399,8 @@ class Benchmark:
self.results[alloc_name] = {}
skip = False
-
- env = dict(os.environ)
- old_ld_preload = env.get('LD_PRELOAD', '')
- env["LD_PRELOAD"] = f"{src.globalvars.builddir}/print_status_on_exit.so"
- env["LD_PRELOAD"] += f" {src.globalvars.builddir}/sig_handlers.so"
- env["LD_PRELOAD"] += f" {alloc['LD_PRELOAD']}"
- env["LD_PRELOAD"] += f" {old_ld_preload}"
-
- if "LD_LIBRARY_PATH" in alloc:
- env["LD_LIBRARY_PATH"] = env.get("LD_LIBRARY_PATH", "")
- env["LD_LIBRARY_PATH"] += f'{os.pathsep}{alloc["LD_LIBRARY_PATH"]}'
-
try:
- self.start_servers(alloc_name=alloc_name, alloc=alloc, env=env)
+ self.start_servers(alloc_name=alloc_name, alloc=alloc, env=os.environ)
except Exception as e:
print_debug(traceback.format_exc())
print_error(e)
@@ -392,15 +409,17 @@ class Benchmark:
# Preallocator hook
if hasattr(self, "preallocator_hook"):
- self.preallocator_hook((alloc_name, alloc), run, env)
+ self.preallocator_hook((alloc_name, alloc), run, os.environ)
# Run benchmark for alloc
for perm in self.iterate_args():
i += 1
+ # create new result entry
if perm not in self.results[alloc_name]:
self.results[alloc_name][perm] = []
+ # starting the server failed -> add empty result and continue
if skip:
self.results[alloc_name][perm].append({})
continue
@@ -417,26 +436,12 @@ class Benchmark:
else:
substitutions["perm"] = ""
- cmd_argv = self.cmd.format(**substitutions)
- cmd_argv = src.util.prefix_cmd_with_abspath(cmd_argv).split()
- argv = []
-
- # Prepend cmd if we are not measuring servers
+ # we measure the cmd -> prepare it accordingly
if self.servers == []:
- prefix_argv = alloc["cmd_prefix"].format(**substitutions).split()
- if self.measure_cmd != "":
- measure_argv = self.measure_cmd.format(**substitutions)
- measure_argv = src.util.prefix_cmd_with_abspath(measure_argv).split()
-
- argv.extend(measure_argv)
-
- argv.extend([f"{src.globalvars.builddir}/exec", "-p", env["LD_PRELOAD"]])
- if alloc["LD_LIBRARY_PATH"] != "":
- argv.extend(["-l", env["LD_LIBRARY_PATH"]])
-
- argv.extend(prefix_argv)
-
- argv.extend(cmd_argv)
+ argv = self.prepare_argv(self.cmd, alloc, os.environ, substitutions)
+ # we measure the server -> run cmd as it is
+ else:
+ argv = self.prepare_argv(self.cmd, substitutions=substitutions, prepend=False)
cwd = os.getcwd()
if hasattr(self, "run_dir"):