Skip to content

Commit

Permalink
DPL: allow printing stacktrace on signposts
Browse files Browse the repository at this point in the history
  • Loading branch information
ktf committed Sep 4, 2024
1 parent 64c47f6 commit 8e63310
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
17 changes: 14 additions & 3 deletions Framework/Core/src/runDataProcessing.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2741,9 +2741,20 @@ void enableSignposts(std::string const& signpostsToEnable)
auto* log = (_o2_log_t*)l;
auto* selectedName = (char const*)context;
std::string prefix = "ch.cern.aliceo2.";
if (strcmp(name, (prefix + selectedName).data()) == 0) {
LOGP(info, "Enabling signposts for stream \"ch.cern.aliceo2.{}\"", selectedName);
_o2_log_set_stacktrace(log, 1);
auto* last = strchr(selectedName, ':');
int maxDepth = 1;
if (last) {
char* err;
maxDepth = strtol(last + 1, &err, 10);
if (*(last + 1) == '\0' || *err != '\0') {
maxDepth = 1;
}
}

auto fullName = prefix + std::string{selectedName, last ? last - selectedName : strlen(selectedName)};
if (strncmp(name, fullName.data(), fullName.size()) == 0) {
LOGP(info, "Enabling signposts for stream \"{}\" with depth {}.", fullName, maxDepth);
_o2_log_set_stacktrace(log, maxDepth);
return false;
} else {
LOGP(info, "Signpost stream \"{}\" disabled. Enable it with o2-log -p {} -a {}", name, pid, (void*)&log->stacktrace);
Expand Down
3 changes: 2 additions & 1 deletion Framework/Foundation/include/Framework/Signpost.h
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,8 @@ void _o2_signpost_event_emit(_o2_log_t* log, _o2_signpost_id_t id, char const* n
O2_LOG_MACRO("%s", prebuffer);
if (log->stacktrace > 1) {
void* traces[o2::framework::BacktraceHelpers::MAX_BACKTRACE_SIZE];
int maxBacktrace = backtrace(traces, o2::framework::BacktraceHelpers::MAX_BACKTRACE_SIZE);
// We add one extra frame, because one is for the logging
int maxBacktrace = backtrace(traces, (log->stacktrace + 1) < o2::framework::BacktraceHelpers::MAX_BACKTRACE_SIZE ? (log->stacktrace + 1) : o2::framework::BacktraceHelpers::MAX_BACKTRACE_SIZE);
o2::framework::BacktraceHelpers::demangled_backtrace_symbols(traces, maxBacktrace, STDERR_FILENO);
}
}
Expand Down

0 comments on commit 8e63310

Please sign in to comment.