Files
swift-mirror/stdlib/public/Concurrency/TracingSignpost.cpp
T
Mike Ash db4692534e [Concurrency] Add more info to tracing calls.
* Have job_run include the actor, executor, and task name.
* Make task_status_changed only trace if one of the tracked values actually changed.
* Add a job_enqueue_executor that covers enqueueing jobs on serial executors (default actors, custom executors, main actor, etc.).
* Actually end the actor lifetime signpost interval.
* Include the actor metadata and context descriptor pointers in actor enqueue/dequeue so the type can be identified.
* Add the task pointer to all task-related signpost messages.
* Emit job_enqueue_main_executor from the swift_task_enqueueImpl path so main actor enqueues appear in traces.
* Add TracingExecutorKind enum and log executorKind in job_enqueue_executor and job_run to distinguish global, default actor, main actor, custom serial executor, and task executor contexts.

While we're here, finally add a test for Concurrency signposts. This is difficult because the signposts are disabled by default and there isn't a good way to turn them on in an automated fashion. Resolve this by adding an environment variable, SWIFT_CONCURRENCY_TRACING_SUBSYSTEM, which overrides the subsystem used by the Concurrency signpost code. The test can use this to set a subsystem that isn't disabled by default, which then allows `log stream` to capture the signposts.
2026-03-26 15:10:48 -04:00

59 lines
1.6 KiB
C++

//===--- TracingSignpost.cpp - Tracing with the signpost API -------*- C++ -*-//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// Concurrency tracing implemented with the os_signpost API.
//
//===----------------------------------------------------------------------===//
#if SWIFT_STDLIB_TRACING
#include "TracingSignpost.h"
#include "swift/Runtime/EnvironmentVariables.h"
#include <stdio.h>
#define SWIFT_LOG_CONCURRENCY_SUBSYSTEM "com.apple.swift.concurrency"
#define SWIFT_LOG_ACTOR_CATEGORY "Actor"
#define SWIFT_LOG_TASK_CATEGORY "Task"
namespace swift {
namespace concurrency {
namespace trace {
os_log_t ActorLog;
os_log_t TaskLog;
swift::once_t LogsToken;
bool TracingEnabled;
void setupLogs(void *unused) {
if (!swift::runtime::trace::shouldEnableTracing()) {
TracingEnabled = false;
return;
}
TracingEnabled = true;
const char *subsystem = SWIFT_LOG_CONCURRENCY_SUBSYSTEM;
const char *envSubsystem =
runtime::environment::concurrencyTracingSubsystem();
if (envSubsystem && envSubsystem[0] != '\0')
subsystem = envSubsystem;
ActorLog = os_log_create(subsystem, SWIFT_LOG_ACTOR_CATEGORY);
TaskLog = os_log_create(subsystem, SWIFT_LOG_TASK_CATEGORY);
}
} // namespace trace
} // namespace concurrency
} // namespace swift
#endif