From 879da82769b47be0e375e5e37ac81697bb0c1fdc Mon Sep 17 00:00:00 2001 From: Ruslan Shestopalyuk Date: Tue, 24 Dec 2024 04:38:56 -0800 Subject: [PATCH] Map SystraceSection to Perfetto instrumentation if the latter is enabled (#48379) Summary: ## 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 --- .../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 f661be97142e..e472374ee62a 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: