Skip to content

Commit fb727f3

Browse files
Markus HandellWebRTC LUCI CQ
authored andcommitted
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 <[email protected]> Commit-Queue: Markus Handell <[email protected]> Cr-Commit-Position: refs/heads/main@{#39443}
1 parent 8cb31cf commit fb727f3

File tree

2 files changed

+27
-16
lines changed

2 files changed

+27
-16
lines changed

rtc_base/task_utils/repeating_task.cc

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ class RepeatingTask {
2424
TimeDelta first_delay,
2525
absl::AnyInvocable<TimeDelta()> task,
2626
Clock* clock,
27-
rtc::scoped_refptr<PendingTaskSafetyFlag> alive_flag);
27+
rtc::scoped_refptr<PendingTaskSafetyFlag> alive_flag,
28+
const Location& location);
2829
RepeatingTask(RepeatingTask&&) = default;
2930
RepeatingTask& operator=(RepeatingTask&&) = delete;
3031
~RepeatingTask() = default;
@@ -35,6 +36,7 @@ class RepeatingTask {
3536
TaskQueueBase* const task_queue_;
3637
const TaskQueueBase::DelayPrecision precision_;
3738
Clock* const clock_;
39+
const Location location_;
3840
absl::AnyInvocable<TimeDelta()> task_;
3941
// This is always finite.
4042
Timestamp next_run_time_ RTC_GUARDED_BY(task_queue_);
@@ -48,10 +50,12 @@ RepeatingTask::RepeatingTask(
4850
TimeDelta first_delay,
4951
absl::AnyInvocable<TimeDelta()> task,
5052
Clock* clock,
51-
rtc::scoped_refptr<PendingTaskSafetyFlag> alive_flag)
53+
rtc::scoped_refptr<PendingTaskSafetyFlag> alive_flag,
54+
const Location& location)
5255
: task_queue_(task_queue),
5356
precision_(precision),
5457
clock_(clock),
58+
location_(location),
5559
task_(std::move(task)),
5660
next_run_time_(clock_->CurrentTime() + first_delay),
5761
alive_flag_(std::move(alive_flag)) {}
@@ -75,8 +79,8 @@ void RepeatingTask::operator()() && {
7579
delay -= lost_time;
7680
delay = std::max(delay, TimeDelta::Zero());
7781

78-
task_queue_->PostDelayedTaskWithPrecision(precision_, std::move(*this),
79-
delay);
82+
task_queue_->PostDelayedTaskWithPrecision(precision_, std::move(*this), delay,
83+
location_);
8084
}
8185

8286
} // namespace
@@ -85,11 +89,14 @@ RepeatingTaskHandle RepeatingTaskHandle::Start(
8589
TaskQueueBase* task_queue,
8690
absl::AnyInvocable<TimeDelta()> closure,
8791
TaskQueueBase::DelayPrecision precision,
88-
Clock* clock) {
92+
Clock* clock,
93+
const Location& location) {
8994
auto alive_flag = PendingTaskSafetyFlag::CreateDetached();
9095
webrtc_repeating_task_impl::RepeatingTaskHandleDTraceProbeStart();
91-
task_queue->PostTask(RepeatingTask(task_queue, precision, TimeDelta::Zero(),
92-
std::move(closure), clock, alive_flag));
96+
task_queue->PostTask(
97+
RepeatingTask(task_queue, precision, TimeDelta::Zero(),
98+
std::move(closure), clock, alive_flag, location),
99+
location);
93100
return RepeatingTaskHandle(std::move(alive_flag));
94101
}
95102

@@ -100,14 +107,15 @@ RepeatingTaskHandle RepeatingTaskHandle::DelayedStart(
100107
TimeDelta first_delay,
101108
absl::AnyInvocable<TimeDelta()> closure,
102109
TaskQueueBase::DelayPrecision precision,
103-
Clock* clock) {
110+
Clock* clock,
111+
const Location& location) {
104112
auto alive_flag = PendingTaskSafetyFlag::CreateDetached();
105113
webrtc_repeating_task_impl::RepeatingTaskHandleDTraceProbeDelayedStart();
106114
task_queue->PostDelayedTaskWithPrecision(
107115
precision,
108116
RepeatingTask(task_queue, precision, first_delay, std::move(closure),
109-
clock, alive_flag),
110-
first_delay);
117+
clock, alive_flag, location),
118+
first_delay, location);
111119
return RepeatingTaskHandle(std::move(alive_flag));
112120
}
113121

rtc_base/task_utils/repeating_task.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@ class RepeatingTaskHandle {
5252
// TaskQueue deletes it. It's perfectly fine to destroy the handle while the
5353
// task is running, since the repeated task is owned by the TaskQueue.
5454
// The tasks are scheduled onto the task queue using the specified precision.
55-
static RepeatingTaskHandle Start(TaskQueueBase* task_queue,
56-
absl::AnyInvocable<TimeDelta()> closure,
57-
TaskQueueBase::DelayPrecision precision =
58-
TaskQueueBase::DelayPrecision::kLow,
59-
Clock* clock = Clock::GetRealTimeClock());
55+
static RepeatingTaskHandle Start(
56+
TaskQueueBase* task_queue,
57+
absl::AnyInvocable<TimeDelta()> closure,
58+
TaskQueueBase::DelayPrecision precision =
59+
TaskQueueBase::DelayPrecision::kLow,
60+
Clock* clock = Clock::GetRealTimeClock(),
61+
const Location& location = Location::Current());
6062

6163
// DelayedStart is equivalent to Start except that the first invocation of the
6264
// closure will be delayed by the given amount.
@@ -66,7 +68,8 @@ class RepeatingTaskHandle {
6668
absl::AnyInvocable<TimeDelta()> closure,
6769
TaskQueueBase::DelayPrecision precision =
6870
TaskQueueBase::DelayPrecision::kLow,
69-
Clock* clock = Clock::GetRealTimeClock());
71+
Clock* clock = Clock::GetRealTimeClock(),
72+
const Location& location = Location::Current());
7073

7174
// Stops future invocations of the repeating task closure. Can only be called
7275
// from the TaskQueue where the task is running. The closure is guaranteed to

0 commit comments

Comments
 (0)