aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile6
-rw-r--r--src/benchmark.py35
-rw-r--r--src/run_cmd.c18
3 files changed, 40 insertions, 19 deletions
diff --git a/src/Makefile b/src/Makefile
index 47d0dd4..8a5e0a4 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -15,7 +15,7 @@ MEMSIZE=$(shell echo $(MEMSIZE_KB)"* 1024" | bc)
.PHONY: all clean
-all: $(OBJDIR)/print_status_on_exit.so $(OBJDIR)/allocators/bumpptr_alloc.so
+all: $(OBJDIR)/print_status_on_exit.so $(OBJDIR)/allocators/bumpptr_alloc.so $(OBJDIR)/run_cmd
$(OBJDIR)/allocators/bumpptr_alloc.so: bumpptr_alloc.c Makefile | $(OBJDIR)/allocators
@echo "Compiling $@...";
@@ -26,6 +26,10 @@ $(OBJDIR)/print_status_on_exit.so: print_status_on_exit.c Makefile | $(OBJDIR)
@echo "Compiling $@...";
$(CC) $(LDFLAGS) -shared $(CFLAGS) -o $@ $<
+$(OBJDIR)/run_cmd: run_cmd.c Makefile | $(OBJDIR)
+ @echo "Compiling $@...";
+ $(CC) $(LDFLAGS) $(CFLAGS) -o $@ $<
+
$(OBJDIR)/allocators:
mkdir -p $@
diff --git a/src/benchmark.py b/src/benchmark.py
index 698a40d..fa99c65 100644
--- a/src/benchmark.py
+++ b/src/benchmark.py
@@ -52,8 +52,8 @@ class Benchmark (object):
print_error("Killing subprocess ", popen.args)
popen.kill()
popen.wait()
- print_debug("Server Out:", popen.stdout)
- print_debug("Server Err:", popen.stderr)
+ print_debug("Server Out:", popen.stdout.read())
+ print_debug("Server Err:", popen.stderr.read())
@staticmethod
def scale_threads_for_cpus(factor, steps=None):
@@ -311,24 +311,23 @@ class Benchmark (object):
substitutions["perm"] = ("{}-"*(len(perm)-1) + "{}").format(*perm)
substitutions.update(alloc)
- actual_cmd = self.cmd.format(**substitutions)
- actual_env = None
+ cmd_argv = self.cmd.format(**substitutions).split()
+ argv = []
# Prepend cmd if we are not measuring servers
if self.server_cmds == []:
- actual_cmd = src.util.prefix_cmd_with_abspath(actual_cmd)
- actual_cmd = "{} {} {}".format(self.measure_cmd,
- alloc["cmd_prefix"],
- actual_cmd)
- # substitute again
- actual_cmd = actual_cmd.format(**substitutions)
-
- actual_env = env
-
- print_debug("\nCmd:", actual_cmd)
- res = subprocess.run(actual_cmd.split(),
- env=actual_env,
- stderr=subprocess.PIPE,
+ prefix_argv = alloc["cmd_prefix"].format(**substitutions).split()
+ measure_argv = self.measure_cmd.format(**substitutions)
+ measure_argv = src.util.prefix_cmd_with_abspath(measure_argv).split()
+
+ argv.extend(prefix_argv)
+ argv.extend(measure_argv)
+ argv.extend(["build/run_cmd", env["LD_PRELOAD"]])
+
+ argv.extend(cmd_argv)
+
+ print_debug("\nCmd:", argv)
+ res = subprocess.run(argv, stderr=subprocess.PIPE,
stdout=subprocess.PIPE,
universal_newlines=True)
@@ -339,7 +338,7 @@ class Benchmark (object):
print_debug("Stdout:\n" + res.stdout)
print_debug("Stderr:\n" + res.stderr)
if res.returncode != 0:
- print_error("{} failed with exit code {} for {}".format(actual_cmd, res.returncode, alloc_name))
+ print_error("{} failed with exit code {} for {}".format(argv, res.returncode, alloc_name))
else:
print_error("Preloading of {} failed for {}".format(alloc["LD_PRELOAD"], alloc_name))
diff --git a/src/run_cmd.c b/src/run_cmd.c
new file mode 100644
index 0000000..aa15964
--- /dev/null
+++ b/src/run_cmd.c
@@ -0,0 +1,18 @@
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+int main(int argc, char* argv[]) {
+ if (argc < 3) {
+ printf("Usage: %s <ld_preload> <cmd> [cmd args]\n");
+ printf("\tset LD_PRELOAD to ld_preload and call execvp <cmd> [cmd args]\n");
+ return 1;
+ }
+
+ // Overwrite LD_PRELOAD.
+ setenv("LD_PRELOAD", argv[1], 1);
+
+ // Run cmd.
+ execvp(argv[2], &argv[2]);
+}