diff options
| author | Florian Fischer <florian.fl.fischer@fau.de> | 2020-05-06 16:56:32 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fl.fischer@fau.de> | 2020-06-02 11:18:47 +0200 |
| commit | 8174a918ea3b7cb216bf7ea98cfdc10661b5c37d (patch) | |
| tree | 0747ec3ccb9f8d7eeccfac35977fc17855ca3bbb /src/analyse.py | |
| parent | 8f52e8fc02dd235582f5961941bcd564e9a681cd (diff) | |
| download | allocbench-8174a918ea3b7cb216bf7ea98cfdc10661b5c37d.tar.gz allocbench-8174a918ea3b7cb216bf7ea98cfdc10661b5c37d.zip | |
make the whole project more python idiomatic
* rename src directory to allocbench
* make global variable names UPPERCASE
* format a lot of code using yapf
* use lowercase ld_preload and ld_library_path as Allocator members
* name expected Errors 'err' and don't raise a new Exception
* disable some pylint messages
Diffstat (limited to 'src/analyse.py')
| -rwxr-xr-x | src/analyse.py | 111 |
1 files changed, 0 insertions, 111 deletions
diff --git a/src/analyse.py b/src/analyse.py deleted file mode 100755 index bd08c98..0000000 --- a/src/analyse.py +++ /dev/null @@ -1,111 +0,0 @@ -#!/usr/bin/env python3 - -# Copyright 2018-2019 Florian Fischer <florian.fl.fischer@fau.de> -# -# This file is part of allocbench. -# -# allocbench is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# allocbench is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with allocbench. If not, see <http://www.gnu.org/licenses/>. -"""Analyze benchmarks and allocators""" - -import importlib -import os -import traceback - -from src.util import find_cmd -from src.util import print_status, print_warn, print_error -from src.util import print_info2, print_debug - -ANALYZSE_ALLOC_NAME = None -ANALYZSE_ALLOC_DICT = None - - -def build_analyze_alloc(): - """Select and build available analysis allocator""" - global ANALYZSE_ALLOC_NAME - global ANALYZSE_ALLOC_DICT - if ANALYZSE_ALLOC_DICT is not None: - return - - if find_cmd("malt") is not None: - ANALYZSE_ALLOC_NAME = "malt" - else: - print_warn("malt not found. Using chattymalloc.") - ANALYZSE_ALLOC_NAME = "chattymalloc" - - analyze_alloc_module = importlib.import_module( - f"src.allocators.{ANALYZSE_ALLOC_NAME}") - - ANALYZSE_ALLOC_DICT = getattr(analyze_alloc_module, - ANALYZSE_ALLOC_NAME).build() - - -def analyze_bench(bench): - """Analyse a single benchmark""" - print_status("Analysing {} ...".format(bench)) - - # Create benchmark result directory - if not os.path.isdir(bench.result_dir): - print_info2("Creating benchmark result dir:", bench.result_dir) - os.makedirs(bench.result_dir, exist_ok=True) - - build_analyze_alloc() - - old_allocs = bench.allocators - old_measure_cmd = bench.measure_cmd - bench.measure_cmd = "" - bench.allocators = {ANALYZSE_ALLOC_NAME: ANALYZSE_ALLOC_DICT} - - try: - bench.run(runs=1) - except Exception: - print_debug(traceback.format_exc()) - print_error("Skipping analysis of", bench, "!") - - bench.measure_cmd = old_measure_cmd - - # Remove results for analyze_alloc - if ANALYZSE_ALLOC_NAME in bench.results: - del bench.results[ANALYZSE_ALLOC_NAME] - if "stats" in bench.results and ANALYZSE_ALLOC_NAME in bench.results[ - "stats"]: - del bench.results["stats"][ANALYZSE_ALLOC_NAME] - - # restore allocs - bench.allocators = old_allocs - - -def analyze_allocators(bench, allocators): - """Analyse a single benchmark for each allocator in allocators""" - # build analyzse allocator before globaly setting LD_PRELOAD - build_analyze_alloc() - - for name, alloc in allocators.items(): - print_status(f"Analysing {name} during {bench} ...") - os.environ["LD_PRELOAD"] = alloc["LD_PRELOAD"] - analyze_bench(bench) - - # save the resulting trace - for perm in bench.iterate_args(): - if bench.servers == []: - if perm: - perm_fmt = ("{}-" * (len(perm) - 1) + "{}").format(*perm) - else: - perm_fmt = "" - else: - perm_fmt = ANALYZSE_ALLOC_NAME - - old_trace = os.path.join(bench.result_dir, f"{perm_fmt}.trace") - new_trace = os.path.join(bench.result_dir, - f"{name}_{perm_fmt}.trace") - os.rename(old_trace, new_trace) |
