Skip to content

Commit fea116b

Browse files
authored
DPL Foundation: add support for macOS o2_signpost API [O2-1054] (#2824)
1 parent 522a328 commit fea116b

File tree

4 files changed

+71
-9
lines changed

4 files changed

+71
-9
lines changed

Framework/Core/src/runDataProcessing.cxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "Framework/ParallelContext.h"
3535
#include "Framework/RawDeviceService.h"
3636
#include "Framework/SimpleRawDeviceService.h"
37+
#define O2_SIGNPOST_DEFINE_CONTEXT
3738
#include "Framework/Signpost.h"
3839
#include "Framework/TextControlService.h"
3940
#include "Framework/CallbackService.h"
@@ -1223,6 +1224,7 @@ int doMain(int argc, char** argv, o2::framework::WorkflowSpec const& workflow,
12231224
std::vector<ConfigParamSpec> const& currentWorkflowOptions,
12241225
o2::framework::ConfigContext& configContext)
12251226
{
1227+
O2_SIGNPOST_INIT();
12261228
std::vector<std::string> currentArgs;
12271229
for (size_t ai = 1; ai < argc; ++ai) {
12281230
currentArgs.push_back(argv[ai]);

Framework/Foundation/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,8 @@ o2_add_test(test_CompilerBuiltins NAME test_FrameworkFoundation_CompilerBuiltins
2929
COMPONENT_NAME FrameworkFoundation
3030
SOURCES test/test_CompilerBuiltins.cxx
3131
PUBLIC_LINK_LIBRARIES O2::FrameworkFoundation)
32+
33+
o2_add_test(test_Signpost NAME test_FrameworkFoundation_Signpost
34+
COMPONENT_NAME FrameworkFoundation
35+
SOURCES test/test_Signpost.cxx
36+
PUBLIC_LINK_LIBRARIES O2::FrameworkFoundation)

Framework/Foundation/include/Framework/Signpost.h

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,67 @@
77
// In applying this license CERN does not waive the privileges and immunities
88
// granted to it by virtue of its status as an Intergovernmental Organization
99
// 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_
1212

1313
#include <cstdint>
1414

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
1944
#include <sys/kdebug_signpost.h>
45+
#define O2_SIGNPOST_INIT()
2046
#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)
2147
#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)
2248
#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
2451
#include <sys/kdebug.h>
2552
#include <sys/syscall.h>
2653
#include <unistd.h>
2754
#ifndef SYS_kdebug_trace
2855
#define SYS_kdebug_trace 180
2956
#endif
57+
#define O2_SIGNPOST_INIT()
3058
#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);
3159
#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);
3260
#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
3463
#include <sys/sdt.h>
64+
#define O2_SIGNPOST_INIT()
3565
#define O2_SIGNPOST(code, arg1, arg2, arg3, arg4) STAP_PROBE4(dpl, probe##code, arg1, arg2, arg3, arg4)
3666
#define O2_SIGNPOST_START(code, arg1, arg2, arg3, arg4) STAP_PROBE4(dpl, start_probe##code, arg1, arg2, arg3, arg4)
3767
#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
3869
#else // by default we do not do anything
70+
#define O2_SIGNPOST_INIT()
3971
#define O2_SIGNPOST(code, arg1, arg2, arg3, arg4)
4072
#define O2_SIGNPOST_START(code, arg1, arg2, arg3, arg4)
4173
#define O2_SIGNPOST_END(code, arg1, arg2, arg3, arg4)
@@ -82,4 +114,4 @@ struct StateMonitoring {
82114
inline static uint32_t level = 0;
83115
};
84116

85-
#endif // o2_framework_Signpost_H_INCLUDED
117+
#endif // O2_FRAMEWORK_SIGNPOST_H_
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
#include <iostream>
12+
#define O2_SIGNPOST_DEFINE_CONTEXT
13+
#include "Framework/Signpost.h"
14+
15+
int main(int argc, char** argv)
16+
{
17+
// To be run inside some profiler (e.g. instruments) to make sure it actually
18+
// works.
19+
O2_SIGNPOST_INIT();
20+
O2_SIGNPOST(dpl, 1000, 0, 0, 0);
21+
O2_SIGNPOST_START(dpl, 1, 0, 0, 0);
22+
O2_SIGNPOST_END(dpl, 1, 0, 0, 0);
23+
}

0 commit comments

Comments
 (0)