File tree Expand file tree Collapse file tree 5 files changed +69
-4
lines changed Expand file tree Collapse file tree 5 files changed +69
-4
lines changed Original file line number Diff line number Diff line change
1
+ // ===--- TracingCommon.h - Common code for runtime/Concurrency -----*- C++ -*-//
2
+ //
3
+ // This source file is part of the Swift.org open source project
4
+ //
5
+ // Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
6
+ // Licensed under Apache License v2.0 with Runtime Library Exception
7
+ //
8
+ // See https://swift.org/LICENSE.txt for license information
9
+ // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10
+ //
11
+ // ===----------------------------------------------------------------------===//
12
+ //
13
+ // Support code shared between swiftCore and swift_Concurrency.
14
+ //
15
+ // ===----------------------------------------------------------------------===//
16
+
17
+ #ifndef SWIFT_TRACING_COMMON_H
18
+ #define SWIFT_TRACING_COMMON_H
19
+
20
+ #if SWIFT_STDLIB_TRACING
21
+
22
+ #include " swift/Runtime/Config.h"
23
+ #include < os/signpost.h>
24
+
25
+ extern const char *__progname;
26
+
27
+ namespace swift {
28
+ namespace runtime {
29
+ namespace trace {
30
+
31
+ static inline bool shouldEnableTracing () {
32
+ if (!SWIFT_RUNTIME_WEAK_CHECK (os_signpost_enabled))
33
+ return false ;
34
+ if (__progname && (strcmp (__progname, " logd" ) == 0 ||
35
+ strcmp (__progname, " diagnosticd" ) == 0 ||
36
+ strcmp (__progname, " notifyd" ) == 0 ))
37
+ return false ;
38
+ return true ;
39
+ }
40
+
41
+ } // namespace trace
42
+ } // namespace runtime
43
+ } // namespace swift
44
+
45
+ #endif
46
+
47
+ #endif // SWIFT_TRACING_H
Original file line number Diff line number Diff line change 17
17
#if SWIFT_STDLIB_CONCURRENCY_TRACING
18
18
19
19
#include " TracingSignpost.h"
20
+ #include " swift/Runtime/TracingCommon.h"
20
21
#include < stdio.h>
21
22
22
23
#define SWIFT_LOG_CONCURRENCY_SUBSYSTEM " com.apple.swift.concurrency"
@@ -30,8 +31,15 @@ namespace trace {
30
31
os_log_t ActorLog;
31
32
os_log_t TaskLog;
32
33
swift::once_t LogsToken;
34
+ bool TracingEnabled;
33
35
34
36
void setupLogs (void *unused) {
37
+ if (!swift::runtime::trace::shouldEnableTracing ()) {
38
+ TracingEnabled = false ;
39
+ return ;
40
+ }
41
+
42
+ TracingEnabled = true ;
35
43
ActorLog = os_log_create (SWIFT_LOG_CONCURRENCY_SUBSYSTEM,
36
44
SWIFT_LOG_ACTOR_CATEGORY);
37
45
TaskLog = os_log_create (SWIFT_LOG_CONCURRENCY_SUBSYSTEM,
Original file line number Diff line number Diff line change @@ -70,6 +70,7 @@ namespace trace {
70
70
extern os_log_t ActorLog;
71
71
extern os_log_t TaskLog;
72
72
extern swift::once_t LogsToken;
73
+ extern bool TracingEnabled;
73
74
74
75
void setupLogs (void *unused);
75
76
@@ -78,9 +79,9 @@ void setupLogs(void *unused);
78
79
// optimized out.
79
80
#define ENSURE_LOGS (...) \
80
81
do { \
81
- if (!SWIFT_RUNTIME_WEAK_CHECK (os_signpost_enabled)) \
82
- return __VA_ARGS__; \
83
82
swift::once (LogsToken, setupLogs, nullptr ); \
83
+ if (!TracingEnabled) \
84
+ return __VA_ARGS__; \
84
85
} while (0 )
85
86
86
87
// Every function does ENSURE_LOGS() before making any os_signpost calls, so
Original file line number Diff line number Diff line change 15
15
// ===----------------------------------------------------------------------===//
16
16
17
17
#include " Tracing.h"
18
+ #include " swift/Runtime/TracingCommon.h"
18
19
19
20
#if SWIFT_STDLIB_TRACING
20
21
@@ -27,8 +28,15 @@ namespace trace {
27
28
28
29
os_log_t ScanLog;
29
30
swift::once_t LogsToken;
31
+ bool TracingEnabled;
30
32
31
33
void setupLogs (void *unused) {
34
+ if (!shouldEnableTracing ()) {
35
+ TracingEnabled = false ;
36
+ return ;
37
+ }
38
+
39
+ TracingEnabled = true ;
32
40
ScanLog = os_log_create (SWIFT_LOG_SUBSYSTEM, SWIFT_LOG_SECTION_SCAN_CATEGORY);
33
41
}
34
42
Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ namespace trace {
34
34
35
35
extern os_log_t ScanLog;
36
36
extern swift::once_t LogsToken;
37
+ extern bool TracingEnabled;
37
38
38
39
void setupLogs (void *unused);
39
40
@@ -48,9 +49,9 @@ void setupLogs(void *unused);
48
49
// optimized out.
49
50
#define ENSURE_LOG (log ) \
50
51
do { \
51
- if (!SWIFT_RUNTIME_WEAK_CHECK (os_signpost_enabled)) \
52
- return {}; \
53
52
swift::once (LogsToken, setupLogs, nullptr ); \
53
+ if (!TracingEnabled) \
54
+ return {}; \
54
55
} while (0 )
55
56
56
57
// / A struct that captures the state of a scan tracing signpost. When the scan
You can’t perform that action at this time.
0 commit comments