Skip to content

Commit b41cb33

Browse files
authored
DPL: remove need for special engineering type (#12515)
We can simply use Instruments one and convert them to something sensible when using the FairLogger implementation.
1 parent f8956cf commit b41cb33

4 files changed

Lines changed: 40 additions & 16 deletions

File tree

Framework/Core/src/runDataProcessing.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ void processChildrenOutput(DriverInfo& driverInfo,
800800
}
801801

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

805805
std::string_view s = info.unprinted;
806806
size_t pos = 0;
@@ -848,7 +848,7 @@ void processChildrenOutput(DriverInfo& driverInfo,
848848
size_t oldSize = info.unprinted.size();
849849
info.unprinted = std::string(s);
850850
int64_t bytesProcessed = oldSize - info.unprinted.size();
851-
O2_SIGNPOST_END(driver, sid, "bytes_processed", "bytes processed by " O2_ENG_TYPE(network - size - in - bytes, PRIi64), bytesProcessed);
851+
O2_SIGNPOST_END(driver, sid, "bytes_processed", "bytes processed by %{xcode:network-size-in-bytes}" PRIi64, bytesProcessed);
852852
}
853853
}
854854

Framework/Foundation/include/Framework/Signpost.h

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,39 @@
1212
#define O2_FRAMEWORK_SIGNPOST_H_
1313

1414
#include <atomic>
15+
#include <array>
1516

1617
struct o2_log_handle_t {
1718
char const* name = nullptr;
1819
void* log = nullptr;
1920
o2_log_handle_t* next = nullptr;
2021
};
2122

23+
// Helper function which replaces engineering types with a printf
24+
// compatible format string.
25+
template <auto N>
26+
constexpr auto remove_engineering_type(char const (&src)[N])
27+
{
28+
std::array<char, N> res = {};
29+
// do whatever string manipulation you want in res.
30+
char* t = res.data();
31+
for (int i = 0; i < N; ++i) {
32+
if (src[i] == '%' && src[i + 1] == '{') {
33+
*t++ = src[i];
34+
while (src[i] != '}' && src[i] != 0) {
35+
++i;
36+
}
37+
if (src[i] == 0) {
38+
*t = 0;
39+
return res;
40+
}
41+
} else {
42+
*t++ = src[i];
43+
}
44+
}
45+
return res;
46+
}
47+
2248
// Loggers registry is actually a feature available to all platforms
2349
// We use this to register the loggers and to walk over them.
2450
// So that also on mac we can have a list of all the registered loggers.
@@ -71,10 +97,10 @@ void* _o2_log_create(char const* name, char const* category);
7197
#define O2_LOG_DEBUG(log, ...) os_log_debug(private_o2_log_##log, __VA_ARGS__)
7298
#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)
7399
#define O2_SIGNPOST_ID_GENERATE(name, log) os_signpost_id_t name = os_signpost_id_generate(private_o2_log_##log)
74-
#define O2_SIGNPOST_EVENT_EMIT(log, id, name, ...) os_signpost_event_emit(private_o2_log_##log, id, name, __VA_ARGS__)
75-
#define O2_SIGNPOST_START(log, id, name, ...) os_signpost_interval_begin(private_o2_log_##log, id, name, __VA_ARGS__)
76-
#define O2_SIGNPOST_END(log, id, name, ...) os_signpost_interval_end(private_o2_log_##log, id, name, __VA_ARGS__)
77-
#define O2_ENG_TYPE(x, what) "%{xcode:" #x "}" what
100+
// FIXME: use __VA_OPT__ when available in C++20
101+
#define O2_SIGNPOST_EVENT_EMIT(log, id, name, format, ...) os_signpost_event_emit(private_o2_log_##log, id, name, format, ##__VA_ARGS__)
102+
#define O2_SIGNPOST_START(log, id, name, format, ...) os_signpost_interval_begin(private_o2_log_##log, id, name, format, ##__VA_ARGS__)
103+
#define O2_SIGNPOST_END(log, id, name, format, ...) os_signpost_interval_end(private_o2_log_##log, id, name, format, ##__VA_ARGS__)
78104

79105
#ifdef O2_SIGNPOST_IMPLEMENTATION
80106
/// We use a wrapper so that we can keep track of the logs.
@@ -465,10 +491,9 @@ void _o2_log_set_stacktrace(_o2_log_t* log, int stacktrace)
465491
#define O2_LOG_DEBUG(log, ...) O2_LOG_MACRO(__VA_ARGS__)
466492
#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)
467493
#define O2_SIGNPOST_ID_GENERATE(name, log) _o2_signpost_id_t name = _o2_signpost_id_generate_local(private_o2_log_##log)
468-
#define O2_SIGNPOST_EVENT_EMIT(log, id, name, ...) _o2_signpost_event_emit(private_o2_log_##log, id, name, __VA_ARGS__)
469-
#define O2_SIGNPOST_START(log, id, name, ...) _o2_signpost_interval_begin(private_o2_log_##log, id, name, __VA_ARGS__)
470-
#define O2_SIGNPOST_END(log, id, name, ...) _o2_signpost_interval_end(private_o2_log_##log, id, name, __VA_ARGS__)
471-
#define O2_ENG_TYPE(x, what) "%" what
494+
#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__)
495+
#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__)
496+
#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__)
472497
#else // This is the release implementation, it does nothing.
473498
#define O2_DECLARE_DYNAMIC_LOG(x)
474499
#define O2_DECLARE_DYNAMIC_STACKTRACE_LOG(x)
@@ -478,10 +503,9 @@ void _o2_log_set_stacktrace(_o2_log_t* log, int stacktrace)
478503
#define O2_LOG_DEBUG(log, ...)
479504
#define O2_SIGNPOST_ID_FROM_POINTER(name, log, pointer)
480505
#define O2_SIGNPOST_ID_GENERATE(name, log)
481-
#define O2_SIGNPOST_EVENT_EMIT(log, id, name, ...)
482-
#define O2_SIGNPOST_START(log, id, name, ...)
483-
#define O2_SIGNPOST_END(log, id, name, ...)
484-
#define O2_ENG_TYPE(x)
506+
#define O2_SIGNPOST_EVENT_EMIT(log, id, name, format, ...)
507+
#define O2_SIGNPOST_START(log, id, name, format, ...)
508+
#define O2_SIGNPOST_END(log, id, name, format, ...)
485509
#endif
486510

487511
#endif // O2_FRAMEWORK_SIGNPOST_H_

Framework/Foundation/test/test_Signpost.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ int main(int argc, char** argv)
3838

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

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

Framework/Foundation/test/test_SignpostLogger.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ int main(int argc, char** argv)
4646

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

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

0 commit comments

Comments
 (0)