From 539788eb6e47ec6ccbce05a367d1b6100b1ec8f6 Mon Sep 17 00:00:00 2001 From: Liron Yahdav Date: Tue, 9 Jul 2024 14:01:39 -0700 Subject: [PATCH] Feed React tracing into Instruments signposts API (#45169) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/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] Reviewed By: sammy-SC Differential Revision: D58895740 fbshipit-source-id: ee1cdff883ac1172f9bafe11ab950738d7ae7f82 --- .../ReactCommon/cxxreact/SystraceSection.h | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/packages/react-native/ReactCommon/cxxreact/SystraceSection.h b/packages/react-native/ReactCommon/cxxreact/SystraceSection.h index 59fa9e35e0e..f661be97142 100644 --- a/packages/react-native/ReactCommon/cxxreact/SystraceSection.h +++ b/packages/react-native/ReactCommon/cxxreact/SystraceSection.h @@ -76,6 +76,7 @@ using SystraceSectionUnwrapped = DummySystraceSection; */ #if defined(__APPLE__) && OS_LOG_TARGET_HAS_10_15_FEATURES && \ !defined(WITH_LOOM_TRACE) + namespace systrace { template @@ -95,6 +96,14 @@ 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 { @@ -102,14 +111,11 @@ struct SystraceSection { template 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; } @@ -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()); @@ -139,7 +144,7 @@ struct SystraceSection { os_signpost_interval_end( systrace::instrumentsLogHandle, signpostID_, - "SystraceSection", + "Systrace", "%s end", name_.data()); }