From 0b6ed6c7d5da08179e43e52f984615f014693028 Mon Sep 17 00:00:00 2001 From: Ruslan Lesiutin Date: Thu, 1 May 2025 00:22:44 -0700 Subject: [PATCH] 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 --- .../HermesRuntimeSamplingProfileSerializer.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/react-native/ReactCommon/hermes/inspector-modern/chrome/HermesRuntimeSamplingProfileSerializer.cpp b/packages/react-native/ReactCommon/hermes/inspector-modern/chrome/HermesRuntimeSamplingProfileSerializer.cpp index 0c654a303a5..f30924441fc 100644 --- a/packages/react-native/ReactCommon/hermes/inspector-modern/chrome/HermesRuntimeSamplingProfileSerializer.cpp +++ b/packages/react-native/ReactCommon/hermes/inspector-modern/chrome/HermesRuntimeSamplingProfileSerializer.cpp @@ -91,14 +91,13 @@ RuntimeSamplingProfile::SampleCallStackFrame convertJSFunctionHermesFrame( RuntimeSamplingProfile::Sample convertHermesSampleToTracingSample( const fhsp::ProfileSample& hermesSample) { uint64_t reconciledTimestamp = hermesSample.getTimestamp(); - const std::vector& hermesSampleCallStack = - hermesSample.getCallStack(); + const auto callStackRange = hermesSample.getCallStackFramesRange(); std::vector reconciledSampleCallStack; - reconciledSampleCallStack.reserve(hermesSampleCallStack.size()); + reconciledSampleCallStack.reserve(hermesSample.getCallStackFramesCount()); - for (const auto& hermesFrame : hermesSampleCallStack) { + for (const auto& hermesFrame : callStackRange) { if (std::holds_alternative( hermesFrame)) { const auto& suspendFrame = @@ -146,12 +145,11 @@ RuntimeSamplingProfile::Sample convertHermesSampleToTracingSample( /* static */ RuntimeSamplingProfile HermesRuntimeSamplingProfileSerializer::serializeToTracingSamplingProfile( const hermes::sampling_profiler::Profile& hermesProfile) { - const std::vector& hermesSamples = - hermesProfile.getSamples(); + const auto samplesRange = hermesProfile.getSamplesRange(); std::vector 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));