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,
absl::AnyInvocable<TimeDelta()> task,
Clock* clock,
rtc::scoped_refptr<PendingTaskSafetyFlag> alive_flag);
rtc::scoped_refptr<PendingTaskSafetyFlag> 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<TimeDelta()> 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<TimeDelta()> task,
Clock* clock,
rtc::scoped_refptr<PendingTaskSafetyFlag> alive_flag)
rtc::scoped_refptr<PendingTaskSafetyFlag> 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<TimeDelta()> 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<TimeDelta()> 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));
}

View file

@ -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<TimeDelta()> closure,
TaskQueueBase::DelayPrecision precision =
TaskQueueBase::DelayPrecision::kLow,
Clock* clock = Clock::GetRealTimeClock());
static RepeatingTaskHandle Start(
TaskQueueBase* task_queue,
absl::AnyInvocable<TimeDelta()> 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<TimeDelta()> 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