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
This commit is contained in:
Ruslan Shestopalyuk authored and Facebook GitHub Bot committed 2024-12-24 07:47:50 -08:00
1 parent 74bdab8bd8
commit 17a644a230
1 file changed
+20
@@ -11,6 +11,11 @@
#include <fbsystrace.h>
#endif
#ifdef WITH_PERFETTO
#include <perfetto.h>
#include <reactperflogger/ReactPerfettoCategories.h>
#endif
#if defined(__APPLE__)
// This is required so that OS_LOG_TARGET_HAS_10_15_FEATURES will be set.
#include <os/trace_base.h>
@@ -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 <typename... ConvertsToStringPiece>
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: