Use in performance.measure (#54337)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/54337

# Changelog: [Internal]

The approach is identical to `console.timeStamp()`, see the diff below for more context.

In this diff, we apply this approach to `performance.measure()`.

Reviewed By: huntie

Differential Revision: D85481863

fbshipit-source-id: 061996b1a3801907fa611889cd2cc59606be5d43
This commit is contained in:
Ruslan Lesiutin authored and meta-codesync[bot] committed 2025-11-06 04:25:36 -08:00
1 parent af23d4e1f0
commit 7722eae226
5 files changed
+24 -3

No files matched your search

@@ -187,7 +187,8 @@ void PerformanceTracer::reportMeasure(
const std::string& name,
HighResTimeStamp start,
HighResDuration duration,
folly::dynamic&& detail) {
folly::dynamic&& detail,
std::function<std::optional<folly::dynamic>()>&& stackTraceProvider) {
if (!tracingAtomic_) {
return;
}
@@ -204,6 +205,7 @@ void PerformanceTracer::reportMeasure(
.duration = duration,
.detail = std::move(detail),
.threadId = getCurrentThreadId(),
.stackTraceProvider = std::move(stackTraceProvider),
});
}
@@ -608,6 +610,12 @@ void PerformanceTracer::enqueueTraceEventsFromPerformanceTracerEvent(
beginEventArgs =
folly::dynamic::object("detail", folly::toJson(event.detail));
}
if (event.stackTraceProvider) {
if (auto maybeStackTrace = event.stackTraceProvider()) {
beginEventArgs["data"] = folly::dynamic::object(
"rnStackTrace", std::move(*maybeStackTrace));
}
}
auto eventId = ++performanceMeasureCount_;
@@ -81,7 +81,8 @@ class PerformanceTracer {
const std::string &name,
HighResTimeStamp start,
HighResDuration duration,
folly::dynamic &&detail = nullptr);
folly::dynamic &&detail = nullptr,
std::function<std::optional<folly::dynamic>()> &&stackTraceProvider = nullptr);
/**
* Record a "TimeStamp" Trace Event - a labelled entry on Performance
@@ -257,6 +258,7 @@ class PerformanceTracer {
HighResDuration duration;
folly::dynamic detail;
ThreadId threadId;
std::function<std::optional<folly::dynamic>()> stackTraceProvider;
HighResTimeStamp createdAt = HighResTimeStamp::now();
};
@@ -16,6 +16,7 @@ target_compile_options(react_performance_timeline PRIVATE -Wpedantic)
target_include_directories(react_performance_timeline PUBLIC ${REACT_COMMON_DIR})
target_link_libraries(react_performance_timeline
jsinspector
jsinspector_tracing
reactperflogger
react_featureflags
@@ -7,6 +7,7 @@
#include "PerformanceEntryReporter.h"
#include <jsinspector-modern/ConsoleTaskOrchestrator.h>
#include <jsinspector-modern/tracing/PerformanceTracer.h>
#include <react/featureflags/ReactNativeFeatureFlags.h>
#include <react/timing/primitives.h>
@@ -381,8 +382,16 @@ void PerformanceEntryReporter::traceMeasure(
}
if (performanceTracer.isTracing()) {
auto taskContext =
jsinspector_modern::ConsoleTaskOrchestrator::getInstance().top();
performanceTracer.reportMeasure(
entry.name, entry.startTime, entry.duration, std::move(detail));
entry.name,
entry.startTime,
entry.duration,
std::move(detail),
taskContext ? taskContext->getSerializedStackTraceProvider()
: nullptr);
}
}
}
@@ -41,6 +41,7 @@ Pod::Spec.new do |s|
resolve_use_frameworks(s, header_mappings_dir: "../../..", module_name: "React_performancetimeline")
s.dependency "React-featureflags"
add_dependency(s, "React-jsinspector", :framework_name => 'jsinspector_modern')
add_dependency(s, "React-jsinspectortracing", :framework_name => 'jsinspector_moderntracing')
s.dependency "React-timing"
s.dependency "React-perflogger"