From 01eb3990beee75ed660fa25ca4766c93a75b141a Mon Sep 17 00:00:00 2001 From: Evan Wilde Date: Thu, 20 Nov 2025 08:17:47 -0800 Subject: [PATCH 1/2] CMake: Runtime: Enable tracing on Apple platforms Adding tracing to concurrency, and enable tracing on the standard library on Apple OSs. rdar://164925172 --- Runtimes/Core/CMakeLists.txt | 2 +- Runtimes/Core/Concurrency/CMakeLists.txt | 8 +++++++- .../Core/cmake/caches/Vendors/Apple/apple-common.cmake | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Runtimes/Core/CMakeLists.txt b/Runtimes/Core/CMakeLists.txt index ff22720b053f2..7a4fd2e06f07c 100644 --- a/Runtimes/Core/CMakeLists.txt +++ b/Runtimes/Core/CMakeLists.txt @@ -106,11 +106,11 @@ defaulted_option(SwiftCore_ENABLE_RUNTIME_OS_VERSIONING "Enable runtime OS versi defaulted_option(SwiftCore_ENABLE_STATIC_PRINT "Disable full print") defaulted_option(SwiftCore_ENABLE_COMPACT_ABSOLUTE_FUNCTION_POINTERS "Resolve absolute function pointer as identity") defaulted_option(SwiftCore_ENABLE_BACKDEPLOYMENT_SUPPORT "Add symbols for runtime backdeployment") -defaulted_option(SwiftCore_ENABLE_STDLIB_TRACING "Enable tracing in the runtime. Assumes the presence of os_log(3) and the os_signpost(3) API.") defaulted_option(SwiftCore_ENABLE_CONCURRENCY "Enable Concurrency runtime support") defaulted_option(SwiftCore_ENABLE_REMOTE_MIRROR "Enable RemoteMirror runtime support") defaulted_option(SwiftCore_ENABLE_DIRECT_RETAIN_RELEASE "Use direct retain release in the runtime/stdlib") defaulted_set(SwiftCore_CONCURRENCY_GLOBAL_EXECUTOR STRING "Default Concurrency global executor implementation") +option(SwiftCore_ENABLE_STDLIB_TRACING "Enable tracing in the runtime. Assumes the precense of os_log(3) and the os_signpost(3) API." OFF) option(SwiftCore_ENABLE_COMMANDLINE_SUPPORT "Enable command line argument support" ON) option(SwiftCore_ENABLE_UNICODE_DATA "Include unicode data in Swift runtimes" ON) option(SwiftCore_ENABLE_SHORT_MANGLING_LOOKUPS "Build with fast-path context descriptor lookups based on well-known short manglings." ON) diff --git a/Runtimes/Core/Concurrency/CMakeLists.txt b/Runtimes/Core/Concurrency/CMakeLists.txt index 5c6d845d2544a..333bd1f59e438 100644 --- a/Runtimes/Core/Concurrency/CMakeLists.txt +++ b/Runtimes/Core/Concurrency/CMakeLists.txt @@ -22,7 +22,6 @@ add_library(swift_Concurrency TaskLocal.cpp TaskStatus.cpp ThreadingError.cpp - TracingSignpost.cpp "${PROJECT_SOURCE_DIR}/CompatibilityOverride/CompatibilityOverride.cpp" "./linker-support/magic-symbols-for-install-name.c" Actor.swift @@ -99,6 +98,13 @@ add_library(swift_Concurrency "${CMAKE_CURRENT_BINARY_DIR}/TaskGroup+addTask.swift" "${CMAKE_CURRENT_BINARY_DIR}/Task+immediate.swift") +if(SwiftCore_ENABLE_STDLIB_TRACING) + target_compile_definitions(swift_Concurrency + PRIVATE SWIFT_STDLIB_CONCURRENCY_TRACING) + target_sources(swift_Concurrency + PRIVATE TracingSignpost.cpp) +endif() + if(APPLE) target_sources(swift_Concurrency PRIVATE CFExecutor.swift diff --git a/Runtimes/Core/cmake/caches/Vendors/Apple/apple-common.cmake b/Runtimes/Core/cmake/caches/Vendors/Apple/apple-common.cmake index abf1ecbb46827..a7cdd701030fc 100644 --- a/Runtimes/Core/cmake/caches/Vendors/Apple/apple-common.cmake +++ b/Runtimes/Core/cmake/caches/Vendors/Apple/apple-common.cmake @@ -13,6 +13,7 @@ set(SwiftCore_ENABLE_RUNTIME_FUNCTION_COUNTERS ON CACHE BOOL "") set(SwiftCore_ENABLE_BACKDEPLOYMENT_SUPPORT ON CACHE BOOL "") set(SwiftCore_ENABLE_FILESYSTEM_SUPPORT ON CACHE BOOL "") set(SwiftCore_ENABLE_STRICT_AVAILABILITY ON CACHE BOOL "") +set(SwiftCore_ENABLE_STDLIB_TRACING ON CACHE BOOL "") set(SwiftCore_OPTIMIZATION_REMARKS "bitstream" CACHE STRING "") From 20cfe0a4e0251a8e8390a71642e9387819b545c7 Mon Sep 17 00:00:00 2001 From: Evan Wilde Date: Thu, 20 Nov 2025 08:32:15 -0800 Subject: [PATCH 2/2] CMake: Verify os_signpost_*/os_log with tracing Adding check to CMake to verify that we have the os_signpost and os_log API available in order to accept enabling the runtime tracing. --- Runtimes/Core/CMakeLists.txt | 2 +- Runtimes/Core/runtime/CMakeLists.txt | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Runtimes/Core/CMakeLists.txt b/Runtimes/Core/CMakeLists.txt index 7a4fd2e06f07c..aa5755c8cf785 100644 --- a/Runtimes/Core/CMakeLists.txt +++ b/Runtimes/Core/CMakeLists.txt @@ -110,7 +110,7 @@ defaulted_option(SwiftCore_ENABLE_CONCURRENCY "Enable Concurrency runtime suppor defaulted_option(SwiftCore_ENABLE_REMOTE_MIRROR "Enable RemoteMirror runtime support") defaulted_option(SwiftCore_ENABLE_DIRECT_RETAIN_RELEASE "Use direct retain release in the runtime/stdlib") defaulted_set(SwiftCore_CONCURRENCY_GLOBAL_EXECUTOR STRING "Default Concurrency global executor implementation") -option(SwiftCore_ENABLE_STDLIB_TRACING "Enable tracing in the runtime. Assumes the precense of os_log(3) and the os_signpost(3) API." OFF) +option(SwiftCore_ENABLE_STDLIB_TRACING "Enable tracing in the runtime. Requires os_log(3) and the os_signpost(3) API." OFF) option(SwiftCore_ENABLE_COMMANDLINE_SUPPORT "Enable command line argument support" ON) option(SwiftCore_ENABLE_UNICODE_DATA "Include unicode data in Swift runtimes" ON) option(SwiftCore_ENABLE_SHORT_MANGLING_LOOKUPS "Build with fast-path context descriptor lookups based on well-known short manglings." ON) diff --git a/Runtimes/Core/runtime/CMakeLists.txt b/Runtimes/Core/runtime/CMakeLists.txt index 795852313f946..073de5f44fdc2 100644 --- a/Runtimes/Core/runtime/CMakeLists.txt +++ b/Runtimes/Core/runtime/CMakeLists.txt @@ -72,6 +72,14 @@ if(SwiftCore_ENABLE_FILESYSTEM_SUPPORT AND (NOT SwiftCore_ARCH_SUBDIR OR NOT Swi message(SEND_ERROR "Filesystem support requires setting `SwiftCore_ARCH_SUBDIR` and `SwiftCore_PLATFORM_SUBDIR`") endif() +if(SwiftCore_ENABLE_STDLIB_TRACING) + check_symbol_exists("os_signpost_interval_begin" "os/signpost.h" SwiftCore_HAS_OS_SIGNPOST) + check_symbol_exists("os_log" "os/log.h" SwiftCore_HAS_OS_LOG) + if(NOT SwiftCore_HAS_OS_LOG OR NOT SwiftCore_HAS_OS_SIGNPOST) + message(SEND_ERROR "Tracing requires 'os_signpost' and 'os_log' APIs") + endif() +endif() + # TODO: Probably worth considering putting half of these in a RuntimeConfig.h.in # file rather than pushing them through macro flags. target_compile_definitions(swiftRuntime