Skip to content

Commit 04dede6

Browse files
authored
Update logging and tracing implementation (#121)
* Update Logging implementation * Update ThreadUtils and add test case * Add Tracing.libraryName * Add TracingTests * Update Signpost * Update traceInternal and traceBody * Fix iOS build issue * Fix test case issue * Fix CI issue
1 parent 99479b1 commit 04dede6

File tree

16 files changed

+829
-211
lines changed

16 files changed

+829
-211
lines changed

.github/workflows/compatibility_tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ jobs:
3232
- name: Run compatibility tests on OpenSwiftUI + macOS
3333
run: |
3434
swift test \
35+
--filter OpenSwiftUICompatibilityTests \
3536
--build-path .build-compatibility-test-debug
3637
env:
3738
OPENSWIFTUI_COMPATIBILITY_TEST: 0
3839
- name: Run compatibility tests on SwiftUI + macOS
3940
run: |
4041
swift test \
42+
--filter OpenSwiftUICompatibilityTests \
4143
--build-path .build-compatibility-test-debug
4244
env:
4345
OPENSWIFTUI_COMPATIBILITY_TEST: 1
@@ -69,6 +71,7 @@ jobs:
6971
run: swift --version
7072
- name: Run compatibility tests on OpenSwiftUI + iOS
7173
run: |
74+
# FIXME: xcodebuild will run all test targets.
7275
xcodebuild test \
7376
-scheme OpenSwiftUI \
7477
-configuration Debug \

Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
//
2+
// kdebug_Private.h
3+
// COpenSwiftUICore
4+
//
5+
// Audited for RELEASE_2024
6+
// Status: Complete
7+
8+
#ifndef kdebug_Private_h
9+
#define kdebug_Private_h
10+
11+
#include "OpenSwiftUIBase.h"
12+
13+
#if OPENSWIFTUI_TARGET_OS_DARWIN
14+
15+
/*
16+
* Copyright (c) 2000-2018 Apple Inc. All rights reserved.
17+
*
18+
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
19+
*
20+
* This file contains Original Code and/or Modifications of Original Code
21+
* as defined in and that are subject to the Apple Public Source License
22+
* Version 2.0 (the 'License'). You may not use this file except in
23+
* compliance with the License. The rights granted to you under the License
24+
* may not be used to create, or enable the creation or redistribution of,
25+
* unlawful or unlicensed copies of an Apple operating system, or to
26+
* circumvent, violate, or enable the circumvention or violation of, any
27+
* terms of an Apple operating system software license agreement.
28+
*
29+
* Please obtain a copy of the License at
30+
* http://www.opensource.apple.com/apsl/ and read it before using this file.
31+
*
32+
* The Original Code and all software distributed under the License are
33+
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
34+
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
35+
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
36+
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
37+
* Please see the License for the specific language governing rights and
38+
* limitations under the License.
39+
*
40+
* @APPLE_OSREFERENCE_LICENSE_HEADER_END@
41+
*/
42+
43+
#include <stdint.h>
44+
#include <stdbool.h>
45+
#include <sys/cdefs.h>
46+
47+
#if OPENSWIFTUI_TARGET_OS_OSX
48+
#include <sys/kdebug.h>
49+
#endif
50+
51+
#include <Availability.h>
52+
53+
#pragma mark - user space SPI
54+
55+
/*
56+
* OS components can use the full precision of the "code" field
57+
* (Class, SubClass, Code) to inject events using kdebug_trace() by
58+
* using:
59+
*
60+
* kdebug_trace(KDBG_CODE(DBG_XPC, 15, 1) | DBG_FUNC_NONE, 1, 2, 3, 4);
61+
*
62+
* These trace points can be included in production code, since they
63+
* use reserved, non-overlapping ranges. The performance impact when
64+
* kernel tracing is not enabled is minimal. However, when tracing is enabled,
65+
* each tracepoint becomes a syscall. For this reason, os_signpost(3) is
66+
* recommended instead of kdebug_trace(2).
67+
*
68+
* Classes can be reserved by filing a Radar in xnu | ktrace.
69+
*
70+
* 64-bit arguments may be truncated if the system is using a 32-bit
71+
* kernel.
72+
*
73+
* On error, -1 will be returned and errno will indicate the error.
74+
*/
75+
OPENSWIFTUI_EXPORT int kdebug_trace(uint32_t code, uint64_t arg1, uint64_t arg2, uint64_t arg3,
76+
uint64_t arg4)
77+
__OSX_AVAILABLE(10.10) __IOS_AVAILABLE(8.2);
78+
79+
/*!
80+
* @function kdebug_trace_string
81+
*
82+
* @discussion
83+
* This function emits strings to kdebug trace along with an ID and allows
84+
* for previously-traced strings to be overwritten and invalidated.
85+
*
86+
* To start tracing a string and generate an ID to use to refer to it:
87+
*
88+
* string_id = kdebug_trace_string(debugid, 0, "string");
89+
*
90+
* To replace a string previously traced:
91+
*
92+
* string_id = kdebug_trace_string(debugid, string_id, "new string");
93+
*
94+
* To invalidate a string ID:
95+
*
96+
* string_id = kdebug_trace_string(debugid, string_id, NULL);
97+
*
98+
* To check for errors:
99+
*
100+
* if ((int64_t)string_id == -1) { perror("string error") }
101+
*
102+
* @param debugid
103+
* The `debugid` to check if its enabled before tracing and include as
104+
* an argument in the event containing the string.
105+
*
106+
* Some classes or subclasses are reserved for specific uses and are not
107+
* allowed to be used with this function. No function qualifiers are
108+
* allowed on `debugid`.
109+
*
110+
* @param str_id
111+
* When 0, a new ID will be generated and returned if tracing is
112+
* enabled.
113+
*
114+
* Otherwise `str_id` must contain an ID that was previously generated
115+
* with this function. Clents should pass NULL in `str` if `str_id`
116+
* is no longer in use. Otherwise, the string previously mapped to
117+
* `str_id` will be overwritten with the contents of `str`.
118+
*
119+
* @param str
120+
* A NUL-terminated 'C' string containing the characters that should be
121+
* traced alongside `str_id`.
122+
*
123+
* If necessary, the string will be truncated at an
124+
* implementation-defined length. The string must not be the empty
125+
* string, but can be NULL if a valid `str_id` is provided.
126+
*
127+
* @return
128+
* 0 if tracing is disabled or `debugid` is being filtered out of trace.
129+
* It can also return (int64_t)-1 if an error occured. Otherwise,
130+
* it returns the ID to use to refer to the string in future
131+
* kdebug_trace(2) calls.
132+
*
133+
* The errors that can occur are:
134+
*
135+
* EINVAL
136+
* There are function qualifiers on `debugid`, `str` is empty, or
137+
* `str_id` was not generated by this function.
138+
* EPERM
139+
* The `debugid`'s class or subclass is reserved for internal use.
140+
* EFAULT
141+
* `str` is an invalid address or NULL when `str_id` is 0.
142+
*/
143+
OPENSWIFTUI_EXPORT uint64_t kdebug_trace_string(uint32_t debugid, uint64_t str_id,
144+
const char *str)
145+
__OSX_AVAILABLE(10.11) __IOS_AVAILABLE(9.0);
146+
147+
/*
148+
* Although the performance impact of kdebug_trace() when kernel
149+
* tracing is not enabled is minimal, it may require the caller to
150+
* perform an expensive calculation/summarization. This cost can be
151+
* skipped by checking the kdebug_is_enabled() predicate:
152+
*
153+
* if (kdebug_is_enabled(KDBG_CODE(DBG_XPC, 15, 1))) {
154+
* uint64_t arg1 = ...;
155+
* uint64_t arg2 = ...;
156+
* kdebug_trace(KDBG_CODE(DBG_XPC, 15, 1) | DBG_FUNC_NONE, arg1, arg2, 0, 0);
157+
* }
158+
*
159+
* If tracing is enabled for the code at the time of the check, 1
160+
* will be returned. Otherwise, 0 will be returned.
161+
*/
162+
OPENSWIFTUI_EXPORT bool kdebug_is_enabled(uint32_t code)
163+
__OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0)
164+
__WATCHOS_AVAILABLE(3.0) __TVOS_AVAILABLE(10.0);
165+
166+
#endif
167+
168+
#endif /* kdebug_Private_h */

Sources/OpenSwiftUI/Core/Log/Log.swift

Lines changed: 0 additions & 79 deletions
This file was deleted.

Sources/OpenSwiftUI/Core/Log/Signpost.swift

Lines changed: 0 additions & 87 deletions
This file was deleted.

Sources/OpenSwiftUI/Core/Update/Update.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ enum Update {
7777

7878
let actions = Update.actions
7979
Update.actions = []
80-
performOnMainThread {
80+
onMainThread {
8181
// TODO: Signpost.postUpdateActions
8282
begin()
8383
for action in actions {

0 commit comments

Comments
 (0)