Define range for iteration over samples and call stack frames (#51029)

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

# Changelog: [Internal]

Instead of exposing vector of samples / call frames directly, we will share pair of iterators that would allow iterating over them in a specified order.

Reviewed By: dannysu

Differential Revision: D73448002

fbshipit-source-id: 16c476453e943a71403b375b168b30da7d261cfa
This commit is contained in:
Ruslan Lesiutin authored and Facebook GitHub Bot committed 2025-05-01 00:22:44 -07:00
1 parent a5f2acde20
commit 0b6ed6c7d5
1 file changed
+6 -8
@@ -91,14 +91,13 @@ RuntimeSamplingProfile::SampleCallStackFrame convertJSFunctionHermesFrame(
RuntimeSamplingProfile::Sample convertHermesSampleToTracingSample(
const fhsp::ProfileSample& hermesSample) {
uint64_t reconciledTimestamp = hermesSample.getTimestamp();
const std::vector<fhsp::ProfileSampleCallStackFrame>& hermesSampleCallStack =
hermesSample.getCallStack();
const auto callStackRange = hermesSample.getCallStackFramesRange();
std::vector<RuntimeSamplingProfile::SampleCallStackFrame>
reconciledSampleCallStack;
reconciledSampleCallStack.reserve(hermesSampleCallStack.size());
reconciledSampleCallStack.reserve(hermesSample.getCallStackFramesCount());
for (const auto& hermesFrame : hermesSampleCallStack) {
for (const auto& hermesFrame : callStackRange) {
if (std::holds_alternative<fhsp::ProfileSampleCallStackSuspendFrame>(
hermesFrame)) {
const auto& suspendFrame =
@@ -146,12 +145,11 @@ RuntimeSamplingProfile::Sample convertHermesSampleToTracingSample(
/* static */ RuntimeSamplingProfile
HermesRuntimeSamplingProfileSerializer::serializeToTracingSamplingProfile(
const hermes::sampling_profiler::Profile& hermesProfile) {
const std::vector<hermes::sampling_profiler::ProfileSample>& hermesSamples =
hermesProfile.getSamples();
const auto samplesRange = hermesProfile.getSamplesRange();
std::vector<RuntimeSamplingProfile::Sample> reconciledSamples;
reconciledSamples.reserve(hermesSamples.size());
reconciledSamples.reserve(hermesProfile.getSamplesCount());
for (const auto& hermesSample : hermesSamples) {
for (const auto& hermesSample : samplesRange) {
RuntimeSamplingProfile::Sample reconciledSample =
convertHermesSampleToTracingSample(hermesSample);
reconciledSamples.push_back(std::move(reconciledSample));