Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Framework/Core/src/runDataProcessing.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "Framework/ParallelContext.h"
#include "Framework/RawDeviceService.h"
#include "Framework/SimpleRawDeviceService.h"
#define O2_SIGNPOST_DEFINE_CONTEXT
#include "Framework/Signpost.h"
#include "Framework/TextControlService.h"
#include "Framework/CallbackService.h"
Expand Down Expand Up @@ -1223,6 +1224,7 @@ int doMain(int argc, char** argv, o2::framework::WorkflowSpec const& workflow,
std::vector<ConfigParamSpec> const& currentWorkflowOptions,
o2::framework::ConfigContext& configContext)
{
O2_SIGNPOST_INIT();
std::vector<std::string> currentArgs;
for (size_t ai = 1; ai < argc; ++ai) {
currentArgs.push_back(argv[ai]);
Expand Down
5 changes: 5 additions & 0 deletions Framework/Foundation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,8 @@ o2_add_test(test_CompilerBuiltins NAME test_FrameworkFoundation_CompilerBuiltins
COMPONENT_NAME FrameworkFoundation
SOURCES test/test_CompilerBuiltins.cxx
PUBLIC_LINK_LIBRARIES O2::FrameworkFoundation)

o2_add_test(test_Signpost NAME test_FrameworkFoundation_Signpost
COMPONENT_NAME FrameworkFoundation
SOURCES test/test_Signpost.cxx
PUBLIC_LINK_LIBRARIES O2::FrameworkFoundation)
50 changes: 41 additions & 9 deletions Framework/Foundation/include/Framework/Signpost.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,67 @@
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#ifndef o2_framework_Signpost_H_INCLUDED
#define o2_framework_Signpost_H_INCLUDED
#ifndef O2_FRAMEWORK_SIGNPOST_H_
#define O2_FRAMEWORK_SIGNPOST_H_

#include <cstdint>

/// Compatibility layer for kdebug_signpost like API. This will improve
/// profiling experience in Instruments. I think something similar can be
/// achieved on Linux using sys/sdt.h.
#if __has_include(<sys/kdebug_signpost.h>) // This will be true Mojave onwards
/// Signpost API implemented using different techonologies:
///
/// * macOS 10.15 onwards os_signpost
/// * macOS 10.14 and below (either kdebug_signpost or kdebug)
/// * linux SystemTap
///
/// Supported systems will have O2_SIGNPOST_API_AVAILABLE defined.
///
/// In order to use it, one must define O2_SIGNPOST_DEFINE_CONTEXT in at least one cxx file,
/// include "Framework/Signpost.h" and invoke O2_SIGNPOST_INIT().
#if defined(__APPLE__) && __has_include(<os/signpost.h>) && (__MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_10_15)
#include <os/signpost.h>
#include <os/log.h>
#ifdef OS_LOG_TARGET_HAS_10_15_FEATURES
#define O2_SIGNPOST_TYPE OS_LOG_CATEGORY_DYNAMIC_TRACING
#else
#define O2_SIGNPOST_TYPE OS_LOG_CATEGORY_POINTS_OF_INTEREST
#endif
#ifdef O2_SIGNPOST_DEFINE_CONTEXT
os_log_t gDPLLog = 0;
#else
static os_log_t gDPLLog;
#endif
#define O2_SIGNPOST_INIT() gDPLLog = os_log_create("ch.cern.alice.dpl", O2_SIGNPOST_TYPE);
#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)
#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)
#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)
#define O2_SIGNPOST_API_AVAILABLE
#elif defined(__APPLE__) && __has_include(<sys/kdebug_signpost.h>) && (__MAC_OS_X_VERSION_MAX_ALLOWED < __MAC_10_15) // Deprecated in Catalina
#include <sys/kdebug_signpost.h>
#define O2_SIGNPOST_INIT()
#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)
#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)
#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)
#elif __has_include(<sys/kdebug.h>) // Compatibility with old API
#define O2_SIGNPOST_API_AVAILABLE
#elif defined(__APPLE__) && __has_include(<sys/kdebug.h>) && (__MAC_OS_X_VERSION_MAX_ALLOWED < __MAC_10_15) // Compatibility with old API
#include <sys/kdebug.h>
#include <sys/syscall.h>
#include <unistd.h>
#ifndef SYS_kdebug_trace
#define SYS_kdebug_trace 180
#endif
#define O2_SIGNPOST_INIT()
#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);
#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);
#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);
#elif __has_include(<sys/sdt.h>) // This will be true on Linux if systemtap-std-dev / systemtap-std-devel
#define O2_SIGNPOST_API_AVAILABLE
#elif (!defined(__APPLE__)) && __has_include(<sys/sdt.h>) // Dtrace support is being dropped by Apple
#include <sys/sdt.h>
#define O2_SIGNPOST_INIT()
#define O2_SIGNPOST(code, arg1, arg2, arg3, arg4) STAP_PROBE4(dpl, probe##code, arg1, arg2, arg3, arg4)
#define O2_SIGNPOST_START(code, arg1, arg2, arg3, arg4) STAP_PROBE4(dpl, start_probe##code, arg1, arg2, arg3, arg4)
#define O2_SIGNPOST_END(code, arg1, arg2, arg3, arg4) STAP_PROBE4(dpl, stop_probe##code, arg1, arg2, arg3, arg4)
#define O2_SIGNPOST_API_AVAILABLE
#else // by default we do not do anything
#define O2_SIGNPOST_INIT()
#define O2_SIGNPOST(code, arg1, arg2, arg3, arg4)
#define O2_SIGNPOST_START(code, arg1, arg2, arg3, arg4)
#define O2_SIGNPOST_END(code, arg1, arg2, arg3, arg4)
Expand Down Expand Up @@ -82,4 +114,4 @@ struct StateMonitoring {
inline static uint32_t level = 0;
};

#endif // o2_framework_Signpost_H_INCLUDED
#endif // O2_FRAMEWORK_SIGNPOST_H_
23 changes: 23 additions & 0 deletions Framework/Foundation/test/test_Signpost.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

#include <iostream>
#define O2_SIGNPOST_DEFINE_CONTEXT
#include "Framework/Signpost.h"

int main(int argc, char** argv)
{
// To be run inside some profiler (e.g. instruments) to make sure it actually
// works.
O2_SIGNPOST_INIT();
O2_SIGNPOST(dpl, 1000, 0, 0, 0);
O2_SIGNPOST_START(dpl, 1, 0, 0, 0);
O2_SIGNPOST_END(dpl, 1, 0, 0, 0);
}