From 7da35d6246bb799597f607a095be1fcd7098306c Mon Sep 17 00:00:00 2001 From: Lukas Rothenberger Date: Mon, 16 Dec 2024 17:48:14 +0100 Subject: [PATCH] feat: demangling reduction.txt --- .../PreProcessor/demangle/driver.py | 4 +- .../PreProcessor/demangle/reduction.py | 74 +++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 discopop_library/PreProcessor/demangle/reduction.py diff --git a/discopop_library/PreProcessor/demangle/driver.py b/discopop_library/PreProcessor/demangle/driver.py index 3996f3ddd..092ff4359 100644 --- a/discopop_library/PreProcessor/demangle/driver.py +++ b/discopop_library/PreProcessor/demangle/driver.py @@ -15,6 +15,7 @@ from discopop_library.PreProcessor.demangle.data_xml import demangle_data_xml from discopop_library.PreProcessor.demangle.dependency_metadata import demangle_dependency_metadata from discopop_library.PreProcessor.demangle.dynamic_dependencies import demangle_dynamic_dependencies +from discopop_library.PreProcessor.demangle.reduction import demangle_reduction from discopop_library.PreProcessor.demangle.static_dependencies import demangle_static_dependencies @@ -36,5 +37,6 @@ def demangle(arguments: PreProcessorArguments, parent_logger: logging.Logger) -> # dynamic_dependencies.txt # demangle_dynamic_dependencies(arguments, logger, cxxfilt_bin) # reduction.txt + demangle_reduction(arguments, logger, cxxfilt_bin) # static_dependencies.txt - demangle_static_dependencies(arguments, logger, cxxfilt_bin) + # demangle_static_dependencies(arguments, logger, cxxfilt_bin) diff --git a/discopop_library/PreProcessor/demangle/reduction.py b/discopop_library/PreProcessor/demangle/reduction.py new file mode 100644 index 000000000..3bc0e897f --- /dev/null +++ b/discopop_library/PreProcessor/demangle/reduction.py @@ -0,0 +1,74 @@ +# This file is part of the DiscoPoP software (http://www.discopop.tu-darmstadt.de) +# +# Copyright (c) 2020, Technische Universitaet Darmstadt, Germany +# +# This software may be modified and distributed under the terms of +# the 3-Clause BSD License. See the LICENSE file in the package base +# directory for details. + +import logging +import os +import re +from discopop_library.PreProcessor.PreProcessorArguments import PreProcessorArguments +from discopop_library.PreProcessor.demangle.utilities import demangle_tag + + +def demangle_reduction(arguments: PreProcessorArguments, parent_logger: logging.Logger, cxxfilt_bin: str) -> None: + logger = parent_logger.getChild("reduction.txt") + logger.info("Starting..") + + # check prerequisites + reduction_path = os.path.join(os.getcwd(), "profiler", "reduction.txt") + if not os.path.exists(reduction_path): + raise FileNotFoundError(reduction_path) + + processed_reduction_path = os.path.join(os.getcwd(), "profiler", "reduction.txt.processed") + + line_count = 0 + with open(reduction_path, "r") as f: + for line in f.readlines(): + line_count += 1 + + if os.path.exists(processed_reduction_path): + os.remove(processed_reduction_path) + + with open(processed_reduction_path, "w+") as of: + with open(reduction_path, "r") as f: + for idx, line in enumerate(f.readlines()): + if idx % 100 == 0: + logger.info("Progress: " + str(round((idx / line_count) * 100, 2)) + "%") + line = line.replace("\n", "") + orig_line = line + + tags = line.split(" ") + demangled_tags = [] + for tag in tags: + # reduce calls to llvm-cxxfilt + call_required = True + if tag in ["FileID", "Line", "Number", "Operation", "Name", "Reduction", "Variable"]: + call_required = False + + if call_required: + if tag.startswith("GEPRESULT_"): + demangled_tags.append( + "GEPRESULT_" + demangle_tag(tag.replace("GEPRESULT_", ""), logger, cxxfilt_bin) + ) + else: + demangled_tags.append(demangle_tag(tag, logger, cxxfilt_bin)) + else: + demangled_tags.append(tag) + + line = " ".join(demangled_tags) + + if len(orig_line) != len(line): + logger.debug("line " + str(idx) + " : " + orig_line) + logger.debug("line " + str(idx) + " : " + line) + logger.debug("") + + of.write(line + "\n") + + # overwrite reduction.txt + os.remove(reduction_path) + os.rename(processed_reduction_path, reduction_path) + + logger.info("Done.")