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
This commit is contained in:
Rubén Norte authored and Facebook GitHub Bot committed 2023-10-25 11:49:00 -07:00
1 parent bf408a409b
commit 8809392d87
2 files changed
+37 -4

No files matched your search

@@ -6,9 +6,9 @@
*/
#include <memory>
#include <sstream>
#include <string>
#include <cxxreact/SystraceSection.h>
#include <fbjni/fbjni.h>
#include <glog/logging.h>
#include <jsi/jsi.h>
@@ -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;
@@ -8,7 +8,8 @@
#import "RCTTurboModule.h"
#import "RCTBlockGuard.h"
#include <glog/logging.h>
#import <cxxreact/SystraceSection.h>
#import <glog/logging.h>
#import <objc/message.h>
#import <objc/runtime.h>
#import <atomic>
@@ -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();
});
}
}