From 50561b553fa1ea7a8492c414a0a1020aea829847 Mon Sep 17 00:00:00 2001 From: Ruslan Shestopalyuk Date: Tue, 24 Dec 2024 01:15:56 -0800 Subject: [PATCH] Map SystraceSection to Perfetto instrumentation if the latter is enabled 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. Differential Revision: D67619443 --- .../ReactCommon/cxxreact/SystraceSection.h | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/packages/react-native/ReactCommon/cxxreact/SystraceSection.h b/packages/react-native/ReactCommon/cxxreact/SystraceSection.h index f661be97142eee..9521c3f0505950 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 @@ -51,12 +56,37 @@ struct ConcreteSystraceSection { explicit ConcreteSystraceSection( const char* name, ConvertsToStringPiece&&... args) - : m_section(TRACE_TAG_REACT_CXX_BRIDGE, name, args...) {} + : m_section(TRACE_TAG_REACT_CXX_BRIDGE, name, args...) { +#ifdef WITH_PERFETTO + TRACE_EVENT_BEGIN("react-native", perfetto::DynamicString{name}, args...); +#endif + } + + ~ConcreteSystraceSection() { +#ifdef WITH_PERFETTO + TRACE_EVENT_END("react-native"); +#endif + } private: fbsystrace::FbSystraceSection m_section; }; using SystraceSectionUnwrapped = ConcreteSystraceSection; +#elif defined(WITH_PERFETTO) +struct PerfettoSystraceSection { + public: + template + explicit PerfettoSystraceSection( + const __unused char* name, + __unused ConvertsToStringPiece&&... args) { + TRACE_EVENT_BEGIN("react-native", perfetto::DynamicString{name}, args...); + } + + ~ConcreteSystraceSection() { + TRACE_EVENT_END("react-native"); + } +}; +using SystraceSectionUnwrapped = PerfettoSystraceSection; #else struct DummySystraceSection { public: