diff options
| author | Florian Fischer <florian.fl.fischer@fau.de> | 2019-03-21 17:53:09 +0100 |
|---|---|---|
| committer | Florian Fischer <florian.fl.fischer@fau.de> | 2019-03-21 17:53:09 +0100 |
| commit | 179583714f9b8806390245f17d8a969aefeb1952 (patch) | |
| tree | 81e6d4dcce7b456abd36222516391083c1dc1f4b | |
| parent | 9165e1dafa8a200073098ec34e73a76646bec9e2 (diff) | |
| download | allocbench-179583714f9b8806390245f17d8a969aefeb1952.tar.gz allocbench-179583714f9b8806390245f17d8a969aefeb1952.zip | |
use exceptions in mysql benchmark
| -rwxr-xr-x | bench.py | 13 | ||||
| -rw-r--r-- | src/benchmark.py | 45 | ||||
| -rw-r--r-- | src/mysql.py | 66 |
3 files changed, 56 insertions, 68 deletions
@@ -105,11 +105,13 @@ def main(): if args.load: with open(os.path.join(args.load, "facts.save"), "rb") as f: old_facts = pickle.load(f) + if old_facts != src.globalvars.facts and args.runs > 0: print_error("Can't combine benchmarks with different facts") print_error("Aborting.") exit(1) - else: + # We are just summarizing old results -> use their facts + elif args.runs == 0: src.globalvars.facts = old_facts else: starttime = datetime.datetime.now().isoformat() @@ -137,10 +139,10 @@ def main(): cwd = os.getcwd() for bench in benchmarks: - try: - if args.benchmarks and not bench in args.benchmarks: - continue + if args.benchmarks and not bench in args.benchmarks: + continue + try: bench = eval("importlib.import_module('src.{0}').{0}".format(bench)) if args.load: @@ -150,8 +152,7 @@ def main(): print_status("Preparing", bench.name, "...") bench.prepare() - if not bench.run(runs=args.runs): - continue + bench.run(runs=args.runs) if need_resultdir: print_info2("Changing cwd to:", resdir) diff --git a/src/benchmark.py b/src/benchmark.py index 024c5b0..38cb5a4 100644 --- a/src/benchmark.py +++ b/src/benchmark.py @@ -124,8 +124,7 @@ class Benchmark (object): # Search for file if fpath: if not is_exe(r): - print_error("requirement:", r, "not found") - return False + raise Exception("Requirement: {} not found".format(r)) else: self.results["facts"]["libcs"][exe_file] = src.facter.get_libc_version(bin=exe_file) # Search in PATH @@ -139,10 +138,7 @@ class Benchmark (object): break if not found: - print_error("requirement:", r, "not found") - return False - - return True + raise Exception("Requirement: {} not found".format(r)) def iterate_args(self, args=None): """Return a dict for each possible combination of args""" @@ -166,7 +162,7 @@ class Benchmark (object): def run(self, runs=5): if runs < 1: - return True + return print_status("Running", self.name, "...") @@ -186,9 +182,7 @@ class Benchmark (object): Benchmark.perf_allowed = True if not Benchmark.perf_allowed: - print_error("Skipping", self.name, "because you don't have the", - "needed permissions to use perf") - return False + raise Exception("You don't have the needed permissions to use perf") n = len(list(self.iterate_args())) * len(self.allocators) for run in range(1, runs + 1): @@ -205,9 +199,8 @@ class Benchmark (object): os.environ["LD_PRELOAD"] += t["LD_PRELOAD"] if hasattr(self, "preallocator_hook"): - if self.preallocator_hook((tname, t), run, - verbose=src.globalvars.verbosity): - return False + self.preallocator_hook((tname, t), run, + verbose=src.globalvars.verbosity) for perm in self.iterate_args(): i += 1 @@ -236,19 +229,15 @@ class Benchmark (object): universal_newlines=True) if res.returncode != 0: - print_error("\n" + actual_cmd, "exited with", res.returncode, - "for", tname) + print() print_debug("Stdout:\n" + res.stdout) print_debug("Stderr:\n" + res.stderr) - print_error("Aborting Benchmark.") - return False + raise Exception("{} failed with exit code {} for {}".format(actual_cmd, res.returncode)) if "ERROR: ld.so" in res.stderr: - print_error("\nPreloading of", t["LD_PRELOAD"], - "failed for", tname) + print() print_debug("Stderr:\n" + res.stderr) - print_error("Aborting Benchmark.") - return False + raise Exception("Preloading of {} failed for {}".format(t["LD_PRELOAD"], tname)) result = {} @@ -288,17 +277,15 @@ class Benchmark (object): os.environ["LD_PRELOAD"] = old_ld_preload if hasattr(self, "postallocator_hook"): - if self.postallocator_hook((tname, t), run, - verbose=src.globalvars.verbosity): - return False + self.postallocator_hook((tname, t), run, + verbose=src.globalvars.verbosity) print() # Reset PATH os.environ["PATH"] = os.environ["PATH"].replace(":build/" + self.name, "") - return True def plot_single_arg(self, yval, ylabel="'y-label'", xlabel="'x-label'", autoticks=True, title="default title", filepostfix="", - sumdir="", arg="", scale=None): + sumdir="", arg="", scale=None, file_ext="png"): args = self.results["args"] allocators = self.results["allocators"] @@ -350,12 +337,12 @@ class Benchmark (object): plt.xlabel(eval(xlabel)) plt.ylabel(eval(ylabel)) plt.title(eval(title)) - plt.savefig(os.path.join(sumdir, ".".join([self.name, filepostfix, "png"]))) + plt.savefig(os.path.join(sumdir, ".".join([self.name, filepostfix, file_ext]))) plt.clf() def plot_fixed_arg(self, yval, ylabel="'y-label'", xlabel="loose_arg", autoticks=True, title="'default title'", filepostfix="", - sumdir="", fixed=[]): + sumdir="", fixed=[], file_ext="png"): args = self.results["args"] allocators = self.results["allocators"] @@ -384,7 +371,7 @@ class Benchmark (object): plt.ylabel(eval(ylabel)) plt.title(eval(title)) plt.savefig(os.path.join(sumdir, ".".join([self.name, arg, - str(arg_value), filepostfix, "png"]))) + str(arg_value), filepostfix, file_ext]))) plt.clf() def write_best_doublearg_tex_table(self, evaluation, sort=">", diff --git a/src/mysql.py b/src/mysql.py index de30141..fa1c81c 100644 --- a/src/mysql.py +++ b/src/mysql.py @@ -59,17 +59,31 @@ class Benchmark_MYSQL(Benchmark): universal_newlines=True) # TODO make sure server comes up ! sleep(10) - return self.server.poll() is None + if self.server.poll() is not None: + print_debug("cmd_prefix:", cmd_prefix, file=sys.stderr) + print_debug("Stderr:", self.server.stderr, file=sys.stderr) + return False + + return True def terminate_server(self): if hasattr(self, "server"): - if self.server.poll() == None: - print_info("Killing still running mysql server") - self.server.kill() + if self.server.poll() is None: + print_info("Terminating mysql server") + self.server.terminate() + + for i in range(0,10): + sleep(1) + if self.server.poll() is not None: + return + + print_info("Killing still running mysql server") + self.server.kill() + self.server.wait() def prepare(self): - if not super().prepare(): - return False + super().prepare() + # Setup Test Environment if not os.path.exists("mysql_test"): print_status("Prepare mysqld directory and database") @@ -89,14 +103,11 @@ class Benchmark_MYSQL(Benchmark): p = subprocess.run(init_db_cmd, stdout=PIPE, stderr=PIPE) if not p.returncode == 0: - print_error("Creating test DB failed with:", p.returncode) print_debug(p.stderr, file=sys.stderr) - return False + raise Exception("Creating test DB failed with:", p.returncode) if not self.start_and_wait_for_server(): - print_error("Starting mysqld failed") - print_debug(self.server.stderr, file=sys.stderr) - return False + raise Exception("Starting mysql server failed with {}".format(self.server.returncode)) # Create sbtest TABLE p = subprocess.run(("mysql -u root -S "+cwd+"/mysql_test/socket").split(" "), @@ -104,27 +115,20 @@ class Benchmark_MYSQL(Benchmark): stdout=PIPE, stderr=PIPE) if not p.returncode == 0: - print_error("Creating test table failed with:", p.returncode) - print_debug(p.stderr, file=sys.stderr) - self.server.kill() - self.server.wait() - return False + print_debug("Stderr:", p.stderr, file=sys.stderr) + self.terminate_server() + raise Exception("Creating test tables failed with:", p.returncode) print_status("Prepare test tables ...") ret = True p = subprocess.run(prepare_cmd, stdout=PIPE, stderr=PIPE) if p.returncode != 0: - print_error("Preparing test tables failed with:", p.returncode) - print_debug(p.stdout, file=sys.stderr) - print_debug(p.stderr, file=sys.stderr) - ret = False - - self.server.kill() - self.server.wait() - - return ret + print_debug("Stdout:", p.stdout, file=sys.stderr) + print_debug("Stderr:", p.stderr, file=sys.stderr) + self.terminate_server() + raise("Preparing test tables failed with:", p.returncode) - return True + self.terminate_server() def cleanup(self): if os.path.exists("mysql_test"): @@ -133,15 +137,11 @@ class Benchmark_MYSQL(Benchmark): def preallocator_hook(self, allocator, run, verbose): if not self.start_and_wait_for_server(cmd_prefix=allocator[1]["cmd_prefix"]): - print_error("Can't start server for", allocator[0] + ".") - print_error("Aborting Benchmark.") print_debug(allocator[1]["cmd_prefix"], file=sys.stderr) - print_debug(self.server.stderr, file=sys.stderr) - return False + raise Exception("Starting mysql server for {} failed with".format(allocator[0], self.server.returncode)) def postallocator_hook(self, allocator, run, verbose): - self.server.kill() - self.server.wait() + self.terminate_server() def process_output(self, result, stdout, stderr, allocator, perm, verbose): result["transactions"] = re.search("transactions:\s*(\d*)", stdout).group(1) @@ -220,7 +220,7 @@ class Benchmark_MYSQL(Benchmark): plt.legend() plt.xlabel("threads") - plt.xticks(range(1, (len(y_vals) + 1)*3, 3), self.results["args"]["nthreads"]) + plt.xticks(range(1, len(norm_y_vals)*nallocs + 1, nallocs), self.results["args"]["nthreads"]) plt.ylabel("transactions normalized") plt.title("sysbench oltp read only") plt.savefig(self.name + ".norm.b.ro.png") |
