Skip to content

Commit

Permalink
Feed React tracing into Instruments signposts API (#45169)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #45169

This is a follow-up to D56280451 where I made all SystraceSection calls feed into the Instruments signposts API. This will additionally do the same for all calls to nativeTraceBeginSection/nativeTraceEndSection from JSITracing.cpp.

Changelog: [Internal]

Differential Revision: D58895740
  • Loading branch information
lyahdav committed Jul 2, 2024
1 parent 3fc7ebb commit 95f096e
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions packages/react-native/ReactCommon/cxxreact/SystraceSection.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ using SystraceSectionUnwrapped = DummySystraceSection;
*/
#if defined(__APPLE__) && OS_LOG_TARGET_HAS_10_15_FEATURES && \
!defined(WITH_LOOM_TRACE)

namespace systrace {

template <typename T, typename = void>
Expand All @@ -95,21 +96,26 @@ static auto render(const T& t)

inline os_log_t instrumentsLogHandle = nullptr;

static inline os_log_t getOrCreateInstrumentsLogHandle() {
if (!instrumentsLogHandle) {
instrumentsLogHandle = os_log_create(
"dev.reactnative.instruments", OS_LOG_CATEGORY_DYNAMIC_TRACING);
}
return instrumentsLogHandle;
}

} // namespace systrace

struct SystraceSection {
public:
template <typename... ConvertsToStringPiece>
explicit SystraceSection(const char* name, ConvertsToStringPiece&&... args)
: systraceSectionUnwrapped_(name, args...) {
if (!systrace::instrumentsLogHandle) {
systrace::instrumentsLogHandle = os_log_create(
"dev.reactnative.instruments", OS_LOG_CATEGORY_DYNAMIC_TRACING);
}
os_log_t instrumentsLogHandle = systrace::getOrCreateInstrumentsLogHandle();

// If the log isn't enabled, we don't want the performance overhead of the
// rest of the code below.
if (!os_signpost_enabled(systrace::instrumentsLogHandle)) {
if (!os_signpost_enabled(instrumentsLogHandle)) {
return;
}

Expand All @@ -121,13 +127,12 @@ struct SystraceSection {
argsString += argsVector[i] + "=" + argsVector[i + 1] + ";";
}

signpostID_ =
os_signpost_id_make_with_pointer(systrace::instrumentsLogHandle, this);
signpostID_ = os_signpost_id_make_with_pointer(instrumentsLogHandle, this);

os_signpost_interval_begin(
systrace::instrumentsLogHandle,
instrumentsLogHandle,
signpostID_,
"SystraceSection",
"Systrace",
"%s begin: %s",
name,
argsString.c_str());
Expand All @@ -139,7 +144,7 @@ struct SystraceSection {
os_signpost_interval_end(
systrace::instrumentsLogHandle,
signpostID_,
"SystraceSection",
"Systrace",
"%s end",
name_.data());
}
Expand Down

0 comments on commit 95f096e

Please sign in to comment.