Skip to content

Commit 5489e18

Browse files
Jiawei Lüfacebook-github-bot
authored andcommitted
Revert D74892330: Use HighResTimeStamp
Differential Revision: D74892330 Original commit changeset: 514ca23dde8e Original Phabricator Diff: D74892330 fbshipit-source-id: e7e2a778fb12ad5214217d3efb48c9f74dfb80f3
1 parent 65ef8fe commit 5489e18

16 files changed

+123
-163
lines changed

packages/react-native/ReactCommon/jsinspector-modern/RuntimeTarget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ RuntimeTargetController::collectSamplingProfile() {
179179

180180
void RuntimeTarget::registerForTracing() {
181181
jsExecutor_([](auto& /*runtime*/) {
182-
tracing::PerformanceTracer::getInstance().reportJavaScriptThread();
182+
PerformanceTracer::getInstance().reportJavaScriptThread();
183183
});
184184
}
185185

packages/react-native/ReactCommon/jsinspector-modern/TracingAgent.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ bool TracingAgent::handleRequest(const cdp::PreparsedRequest& req) {
4444
}
4545

4646
bool correctlyStartedPerformanceTracer =
47-
tracing::PerformanceTracer::getInstance().startTracing();
47+
PerformanceTracer::getInstance().startTracing();
4848

4949
if (!correctlyStartedPerformanceTracer) {
5050
frontendChannel_(cdp::jsonError(
@@ -56,7 +56,7 @@ bool TracingAgent::handleRequest(const cdp::PreparsedRequest& req) {
5656
}
5757

5858
instanceAgent_->startTracing();
59-
instanceTracingStartTimestamp_ = HighResTimeStamp::now();
59+
instanceTracingStartTimestamp_ = std::chrono::steady_clock::now();
6060
frontendChannel_(cdp::jsonResult(req.id));
6161

6262
return true;
@@ -73,8 +73,7 @@ bool TracingAgent::handleRequest(const cdp::PreparsedRequest& req) {
7373

7474
instanceAgent_->stopTracing();
7575

76-
tracing::PerformanceTracer& performanceTracer =
77-
tracing::PerformanceTracer::getInstance();
76+
PerformanceTracer& performanceTracer = PerformanceTracer::getInstance();
7877
bool correctlyStopped = performanceTracer.stopTracing();
7978
if (!correctlyStopped) {
8079
frontendChannel_(cdp::jsonError(

packages/react-native/ReactCommon/jsinspector-modern/TracingAgent.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
#include "InstanceAgent.h"
1212

1313
#include <jsinspector-modern/cdp/CdpJson.h>
14-
#include <jsinspector-modern/tracing/Timing.h>
15-
#include <react/timing/primitives.h>
1614

1715
namespace facebook::react::jsinspector_modern {
1816

@@ -56,10 +54,9 @@ class TracingAgent {
5654

5755
/**
5856
* Timestamp of when we started tracing of an Instance, will be used as a
59-
* a start of JavaScript samples recording and as a time origin for the events
60-
* in this trace.
57+
* a start of JavaScript samples recording.
6158
*/
62-
HighResTimeStamp instanceTracingStartTimestamp_;
59+
std::chrono::steady_clock::time_point instanceTracingStartTimestamp_;
6360
};
6461

6562
} // namespace facebook::react::jsinspector_modern

packages/react-native/ReactCommon/jsinspector-modern/tracing/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ target_include_directories(jsinspector_tracing PUBLIC ${REACT_COMMON_DIR})
1919
target_link_libraries(jsinspector_tracing
2020
folly_runtime
2121
oscompat
22-
react_timing
2322
)
2423
target_compile_reactnative_options(jsinspector_tracing PRIVATE)
2524
target_compile_options(jsinspector_tracing PRIVATE -Wpedantic)

packages/react-native/ReactCommon/jsinspector-modern/tracing/EventLoopReporter.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,35 @@
1414
namespace facebook::react::jsinspector_modern::tracing {
1515

1616
#if defined(REACT_NATIVE_DEBUGGER_ENABLED)
17+
namespace {
18+
19+
inline uint64_t formatTimePointToUnixTimestamp(
20+
std::chrono::steady_clock::time_point timestamp) {
21+
return std::chrono::duration_cast<std::chrono::microseconds>(
22+
timestamp.time_since_epoch())
23+
.count();
24+
}
25+
26+
} // namespace
1727

1828
EventLoopReporter::EventLoopReporter(EventLoopPhase phase)
19-
: startTimestamp_(HighResTimeStamp::now()), phase_(phase) {}
29+
: startTimestamp_(std::chrono::steady_clock::now()), phase_(phase) {}
2030

2131
EventLoopReporter::~EventLoopReporter() {
2232
PerformanceTracer& performanceTracer = PerformanceTracer::getInstance();
2333
if (performanceTracer.isTracing()) {
24-
auto end = HighResTimeStamp::now();
34+
auto end = std::chrono::steady_clock::now();
2535
switch (phase_) {
2636
case EventLoopPhase::Task:
27-
performanceTracer.reportEventLoopTask(startTimestamp_, end);
37+
performanceTracer.reportEventLoopTask(
38+
formatTimePointToUnixTimestamp(startTimestamp_),
39+
formatTimePointToUnixTimestamp(end));
2840
break;
2941

3042
case EventLoopPhase::Microtasks:
31-
performanceTracer.reportEventLoopMicrotasks(startTimestamp_, end);
43+
performanceTracer.reportEventLoopMicrotasks(
44+
formatTimePointToUnixTimestamp(startTimestamp_),
45+
formatTimePointToUnixTimestamp(end));
3246
break;
3347

3448
default:

packages/react-native/ReactCommon/jsinspector-modern/tracing/EventLoopReporter.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77

88
#pragma once
99

10-
#if defined(REACT_NATIVE_DEBUGGER_ENABLED)
11-
#include <react/timing/primitives.h>
12-
#endif
10+
#include <chrono>
1311

1412
namespace facebook::react::jsinspector_modern::tracing {
1513

@@ -31,7 +29,7 @@ struct EventLoopReporter {
3129

3230
private:
3331
#if defined(REACT_NATIVE_DEBUGGER_ENABLED)
34-
HighResTimeStamp startTimestamp_;
32+
std::chrono::steady_clock::time_point startTimestamp_;
3533
EventLoopPhase phase_;
3634
#endif
3735
};

packages/react-native/ReactCommon/jsinspector-modern/tracing/PerformanceTracer.cpp

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77

88
#include "PerformanceTracer.h"
9-
#include "Timing.h"
109

1110
#include <oscompat/OSCompat.h>
1211

@@ -15,7 +14,17 @@
1514
#include <array>
1615
#include <mutex>
1716

18-
namespace facebook::react::jsinspector_modern::tracing {
17+
namespace facebook::react::jsinspector_modern {
18+
19+
namespace {
20+
21+
uint64_t getUnixTimestampOfNow() {
22+
return std::chrono::duration_cast<std::chrono::microseconds>(
23+
std::chrono::steady_clock::now().time_since_epoch())
24+
.count();
25+
}
26+
27+
} // namespace
1928

2029
PerformanceTracer& PerformanceTracer::getInstance() {
2130
static PerformanceTracer tracer;
@@ -43,7 +52,7 @@ bool PerformanceTracer::startTracing() {
4352
.name = "TracingStartedInPage",
4453
.cat = "disabled-by-default-devtools.timeline",
4554
.ph = 'I',
46-
.ts = HighResTimeStamp::now(),
55+
.ts = getUnixTimestampOfNow(),
4756
.pid = processId_,
4857
.tid = oscompat::getCurrentThreadId(),
4958
.args = folly::dynamic::object("data", folly::dynamic::object()),
@@ -69,7 +78,7 @@ bool PerformanceTracer::stopTracing() {
6978
.name = "ReactNative-TracingStopped",
7079
.cat = "disabled-by-default-devtools.timeline",
7180
.ph = 'I',
72-
.ts = HighResTimeStamp::now(),
81+
.ts = getUnixTimestampOfNow(),
7382
.pid = processId_,
7483
.tid = oscompat::getCurrentThreadId(),
7584
});
@@ -108,7 +117,7 @@ void PerformanceTracer::collectEvents(
108117

109118
void PerformanceTracer::reportMark(
110119
const std::string_view& name,
111-
HighResTimeStamp start) {
120+
uint64_t start) {
112121
if (!tracing_) {
113122
return;
114123
}
@@ -130,8 +139,8 @@ void PerformanceTracer::reportMark(
130139

131140
void PerformanceTracer::reportMeasure(
132141
const std::string_view& name,
133-
HighResTimeStamp start,
134-
HighResDuration duration,
142+
uint64_t start,
143+
uint64_t duration,
135144
const std::optional<DevToolsTrackEntryPayload>& trackMetadata) {
136145
if (!tracing_) {
137146
return;
@@ -188,7 +197,7 @@ void PerformanceTracer::reportProcess(uint64_t id, const std::string& name) {
188197
.name = "process_name",
189198
.cat = "__metadata",
190199
.ph = 'M',
191-
.ts = TRACING_TIME_ORIGIN,
200+
.ts = 0,
192201
.pid = id,
193202
.tid = 0,
194203
.args = folly::dynamic::object("name", name),
@@ -213,7 +222,7 @@ void PerformanceTracer::reportThread(uint64_t id, const std::string& name) {
213222
.name = "thread_name",
214223
.cat = "__metadata",
215224
.ph = 'M',
216-
.ts = TRACING_TIME_ORIGIN,
225+
.ts = 0,
217226
.pid = processId_,
218227
.tid = id,
219228
.args = folly::dynamic::object("name", name),
@@ -228,15 +237,13 @@ void PerformanceTracer::reportThread(uint64_t id, const std::string& name) {
228237
.name = "ReactNative-ThreadRegistered",
229238
.cat = "disabled-by-default-devtools.timeline",
230239
.ph = 'I',
231-
.ts = TRACING_TIME_ORIGIN,
240+
.ts = 0,
232241
.pid = processId_,
233242
.tid = id,
234243
});
235244
}
236245

237-
void PerformanceTracer::reportEventLoopTask(
238-
HighResTimeStamp start,
239-
HighResTimeStamp end) {
246+
void PerformanceTracer::reportEventLoopTask(uint64_t start, uint64_t end) {
240247
if (!tracing_) {
241248
return;
242249
}
@@ -258,8 +265,8 @@ void PerformanceTracer::reportEventLoopTask(
258265
}
259266

260267
void PerformanceTracer::reportEventLoopMicrotasks(
261-
HighResTimeStamp start,
262-
HighResTimeStamp end) {
268+
uint64_t start,
269+
uint64_t end) {
263270
if (!tracing_) {
264271
return;
265272
}
@@ -283,36 +290,33 @@ void PerformanceTracer::reportEventLoopMicrotasks(
283290
folly::dynamic PerformanceTracer::getSerializedRuntimeProfileTraceEvent(
284291
uint64_t threadId,
285292
uint16_t profileId,
286-
HighResTimeStamp profileTimestamp) {
293+
uint64_t eventUnixTimestamp) {
287294
// CDT prioritizes event timestamp over startTime metadata field.
288295
// https://fburl.com/lo764pf4
289296
return serializeTraceEvent(TraceEvent{
290297
.id = profileId,
291298
.name = "Profile",
292299
.cat = "disabled-by-default-v8.cpu_profiler",
293300
.ph = 'P',
294-
.ts = profileTimestamp,
301+
.ts = eventUnixTimestamp,
295302
.pid = processId_,
296303
.tid = threadId,
297304
.args = folly::dynamic::object(
298-
"data",
299-
folly ::dynamic::object(
300-
"startTime",
301-
highResTimeStampToTracingClockTimeStamp(profileTimestamp))),
305+
"data", folly ::dynamic::object("startTime", eventUnixTimestamp)),
302306
});
303307
}
304308

305309
folly::dynamic PerformanceTracer::getSerializedRuntimeProfileChunkTraceEvent(
306310
uint16_t profileId,
307311
uint64_t threadId,
308-
HighResTimeStamp chunkTimestamp,
312+
uint64_t eventUnixTimestamp,
309313
const tracing::TraceEventProfileChunk& traceEventProfileChunk) {
310314
return serializeTraceEvent(TraceEvent{
311315
.id = profileId,
312316
.name = "ProfileChunk",
313317
.cat = "disabled-by-default-v8.cpu_profiler",
314318
.ph = 'P',
315-
.ts = chunkTimestamp,
319+
.ts = eventUnixTimestamp,
316320
.pid = processId_,
317321
.tid = threadId,
318322
.args =
@@ -332,15 +336,15 @@ folly::dynamic PerformanceTracer::serializeTraceEvent(
332336
result["name"] = event.name;
333337
result["cat"] = event.cat;
334338
result["ph"] = std::string(1, event.ph);
335-
result["ts"] = highResTimeStampToTracingClockTimeStamp(event.ts);
339+
result["ts"] = event.ts;
336340
result["pid"] = event.pid;
337341
result["tid"] = event.tid;
338342
result["args"] = event.args;
339343
if (event.dur.has_value()) {
340-
result["dur"] = highResDurationToTracingClockDuration(event.dur.value());
344+
result["dur"] = event.dur.value();
341345
}
342346

343347
return result;
344348
}
345349

346-
} // namespace facebook::react::jsinspector_modern::tracing
350+
} // namespace facebook::react::jsinspector_modern

packages/react-native/ReactCommon/jsinspector-modern/tracing/PerformanceTracer.h

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@
1111
#include "TraceEvent.h"
1212
#include "TraceEventProfile.h"
1313

14-
#include <react/timing/primitives.h>
15-
1614
#include <folly/dynamic.h>
15+
1716
#include <functional>
1817
#include <mutex>
1918
#include <optional>
2019
#include <vector>
2120

22-
namespace facebook::react::jsinspector_modern::tracing {
21+
namespace facebook::react::jsinspector_modern {
2322

2423
// TODO: Review how this API is integrated into jsinspector_modern (singleton
2524
// design is copied from earlier FuseboxTracer prototype).
@@ -66,7 +65,7 @@ class PerformanceTracer {
6665
*
6766
* See https://w3c.github.io/user-timing/#mark-method.
6867
*/
69-
void reportMark(const std::string_view& name, HighResTimeStamp start);
68+
void reportMark(const std::string_view& name, uint64_t start);
7069

7170
/**
7271
* Record a `Performance.measure()` event - a labelled duration. If not
@@ -76,8 +75,8 @@ class PerformanceTracer {
7675
*/
7776
void reportMeasure(
7877
const std::string_view& name,
79-
HighResTimeStamp start,
80-
HighResDuration duration,
78+
uint64_t start,
79+
uint64_t duration,
8180
const std::optional<DevToolsTrackEntryPayload>& trackMetadata);
8281

8382
/**
@@ -100,13 +99,13 @@ class PerformanceTracer {
10099
* Record an Event Loop tick, which will be represented as an Event Loop task
101100
* on a timeline view and grouped with JavaScript samples.
102101
*/
103-
void reportEventLoopTask(HighResTimeStamp start, HighResTimeStamp end);
102+
void reportEventLoopTask(uint64_t start, uint64_t end);
104103

105104
/**
106105
* Record Microtasks phase of the Event Loop tick. Will be represented as a
107106
* "Run Microtasks" block under a task.
108107
*/
109-
void reportEventLoopMicrotasks(HighResTimeStamp start, HighResTimeStamp end);
108+
void reportEventLoopMicrotasks(uint64_t start, uint64_t end);
110109

111110
/**
112111
* Create and serialize Profile Trace Event.
@@ -115,7 +114,7 @@ class PerformanceTracer {
115114
folly::dynamic getSerializedRuntimeProfileTraceEvent(
116115
uint64_t threadId,
117116
uint16_t profileId,
118-
HighResTimeStamp profileTimestamp);
117+
uint64_t eventUnixTimestamp);
119118

120119
/**
121120
* Create and serialize ProfileChunk Trace Event.
@@ -124,8 +123,8 @@ class PerformanceTracer {
124123
folly::dynamic getSerializedRuntimeProfileChunkTraceEvent(
125124
uint16_t profileId,
126125
uint64_t threadId,
127-
HighResTimeStamp chunkTimestamp,
128-
const TraceEventProfileChunk& traceEventProfileChunk);
126+
uint64_t eventUnixTimestamp,
127+
const tracing::TraceEventProfileChunk& traceEventProfileChunk);
129128

130129
private:
131130
PerformanceTracer();
@@ -136,11 +135,10 @@ class PerformanceTracer {
136135
folly::dynamic serializeTraceEvent(const TraceEvent& event) const;
137136

138137
bool tracing_{false};
139-
140138
uint64_t processId_;
141139
uint32_t performanceMeasureCount_{0};
142140
std::vector<TraceEvent> buffer_;
143141
std::mutex mutex_;
144142
};
145143

146-
} // namespace facebook::react::jsinspector_modern::tracing
144+
} // namespace facebook::react::jsinspector_modern

packages/react-native/ReactCommon/jsinspector-modern/tracing/React-jsinspectortracing.podspec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ Pod::Spec.new do |s|
4747
end
4848

4949
s.dependency "React-oscompat"
50-
s.dependency "React-timing"
5150

5251
add_rn_third_party_dependencies(s)
5352
end

0 commit comments

Comments
 (0)