From 8809392d87d687196a67a66d75e7b767d36237fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Wed, 25 Oct 2023 11:49:00 -0700 Subject: [PATCH] Add Systrace sections for async TurboModule calls on Android and iOS (#41192) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/41192 We currently don't have visibility on what the native module thread is doing when it's busy (on Android). This adds Systrace blocks to at least know the native module and the method we're running there. Changelog: [internal] Reviewed By: ryancat Differential Revision: D50645557 fbshipit-source-id: 5cb6a7f1166bfd50c28f0aba634552c35a34c941 --- .../android/ReactCommon/JavaTurboModule.cpp | 20 +++++++++++++++++- .../ios/ReactCommon/RCTTurboModule.mm | 21 ++++++++++++++++--- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp b/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp index 724d91e3ccb..2153e5e8e7c 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp +++ b/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp @@ -6,9 +6,9 @@ */ #include -#include #include +#include #include #include #include @@ -739,6 +739,15 @@ jsi::Value JavaTurboModule::invokeJavaMethod( moduleNameStr = name_, methodNameStr, id = getUniqueId()]() mutable { + SystraceSection s( + "JavaTurboModuleAsyncMethodInvocation", + "module", + moduleNameStr, + "method", + methodNameStr, + "returnType", + "void"); + auto instance = instance_.lockLocal(); if (!instance) { return; @@ -822,6 +831,15 @@ jsi::Value JavaTurboModule::invokeJavaMethod( moduleNameStr = name_, methodNameStr, id = getUniqueId()]() mutable { + SystraceSection s( + "JavaTurboModuleAsyncMethodInvocation", + "module", + moduleNameStr, + "method", + methodNameStr, + "returnType", + "promise"); + auto instance = instance_.lockLocal(); if (!instance) { return; diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.mm b/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.mm index 8caecfb664b..ff46972196f 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.mm +++ b/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.mm @@ -8,7 +8,8 @@ #import "RCTTurboModule.h" #import "RCTBlockGuard.h" -#include +#import +#import #import #import #import @@ -425,7 +426,17 @@ id ObjCTurboModule::performMethodInvocation( } else { asyncCallCounter = getUniqueId(); TurboModulePerfLogger::asyncMethodCallDispatch(moduleName, methodName); - nativeMethodCallInvoker_->invokeAsync(methodNameStr, [block]() -> void { block(); }); + nativeMethodCallInvoker_->invokeAsync(methodNameStr, [block, moduleName, methodNameStr]() -> void { + SystraceSection s( + "RCTTurboModuleAsyncMethodInvocation", + "module", + moduleName, + "method", + methodNameStr, + "returnType", + "promise"); + block(); + }); return nil; } } @@ -475,7 +486,11 @@ void ObjCTurboModule::performVoidMethodInvocation( } else { asyncCallCounter = getUniqueId(); TurboModulePerfLogger::asyncMethodCallDispatch(moduleName, methodName); - nativeMethodCallInvoker_->invokeAsync(methodNameStr, [block]() -> void { block(); }); + nativeMethodCallInvoker_->invokeAsync(methodNameStr, [moduleName, methodNameStr, block]() -> void { + SystraceSection s( + "RCTTurboModuleAsyncMethodInvocation", "module", moduleName, "method", methodNameStr, "returnType", "void"); + block(); + }); } }