Skip to content

[6.0][Runtime] Don't emit signposts until the system is ready. #73677

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 17, 2024
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
17 changes: 16 additions & 1 deletion include/swift/Runtime/TracingCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@
#include "swift/Runtime/Config.h"
#include <os/signpost.h>

extern const char *__progname;
extern "C" const char *__progname;

// This function may not be present when building at desk, and isn't really
// needed there, so just skip it in that case.
#if SWIFT_BNI_OS_BUILD
extern "C" bool _os_trace_lazy_init_completed_4swift(void);
#endif

namespace swift {
namespace runtime {
Expand All @@ -40,6 +46,15 @@ static inline bool shouldEnableTracing() {
return true;
}

static inline bool tracingReady() {
#if SWIFT_BNI_OS_BUILD
if (!_os_trace_lazy_init_completed_4swift())
return false;
#endif

return true;
}

} // namespace trace
} // namespace runtime
} // namespace swift
Expand Down
1 change: 0 additions & 1 deletion stdlib/public/Concurrency/TracingSignpost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#if SWIFT_STDLIB_CONCURRENCY_TRACING

#include "TracingSignpost.h"
#include "swift/Runtime/TracingCommon.h"
#include <stdio.h>

#define SWIFT_LOG_CONCURRENCY_SUBSYSTEM "com.apple.swift.concurrency"
Expand Down
3 changes: 3 additions & 0 deletions stdlib/public/Concurrency/TracingSignpost.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "swift/Basic/Lazy.h"
#include "swift/Runtime/Casting.h"
#include "swift/Runtime/HeapObject.h"
#include "swift/Runtime/TracingCommon.h"
#include <inttypes.h>
#include <os/log.h>
#include <os/signpost.h>
Expand Down Expand Up @@ -79,6 +80,8 @@ void setupLogs(void *unused);
// optimized out.
#define ENSURE_LOGS(...) \
do { \
if (!runtime::trace::tracingReady()) \
return __VA_ARGS__; \
swift::once(LogsToken, setupLogs, nullptr); \
if (!TracingEnabled) \
return __VA_ARGS__; \
Expand Down
1 change: 0 additions & 1 deletion stdlib/public/runtime/Tracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
//===----------------------------------------------------------------------===//

#include "Tracing.h"
#include "swift/Runtime/TracingCommon.h"

#if SWIFT_STDLIB_TRACING

Expand Down
3 changes: 3 additions & 0 deletions stdlib/public/runtime/Tracing.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "llvm/ADT/StringRef.h"
#include "swift/ABI/Metadata.h"
#include "swift/Demangling/Demangler.h"
#include "swift/Runtime/TracingCommon.h"

#if SWIFT_STDLIB_TRACING
#include <os/signpost.h>
Expand Down Expand Up @@ -49,6 +50,8 @@ void setupLogs(void *unused);
// optimized out.
#define ENSURE_LOG(log) \
do { \
if (!tracingReady()) \
return {}; \
swift::once(LogsToken, setupLogs, nullptr); \
if (!TracingEnabled) \
return {}; \
Expand Down