diff options
| author | Florian Fischer <florian.fl.fischer@fau.de> | 2019-11-22 20:36:09 +0100 |
|---|---|---|
| committer | Florian Fischer <florian.fl.fischer@fau.de> | 2019-11-22 20:36:09 +0100 |
| commit | d6e9d1c4742a63bcf2f85ec3382ef3e610fd9231 (patch) | |
| tree | 74ace51468fe4424871150d4082f3eba156f9612 | |
| parent | f47746c010ec707ebb86087646a51c60abcf3760 (diff) | |
| download | allocbench-d6e9d1c4742a63bcf2f85ec3382ef3e610fd9231.tar.gz allocbench-d6e9d1c4742a63bcf2f85ec3382ef3e610fd9231.zip | |
extract perf check from way too long run method
| -rw-r--r-- | src/benchmark.py | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/src/benchmark.py b/src/benchmark.py index d77b09d..463cd7a 100644 --- a/src/benchmark.py +++ b/src/benchmark.py @@ -76,6 +76,26 @@ class Benchmark: nthreads = [(i + 1) * factor for i in range(entries)] divider *= 2 + @staticmethod + def is_perf_allowed(): + """raise an exception if perf is not allowed on this system""" + if Benchmark.perf_allowed is None: + print_info("Check if you are allowed to use perf ...") + res = subprocess.run(["perf", "stat", "ls"], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + universal_newlines=True) + + if res.returncode != 0: + print_error(f"Test perf run failed with exit status: {res.returncode}") + print_debug(res.stderr) + Benchmark.perf_allowed = False + else: + Benchmark.perf_allowed = True + + if not Benchmark.perf_allowed: + raise Exception("You don't have the needed permissions to use perf") + def __str__(self): return self.name @@ -313,24 +333,10 @@ class Benchmark: def run(self, runs=3): """generic run implementation""" - # check if perf is allowed on this system - if self.measure_cmd == self.defaults["measure_cmd"]: - if Benchmark.perf_allowed is None: - print_info("Check if you are allowed to use perf ...") - res = subprocess.run(["perf", "stat", "ls"], - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - universal_newlines=True) - - if res.returncode != 0: - print_error("Test perf run failed with:") - print_debug(res.stderr) - Benchmark.perf_allowed = False - else: - Benchmark.perf_allowed = True - if not Benchmark.perf_allowed: - raise Exception("You don't have the needed permissions to use perf") + # check if we are allowed to use perf + if self.measure_cmd.startswith("perf"): + Benchmark.is_perf_allowed() # save one valid result to expand invalid results valid_result = {} |
