Skip to content

Commit 8809392

Browse files
rubennortefacebook-github-bot
authored andcommitted
Add Systrace sections for async TurboModule calls on Android and iOS (#41192)
Summary: Pull Request resolved: #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
1 parent bf408a4 commit 8809392

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
*/
77

88
#include <memory>
9-
#include <sstream>
109
#include <string>
1110

11+
#include <cxxreact/SystraceSection.h>
1212
#include <fbjni/fbjni.h>
1313
#include <glog/logging.h>
1414
#include <jsi/jsi.h>
@@ -739,6 +739,15 @@ jsi::Value JavaTurboModule::invokeJavaMethod(
739739
moduleNameStr = name_,
740740
methodNameStr,
741741
id = getUniqueId()]() mutable {
742+
SystraceSection s(
743+
"JavaTurboModuleAsyncMethodInvocation",
744+
"module",
745+
moduleNameStr,
746+
"method",
747+
methodNameStr,
748+
"returnType",
749+
"void");
750+
742751
auto instance = instance_.lockLocal();
743752
if (!instance) {
744753
return;
@@ -822,6 +831,15 @@ jsi::Value JavaTurboModule::invokeJavaMethod(
822831
moduleNameStr = name_,
823832
methodNameStr,
824833
id = getUniqueId()]() mutable {
834+
SystraceSection s(
835+
"JavaTurboModuleAsyncMethodInvocation",
836+
"module",
837+
moduleNameStr,
838+
"method",
839+
methodNameStr,
840+
"returnType",
841+
"promise");
842+
825843
auto instance = instance_.lockLocal();
826844
if (!instance) {
827845
return;

packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.mm

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
#import "RCTTurboModule.h"
99
#import "RCTBlockGuard.h"
1010

11-
#include <glog/logging.h>
11+
#import <cxxreact/SystraceSection.h>
12+
#import <glog/logging.h>
1213
#import <objc/message.h>
1314
#import <objc/runtime.h>
1415
#import <atomic>
@@ -425,7 +426,17 @@ id convertJSIValueToObjCObject(jsi::Runtime &runtime, const jsi::Value &value, s
425426
} else {
426427
asyncCallCounter = getUniqueId();
427428
TurboModulePerfLogger::asyncMethodCallDispatch(moduleName, methodName);
428-
nativeMethodCallInvoker_->invokeAsync(methodNameStr, [block]() -> void { block(); });
429+
nativeMethodCallInvoker_->invokeAsync(methodNameStr, [block, moduleName, methodNameStr]() -> void {
430+
SystraceSection s(
431+
"RCTTurboModuleAsyncMethodInvocation",
432+
"module",
433+
moduleName,
434+
"method",
435+
methodNameStr,
436+
"returnType",
437+
"promise");
438+
block();
439+
});
429440
return nil;
430441
}
431442
}
@@ -475,7 +486,11 @@ id convertJSIValueToObjCObject(jsi::Runtime &runtime, const jsi::Value &value, s
475486
} else {
476487
asyncCallCounter = getUniqueId();
477488
TurboModulePerfLogger::asyncMethodCallDispatch(moduleName, methodName);
478-
nativeMethodCallInvoker_->invokeAsync(methodNameStr, [block]() -> void { block(); });
489+
nativeMethodCallInvoker_->invokeAsync(methodNameStr, [moduleName, methodNameStr, block]() -> void {
490+
SystraceSection s(
491+
"RCTTurboModuleAsyncMethodInvocation", "module", moduleName, "method", methodNameStr, "returnType", "void");
492+
block();
493+
});
479494
}
480495
}
481496

0 commit comments

Comments
 (0)