Skip to content

Commit e5c61b3

Browse files
committed
[Concurrency] Minor tweaks to continuation, task, and job tracing.
Change continuation signposts to emit an interval for init/resume. Fix task_create to take the decoded flags as separate parameters, matching other calls. Move job_run trace calls into runJobInEstablishedExecutorContext. swift_job_runImpl didn't catch everything. rdar://92149411
1 parent 1b8c430 commit e5c61b3

File tree

5 files changed

+38
-35
lines changed

5 files changed

+38
-35
lines changed

stdlib/public/Concurrency/Actor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,9 @@ void swift::runJobInEstablishedExecutorContext(Job *job) {
232232
// it afterwards.
233233
task->flagAsRunning();
234234

235+
auto traceHandle = concurrency::trace::job_run_begin(job);
235236
task->runInFullyEstablishedContext();
237+
concurrency::trace::job_run_end(traceHandle);
236238

237239
assert(ActiveTask::get() == nullptr &&
238240
"active task wasn't cleared before suspending?");
@@ -1505,12 +1507,10 @@ static void swift_job_runImpl(Job *job, ExecutorRef executor) {
15051507
if (!executor.isGeneric()) trackingInfo.disallowSwitching();
15061508

15071509
trackingInfo.enterAndShadow(executor);
1508-
auto traceHandle = concurrency::trace::job_run_begin(job, &executor);
15091510

15101511
SWIFT_TASK_DEBUG_LOG("job %p", job);
15111512
runJobInEstablishedExecutorContext(job);
15121513

1513-
concurrency::trace::job_run_end(&executor, traceHandle);
15141514
trackingInfo.leave();
15151515

15161516
// Give up the current executor if this is a switching context

stdlib/public/Concurrency/Task.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,11 @@ static AsyncTaskAndContext swift_task_create_commonImpl(
836836
// be is the final hop. Store a signed null instead.
837837
initialContext->Parent = nullptr;
838838

839-
concurrency::trace::task_create(task, parent, group, asyncLet);
839+
concurrency::trace::task_create(
840+
task, parent, group, asyncLet,
841+
static_cast<uint8_t>(task->Flags.getPriority()),
842+
task->Flags.task_isChildTask(), task->Flags.task_isFuture(),
843+
task->Flags.task_isGroupChildTask(), task->Flags.task_isAsyncLetTask());
840844

841845
// Attach to the group, if needed.
842846
if (group) {

stdlib/public/Concurrency/Tracing.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ void actor_note_job_queue(HeapObject *actor, Job *first,
5858
// Task trace calls.
5959

6060
void task_create(AsyncTask *task, AsyncTask *parent, TaskGroup *group,
61-
AsyncLet *asyncLet);
61+
AsyncLet *asyncLet, uint8_t jobPriority, bool isChildTask,
62+
bool isFuture, bool isGroupChildTask, bool isAsyncLetTask);
6263

6364
void task_destroy(AsyncTask *task);
6465

@@ -103,9 +104,9 @@ struct job_run_info {
103104
// call to task_run_end. Any information we want to log must be
104105
// extracted from the job when we start to run it because execution
105106
// will invalidate the job.
106-
job_run_info job_run_begin(Job *job, ExecutorRef *executor);
107+
job_run_info job_run_begin(Job *job);
107108

108-
void job_run_end(ExecutorRef *executor, job_run_info info);
109+
void job_run_end(job_run_info info);
109110

110111
} // namespace trace
111112
} // namespace concurrency

stdlib/public/Concurrency/TracingSignpost.h

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,8 @@
5555
#define SWIFT_LOG_TASK_FLAGS_CHANGED_NAME "task_flags_changed"
5656
#define SWIFT_LOG_TASK_STATUS_CHANGED_NAME "task_status_changed"
5757
#define SWIFT_LOG_TASK_WAIT_NAME "task_wait"
58-
#define SWIFT_LOG_TASK_CONTINUATION_INIT "task_continuation_init"
58+
#define SWIFT_LOG_TASK_CONTINUATION "task_continuation"
5959
#define SWIFT_LOG_TASK_CONTINUATION_AWAIT "task_continuation_await"
60-
#define SWIFT_LOG_TASK_CONTINUATION_RESUME "task_continuation_resume"
6160
#define SWIFT_LOG_JOB_ENQUEUE_GLOBAL_NAME "job_enqueue_global"
6261
#define SWIFT_LOG_JOB_ENQUEUE_GLOBAL_WITH_DELAY_NAME \
6362
"job_enqueue_global_with_delay"
@@ -178,16 +177,21 @@ inline void actor_note_job_queue(HeapObject *actor, Job *first,
178177
// Task trace calls.
179178

180179
inline void task_create(AsyncTask *task, AsyncTask *parent, TaskGroup *group,
181-
AsyncLet *asyncLet) {
180+
AsyncLet *asyncLet, uint8_t jobPriority,
181+
bool isChildTask, bool isFuture, bool isGroupChildTask,
182+
bool isAsyncLetTask) {
182183
ENSURE_LOGS();
183184
auto id = os_signpost_id_make_with_pointer(TaskLog, task);
184185
auto parentID = parent ? parent->getTaskId() : 0;
185186
os_signpost_interval_begin(
186187
TaskLog, id, SWIFT_LOG_TASK_LIFETIME_NAME,
187-
"task=%" PRIx64 " resumefn=%p flags=0x%" PRIx32
188-
" parent=%" PRIx64 " group=%p asyncLet=%p",
189-
task->getTaskId(), task->getResumeFunctionForLogging(),
190-
task->Flags.getOpaqueValue(), parentID, group, asyncLet);
188+
"task=%" PRIx64
189+
" resumefn=%p jobPriority=%u isChildTask=%{bool}d, isFuture=%{bool}d "
190+
"isGroupChildTask=%{bool}d isAsyncLetTask=%{bool}d parent=%" PRIx64
191+
" group=%p asyncLet=%p",
192+
task->getTaskId(), task->getResumeFunctionForLogging(), jobPriority,
193+
isChildTask, isFuture, isGroupChildTask, isAsyncLetTask, parentID, group,
194+
asyncLet);
191195
}
192196

193197
inline void task_destroy(AsyncTask *task) {
@@ -244,9 +248,9 @@ inline void task_continuation_init(AsyncTask *task,
244248
ContinuationAsyncContext *context) {
245249
ENSURE_LOGS();
246250
auto id = os_signpost_id_make_with_pointer(TaskLog, context);
247-
os_signpost_event_emit(TaskLog, id, SWIFT_LOG_TASK_CONTINUATION_INIT,
248-
"task=%" PRIx64 " context=%p", task->getTaskId(),
249-
context);
251+
os_signpost_interval_begin(TaskLog, id, SWIFT_LOG_TASK_CONTINUATION,
252+
"task=%" PRIx64 " context=%p", task->getTaskId(),
253+
context);
250254
}
251255

252256
inline void task_continuation_await(ContinuationAsyncContext *context) {
@@ -260,8 +264,8 @@ inline void task_continuation_resume(ContinuationAsyncContext *context,
260264
bool error) {
261265
ENSURE_LOGS();
262266
auto id = os_signpost_id_make_with_pointer(TaskLog, context);
263-
os_signpost_event_emit(TaskLog, id, SWIFT_LOG_TASK_CONTINUATION_RESUME,
264-
"context=%p error=%{bool}d", context, error);
267+
os_signpost_interval_end(TaskLog, id, SWIFT_LOG_TASK_CONTINUATION,
268+
"context=%p error=%{bool}d", context, error);
265269
}
266270

267271
inline void job_enqueue_global(Job *job) {
@@ -293,7 +297,7 @@ inline void job_enqueue_main_executor(Job *job) {
293297
}
294298
}
295299

296-
inline job_run_info job_run_begin(Job *job, ExecutorRef *executor) {
300+
inline job_run_info job_run_begin(Job *job) {
297301
auto invalidInfo = []{
298302
return job_run_info{ 0, OS_SIGNPOST_ID_INVALID };
299303
};
@@ -302,25 +306,18 @@ inline job_run_info job_run_begin(Job *job, ExecutorRef *executor) {
302306
ENSURE_LOGS(invalidInfo());
303307
auto handle = os_signpost_id_generate(TaskLog);
304308
auto taskId = task->getTaskId();
305-
os_signpost_interval_begin(
306-
TaskLog, handle, SWIFT_LOG_JOB_RUN_NAME,
307-
"task=%" PRIx64
308-
" executorIdentity=%p executorImplementation=0x%" PRIxPTR,
309-
taskId, executor->getIdentity(), executor->getRawImplementation());
309+
os_signpost_interval_begin(TaskLog, handle, SWIFT_LOG_JOB_RUN_NAME,
310+
"task=%" PRIx64, taskId);
310311
return { taskId, handle };
311312
}
312313
return invalidInfo();
313314
}
314315

315-
inline void job_run_end(ExecutorRef *executor, job_run_info info) {
316+
inline void job_run_end(job_run_info info) {
316317
if (info.handle != OS_SIGNPOST_ID_INVALID) {
317318
ENSURE_LOGS();
318-
os_signpost_interval_end(
319-
TaskLog, info.handle, SWIFT_LOG_JOB_RUN_NAME,
320-
"task=%" PRIx64
321-
" executorIdentity=%p executorImplementation=0x%" PRIxPTR,
322-
info.taskId, executor->getIdentity(),
323-
executor->getRawImplementation());
319+
os_signpost_interval_end(TaskLog, info.handle, SWIFT_LOG_JOB_RUN_NAME,
320+
"task=%" PRIx64, info.taskId);
324321
}
325322
}
326323

stdlib/public/Concurrency/TracingStubs.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ inline void actor_note_job_queue(HeapObject *actor, Job *first,
4343
Job *(*getNext)(Job *)) {}
4444

4545
inline void task_create(AsyncTask *task, AsyncTask *parent, TaskGroup *group,
46-
AsyncLet *asyncLet) {}
46+
AsyncLet *asyncLet, uint8_t jobPriority,
47+
bool isChildTask, bool isFuture, bool isGroupChildTask,
48+
bool isAsyncLetTask) {}
4749

4850
inline void task_destroy(AsyncTask *task) {}
4951

@@ -74,10 +76,9 @@ inline void job_enqueue_global_with_delay(unsigned long long delay, Job *job) {}
7476

7577
inline void job_enqueue_main_executor(Job *job) {}
7678

77-
inline job_run_info job_run_begin(Job *job, ExecutorRef *executor) { return {}; }
79+
inline job_run_info job_run_begin(Job *job) { return {}; }
7880

79-
inline void job_run_end(ExecutorRef *executor, job_run_info info) {
80-
}
81+
inline void job_run_end(job_run_info info) {}
8182

8283
} // namespace trace
8384
} // namespace concurrency

0 commit comments

Comments
 (0)