aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fl.fischer@fau.de>2020-05-06 16:56:32 +0200
committerFlorian Fischer <florian.fl.fischer@fau.de>2020-06-02 11:18:47 +0200
commit8174a918ea3b7cb216bf7ea98cfdc10661b5c37d (patch)
tree0747ec3ccb9f8d7eeccfac35977fc17855ca3bbb /scripts
parent8f52e8fc02dd235582f5961941bcd564e9a681cd (diff)
downloadallocbench-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 'scripts')
-rwxr-xr-xscripts/histogram.py29
-rwxr-xr-xscripts/paper_plots.py42
-rwxr-xr-xscripts/print_facts.py13
3 files changed, 53 insertions, 31 deletions
diff --git a/scripts/histogram.py b/scripts/histogram.py
index 2dd3b6c..5bca21c 100755
--- a/scripts/histogram.py
+++ b/scripts/histogram.py
@@ -1,5 +1,22 @@
#!/usr/bin/env python3
+# Copyright 2018-2020 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/>.
+
"""Plot an interactive histogram from malt or chattymalloc output file"""
import argparse
@@ -15,7 +32,6 @@ currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentfram
parentdir = os.path.dirname(currentdir)
sys.path.insert(0, parentdir)
-import src.chattyparser
def main():
parser = argparse.ArgumentParser(description="Plot histograms using a malt or chattymalloc output file")
@@ -30,11 +46,16 @@ def main():
fname = os.path.basename(fpath)
# chattymalloc
if fname.startswith("chatty") and fext == ".txt":
- hist, calls, _ = src.chattyparser.parse(args.input_file, coll_size=False)
+ try:
+ chattyparser = importlib.import_module("chattyparser")
+ except ModuleNotFoundError as err:
+ print("Can't import chattyparser")
+ sys.exit(1)
+ hist, calls, _ = chattyparser.parse(args.input_file, coll_size=False)
# malt
else:
with open(args.input_file, "r") as json_file:
- malt_res = json.load(json_file)
+ malt_res = json.load(json_file)
hist = malt_res["memStats"]["sizeMap"]
calls = {}
@@ -49,7 +70,7 @@ def main():
print(size, amount, file=csv_file)
if not args.no_ascii:
- src.chattyparser.plot_hist_ascii(f"{fpath}.hist.txt", hist, calls)
+ chattyparser.plot_hist_ascii(f"{fpath}.hist.txt", hist, calls)
if args.interactive:
sizes = []
diff --git a/scripts/paper_plots.py b/scripts/paper_plots.py
index 9b15220..d1aad21 100755
--- a/scripts/paper_plots.py
+++ b/scripts/paper_plots.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
-# Copyright 2018-2019 Florian Fischer <florian.fl.fischer@fau.de>
+# Copyright 2018-2020 Florian Fischer <florian.fl.fischer@fau.de>
#
# This file is part of allocbench.
#
@@ -28,17 +28,17 @@ currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentfram
parentdir = os.path.dirname(currentdir)
sys.path.insert(0, parentdir)
-import src.allocators.paper
-import src.facter
-import src.globalvars
-import src.plots as plt
-from src.util import print_status, print_warn, print_error
-from src.util import print_license_and_exit
+from allocbench.allocators.paper import allocators as paper_allocators
+import allocbench.facter as facter
+import allocbench.globalvars
+import allocbench.plots as plt
+from allocbench.util import print_status, print_warn, print_error
+from allocbench.util import print_license_and_exit
-ALLOCATOR_NAMES = [a.name for a in src.allocators.paper.allocators]
-SURVEY_ALLOCATORS = [a.name for a in src.allocators.paper.allocators if not '-' in a.name or a.name not in ["speedymalloc", "bumpptr"]]
-TCMALLOCS = [a.name for a in src.allocators.paper.allocators if a.name.startswith("TCMalloc")]
-ALIGNED_ALLOCATORS = [a.name for a in src.allocators.paper.allocators if a.name.endswith("-Aligned")]
+ALLOCATOR_NAMES = [a.name for a in paper_allocators]
+SURVEY_ALLOCATORS = [a.name for a in paper_allocators if not '-' in a.name or a.name not in ["speedymalloc", "bumpptr"]]
+TCMALLOCS = [a.name for a in paper_allocators if a.name.startswith("TCMalloc")]
+ALIGNED_ALLOCATORS = [a.name for a in paper_allocators if a.name.endswith("-Aligned")]
def falsesharing_plots(falsesharing):
@@ -110,8 +110,8 @@ def blowup_plots(blowup):
bar=True)
def loop_plots(loop):
- args = blowup.results["args"]
- loop.results["allocators"] = {k: v for k, v in blowup.results["allocators"].items() if k in ALLOCATOR_NAMES}
+ args = loop.results["args"]
+ loop.results["allocators"] = {k: v for k, v in loop.results["allocators"].items() if k in ALLOCATOR_NAMES}
plt.pgfplot(loop,
loop.iterate_args_fixed({"threads": 40}, args),
@@ -178,7 +178,7 @@ def summarize(benchmarks=None, exclude_benchmarks=None):
if exclude_benchmarks and benchmark in exclude_benchmarks:
continue
- bench_module = importlib.import_module(f"src.benchmarks.{benchmark}")
+ bench_module = importlib.import_module(f"allocbench.benchmarks.{benchmark}")
if not hasattr(bench_module, benchmark):
print_error(f"{benchmark} has no member {benchmark}")
@@ -187,14 +187,14 @@ def summarize(benchmarks=None, exclude_benchmarks=None):
bench = getattr(bench_module, benchmark)
try:
- bench.load(src.globalvars.resdir)
+ bench.load(allocbench.globalvars.resdir)
except FileNotFoundError:
print_warn(f"Skipping {bench.name}. No results found")
continue
print_status(f"Summarizing {bench.name} ...")
- res_dir = os.path.join(src.globalvars.resdir, bench.name, "paper")
+ res_dir = os.path.join(allocbench.globalvars.resdir, bench.name, "paper")
if not os.path.isdir(res_dir):
os.makedirs(res_dir)
os.chdir(res_dir)
@@ -212,7 +212,7 @@ if __name__ == "__main__":
parser.add_argument("--version",
help="print version info and exit",
action='version',
- version=f"allocbench {src.facter.allocbench_version()}")
+ version=f"allocbench {facter.allocbench_version()}")
parser.add_argument("-v", "--verbose", help="more output", action='count')
parser.add_argument("-b",
"--benchmarks",
@@ -229,19 +229,19 @@ if __name__ == "__main__":
args = parser.parse_args()
if args.verbose:
- src.globalvars.verbosity = args.verbose
+ allocbench.globalvars.verbosity = args.verbose
if args.latex_preamble:
- src.globalvars.latex_custom_preamble = args.latex_preamble
+ allocbench.globalvars.latex_custom_preamble = args.latex_preamble
if not os.path.isdir(args.results):
print_error(f"{args.results} is no directory")
sys.exit(1)
- src.globalvars.resdir = args.results
+ allocbench.globalvars.resdir = args.results
# Load facts
- src.facter.load_facts(src.globalvars.resdir)
+ facter.load_facts(allocbench.globalvars.resdir)
summarize(benchmarks=args.benchmarks,
exclude_benchmarks=args.exclude_benchmarks)
diff --git a/scripts/print_facts.py b/scripts/print_facts.py
index 831cc78..389028e 100755
--- a/scripts/print_facts.py
+++ b/scripts/print_facts.py
@@ -29,9 +29,10 @@ CURRENTDIR = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentfram
PARENTDIR = os.path.dirname(CURRENTDIR)
sys.path.insert(0, PARENTDIR)
-import src.facter
-from src.plots import print_facts, print_common_facts
-from src.util import print_error
+import allocbench.facter as facter
+from allocbench.globalvars import BENCHMARKS
+from allocbench.plots import print_facts, print_common_facts
+from allocbench.util import print_error
def main():
@@ -40,15 +41,15 @@ def main():
args = parser.parse_args()
# Load common facts
- src.facter.load_facts(args.results)
+ facter.load_facts(args.results)
print_common_facts()
cwd = os.getcwd()
os.chdir(args.results)
- for benchmark in src.globalvars.benchmarks:
- bench_module = importlib.import_module(f"src.benchmarks.{benchmark}")
+ for benchmark in BENCHMARKS:
+ bench_module = importlib.import_module(f"allocbench.benchmarks.{benchmark}")
if not hasattr(bench_module, benchmark):
print_error(f"{benchmark} has no member {benchmark}")