Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions packages/react-native/ReactCommon/cxxreact/TraceSection.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
#include <reactperflogger/ReactPerfettoCategories.h>
#endif

#if defined(__ANDROID__) && __ANDROID_API__ >= 23 && !defined(WITH_PERFETTO) && !defined(WITH_FBSYSTRACE)
#include <android/trace.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 @@ -95,6 +99,34 @@ struct ConcreteTraceSection {
fbsystrace::FbSystraceSection m_section;
};
using TraceSectionUnwrapped = ConcreteTraceSection;
#elif defined(__ANDROID__) && __ANDROID_API__ >= 23
// Route TraceSection to the platform ATrace API so
// that C++ sections show up in Perfetto/systrace captures of OSS builds.
struct ATraceSection {
public:
template <typename... ConvertsToStringPiece>
explicit ATraceSection(const char *name, [[maybe_unused]] ConvertsToStringPiece &&...args)
{
if (ATrace_isEnabled()) {
ATrace_beginSection(name);
active_ = true;
}
}

~ATraceSection()
{
if (active_) {
ATrace_endSection();
}
}

ATraceSection(const ATraceSection &) = delete;
ATraceSection &operator=(const ATraceSection &) = delete;

private:
bool active_{false};
};
using TraceSectionUnwrapped = ATraceSection;
#else
struct DummyTraceSection {
public:
Expand Down
Loading