diff options
Diffstat (limited to 'benchmark.py')
| -rw-r--r-- | benchmark.py | 70 |
1 files changed, 48 insertions, 22 deletions
diff --git a/benchmark.py b/benchmark.py index 92a670d..2d5fc94 100644 --- a/benchmark.py +++ b/benchmark.py @@ -42,6 +42,7 @@ class Benchmark (object): self.requirements = [] def save(self, path=None, verbose=False): + print(self.results) f = path if path else self.name + ".save" if verbose: print("Saving results to:", self.name + ".save") @@ -115,15 +116,19 @@ class Benchmark (object): def analyse(self, verbose=False): for perm in self.iterate_args(): - file_name = ".".join(list(self.name, *p.items())) - - actual_cmd = analyse_cmd.format(file_name + ".png") - if "binary_suffix" in cmd: - p["binary_suffix"] = "" - actual_cmd += cmd.format(**perm._asdict()) + perm = perm._asdict() + file_name = self.name + "." + file_name += ".".join([str(x) for x in perm.values()]) + file_name += ".memusage" + + actual_cmd = self.analyse_cmd.format(file_name + ".png") + if "binary_suffix" in self.cmd: + perm["binary_suffix"] = "" + actual_cmd += self.cmd.format(**perm) with open(file_name + ".hist", "w") as f: res = subprocess.run(actual_cmd.split(), + stdout=subprocess.PIPE, stderr=f, universal_newlines=True) @@ -133,18 +138,34 @@ class Benchmark (object): print("You may look at", file_name + ".hist", "to fix this.") return + def parse_chattymalloc_data(self, path="chattymalloc.data"): + hist = {} + with open(path, "r") as f: + for l in f.readlines(): + n = int(l) + hist[n] = hist.get(n, 0) + 1 + return hist def run(self, verbose=False, runs=5): - n = len(list(self.iterate_args())) + n = len(list(self.iterate_args())) * len(self.targets) + i = 0 for run in range(1, runs + 1): print(str(run) + ". run") - for i, perm in enumerate(self.iterate_args()): - print(i + 1, "of", n, "\r", end='') + for tname, t in self.targets.items(): + if not tname in self.results: + self.results[tname] = {} + + os.environ["LD_PRELOAD"] = "build/print_status_on_exit.so " + os.environ["LD_PRELOAD"] += t["LD_PRELOAD"] + + if hasattr(self, "pretarget_hook"): + if self.pretarget_hook((tname, t), run, verbose): + return False - for tname, t in self.targets.items(): - if not tname in self.results: - self.results[tname] = {} + for perm in self.iterate_args(): + i += 1 + print(i + 1, "of", n, "\r", end='') actual_cmd = self.perf_cmd @@ -152,16 +173,13 @@ class Benchmark (object): perm_dict.update(t) actual_cmd += self.cmd.format(**perm_dict) - os.environ["LD_PRELOAD"] = "build/print_status_on_exit.so " - os.environ["LD_PRELOAD"] += t["LD_PRELOAD"] - res = subprocess.run(actual_cmd.split(), stderr=subprocess.PIPE, stdout=subprocess.PIPE, universal_newlines=True) if res.returncode != 0: - print("\n" + actual_cmd, "exited with", res.returncode) + print("\n" + actual_cmd, "exited with", res.returncode, "for", tname) print("Aborting Benchmark.") print("Stdout:\n" + res.stdout) print("Stderr:\n" + res.stderr) @@ -175,7 +193,7 @@ class Benchmark (object): result = {} - # Read VmHWM from status file # If our benchmark didn't fork + # Read VmHWM from status file. If our benchmark didn't fork # the first occurance of VmHWM is from our benchmark with open("status", "r") as f: for l in f.readlines(): @@ -184,15 +202,23 @@ class Benchmark (object): break os.remove("status") - # Parse perf output - csvreader = csv.reader(res.stderr.splitlines(), delimiter=',') - for row in csvreader: - # Split of the user/kernel space info to be better portable - result[row[2].split(":")[0]] = row[0] + if hasattr(self, "process_stdout"): + self.process_stdout(result, res.stdout) + + # Parse perf output if available + if self.perf_cmd != "": + csvreader = csv.reader(res.stderr.splitlines(), delimiter=',') + for row in csvreader: + # Split of the user/kernel space info to be better portable + result[row[2].split(":")[0]] = row[0] if run == 1: self.results[tname][perm] = [] self.results[tname][perm].append(result) + + if hasattr(self, "posttarget_hook"): + if self.posttarget_hook((tname, t), run, verbose): + return False print() return True |
