From fb727f3a5f530db428cf3a13a909ef6cbd580528 Mon Sep 17 00:00:00 2001 From: Markus Handell Date: Wed, 1 Mar 2023 14:15:35 +0100 Subject: [PATCH] Implement support for Chrome task origin tracing. #3.9/4 This CL forwards repeating task client locations to the passed task queue. Bug: chromium:1416199 Change-Id: I437d596f8d327d13498b47dfc0a03812af870331 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/295623 Reviewed-by: Harald Alvestrand Commit-Queue: Markus Handell Cr-Commit-Position: refs/heads/main@{#39443} --- rtc_base/task_utils/repeating_task.cc | 28 +++++++++++++++++---------- rtc_base/task_utils/repeating_task.h | 15 ++++++++------ 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/rtc_base/task_utils/repeating_task.cc b/rtc_base/task_utils/repeating_task.cc index 222ab1ad67..6b76d7673a 100644 --- a/rtc_base/task_utils/repeating_task.cc +++ b/rtc_base/task_utils/repeating_task.cc @@ -24,7 +24,8 @@ class RepeatingTask { TimeDelta first_delay, absl::AnyInvocable task, Clock* clock, - rtc::scoped_refptr alive_flag); + rtc::scoped_refptr alive_flag, + const Location& location); RepeatingTask(RepeatingTask&&) = default; RepeatingTask& operator=(RepeatingTask&&) = delete; ~RepeatingTask() = default; @@ -35,6 +36,7 @@ class RepeatingTask { TaskQueueBase* const task_queue_; const TaskQueueBase::DelayPrecision precision_; Clock* const clock_; + const Location location_; absl::AnyInvocable task_; // This is always finite. Timestamp next_run_time_ RTC_GUARDED_BY(task_queue_); @@ -48,10 +50,12 @@ RepeatingTask::RepeatingTask( TimeDelta first_delay, absl::AnyInvocable task, Clock* clock, - rtc::scoped_refptr alive_flag) + rtc::scoped_refptr alive_flag, + const Location& location) : task_queue_(task_queue), precision_(precision), clock_(clock), + location_(location), task_(std::move(task)), next_run_time_(clock_->CurrentTime() + first_delay), alive_flag_(std::move(alive_flag)) {} @@ -75,8 +79,8 @@ void RepeatingTask::operator()() && { delay -= lost_time; delay = std::max(delay, TimeDelta::Zero()); - task_queue_->PostDelayedTaskWithPrecision(precision_, std::move(*this), - delay); + task_queue_->PostDelayedTaskWithPrecision(precision_, std::move(*this), delay, + location_); } } // namespace @@ -85,11 +89,14 @@ RepeatingTaskHandle RepeatingTaskHandle::Start( TaskQueueBase* task_queue, absl::AnyInvocable closure, TaskQueueBase::DelayPrecision precision, - Clock* clock) { + Clock* clock, + const Location& location) { auto alive_flag = PendingTaskSafetyFlag::CreateDetached(); webrtc_repeating_task_impl::RepeatingTaskHandleDTraceProbeStart(); - task_queue->PostTask(RepeatingTask(task_queue, precision, TimeDelta::Zero(), - std::move(closure), clock, alive_flag)); + task_queue->PostTask( + RepeatingTask(task_queue, precision, TimeDelta::Zero(), + std::move(closure), clock, alive_flag, location), + location); return RepeatingTaskHandle(std::move(alive_flag)); } @@ -100,14 +107,15 @@ RepeatingTaskHandle RepeatingTaskHandle::DelayedStart( TimeDelta first_delay, absl::AnyInvocable closure, TaskQueueBase::DelayPrecision precision, - Clock* clock) { + Clock* clock, + const Location& location) { auto alive_flag = PendingTaskSafetyFlag::CreateDetached(); webrtc_repeating_task_impl::RepeatingTaskHandleDTraceProbeDelayedStart(); task_queue->PostDelayedTaskWithPrecision( precision, RepeatingTask(task_queue, precision, first_delay, std::move(closure), - clock, alive_flag), - first_delay); + clock, alive_flag, location), + first_delay, location); return RepeatingTaskHandle(std::move(alive_flag)); } diff --git a/rtc_base/task_utils/repeating_task.h b/rtc_base/task_utils/repeating_task.h index e5ea3d8174..c45de95ecc 100644 --- a/rtc_base/task_utils/repeating_task.h +++ b/rtc_base/task_utils/repeating_task.h @@ -52,11 +52,13 @@ class RepeatingTaskHandle { // TaskQueue deletes it. It's perfectly fine to destroy the handle while the // task is running, since the repeated task is owned by the TaskQueue. // The tasks are scheduled onto the task queue using the specified precision. - static RepeatingTaskHandle Start(TaskQueueBase* task_queue, - absl::AnyInvocable closure, - TaskQueueBase::DelayPrecision precision = - TaskQueueBase::DelayPrecision::kLow, - Clock* clock = Clock::GetRealTimeClock()); + static RepeatingTaskHandle Start( + TaskQueueBase* task_queue, + absl::AnyInvocable closure, + TaskQueueBase::DelayPrecision precision = + TaskQueueBase::DelayPrecision::kLow, + Clock* clock = Clock::GetRealTimeClock(), + const Location& location = Location::Current()); // DelayedStart is equivalent to Start except that the first invocation of the // closure will be delayed by the given amount. @@ -66,7 +68,8 @@ class RepeatingTaskHandle { absl::AnyInvocable closure, TaskQueueBase::DelayPrecision precision = TaskQueueBase::DelayPrecision::kLow, - Clock* clock = Clock::GetRealTimeClock()); + Clock* clock = Clock::GetRealTimeClock(), + const Location& location = Location::Current()); // Stops future invocations of the repeating task closure. Can only be called // from the TaskQueue where the task is running. The closure is guaranteed to