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 1717#if SWIFT_STDLIB_CONCURRENCY_TRACING
1818
1919#include " TracingSignpost.h"
20+ #include " swift/Runtime/TracingCommon.h"
2021#include < stdio.h>
2122
2223#define SWIFT_LOG_CONCURRENCY_SUBSYSTEM " com.apple.swift.concurrency"
@@ -30,8 +31,15 @@ namespace trace {
3031os_log_t ActorLog;
3132os_log_t TaskLog;
3233swift::once_t LogsToken;
34+ bool TracingEnabled;
3335
3436void setupLogs (void *unused) {
37+ if (!swift::runtime::trace::shouldEnableTracing ()) {
38+ TracingEnabled = false ;
39+ return ;
40+ }
41+
42+ TracingEnabled = true ;
3543 ActorLog = os_log_create (SWIFT_LOG_CONCURRENCY_SUBSYSTEM,
3644 SWIFT_LOG_ACTOR_CATEGORY);
3745 TaskLog = os_log_create (SWIFT_LOG_CONCURRENCY_SUBSYSTEM,
Original file line number Diff line number Diff line change @@ -70,6 +70,7 @@ namespace trace {
7070extern os_log_t ActorLog;
7171extern os_log_t TaskLog;
7272extern swift::once_t LogsToken;
73+ extern bool TracingEnabled;
7374
7475void setupLogs (void *unused);
7576
@@ -78,9 +79,9 @@ void setupLogs(void *unused);
7879// optimized out.
7980#define ENSURE_LOGS (...) \
8081 do { \
81- if (!SWIFT_RUNTIME_WEAK_CHECK (os_signpost_enabled)) \
82- return __VA_ARGS__; \
8382 swift::once (LogsToken, setupLogs, nullptr ); \
83+ if (!TracingEnabled) \
84+ return __VA_ARGS__; \
8485 } while (0 )
8586
8687// Every function does ENSURE_LOGS() before making any os_signpost calls, so
Original file line number Diff line number Diff line change 1515// ===----------------------------------------------------------------------===//
1616
1717#include " Tracing.h"
18+ #include " swift/Runtime/TracingCommon.h"
1819
1920#if SWIFT_STDLIB_TRACING
2021
@@ -27,8 +28,15 @@ namespace trace {
2728
2829os_log_t ScanLog;
2930swift::once_t LogsToken;
31+ bool TracingEnabled;
3032
3133void setupLogs (void *unused) {
34+ if (!shouldEnableTracing ()) {
35+ TracingEnabled = false ;
36+ return ;
37+ }
38+
39+ TracingEnabled = true ;
3240 ScanLog = os_log_create (SWIFT_LOG_SUBSYSTEM, SWIFT_LOG_SECTION_SCAN_CATEGORY);
3341}
3442
Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ namespace trace {
3434
3535extern os_log_t ScanLog;
3636extern swift::once_t LogsToken;
37+ extern bool TracingEnabled;
3738
3839void setupLogs (void *unused);
3940
@@ -48,9 +49,9 @@ void setupLogs(void *unused);
4849// optimized out.
4950#define ENSURE_LOG (log ) \
5051 do { \
51- if (!SWIFT_RUNTIME_WEAK_CHECK (os_signpost_enabled)) \
52- return {}; \
5352 swift::once (LogsToken, setupLogs, nullptr ); \
53+ if (!TracingEnabled) \
54+ return {}; \
5455 } while (0 )
5556
5657// / 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