Skip to content

Commit

Permalink
DPL: remove need for special engineering type
Browse files Browse the repository at this point in the history
We can simply use Instruments one and convert them to something sensible when
using the FairLogger implementation.
  • Loading branch information
ktf committed Jan 11, 2024
1 parent 8d12ff8 commit b41d10b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Framework/Core/src/runDataProcessing.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ void processChildrenOutput(DriverInfo& driverInfo,
}

O2_SIGNPOST_ID_FROM_POINTER(sid, driver, &info);
O2_SIGNPOST_START(driver, sid, "bytes_processed", "bytes processed by " O2_ENG_TYPE(pid, "d"), info.pid);
O2_SIGNPOST_START(driver, sid, "bytes_processed", "bytes processed by %{xcode:pid}d", info.pid);

std::string_view s = info.unprinted;
size_t pos = 0;
Expand Down Expand Up @@ -848,7 +848,7 @@ void processChildrenOutput(DriverInfo& driverInfo,
size_t oldSize = info.unprinted.size();
info.unprinted = std::string(s);
int64_t bytesProcessed = oldSize - info.unprinted.size();
O2_SIGNPOST_END(driver, sid, "bytes_processed", "bytes processed by " O2_ENG_TYPE(network - size - in - bytes, PRIi64), bytesProcessed);
O2_SIGNPOST_END(driver, sid, "bytes_processed", "bytes processed by %{xcode:network-size-in-bytes}" PRIi64, bytesProcessed);
}
}

Expand Down
48 changes: 36 additions & 12 deletions Framework/Foundation/include/Framework/Signpost.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,39 @@
#define O2_FRAMEWORK_SIGNPOST_H_

#include <atomic>
#include <array>

struct o2_log_handle_t {
char const* name = nullptr;
void* log = nullptr;
o2_log_handle_t* next = nullptr;
};

// Helper function which replaces engineering types with a printf
// compatible format string.
template <auto N>
constexpr auto remove_engineering_type(char const (&src)[N]) {
std::array<char, N> res = {};
// do whatever string manipulation you want in res.
char *t = res.data();
for (int i = 0; i < N; ++i) {
if (src[i] == '%' && src[i+1] == '{')
{
*t++ = src[i];
while (src[i] != '}' && src[i] != 0) {
++i;
}
if (src[i] == 0) {
*t = 0;
return res;
}
} else {
*t++ = src[i];
}
}
return res;
}

// Loggers registry is actually a feature available to all platforms
// We use this to register the loggers and to walk over them.
// So that also on mac we can have a list of all the registered loggers.
Expand Down Expand Up @@ -71,10 +97,10 @@ void* _o2_log_create(char const* name, char const* category);
#define O2_LOG_DEBUG(log, ...) os_log_debug(private_o2_log_##log, __VA_ARGS__)
#define O2_SIGNPOST_ID_FROM_POINTER(name, log, pointer) os_signpost_id_t name = os_signpost_id_make_with_pointer(private_o2_log_##log, pointer)
#define O2_SIGNPOST_ID_GENERATE(name, log) os_signpost_id_t name = os_signpost_id_generate(private_o2_log_##log)
#define O2_SIGNPOST_EVENT_EMIT(log, id, name, ...) os_signpost_event_emit(private_o2_log_##log, id, name, __VA_ARGS__)
#define O2_SIGNPOST_START(log, id, name, ...) os_signpost_interval_begin(private_o2_log_##log, id, name, __VA_ARGS__)
#define O2_SIGNPOST_END(log, id, name, ...) os_signpost_interval_end(private_o2_log_##log, id, name, __VA_ARGS__)
#define O2_ENG_TYPE(x, what) "%{xcode:" #x "}" what
// FIXME: use __VA_OPT__ when available in C++20
#define O2_SIGNPOST_EVENT_EMIT(log, id, name, format, ...) os_signpost_event_emit(private_o2_log_##log, id, name, format, ##__VA_ARGS__)
#define O2_SIGNPOST_START(log, id, name, format, ...) os_signpost_interval_begin(private_o2_log_##log, id, name, format, ##__VA_ARGS__)
#define O2_SIGNPOST_END(log, id, name, format, ...) os_signpost_interval_end(private_o2_log_##log, id, name, format, ##__VA_ARGS__)

#ifdef O2_SIGNPOST_IMPLEMENTATION
/// We use a wrapper so that we can keep track of the logs.
Expand Down Expand Up @@ -465,10 +491,9 @@ void _o2_log_set_stacktrace(_o2_log_t* log, int stacktrace)
#define O2_LOG_DEBUG(log, ...) O2_LOG_MACRO(__VA_ARGS__)
#define O2_SIGNPOST_ID_FROM_POINTER(name, log, pointer) _o2_signpost_id_t name = _o2_signpost_id_make_with_pointer(private_o2_log_##log, pointer)
#define O2_SIGNPOST_ID_GENERATE(name, log) _o2_signpost_id_t name = _o2_signpost_id_generate_local(private_o2_log_##log)
#define O2_SIGNPOST_EVENT_EMIT(log, id, name, ...) _o2_signpost_event_emit(private_o2_log_##log, id, name, __VA_ARGS__)
#define O2_SIGNPOST_START(log, id, name, ...) _o2_signpost_interval_begin(private_o2_log_##log, id, name, __VA_ARGS__)
#define O2_SIGNPOST_END(log, id, name, ...) _o2_signpost_interval_end(private_o2_log_##log, id, name, __VA_ARGS__)
#define O2_ENG_TYPE(x, what) "%" what
#define O2_SIGNPOST_EVENT_EMIT(log, id, name, format, ...) _o2_signpost_event_emit(private_o2_log_##log, id, name, remove_engineering_type(format).data(), ##__VA_ARGS__)
#define O2_SIGNPOST_START(log, id, name, format, ...) _o2_signpost_interval_begin(private_o2_log_##log, id, name, remove_engineering_type(format).data(), ##__VA_ARGS__)
#define O2_SIGNPOST_END(log, id, name, format, ...) _o2_signpost_interval_end(private_o2_log_##log, id, name, remove_engineering_type(format).data(), ##__VA_ARGS__)
#else // This is the release implementation, it does nothing.
#define O2_DECLARE_DYNAMIC_LOG(x)
#define O2_DECLARE_DYNAMIC_STACKTRACE_LOG(x)
Expand All @@ -478,10 +503,9 @@ void _o2_log_set_stacktrace(_o2_log_t* log, int stacktrace)
#define O2_LOG_DEBUG(log, ...)
#define O2_SIGNPOST_ID_FROM_POINTER(name, log, pointer)
#define O2_SIGNPOST_ID_GENERATE(name, log)
#define O2_SIGNPOST_EVENT_EMIT(log, id, name, ...)
#define O2_SIGNPOST_START(log, id, name, ...)
#define O2_SIGNPOST_END(log, id, name, ...)
#define O2_ENG_TYPE(x)
#define O2_SIGNPOST_EVENT_EMIT(log, id, name, format, ...)
#define O2_SIGNPOST_START(log, id, name, format, ...)
#define O2_SIGNPOST_END(log, id, name, format, ...)
#endif

#endif // O2_FRAMEWORK_SIGNPOST_H_
2 changes: 1 addition & 1 deletion Framework/Foundation/test/test_Signpost.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ int main(int argc, char** argv)

// This has an engineering type, which we will not use on Linux / FairLogger
O2_SIGNPOST_ID_FROM_POINTER(id4, test_Signpost, &id3);
O2_SIGNPOST_START(test_Signpost, id4, "Test category", "A signpost with an engineering type formatter " O2_ENG_TYPE(size - in - bytes, "d"), 1);
O2_SIGNPOST_START(test_Signpost, id4, "Test category", "A signpost with an engineering type formatter %{size-in-bytes}d", 1);
O2_SIGNPOST_END(test_Signpost, id4, "Test category", "A signpost interval from a pointer");

O2_SIGNPOST_START(test_SignpostDynamic, id, "Test category", "This is dynamic signpost which you will not see, because they are off by default");
Expand Down
2 changes: 1 addition & 1 deletion Framework/Foundation/test/test_SignpostLogger.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ int main(int argc, char** argv)

// This has an engineering type, which we will not use on Linux / FairLogger
O2_SIGNPOST_ID_FROM_POINTER(id4, test_Signpost, &id3);
O2_SIGNPOST_START(test_Signpost, id4, "Test category", "A signpost with an engineering type formatter " O2_ENG_TYPE(size - in - bytes, "d"), 1);
O2_SIGNPOST_START(test_Signpost, id4, "Test category", "A signpost with an engineering type formatter %{size-in-bytes}d", 1);
O2_SIGNPOST_END(test_Signpost, id4, "Test category", "A signpost interval from a pointer");

O2_SIGNPOST_START(test_SignpostDynamic, id, "Test category", "This is dynamic signpost which you will not see, because they are off by default");
Expand Down

0 comments on commit b41d10b

Please sign in to comment.