Skip to content

Commit 251eb3f

Browse files
rubennortefacebook-github-bot
authored andcommitted
Log task ID when scheduling and executing tasks in RuntimeScheduler (facebook#52191)
Summary: Pull Request resolved: facebook#52191 Changelog: [internal] Some time ago we added logging for the timer ID in Systrace/Perfetto so we could see where timers were scheduled vs. executed. This diff adds support for the same functionality for tasks in the runtime scheduler. Reviewed By: javache Differential Revision: D77039038 fbshipit-source-id: 792d2fe29b44fb209f9129f46f9d661dad7ebdff
1 parent 3782fe8 commit 251eb3f

3 files changed

Lines changed: 26 additions & 17 deletions

File tree

packages/react-native/ReactCommon/react/renderer/runtimescheduler/RuntimeScheduler_Modern.cpp

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,6 @@ void RuntimeScheduler_Modern::scheduleWork(RawCallback&& callback) noexcept {
5050
std::shared_ptr<Task> RuntimeScheduler_Modern::scheduleTask(
5151
SchedulerPriority priority,
5252
jsi::Function&& callback) noexcept {
53-
TraceSection s(
54-
"RuntimeScheduler::scheduleTask",
55-
"priority",
56-
serialize(priority),
57-
"callbackType",
58-
"jsi::Function");
59-
6053
auto expirationTime = now_() + timeoutForSchedulerPriority(priority);
6154
auto task =
6255
std::make_shared<Task>(priority, std::move(callback), expirationTime);
@@ -69,13 +62,6 @@ std::shared_ptr<Task> RuntimeScheduler_Modern::scheduleTask(
6962
std::shared_ptr<Task> RuntimeScheduler_Modern::scheduleTask(
7063
SchedulerPriority priority,
7164
RawCallback&& callback) noexcept {
72-
TraceSection s(
73-
"RuntimeScheduler::scheduleTask",
74-
"priority",
75-
serialize(priority),
76-
"callbackType",
77-
"RawCallback");
78-
7965
auto expirationTime = now_() + timeoutForSchedulerPriority(priority);
8066
auto task =
8167
std::make_shared<Task>(priority, std::move(callback), expirationTime);
@@ -233,6 +219,13 @@ void RuntimeScheduler_Modern::setIntersectionObserverDelegate(
233219
#pragma mark - Private
234220

235221
void RuntimeScheduler_Modern::scheduleTask(std::shared_ptr<Task> task) {
222+
TraceSection s(
223+
"RuntimeScheduler::scheduleTask",
224+
"priority",
225+
serialize(task->priority),
226+
"id",
227+
task->id);
228+
236229
bool shouldScheduleEventLoop = false;
237230

238231
{
@@ -384,6 +377,8 @@ void RuntimeScheduler_Modern::executeTask(
384377
bool didUserCallbackTimeout) const {
385378
TraceSection s(
386379
"RuntimeScheduler::executeTask",
380+
"id",
381+
task.id,
387382
"priority",
388383
serialize(task.priority),
389384
"didUserCallbackTimeout",

packages/react-native/ReactCommon/react/renderer/runtimescheduler/Task.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,37 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
#include "RuntimeScheduler.h"
8+
#include "Task.h"
9+
#include <atomic>
910

1011
namespace facebook::react {
1112

13+
namespace {
14+
15+
inline uint64_t getNextId() noexcept {
16+
static std::atomic<uint64_t> nextId = 1;
17+
return nextId++;
18+
}
19+
20+
} // namespace
21+
1222
Task::Task(
1323
SchedulerPriority priority,
1424
jsi::Function&& callback,
1525
HighResTimeStamp expirationTime)
1626
: priority(priority),
1727
callback(std::move(callback)),
18-
expirationTime(expirationTime) {}
28+
expirationTime(expirationTime),
29+
id(getNextId()) {}
1930

2031
Task::Task(
2132
SchedulerPriority priority,
2233
RawCallback&& callback,
2334
HighResTimeStamp expirationTime)
2435
: priority(priority),
2536
callback(std::move(callback)),
26-
expirationTime(expirationTime) {}
37+
expirationTime(expirationTime),
38+
id(getNextId()) {}
2739

2840
jsi::Value Task::execute(jsi::Runtime& runtime, bool didUserCallbackTimeout) {
2941
auto result = jsi::Value::undefined();

packages/react-native/ReactCommon/react/renderer/runtimescheduler/Task.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <jsi/jsi.h>
1212
#include <react/timing/primitives.h>
1313

14+
#include <cstdint>
1415
#include <optional>
1516
#include <variant>
1617

@@ -41,6 +42,7 @@ struct Task final : public jsi::NativeState {
4142
SchedulerPriority priority;
4243
std::optional<std::variant<jsi::Function, RawCallback>> callback;
4344
HighResTimeStamp expirationTime;
45+
uint64_t id;
4446

4547
jsi::Value execute(jsi::Runtime& runtime, bool didUserCallbackTimeout);
4648
};

0 commit comments

Comments
 (0)