Skip to content

Commit

Permalink
Implement support for Chrome task origin tracing. #3.9/4
Browse files Browse the repository at this point in the history
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}
  • Loading branch information
Markus Handell authored and WebRTC LUCI CQ committed Mar 1, 2023
1 parent 8cb31cf commit fb727f3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
28 changes: 18 additions & 10 deletions rtc_base/task_utils/repeating_task.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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_);
Expand All @@ -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)) {}
Expand All @@ -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
Expand All @@ -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));
}

Expand All @@ -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));
}

Expand Down
15 changes: 9 additions & 6 deletions rtc_base/task_utils/repeating_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down

0 comments on commit fb727f3

Please sign in to comment.