Skip to content

Commit

Permalink
feat: demangling reduction.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasrothenberger committed Dec 16, 2024
1 parent a7949b4 commit 7da35d6
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 1 deletion.
4 changes: 3 additions & 1 deletion discopop_library/PreProcessor/demangle/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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)
74 changes: 74 additions & 0 deletions discopop_library/PreProcessor/demangle/reduction.py
Original file line number Diff line number Diff line change
@@ -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.")

0 comments on commit 7da35d6

Please sign in to comment.