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 <hta@webrtc.org>
Commit-Queue: Markus Handell <handellm@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#39443}
This commit is contained in:
Markus Handell 2023-03-01 14:15:35 +01:00 committed by WebRTC LUCI CQ
parent 8cb31cf125
commit fb727f3a5f
2 changed files with 27 additions and 16 deletions

View file

@ -24,7 +24,8 @@ class RepeatingTask {
TimeDelta first_delay, TimeDelta first_delay,
absl::AnyInvocable<TimeDelta()> task, absl::AnyInvocable<TimeDelta()> task,
Clock* clock, Clock* clock,
rtc::scoped_refptr<PendingTaskSafetyFlag> alive_flag); rtc::scoped_refptr<PendingTaskSafetyFlag> alive_flag,
const Location& location);
RepeatingTask(RepeatingTask&&) = default; RepeatingTask(RepeatingTask&&) = default;
RepeatingTask& operator=(RepeatingTask&&) = delete; RepeatingTask& operator=(RepeatingTask&&) = delete;
~RepeatingTask() = default; ~RepeatingTask() = default;
@ -35,6 +36,7 @@ class RepeatingTask {
TaskQueueBase* const task_queue_; TaskQueueBase* const task_queue_;
const TaskQueueBase::DelayPrecision precision_; const TaskQueueBase::DelayPrecision precision_;
Clock* const clock_; Clock* const clock_;
const Location location_;
absl::AnyInvocable<TimeDelta()> task_; absl::AnyInvocable<TimeDelta()> task_;
// This is always finite. // This is always finite.
Timestamp next_run_time_ RTC_GUARDED_BY(task_queue_); Timestamp next_run_time_ RTC_GUARDED_BY(task_queue_);
@ -48,10 +50,12 @@ RepeatingTask::RepeatingTask(
TimeDelta first_delay, TimeDelta first_delay,
absl::AnyInvocable<TimeDelta()> task, absl::AnyInvocable<TimeDelta()> task,
Clock* clock, Clock* clock,
rtc::scoped_refptr<PendingTaskSafetyFlag> alive_flag) rtc::scoped_refptr<PendingTaskSafetyFlag> alive_flag,
const Location& location)
: task_queue_(task_queue), : task_queue_(task_queue),
precision_(precision), precision_(precision),
clock_(clock), clock_(clock),
location_(location),
task_(std::move(task)), task_(std::move(task)),
next_run_time_(clock_->CurrentTime() + first_delay), next_run_time_(clock_->CurrentTime() + first_delay),
alive_flag_(std::move(alive_flag)) {} alive_flag_(std::move(alive_flag)) {}
@ -75,8 +79,8 @@ void RepeatingTask::operator()() && {
delay -= lost_time; delay -= lost_time;
delay = std::max(delay, TimeDelta::Zero()); delay = std::max(delay, TimeDelta::Zero());
task_queue_->PostDelayedTaskWithPrecision(precision_, std::move(*this), task_queue_->PostDelayedTaskWithPrecision(precision_, std::move(*this), delay,
delay); location_);
} }
} // namespace } // namespace
@ -85,11 +89,14 @@ RepeatingTaskHandle RepeatingTaskHandle::Start(
TaskQueueBase* task_queue, TaskQueueBase* task_queue,
absl::AnyInvocable<TimeDelta()> closure, absl::AnyInvocable<TimeDelta()> closure,
TaskQueueBase::DelayPrecision precision, TaskQueueBase::DelayPrecision precision,
Clock* clock) { Clock* clock,
const Location& location) {
auto alive_flag = PendingTaskSafetyFlag::CreateDetached(); auto alive_flag = PendingTaskSafetyFlag::CreateDetached();
webrtc_repeating_task_impl::RepeatingTaskHandleDTraceProbeStart(); webrtc_repeating_task_impl::RepeatingTaskHandleDTraceProbeStart();
task_queue->PostTask(RepeatingTask(task_queue, precision, TimeDelta::Zero(), task_queue->PostTask(
std::move(closure), clock, alive_flag)); RepeatingTask(task_queue, precision, TimeDelta::Zero(),
std::move(closure), clock, alive_flag, location),
location);
return RepeatingTaskHandle(std::move(alive_flag)); return RepeatingTaskHandle(std::move(alive_flag));
} }
@ -100,14 +107,15 @@ RepeatingTaskHandle RepeatingTaskHandle::DelayedStart(
TimeDelta first_delay, TimeDelta first_delay,
absl::AnyInvocable<TimeDelta()> closure, absl::AnyInvocable<TimeDelta()> closure,
TaskQueueBase::DelayPrecision precision, TaskQueueBase::DelayPrecision precision,
Clock* clock) { Clock* clock,
const Location& location) {
auto alive_flag = PendingTaskSafetyFlag::CreateDetached(); auto alive_flag = PendingTaskSafetyFlag::CreateDetached();
webrtc_repeating_task_impl::RepeatingTaskHandleDTraceProbeDelayedStart(); webrtc_repeating_task_impl::RepeatingTaskHandleDTraceProbeDelayedStart();
task_queue->PostDelayedTaskWithPrecision( task_queue->PostDelayedTaskWithPrecision(
precision, precision,
RepeatingTask(task_queue, precision, first_delay, std::move(closure), RepeatingTask(task_queue, precision, first_delay, std::move(closure),
clock, alive_flag), clock, alive_flag, location),
first_delay); first_delay, location);
return RepeatingTaskHandle(std::move(alive_flag)); return RepeatingTaskHandle(std::move(alive_flag));
} }

View file

@ -52,11 +52,13 @@ class RepeatingTaskHandle {
// TaskQueue deletes it. It's perfectly fine to destroy the handle while the // 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. // task is running, since the repeated task is owned by the TaskQueue.
// The tasks are scheduled onto the task queue using the specified precision. // The tasks are scheduled onto the task queue using the specified precision.
static RepeatingTaskHandle Start(TaskQueueBase* task_queue, static RepeatingTaskHandle Start(
absl::AnyInvocable<TimeDelta()> closure, TaskQueueBase* task_queue,
TaskQueueBase::DelayPrecision precision = absl::AnyInvocable<TimeDelta()> closure,
TaskQueueBase::DelayPrecision::kLow, TaskQueueBase::DelayPrecision precision =
Clock* clock = Clock::GetRealTimeClock()); TaskQueueBase::DelayPrecision::kLow,
Clock* clock = Clock::GetRealTimeClock(),
const Location& location = Location::Current());
// DelayedStart is equivalent to Start except that the first invocation of the // DelayedStart is equivalent to Start except that the first invocation of the
// closure will be delayed by the given amount. // closure will be delayed by the given amount.
@ -66,7 +68,8 @@ class RepeatingTaskHandle {
absl::AnyInvocable<TimeDelta()> closure, absl::AnyInvocable<TimeDelta()> closure,
TaskQueueBase::DelayPrecision precision = TaskQueueBase::DelayPrecision precision =
TaskQueueBase::DelayPrecision::kLow, 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 // 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 // from the TaskQueue where the task is running. The closure is guaranteed to