mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Instrument sync and async method calls (#28893)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/28893 `JSIExecutor::callSerializableNativeHook` converts the arguments from `JSI::Value` to `folly::dynamic`. Then, `RCTNativeModule` converts the arguments from `folly::dynamic` to ObjC data structures in its `static invokeInner` function. Therefore, I decided to start the sync markers inside `JSIExecutor::callSerializableNativeHook`, which required me to expose these two methode `ModuleRegistry::getModuleName` and `ModuleRegistry::getModuleSyncMethodName`. This shouldn't modify performance because we eagerly generate a NativeModule's methods when it's first required. So, at worst, this is doing a cache lookup. Changelog: [Internal] Reviewed By: PeteTheHeat Differential Revision: D21443610 fbshipit-source-id: 67cf563b0b06153e56e63ba7e186eea31eafc853
This commit is contained in:
committed by
Facebook GitHub Bot
parent
bf0e516086
commit
0b8a82a6ee
@@ -50,6 +50,26 @@ std::string JavaNativeModule::getName() {
|
||||
return getNameMethod(wrapper_)->toStdString();
|
||||
}
|
||||
|
||||
std::string JavaNativeModule::getSyncMethodName(unsigned int reactMethodId) {
|
||||
if (reactMethodId >= syncMethods_.size()) {
|
||||
throw std::invalid_argument(folly::to<std::string>(
|
||||
"methodId ",
|
||||
reactMethodId,
|
||||
" out of range [0..",
|
||||
syncMethods_.size(),
|
||||
"]"));
|
||||
}
|
||||
|
||||
auto &methodInvoker = syncMethods_[reactMethodId];
|
||||
|
||||
if (!methodInvoker.hasValue()) {
|
||||
throw std::invalid_argument(folly::to<std::string>(
|
||||
"methodId ", reactMethodId, " is not a recognized sync method"));
|
||||
}
|
||||
|
||||
return methodInvoker->getMethodName();
|
||||
}
|
||||
|
||||
std::vector<MethodDescriptor> JavaNativeModule::getMethods() {
|
||||
std::vector<MethodDescriptor> ret;
|
||||
syncMethods_.clear();
|
||||
@@ -69,6 +89,7 @@ std::vector<MethodDescriptor> JavaNativeModule::getMethods() {
|
||||
syncMethods_.begin() + methodIndex,
|
||||
MethodInvoker(
|
||||
desc->getMethod(),
|
||||
methodName,
|
||||
desc->getSignature(),
|
||||
getName() + "." + methodName,
|
||||
true));
|
||||
@@ -148,6 +169,7 @@ NewJavaNativeModule::NewJavaNativeModule(
|
||||
auto name = desc->getName();
|
||||
methods_.emplace_back(
|
||||
desc->getMethod(),
|
||||
desc->getName(),
|
||||
desc->getSignature(),
|
||||
moduleName + "." + name,
|
||||
type == "syncHook");
|
||||
|
||||
@@ -69,6 +69,7 @@ class JavaNativeModule : public NativeModule {
|
||||
messageQueueThread_(std::move(messageQueueThread)) {}
|
||||
|
||||
std::string getName() override;
|
||||
std::string getSyncMethodName(unsigned int reactMethodId) override;
|
||||
folly::dynamic getConstants() override;
|
||||
std::vector<MethodDescriptor> getMethods() override;
|
||||
void invoke(unsigned int reactMethodId, folly::dynamic &¶ms, int callId)
|
||||
|
||||
@@ -190,10 +190,12 @@ std::size_t countJsArgs(const std::string &signature) {
|
||||
|
||||
MethodInvoker::MethodInvoker(
|
||||
alias_ref<JReflectMethod::javaobject> method,
|
||||
std::string methodName,
|
||||
std::string signature,
|
||||
std::string traceName,
|
||||
bool isSync)
|
||||
: method_(method->getMethodID()),
|
||||
methodName_(methodName),
|
||||
signature_(signature),
|
||||
jsArgCount_(countJsArgs(signature) - 2),
|
||||
traceName_(std::move(traceName)),
|
||||
@@ -203,6 +205,10 @@ MethodInvoker::MethodInvoker(
|
||||
<< "Non-sync hooks cannot have a non-void return type";
|
||||
}
|
||||
|
||||
std::string MethodInvoker::getMethodName() const {
|
||||
return methodName_;
|
||||
}
|
||||
|
||||
MethodCallResult MethodInvoker::invoke(
|
||||
std::weak_ptr<Instance> &instance,
|
||||
alias_ref<JBaseJavaModule::javaobject> module,
|
||||
|
||||
@@ -37,6 +37,7 @@ class MethodInvoker {
|
||||
public:
|
||||
MethodInvoker(
|
||||
jni::alias_ref<JReflectMethod::javaobject> method,
|
||||
std::string methodName,
|
||||
std::string signature,
|
||||
std::string traceName,
|
||||
bool isSync);
|
||||
@@ -46,12 +47,15 @@ class MethodInvoker {
|
||||
jni::alias_ref<JBaseJavaModule::javaobject> module,
|
||||
const folly::dynamic ¶ms);
|
||||
|
||||
std::string getMethodName() const;
|
||||
|
||||
bool isSyncHook() const {
|
||||
return isSync_;
|
||||
}
|
||||
|
||||
private:
|
||||
jmethodID method_;
|
||||
std::string methodName_;
|
||||
std::string signature_;
|
||||
std::size_t jsArgCount_;
|
||||
std::string traceName_;
|
||||
|
||||
Reference in New Issue
Block a user