From 17a644a230d2db63790138ce4880485f263a9e53 Mon Sep 17 00:00:00 2001 From: Ruslan Shestopalyuk Date: Tue, 24 Dec 2024 07:47:50 -0800 Subject: [PATCH] Map SystraceSection to Perfetto instrumentation if the latter is enabled (#48379) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/48379 ## Changelog: [Internal] - We have a good portion of RN core code already instrumented with `SystraceSection` blocks, and those do the timing via fbsystrace, which may or may not be enabled in the system and generally is obsolete. This maps the blocks to the corresponding Perfetto instrumentation, in case the latter is enabled, which will allow to get this information in Perfetto sessions without need to have fbsystrace present. Reviewed By: javache Differential Revision: D67619443 fbshipit-source-id: 52e5666472ad118fbec176a0e82d72a5200a358a --- .../ReactCommon/cxxreact/SystraceSection.h | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/packages/react-native/ReactCommon/cxxreact/SystraceSection.h b/packages/react-native/ReactCommon/cxxreact/SystraceSection.h index f661be97142..e472374ee62 100644 --- a/packages/react-native/ReactCommon/cxxreact/SystraceSection.h +++ b/packages/react-native/ReactCommon/cxxreact/SystraceSection.h @@ -11,6 +11,11 @@ #include #endif +#ifdef WITH_PERFETTO +#include +#include +#endif + #if defined(__APPLE__) // This is required so that OS_LOG_TARGET_HAS_10_15_FEATURES will be set. #include @@ -44,6 +49,21 @@ namespace facebook::react { * different values in different files, there is no inconsistency in the sizes * of defined symbols. */ +#elif defined(WITH_PERFETTO) +struct TraceSection { + public: + template + explicit TraceSection( + const __unused char* name, + __unused ConvertsToStringPiece&&... args) { + TRACE_EVENT_BEGIN("react-native", perfetto::DynamicString{name}, args...); + } + + ~TraceSection() { + TRACE_EVENT_END("react-native"); + } +}; +using SystraceSectionUnwrapped = TraceSection; #elif defined(WITH_FBSYSTRACE) struct ConcreteSystraceSection { public: