diff options
| author | Florian Fischer <florian.fl.fischer@fau.de> | 2019-03-06 13:20:52 +0100 |
|---|---|---|
| committer | Florian Fischer <florian.fl.fischer@fau.de> | 2019-03-06 13:20:52 +0100 |
| commit | 0623a281998ee1d7a62c3f904f76888446cb237a (patch) | |
| tree | dee8d03233c2d867106e9d4a346ca12742afc8c8 | |
| parent | 6027198427d77ae48932104eed2615968ae74616 (diff) | |
| download | allocbench-0623a281998ee1d7a62c3f904f76888446cb237a.tar.gz allocbench-0623a281998ee1d7a62c3f904f76888446cb237a.zip | |
add allocators to globalvars; kill mysql server on exit; save libc versions of requirements
| -rwxr-xr-x | bench.py | 16 | ||||
| -rw-r--r-- | src/allocators.py | 16 | ||||
| -rw-r--r-- | src/benchmark.py | 10 | ||||
| -rw-r--r-- | src/facter.py | 22 | ||||
| -rw-r--r-- | src/globalvars.py | 3 | ||||
| -rw-r--r-- | src/mysql.py | 12 |
6 files changed, 54 insertions, 25 deletions
@@ -6,7 +6,6 @@ import importlib import os import subprocess -import src.allocators import src.facter import src.globalvars from src.util import * @@ -62,6 +61,7 @@ def main(): subprocess.run(make_cmd) + # Default allocator definition file allocators_file = os.path.join("build", "allocators", "allocators.py") if args.allocators or os.path.isfile(allocators_file): @@ -69,12 +69,17 @@ def main(): src.globalvars.allocators_file = allocators_file with open(allocators_file, "r") as f: - print_status("Sourcing allocators definition ...") + print_status("Sourcing allocators definitions at", allocators_file, + "...") g = {} exec(f.read(), g) - src.allocators.allocators = g["allocators"] + src.globalvars.allocators = g["allocators"] + else: + print_status("Using system-wide installed allocators ...") + # Normal import fails + importlib.import_module('src.allocators') - print_info("Allocators:", *src.allocators.allocators.keys()) + print_info("Allocators:", *src.globalvars.allocators.keys()) # Create result directory if we save or summarize results need_resultdir = not (args.nosum and args.dont_save) @@ -82,11 +87,10 @@ def main(): if args.resultdir: resdir = os.path.join(args.resultdir) else: - hostname = src.facter.get_hostname() # TODO use saved hostname if args.load and args.runs < 2: pass - resdir = os.path.join("results", hostname, + resdir = os.path.join("results", src.globalvars.facts["hostname"], datetime.datetime.now().strftime("%Y-%m-%dT%H:%M")) try: print_info2("Creating result dir:", resdir) diff --git a/src/allocators.py b/src/allocators.py index 717c500..26fab5b 100644 --- a/src/allocators.py +++ b/src/allocators.py @@ -3,12 +3,14 @@ import os import subprocess +import src.globalvars + maybe_allocators = ["tcmalloc", "jemalloc", "hoard"] -allocators = {"libc": {"cmd_prefix" : "", - "binary_suffix" : "", - "LD_PRELOAD" : "", - "color" : "C1"}} +src.globalvars.allocators = {"libc": {"cmd_prefix" : "", + "binary_suffix" : "", + "LD_PRELOAD" : "", + "color" : "C1"}} for i, t in enumerate(maybe_allocators): try: @@ -17,7 +19,9 @@ for i, t in enumerate(maybe_allocators): universal_newlines=True).stdout.strip() if path != "": - allocators[t] = {"cmd_prefix": "", "binary_suffix": "", - "LD_PRELOAD": path, "color": "C"+str(i+2)} + src.globalvars.allocators[t] = {"cmd_prefix": "", + "binary_suffix": "", + "LD_PRELOAD": path, + "color": "C"+str(i+2)} except: pass diff --git a/src/benchmark.py b/src/benchmark.py index 18934f7..7d3207f 100644 --- a/src/benchmark.py +++ b/src/benchmark.py @@ -9,7 +9,6 @@ import pickle import shutil import subprocess -from src.allocators import allocators import src.globalvars from src.util import * @@ -25,7 +24,7 @@ class Benchmark (object): "measure_cmd": "perf stat -x, -d", "cmd": "true", - "allocators": allocators, + "allocators": src.globalvars.allocators, } @staticmethod @@ -41,7 +40,7 @@ class Benchmark (object): steps = 10 # Special thread counts - nthreads = set([1, cpus/2, cpus, cpus*factor]) + nthreads = set([1, int(cpus/2), cpus, cpus*factor]) nthreads.update(range(steps, cpus * factor + 1, steps)) nthreads = list(nthreads) nthreads.sort() @@ -64,6 +63,7 @@ class Benchmark (object): self.results = {} self.results["args"] = self.args self.results["allocators"] = self.allocators + self.results["facts"] = {"libcs": {}} self.results.update({t: {} for t in self.allocators}) if not hasattr(self, "requirements"): @@ -125,13 +125,17 @@ class Benchmark (object): if not is_exe(r): print_error("requirement:", r, "not found") return False + else: + self.results["facts"]["libcs"][exe_file] = src.facter.get_libc_version(bin=exe_file) # Search in PATH else: found = False for path in os.environ["PATH"].split(os.pathsep): exe_file = os.path.join(path, r) if is_exe(exe_file): + self.results["facts"]["libcs"][exe_file] = src.facter.get_libc_version(bin=exe_file) found = True + break if not found: print_error("requirement:", r, "not found") diff --git a/src/facter.py b/src/facter.py index 4e68665..6f6ba87 100644 --- a/src/facter.py +++ b/src/facter.py @@ -1,18 +1,22 @@ +import multiprocessing +import os import platform import sys -def get_uname(): - return " ".join(platform.uname()) +import src.globalvars as gv -def get_kernel_version(): - return get_uname().split()[2] -def get_hostname(): - return platform.uname().node +# Populate src.globalvars.facts on import +_uname = platform.uname() +gv.facts["hostname"] = _uname.node +gv.facts["system"] = _uname.system +gv.facts["kernel"] = _uname.release +gv.facts["arch"] = _uname.machine +gv.facts["cpus"] = multiprocessing.cpu_count() + +with open(os.path.join(gv.builddir, "ccinfo"), "r") as ccinfo: + gv.facts["cc"] = ccinfo.readlines()[-1][:-1] -def get_cc_version(): - with open("build/ccinfo", "r") as ccinfo: - return ccinfo.readlines()[-1][:-1] def get_libc_version(bin=None): bin = bin or sys.executable diff --git a/src/globalvars.py b/src/globalvars.py index fb80a26..0dcfd2c 100644 --- a/src/globalvars.py +++ b/src/globalvars.py @@ -7,6 +7,9 @@ facts = {} """Verbosity level -1: quiet, 0: status, 1: info, 2: stdout of subcommands, 3: debug info""" verbosity = 0 +"""Dict holding the allocators to compare""" +allocators = {} + """File were the allocators definitions are loaded from""" allocators_file = None diff --git a/src/mysql.py b/src/mysql.py index 2f0bce5..0ba820e 100644 --- a/src/mysql.py +++ b/src/mysql.py @@ -1,3 +1,4 @@ +import atexit import copy import matplotlib.pyplot as plt import numpy as np @@ -9,7 +10,7 @@ from subprocess import PIPE import sys from time import sleep -from src.allocators import allocators +from src.globalvars import allocators from src.benchmark import Benchmark from src.util import * @@ -42,6 +43,9 @@ class Benchmark_MYSQL(Benchmark): self.measure_cmd = "" self.requirements = ["mysqld", "sysbench"] + + atexit.register(self.terminate_server) + super().__init__() def start_and_wait_for_server(self, cmd_prefix=""): @@ -54,6 +58,12 @@ class Benchmark_MYSQL(Benchmark): sleep(10) return self.server.poll() is None + def terminate_server(self): + if self.server: + if self.server.poll() == None: + print_info("Killing still running mysql server") + self.server.kill() + def prepare(self): if not super().prepare(): return False |
