Skip to content

Commit

Permalink
Map SystraceSection to Perfetto instrumentation if the latter is enabled
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rshest authored and facebook-github-bot committed Dec 24, 2024
1 parent 974fdf9 commit 50561b5
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion packages/react-native/ReactCommon/cxxreact/SystraceSection.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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 <typename... ConvertsToStringPiece>
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:
Expand Down

0 comments on commit 50561b5

Please sign in to comment.