Skip to content
Snippets Groups Projects
Commit 14d7242e authored by Florian Fischer's avatar Florian Fischer
Browse files

fmt allocator.py with yapf

parent a42f1009
No related branches found
No related tags found
No related merge requests found
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with allocbench. If not, see <http://www.gnu.org/licenses/>. # along with allocbench. If not, see <http://www.gnu.org/licenses/>.
"""Alloactor related class definitions and helpers""" """Alloactor related class definitions and helpers"""
from datetime import datetime from datetime import datetime
...@@ -29,9 +28,9 @@ from src.artifact import ArchiveArtifact, GitArtifact ...@@ -29,9 +28,9 @@ from src.artifact import ArchiveArtifact, GitArtifact
import src.globalvars import src.globalvars
from src.util import print_status, print_debug, print_error, print_info2, run_cmd from src.util import print_status, print_debug, print_error, print_info2, run_cmd
LIBRARY_PATH = "" LIBRARY_PATH = ""
for line in run_cmd(["ldconfig", "-v", "-N"], capture=True).stdout.splitlines(): for line in run_cmd(["ldconfig", "-v", "-N"],
capture=True).stdout.splitlines():
if not line.startswith('\t'): if not line.startswith('\t'):
LIBRARY_PATH += line LIBRARY_PATH += line
...@@ -50,9 +49,10 @@ class Allocator: ...@@ -50,9 +49,10 @@ class Allocator:
patches, and instructions to build the allocator. patches, and instructions to build the allocator.
Allocator.build will compile the allocator and produce a for allocbench usable Allocator.build will compile the allocator and produce a for allocbench usable
allocator dict""" allocator dict"""
allowed_attributes = ["binary_suffix", "cmd_prefix", "LD_PRELOAD", "LD_LIBRARY_PATH", "color", allowed_attributes = [
"sources", "version", "patches", "prepare_cmds", "binary_suffix", "cmd_prefix", "LD_PRELOAD", "LD_LIBRARY_PATH",
"build_cmds"] "color", "sources", "version", "patches", "prepare_cmds", "build_cmds"
]
def __init__(self, name, **kwargs): def __init__(self, name, **kwargs):
self.class_file = inspect.getfile(self.__class__) self.class_file = inspect.getfile(self.__class__)
...@@ -93,12 +93,16 @@ class Allocator: ...@@ -93,12 +93,16 @@ class Allocator:
print_status(f"Patching {self.name} ...") print_status(f"Patching {self.name} ...")
for patch in self.patches: for patch in self.patches:
with open(patch.format(patchdir=self.patchdir), "r") as patch_file: with open(patch.format(patchdir=self.patchdir),
"r") as patch_file:
patch_content = patch_file.read() patch_content = patch_file.read()
# check if patch is already applied # check if patch is already applied
already_patched = run_cmd(["patch", "-R", "-p0", "-s", "-f", "--dry-run"], already_patched = run_cmd(
cwd=cwd, input=patch_content, check=False).returncode ["patch", "-R", "-p0", "-s", "-f", "--dry-run"],
cwd=cwd,
input=patch_content,
check=False).returncode
if not already_patched: if not already_patched:
try: try:
run_cmd(["patch", "-p0"], cwd=cwd, input=patch_content) run_cmd(["patch", "-p0"], cwd=cwd, input=patch_content)
...@@ -126,7 +130,8 @@ class Allocator: ...@@ -126,7 +130,8 @@ class Allocator:
print_info2("Old build found. Comparing build time with mtime") print_info2("Old build found. Comparing build time with mtime")
with open(buildtimestamp_path, "r") as buildtimestamp_file: with open(buildtimestamp_path, "r") as buildtimestamp_file:
timestamp = datetime.fromtimestamp(float(buildtimestamp_file.read())) timestamp = datetime.fromtimestamp(
float(buildtimestamp_file.read()))
modtime = os.stat(self.class_file).st_mtime modtime = os.stat(self.class_file).st_mtime
modtime = datetime.fromtimestamp(modtime) modtime = datetime.fromtimestamp(modtime)
...@@ -134,7 +139,8 @@ class Allocator: ...@@ -134,7 +139,8 @@ class Allocator:
build_needed = timestamp < modtime build_needed = timestamp < modtime
print_debug("Time of last build:", timestamp.isoformat()) print_debug("Time of last build:", timestamp.isoformat())
print_debug("Last modification of allocators file:", modtime.isoformat()) print_debug("Last modification of allocators file:",
modtime.isoformat())
print_info2("" if build_needed else "No " + "build needed") print_info2("" if build_needed else "No " + "build needed")
if build_needed: if build_needed:
...@@ -158,11 +164,13 @@ class Allocator: ...@@ -158,11 +164,13 @@ class Allocator:
buildtimestamp_file.write(str(datetime.now().timestamp())) buildtimestamp_file.write(str(datetime.now().timestamp()))
print_info2("Create allocator dictionary") print_info2("Create allocator dictionary")
res_dict = {"cmd_prefix": self.cmd_prefix or "", res_dict = {
"cmd_prefix": self.cmd_prefix or "",
"binary_suffix": self.binary_suffix or "", "binary_suffix": self.binary_suffix or "",
"LD_PRELOAD": self.LD_PRELOAD or "", "LD_PRELOAD": self.LD_PRELOAD or "",
"LD_LIBRARY_PATH": self.LD_LIBRARY_PATH or "", "LD_LIBRARY_PATH": self.LD_LIBRARY_PATH or "",
"color": self.color} "color": self.color
}
for attr in ["LD_PRELOAD", "LD_LIBRARY_PATH", "cmd_prefix"]: for attr in ["LD_PRELOAD", "LD_LIBRARY_PATH", "cmd_prefix"]:
value = getattr(self, attr, "") or "" value = getattr(self, attr, "") or ""
...@@ -187,6 +195,7 @@ def read_allocators_collection_file(alloc_path): ...@@ -187,6 +195,7 @@ def read_allocators_collection_file(alloc_path):
print_error("No global dictionary 'allocators' in", alloc_path) print_error("No global dictionary 'allocators' in", alloc_path)
return {} return {}
def collect_allocators(allocators): def collect_allocators(allocators):
"""Collect allocators to benchmark """Collect allocators to benchmark
...@@ -224,8 +233,11 @@ def collect_allocators(allocators): ...@@ -224,8 +233,11 @@ def collect_allocators(allocators):
for alloc in module.allocators: for alloc in module.allocators:
ret[alloc.name] = alloc.build() ret[alloc.name] = alloc.build()
# name is single allocator # name is single allocator
elif issubclass(getattr(module, name).__class__, src.allocator.Allocator): elif issubclass(
getattr(module, name).__class__, src.allocator.Allocator):
ret[name] = getattr(module, name).build() ret[name] = getattr(module, name).build()
else: else:
print_error(name, "is neither a python file or a known allocator definition.") print_error(
name,
"is neither a python file or a known allocator definition.")
return ret return ret
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment