Skip to content

Commit 2322357

Browse files
sbuggayfacebook-github-bot
authored andcommitted
Add optional screenshot argument to FrameTimingSequence
Summary: Instead of creating another buffer, optionally include screenshots if they are enabled in `FrameTimingSequence`. Changelog: [Internal] Differential Revision: D87936871
1 parent 78b8357 commit 2322357

File tree

5 files changed

+23
-3
lines changed

5 files changed

+23
-3
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/inspector/FrameTimingSequence.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ internal data class FrameTimingSequence(
1313
val beginDrawingTimestamp: Long,
1414
val commitTimestamp: Long,
1515
val endDrawingTimestamp: Long,
16+
val screenshot: String? = null,
1617
)

packages/react-native/ReactAndroid/src/main/jni/react/runtime/jni/JReactHostInspectorTarget.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ void JReactHostInspectorTarget::recordFrameTimings(
300300
frameTimingSequence->getBeginDrawingTimestamp(),
301301
frameTimingSequence->getCommitTimestamp(),
302302
frameTimingSequence->getEndDrawingTimestamp(),
303+
frameTimingSequence->getScreenshot(),
303304
});
304305
}
305306

packages/react-native/ReactAndroid/src/main/jni/react/runtime/jni/JReactHostInspectorTarget.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,17 @@ struct JFrameTimingSequence : public jni::JavaClass<JFrameTimingSequence> {
6767
return HighResTimeStamp::fromChronoSteadyClockTimePoint(
6868
std::chrono::steady_clock::time_point(std::chrono::nanoseconds(getFieldValue(field))));
6969
}
70+
71+
std::optional<std::string> getScreenshot() const
72+
{
73+
auto field = javaClassStatic()->getField<jstring>("screenshot");
74+
auto javaScreenshot = getFieldValue(field);
75+
if (javaScreenshot) {
76+
auto jstring = jni::static_ref_cast<jni::JString>(javaScreenshot);
77+
return jstring->toStdString();
78+
}
79+
return std::nullopt;
80+
}
7081
};
7182

7283
struct JReactHostImpl : public jni::JavaClass<JReactHostImpl> {

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ struct FrameTimingSequence {
2424
ThreadId threadId,
2525
HighResTimeStamp beginDrawingTimestamp,
2626
HighResTimeStamp commitTimestamp,
27-
HighResTimeStamp endDrawingTimestamp)
27+
HighResTimeStamp endDrawingTimestamp,
28+
std::optional<std::string> screenshot = std::nullopt)
2829
: id(id),
2930
threadId(threadId),
3031
beginDrawingTimestamp(beginDrawingTimestamp),
3132
commitTimestamp(commitTimestamp),
32-
endDrawingTimestamp(endDrawingTimestamp)
33+
endDrawingTimestamp(endDrawingTimestamp),
34+
screenshot(std::move(screenshot))
3335
{
3436
}
3537

@@ -46,6 +48,11 @@ struct FrameTimingSequence {
4648
HighResTimeStamp beginDrawingTimestamp;
4749
HighResTimeStamp commitTimestamp;
4850
HighResTimeStamp endDrawingTimestamp;
51+
52+
/**
53+
* Optional screenshot data (base64 encoded) captured during the frame.
54+
*/
55+
std::optional<std::string> screenshot;
4956
};
5057

5158
} // namespace facebook::react::jsinspector_modern::tracing

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ constexpr int FALLBACK_LAYER_TREE_ID = 1;
100100
chunk.push_back(
101101
TraceEventSerializer::serialize(std::move(setLayerTreeIdEvent)));
102102

103-
for (const auto& frameTimingSequence : frameTimings) {
103+
for (auto&& frameTimingSequence : frameTimings) {
104104
if (chunk.size() >= chunkSize) {
105105
chunkCallback(std::move(chunk));
106106
chunk = generateNewChunk(chunkSize);

0 commit comments

Comments
 (0)