Skip to content
Snippets Groups Projects
Verified Commit 898062bd authored by Simon Schwitanski's avatar Simon Schwitanski :slight_smile:
Browse files

Add stack path depth patch

parent 2d103921
No related branches found
No related tags found
No related merge requests found
Pipeline #396486 passed
...@@ -115,6 +115,7 @@ RUN cd MUST-v${MUST_VERSION} && \ ...@@ -115,6 +115,7 @@ RUN cd MUST-v${MUST_VERSION} && \
patch externals/typeart/scripts/typeart-wrapper.in < /patches/typeart-fpic.patch && \ patch externals/typeart/scripts/typeart-wrapper.in < /patches/typeart-fpic.patch && \
patch modules/MpiTypeArt/MpiTypeArt.cpp < /patches/typeart-output.patch && \ patch modules/MpiTypeArt/MpiTypeArt.cpp < /patches/typeart-output.patch && \
patch -p1 < /patches/relative-paths.patch && \ patch -p1 < /patches/relative-paths.patch && \
patch -p1 < /patches/stack-path-depth.patch && \
cd build && \ cd build && \
CC=clang CXX=clang++ MPICH_CC=clang MPICH_CXX=clang++ OMPI_CC=clang OMPI_CXX=clang \ CC=clang CXX=clang++ MPICH_CC=clang MPICH_CXX=clang++ OMPI_CC=clang OMPI_CXX=clang \
cmake .. -DCMAKE_INSTALL_PREFIX=/opt/must -DUSE_BACKWARD=ON -DENABLE_TESTS=ON -DENABLE_FORTRAN=ON -DLLVM_FILECHECK_PATH=$(which FileCheck) -DCMAKE_BUILD_TYPE=Release && \ cmake .. -DCMAKE_INSTALL_PREFIX=/opt/must -DUSE_BACKWARD=ON -DENABLE_TESTS=ON -DENABLE_FORTRAN=ON -DLLVM_FILECHECK_PATH=$(which FileCheck) -DCMAKE_BUILD_TYPE=Release && \
......
diff --git a/modules/MustBase/InitLocationId.cpp b/modules/MustBase/InitLocationId.cpp
index 202cf077..184b61f7 100644
--- a/modules/MustBase/InitLocationId.cpp
+++ b/modules/MustBase/InitLocationId.cpp
@@ -72,6 +72,12 @@ InitLocationId::InitLocationId(const char* instanceName)
<< std::endl;
assert(0);
}
+
+ myStackPathDepth = -1;
+ const char* depth_str = std::getenv("MUST_STACKTRACE_PATH_DEPTH");
+ if (depth_str != nullptr) {
+ myStackPathDepth = std::atoi(depth_str);
+ }
}
//=============================
@@ -90,6 +96,31 @@ InitLocationId::~InitLocationId()
}
}
+std::string InitLocationId::truncatePath(int height, std::string path)
+{
+ if (height <= 0)
+ return std::string(path);
+
+ auto rit = path.rbegin();
+ std::string::size_type pos = path.length();
+ int path_separator_count = 0;
+ // search for path separators backwards and abort if height is reached
+ while (path_separator_count < height) {
+ pos = path.rfind('/', pos - 1);
+ if (pos == std::string::npos) {
+ pos = 0;
+ break;
+ } else {
+ path_separator_count++;
+ }
+ }
+
+ if (pos > 0) // prepend truncation sequence
+ return "[...]" + path.substr(pos, path.length());
+ else
+ return std::string(path);
+}
+
//=============================
// init
//=============================
@@ -186,7 +217,7 @@ GTI_ANALYSIS_RETURN InitLocationId::init(MustLocationId* pStorage, const char* c
thisFullLocation.stack.emplace_back(trace.object_filename, trace.object_function);
} else {
thisFullLocation.stack.emplace_back(
- trace.source.filename,
+ truncatePath(myStackPathDepth, trace.source.filename),
trace.source.function,
std::to_string(trace.source.line));
}
diff --git a/modules/MustBase/InitLocationId.h b/modules/MustBase/InitLocationId.h
index 2aee6407..d1fdc01f 100644
--- a/modules/MustBase/InitLocationId.h
+++ b/modules/MustBase/InitLocationId.h
@@ -68,6 +68,10 @@ class InitLocationId : public gti::ModuleBase<InitLocationId, I_InitLocationId>
I_GenerateLocationId* myGenLId;
handleNewLocationP myNewLocFct;
+ private:
+ int myStackPathDepth;
+ std::string truncatePath(int length, std::string path);
+
#ifdef ENABLE_STACKTRACE
/**
* Helper function to call the handleNewLocation call when we use the callpath module
--
2.39.1
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment