|
7 | 7 | // In applying this license CERN does not waive the privileges and immunities |
8 | 8 | // granted to it by virtue of its status as an Intergovernmental Organization |
9 | 9 | // or submit itself to any jurisdiction. |
10 | | -#ifndef o2_framework_Signpost_H_INCLUDED |
11 | | -#define o2_framework_Signpost_H_INCLUDED |
| 10 | +#ifndef O2_FRAMEWORK_SIGNPOST_H_ |
| 11 | +#define O2_FRAMEWORK_SIGNPOST_H_ |
12 | 12 |
|
13 | 13 | #include <cstdint> |
14 | 14 |
|
15 | | -/// Compatibility layer for kdebug_signpost like API. This will improve |
16 | | -/// profiling experience in Instruments. I think something similar can be |
17 | | -/// achieved on Linux using sys/sdt.h. |
18 | | -#if __has_include(<sys/kdebug_signpost.h>) // This will be true Mojave onwards |
| 15 | +/// Signpost API implemented using different techonologies: |
| 16 | +/// |
| 17 | +/// * macOS 10.15 onwards os_signpost |
| 18 | +/// * macOS 10.14 and below (either kdebug_signpost or kdebug) |
| 19 | +/// * linux SystemTap |
| 20 | +/// |
| 21 | +/// Supported systems will have O2_SIGNPOST_API_AVAILABLE defined. |
| 22 | +/// |
| 23 | +/// In order to use it, one must define O2_SIGNPOST_DEFINE_CONTEXT in at least one cxx file, |
| 24 | +/// include "Framework/Signpost.h" and invoke O2_SIGNPOST_INIT(). |
| 25 | +#if defined(__APPLE__) && __has_include(<os/signpost.h>) && (__MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_10_15) |
| 26 | +#include <os/signpost.h> |
| 27 | +#include <os/log.h> |
| 28 | +#ifdef OS_LOG_TARGET_HAS_10_15_FEATURES |
| 29 | +#define O2_SIGNPOST_TYPE OS_LOG_CATEGORY_DYNAMIC_TRACING |
| 30 | +#else |
| 31 | +#define O2_SIGNPOST_TYPE OS_LOG_CATEGORY_POINTS_OF_INTEREST |
| 32 | +#endif |
| 33 | +#ifdef O2_SIGNPOST_DEFINE_CONTEXT |
| 34 | +os_log_t gDPLLog = 0; |
| 35 | +#else |
| 36 | +static os_log_t gDPLLog; |
| 37 | +#endif |
| 38 | +#define O2_SIGNPOST_INIT() gDPLLog = os_log_create("ch.cern.alice.dpl", O2_SIGNPOST_TYPE); |
| 39 | +#define O2_SIGNPOST(code, arg1, arg2, arg3, color) os_signpost_event_emit(gDPLLog, OS_SIGNPOST_ID_EXCLUSIVE, "##code", "%lu %lu %lu %lu", (uintptr_t)arg1, (uintptr_t)arg2, (uintptr_t)arg3, (uintptr_t)color) |
| 40 | +#define O2_SIGNPOST_START(code, interval_id, arg2, arg3, color) os_signpost_interval_begin(gDPLLog, (os_signpost_id_t)interval_id, "##code", "%lu %lu %lu", (uintptr_t)arg2, (uintptr_t)arg3, (uintptr_t)color) |
| 41 | +#define O2_SIGNPOST_END(code, interval_id, arg2, arg3, color) os_signpost_interval_end(gDPLLog, (os_signpost_id_t)interval_id, "##code", "%lu %lu %lu", (uintptr_t)arg2, (uintptr_t)arg3, (uintptr_t)color) |
| 42 | +#define O2_SIGNPOST_API_AVAILABLE |
| 43 | +#elif defined(__APPLE__) && __has_include(<sys/kdebug_signpost.h>) && (__MAC_OS_X_VERSION_MAX_ALLOWED < __MAC_10_15) // Deprecated in Catalina |
19 | 44 | #include <sys/kdebug_signpost.h> |
| 45 | +#define O2_SIGNPOST_INIT() |
20 | 46 | #define O2_SIGNPOST(code, arg1, arg2, arg3, color) kdebug_signpost((uint32_t)code, (uintptr_t)arg1, (uintptr_t)arg2, (uintptr_t)arg3, (uintptr_t)color) |
21 | 47 | #define O2_SIGNPOST_START(code, interval_id, arg2, arg3, color) kdebug_signpost_start((uint32_t)code, (uintptr_t)interval_id, (uintptr_t)arg2, (uintptr_t)arg3, (uintptr_t)color) |
22 | 48 | #define O2_SIGNPOST_END(code, interval_id, arg2, arg3, color) kdebug_signpost_end((uint32_t)code, (uintptr_t)interval_id, (uintptr_t)arg2, (uintptr_t)arg3, (uintptr_t)color) |
23 | | -#elif __has_include(<sys/kdebug.h>) // Compatibility with old API |
| 49 | +#define O2_SIGNPOST_API_AVAILABLE |
| 50 | +#elif defined(__APPLE__) && __has_include(<sys/kdebug.h>) && (__MAC_OS_X_VERSION_MAX_ALLOWED < __MAC_10_15) // Compatibility with old API |
24 | 51 | #include <sys/kdebug.h> |
25 | 52 | #include <sys/syscall.h> |
26 | 53 | #include <unistd.h> |
27 | 54 | #ifndef SYS_kdebug_trace |
28 | 55 | #define SYS_kdebug_trace 180 |
29 | 56 | #endif |
| 57 | +#define O2_SIGNPOST_INIT() |
30 | 58 | #define O2_SIGNPOST(code, arg1, arg2, arg3, arg4) syscall(SYS_kdebug_trace, APPSDBG_CODE(DBG_MACH_CHUD, (uint32_t)code) | DBG_FUNC_NONE, (uintptr_t)arg1, (uintptr_t)arg2, (uintptr_t)arg3, (uintptr_t)arg4); |
31 | 59 | #define O2_SIGNPOST_START(code, arg1, arg2, arg3, arg4) syscall(SYS_kdebug_trace, APPSDBG_CODE(DBG_MACH_CHUD, (uint32_t)code) | DBG_FUNC_START, (uintptr_t)arg1, (uintptr_t)arg2, (uintptr_t)arg3, (uintptr_t)arg4); |
32 | 60 | #define O2_SIGNPOST_END(code, arg1, arg2, arg3, arg4) syscall(SYS_kdebug_trace, APPSDBG_CODE(DBG_MACH_CHUD, (uintptr_t)code) | DBG_FUNC_END, (uintptr_t)arg1, (uintptr_t)arg2, (uintptr_t)arg3, (uintptr_t)arg4); |
33 | | -#elif __has_include(<sys/sdt.h>) // This will be true on Linux if systemtap-std-dev / systemtap-std-devel |
| 61 | +#define O2_SIGNPOST_API_AVAILABLE |
| 62 | +#elif (!defined(__APPLE__)) && __has_include(<sys/sdt.h>) // Dtrace support is being dropped by Apple |
34 | 63 | #include <sys/sdt.h> |
| 64 | +#define O2_SIGNPOST_INIT() |
35 | 65 | #define O2_SIGNPOST(code, arg1, arg2, arg3, arg4) STAP_PROBE4(dpl, probe##code, arg1, arg2, arg3, arg4) |
36 | 66 | #define O2_SIGNPOST_START(code, arg1, arg2, arg3, arg4) STAP_PROBE4(dpl, start_probe##code, arg1, arg2, arg3, arg4) |
37 | 67 | #define O2_SIGNPOST_END(code, arg1, arg2, arg3, arg4) STAP_PROBE4(dpl, stop_probe##code, arg1, arg2, arg3, arg4) |
| 68 | +#define O2_SIGNPOST_API_AVAILABLE |
38 | 69 | #else // by default we do not do anything |
| 70 | +#define O2_SIGNPOST_INIT() |
39 | 71 | #define O2_SIGNPOST(code, arg1, arg2, arg3, arg4) |
40 | 72 | #define O2_SIGNPOST_START(code, arg1, arg2, arg3, arg4) |
41 | 73 | #define O2_SIGNPOST_END(code, arg1, arg2, arg3, arg4) |
@@ -82,4 +114,4 @@ struct StateMonitoring { |
82 | 114 | inline static uint32_t level = 0; |
83 | 115 | }; |
84 | 116 |
|
85 | | -#endif // o2_framework_Signpost_H_INCLUDED |
| 117 | +#endif // O2_FRAMEWORK_SIGNPOST_H_ |
0 commit comments