diff options
| author | Florian Fischer <florian.fl.fischer@fau.de> | 2019-03-05 15:47:11 +0100 |
|---|---|---|
| committer | Florian Fischer <florian.fl.fischer@fau.de> | 2019-03-05 15:47:11 +0100 |
| commit | 569f4af9656e1f56b84fb0c3fbbeebd5b6bf9714 (patch) | |
| tree | 8a268d2164f8d5d5edeaf9ba7a81ee0044ddda83 | |
| parent | 373e47ad602347b4b59ea3fa0f43674879d6acf2 (diff) | |
| download | allocbench-569f4af9656e1f56b84fb0c3fbbeebd5b6bf9714.tar.gz allocbench-569f4af9656e1f56b84fb0c3fbbeebd5b6bf9714.zip | |
use new verbosity system in allocator.py
| -rw-r--r-- | allocators/BA_allocators.py | 13 | ||||
| -rw-r--r-- | allocators/no_falsesharing.py | 10 | ||||
| -rwxr-xr-x | bench.py | 4 | ||||
| -rw-r--r-- | src/allocator.py | 117 |
4 files changed, 77 insertions, 67 deletions
diff --git a/allocators/BA_allocators.py b/allocators/BA_allocators.py index accd1a2..6ae438f 100644 --- a/allocators/BA_allocators.py +++ b/allocators/BA_allocators.py @@ -1,11 +1,9 @@ import os import subprocess -from src.allocator import library_path +from src.allocator import * from src.allocator import Allocator as Alloc -from src.allocator import Allocator_Patched as Alloc_Patched from src.allocator import Allocator_Sources as Alloc_Src -from src.allocator import builddir optimisation_flag = "-O2" @@ -47,17 +45,16 @@ jemalloc = Alloc("jemalloc", "mkdir {dir}"], color="C4") -hoard = Alloc_Patched("Hoard", - Alloc("Hoard", sources=Alloc_Src("Hoard", +hoard = Alloc("Hoard", sources=Alloc_Src("Hoard", retrieve_cmds=["git clone https://github.com/emeryberger/Hoard.git"]), LD_PRELOAD="{srcdir}/src/libhoard.so", build_cmds=["cd {srcdir}/src; make", "mkdir {dir}"], - color="C5"), - ["allocators/hoard_make.patch"]) + color="C5", + patches=["allocators/hoard_make.patch"]) allocators_to_build = [glibc, glibc_notc, tcmalloc, jemalloc, hoard] -allocators = {a.name: a.build(verbose=verbose) for a in allocators_to_build} +allocators = {a.name: a.build() for a in allocators_to_build} diff --git a/allocators/no_falsesharing.py b/allocators/no_falsesharing.py index 880d4e8..628c7fc 100644 --- a/allocators/no_falsesharing.py +++ b/allocators/no_falsesharing.py @@ -1,11 +1,9 @@ import os import subprocess -from src.allocator import library_path +from src.allocator import * from src.allocator import Allocator as Alloc -from src.allocator import Allocator_Patched as Alloc_Patched from src.allocator import Allocator_Sources as Alloc_Src -from src.allocator import builddir optimisation_flag = "-O2" @@ -21,7 +19,7 @@ glibc = Alloc("glibc", sources=glibc_src, "cd glibc-build; make install"], cmd_prefix="{dir}/lib/ld-linux-x86-64.so.2 --library-path {dir}/lib:"+library_path) -glibc_nofs = Alloc_Patched("glibc_nofs", glibc, +glibc_nofs = patch_alloc("glibc_nofs", glibc, ["allocators/glibc_2.28_no_passive_falsesharing.patch"]) tcmalloc_src = Alloc_Src("gperftools", @@ -35,10 +33,10 @@ tcmalloc = Alloc("tcmalloc", sources=tcmalloc_src, "cd {srcdir}; make install -j4"], color="C3") -tcmalloc_nofs = Alloc_Patched("tcmalloc_nofs", tcmalloc, +tcmalloc_nofs = patch_alloc("tcmalloc_nofs", tcmalloc, ["allocators/tcmalloc_2.7_no_active_falsesharing.patch"], color="C4") allocators_to_build = [glibc, glibc_nofs, tcmalloc, tcmalloc_nofs] -allocators = {a.name: a.build(verbose=verbose) for a in allocators_to_build} +allocators = {a.name: a.build() for a in allocators_to_build} @@ -62,14 +62,14 @@ def main(): subprocess.run(make_cmd) - # Prepare compared allocators allocators_file = os.path.join("build", "allocators", "allocators.py") if args.allocators or os.path.isfile(allocators_file): allocators_files = args.allocators or allocators_file with open(allocators_files, "r") as f: - g = {"verbosity": verbosity} + print_status("Sourcing allocators definition ...") + g= {} exec(f.read(), g) src.allocators.allocators = g["allocators"] diff --git a/src/allocator.py b/src/allocator.py index ddf16e3..f530540 100644 --- a/src/allocator.py +++ b/src/allocator.py @@ -5,6 +5,9 @@ import shutil import subprocess import sys +import src.globalvars +from src.util import * + library_path = "" for l in subprocess.run(["ldconfig", "-v"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, @@ -27,57 +30,61 @@ class Allocator_Sources (object): self.prepare_cmds = prepare_cmds self.reset_cmds = reset_cmds - def run_cmds(self, function, verbose, cwd=srcdir): - print(function, self.name, "...") + def run_cmds(self, function, cwd=srcdir): + print_status(function, self.name, "...", flush=True) + cmds = getattr(self, function+"_cmds") + + stdout = subprocess.PIPE if src.globalvars.verbosity < 2 else None + for cmd in cmds: - stdout = subprocess.PIPE if not verbose else None - stderr = subprocess.PIPE if not verbose else None - p = subprocess.run(cmd, shell=True, cwd=cwd, stderr=stderr, + p = subprocess.run(cmd, shell=True, cwd=cwd, stderr=stderr.PIPE, stdout=stdout) if p.returncode: - print(function, self.name, "failed with", p.returncode, + print_error(function, self.name, "failed with", p.returncode, file=sys.stderr) - print(p.stderr, file=sys.stderr) + print_debug(p.stderr, file=sys.stderr) return False return True - def prepare(self, verbose): + def prepare(self): if not os.path.isdir(self.dir): - if (not self.run_cmds("retrieve", verbose) or - not self.run_cmds("prepare", verbose, cwd=self.dir)): + if (not self.run_cmds("retrieve") or + not self.run_cmds("prepare", cwd=self.dir)): shutil.rmtree(self.dir, ignore_errors=True) exit(1) else: - self.reset(verbose) + self.reset() - def reset(self, verbose): - if not self.run_cmds("reset", verbose, cwd=self.dir): + def reset(self): + if not self.run_cmds("reset", cwd=self.dir): exit(1) - def patch(self, patches, verbose): - self.prepare(verbose) - self.reset(verbose) - stdout = subprocess.PIPE if not verbose else None - stderr = subprocess.PIPE + def patch(self, patches): + if not patches: + return + + stdout = subprocess.PIPE if src.globalvars.verbosity < 2 else None cwd = os.path.join(srcdir, self.name) - print("Patching", self.name, "...") + print_status("Patching", self.name, "...", flush=True) for patch in patches: with open(patch, "rb") as f: - p = subprocess.run("patch -p1", shell=True, cwd=cwd, stderr=stderr, - stdout=stdout, input=f.read()) + p = subprocess.run("patch -p1", shell=True, cwd=cwd, + stderr=subprocess.PIPE, stdout=stdout, + input=f.read()) if p.returncode: - print("Patching of", self.name, "failed.", file=sys.stderr) + print_error("Patching of", self.name, "failed.", file=sys.stderr) + print_debug(p.stderr, file=sys.stderr) exit(1) class Allocator (object): allowed_attributes = ["binary_suffix", "version", "sources", "build_cmds", - "LD_PRELOAD", "cmd_prefix", "color"] + "LD_PRELOAD", "cmd_prefix", "color", "patches"] def __init__(self, name, **kwargs): self.name = name @@ -90,38 +97,50 @@ class Allocator (object): if not hasattr(self, attr): setattr(self, attr, None) - def build(self, verbose=False): + def build(self): build_needed = not os.path.isdir(self.dir) + builddef_file = os.path.join(self.dir, ".builddef") if not build_needed: + print_info2("Old build found. Comparing builddefs") + old_def = "" - with open(os.path.join(self.dir, ".builddef"), "rb") as f: + with open(builddef_file, "rb") as f: old_def = pickle.dumps(pickle.load(f)) build_needed = old_def != pickle.dumps(self) + print_debug("Old Def.:", old_def) + print_debug("New Def.:", pickle.dumps(self)) + print_info2("Build needed:", build_needed) + if build_needed: if self.sources: - self.sources.prepare(verbose) + self.sources.prepare() + self.sources.patch(self.patches) if self.build_cmds: - print("Building", self.name, "...") + print_status("Building", self.name, "...", flush=True) + + stdout = subprocess.PIPE if src.globalvars.verbosity < 2 else None + for cmd in self.build_cmds: cmd = cmd.format(**{"dir": self.dir, "srcdir": self.sources.dir}) - stdout = subprocess.PIPE if not verbose else None - stderr = subprocess.PIPE + p = subprocess.run(cmd, cwd=builddir, shell=True, - stderr=stderr, stdout=stdout) + stderr=subprocess.PIPE, stdout=stdout) if p.returncode: - print(cmd) - print(p.stderr) - print("Building", self.name, "failed ...") + print_error(cmd, "failed with:", p.returncode) + print_debug(p.stderr, file=sys.stderr) + print_error("Building", self.name, "failed ...") shutil.rmtree(self.dir, ignore_errors=True) exit(2) - with open(os.path.join(self.dir, ".builddef"), "wb") as f: + with open(builddef_file, "wb") as f: + print_info2("Save build definition to:", builddef_file) pickle.dump(self, f) + print_info2("Create allocator dictionary") for attr in ["LD_PRELOAD", "cmd_prefix"]: try: value = getattr(self, attr) @@ -130,25 +149,21 @@ class Allocator (object): except AttributeError: setattr(self, attr, "") - return {"cmd_prefix": self.cmd_prefix, - "binary_suffix": self.binary_suffix or "", - "LD_PRELOAD": self.LD_PRELOAD, - "color": self.color} - + res_dict = {"cmd_prefix": self.cmd_prefix, + "binary_suffix": self.binary_suffix or "", + "LD_PRELOAD": self.LD_PRELOAD, + "color": self.color} + print_debug("Resulting dictionary:", res_dict) + return res_dict -class Allocator_Patched (object): - def __init__(self, name, alloc, patches, **kwargs): - self.name = name - self.patches = patches - self.alloc = copy.deepcopy(alloc) - self.alloc.name = self.name - self.alloc.dir = os.path.join(builddir, self.name) - self.alloc.__dict__.update((k, v) for k, v in kwargs.items() if k in self.alloc.allowed_attributes) +def patch_alloc(name, alloc, patches, **kwargs): + new_alloc = copy.deepcopy(alloc) + new_alloc.name = name + new_alloc.patches = patches - def build(self, verbose=False): + new_alloc.dir = os.path.join(builddir, name) + new_alloc.__dict__.update((k, v) for k, v in kwargs.items() if k in alloc.allowed_attributes) - if not os.path.isdir(self.alloc.dir): - self.alloc.sources.patch(self.patches, verbose) + return new_alloc - return self.alloc.build(verbose=verbose) |
