mirror of
https://github.com/status-im/react-native.git
synced 2025-02-04 05:34:15 +00:00
Create tracing name in C++ instead of Java
Reviewed By: mhorowitz Differential Revision: D3469140 fbshipit-source-id: 77a00a7150573e44f219972556cbb936a57d7054
This commit is contained in:
parent
af24e8001a
commit
95401aba72
@ -32,8 +32,7 @@ public interface CatalystInstance extends MemoryPressureListener {
|
||||
ExecutorToken executorToken,
|
||||
String module,
|
||||
String method,
|
||||
NativeArray arguments,
|
||||
String tracingName);
|
||||
NativeArray arguments);
|
||||
/**
|
||||
* Destroys this catalyst instance, waiting for any other threads in ReactQueueConfiguration
|
||||
* (besides the UI thread) to finish running. Must be called from the UI thread so that we can
|
||||
|
@ -164,8 +164,7 @@ public class CatalystInstanceImpl implements CatalystInstance {
|
||||
ExecutorToken executorToken,
|
||||
String module,
|
||||
String method,
|
||||
NativeArray arguments,
|
||||
String tracingName) {
|
||||
NativeArray arguments) {
|
||||
if (mIsBeingDestroyed) {
|
||||
FLog.w(ReactConstants.TAG, "Calling JS function after bridge has been destroyed.");
|
||||
return;
|
||||
@ -178,10 +177,11 @@ public class CatalystInstanceImpl implements CatalystInstance {
|
||||
|
||||
incrementPendingJSCalls();
|
||||
|
||||
Assertions.assertNotNull(mBridge).callFunction(executorToken,
|
||||
module,
|
||||
method, arguments, tracingName);
|
||||
}
|
||||
Assertions.assertNotNull(mBridge).callFunction(
|
||||
executorToken,
|
||||
module,
|
||||
method, arguments);
|
||||
}
|
||||
}
|
||||
|
||||
// This is called from java code, so it won't be stripped anyway, but proguard will rename it,
|
||||
|
@ -13,10 +13,8 @@ import javax.annotation.concurrent.Immutable;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.facebook.react.common.build.ReactBuildConfig;
|
||||
@ -28,11 +26,9 @@ import com.facebook.react.common.build.ReactBuildConfig;
|
||||
public class JavaScriptModuleRegistration {
|
||||
|
||||
private final Class<? extends JavaScriptModule> mModuleInterface;
|
||||
private final Map<Method, String> mMethodsToTracingNames;
|
||||
|
||||
public JavaScriptModuleRegistration(Class<? extends JavaScriptModule> moduleInterface) {
|
||||
mModuleInterface = moduleInterface;
|
||||
mMethodsToTracingNames = new HashMap<>();
|
||||
|
||||
if (ReactBuildConfig.DEBUG) {
|
||||
Set<String> methodNames = new LinkedHashSet<>();
|
||||
@ -46,15 +42,6 @@ public class JavaScriptModuleRegistration {
|
||||
}
|
||||
}
|
||||
|
||||
public String getTracingName(Method method) {
|
||||
String name = mMethodsToTracingNames.get(method);
|
||||
if (name == null) {
|
||||
name = "JSCall__" + getName() + "_" + method.getName();
|
||||
mMethodsToTracingNames.put(method, name);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
public Class<? extends JavaScriptModule> getModuleInterface() {
|
||||
return mModuleInterface;
|
||||
}
|
||||
|
@ -106,14 +106,13 @@ public class JavaScriptModuleRegistry {
|
||||
FLog.w(ReactConstants.TAG, "Dropping JS call, ExecutorToken went away...");
|
||||
return null;
|
||||
}
|
||||
String tracingName = mModuleRegistration.getTracingName(method);
|
||||
NativeArray jsArgs = args != null ? Arguments.fromJavaArgs(args) : new WritableNativeArray();
|
||||
mCatalystInstance.callFunction(
|
||||
executorToken,
|
||||
mModuleRegistration.getName(),
|
||||
method.getName(),
|
||||
jsArgs,
|
||||
tracingName);
|
||||
jsArgs
|
||||
);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ public class ReactBridge extends Countable {
|
||||
*/
|
||||
public native void loadScriptFromAssets(AssetManager assetManager, String assetName);
|
||||
public native void loadScriptFromFile(@Nullable String fileName, @Nullable String sourceURL);
|
||||
public native void callFunction(ExecutorToken executorToken, String module, String method, NativeArray arguments, String tracingName);
|
||||
public native void callFunction(ExecutorToken executorToken, String module, String method, NativeArray arguments);
|
||||
public native void invokeCallback(ExecutorToken executorToken, int callbackID, NativeArray arguments);
|
||||
public native void setGlobalVariable(String propertyName, String jsonEncodedArgument);
|
||||
public native boolean supportsProfiling();
|
||||
|
@ -182,16 +182,14 @@ public class CatalystInstanceImpl implements CatalystInstance {
|
||||
ExecutorToken token,
|
||||
String module,
|
||||
String method,
|
||||
NativeArray arguments,
|
||||
String tracingName);
|
||||
NativeArray arguments);
|
||||
|
||||
@Override
|
||||
public void callFunction(
|
||||
ExecutorToken executorToken,
|
||||
final String module,
|
||||
final String method,
|
||||
final NativeArray arguments,
|
||||
final String tracingName) {
|
||||
final NativeArray arguments) {
|
||||
if (mDestroyed) {
|
||||
FLog.w(ReactConstants.TAG, "Calling JS function after bridge has been destroyed.");
|
||||
return;
|
||||
@ -200,7 +198,7 @@ public class CatalystInstanceImpl implements CatalystInstance {
|
||||
throw new RuntimeException("Attempt to call JS function before JS bundle is loaded.");
|
||||
}
|
||||
|
||||
callJSFunction(executorToken, module, method, arguments, tracingName);
|
||||
callJSFunction(executorToken, module, method, arguments);
|
||||
}
|
||||
|
||||
private native void callJSCallback(ExecutorToken executorToken, int callbackID, NativeArray arguments);
|
||||
|
@ -49,10 +49,11 @@ void Bridge::callFunction(
|
||||
ExecutorToken executorToken,
|
||||
const std::string& moduleId,
|
||||
const std::string& methodId,
|
||||
const folly::dynamic& arguments,
|
||||
const std::string& tracingName) {
|
||||
const folly::dynamic& arguments) {
|
||||
#ifdef WITH_FBSYSTRACE
|
||||
int systraceCookie = m_systraceCookie++;
|
||||
std::string tracingName = fbsystrace_is_tracing(TRACE_TAG_REACT_CXX_BRIDGE) ?
|
||||
folly::to<std::string>("JSCall__", moduleId, '_', methodId) : std::string();
|
||||
FbSystraceAsyncFlow::begin(
|
||||
TRACE_TAG_REACT_CXX_BRIDGE,
|
||||
tracingName.c_str(),
|
||||
@ -60,14 +61,14 @@ void Bridge::callFunction(
|
||||
#endif
|
||||
|
||||
#ifdef WITH_FBSYSTRACE
|
||||
runOnExecutorQueue(executorToken, [moduleId, methodId, arguments, tracingName, systraceCookie] (JSExecutor* executor) {
|
||||
runOnExecutorQueue(executorToken, [moduleId, methodId, arguments, tracingName = std::move(tracingName), systraceCookie] (JSExecutor* executor) {
|
||||
FbSystraceAsyncFlow::end(
|
||||
TRACE_TAG_REACT_CXX_BRIDGE,
|
||||
tracingName.c_str(),
|
||||
systraceCookie);
|
||||
FbSystraceSection s(TRACE_TAG_REACT_CXX_BRIDGE, tracingName.c_str());
|
||||
#else
|
||||
runOnExecutorQueue(executorToken, [moduleId, methodId, arguments, tracingName] (JSExecutor* executor) {
|
||||
runOnExecutorQueue(executorToken, [moduleId, methodId, arguments] (JSExecutor* executor) {
|
||||
#endif
|
||||
// This is safe because we are running on the executor's thread: it won't
|
||||
// destruct until after it's been unregistered (which we check above) and
|
||||
|
@ -68,8 +68,7 @@ public:
|
||||
ExecutorToken executorToken,
|
||||
const std::string& module,
|
||||
const std::string& method,
|
||||
const folly::dynamic& args,
|
||||
const std::string& tracingName);
|
||||
const folly::dynamic& args);
|
||||
|
||||
/**
|
||||
* Invokes a callback with the cbID, and optional additional arguments in JS.
|
||||
|
@ -293,7 +293,7 @@ static void loadScriptFromFile(JNIEnv* env, jobject obj, jstring fileName, jstri
|
||||
}
|
||||
|
||||
static void callFunction(JNIEnv* env, jobject obj, JExecutorToken::jhybridobject jExecutorToken, jstring module, jstring method,
|
||||
NativeArray::jhybridobject args, jstring tracingName) {
|
||||
NativeArray::jhybridobject args) {
|
||||
auto bridge = extractRefPtr<CountableBridge>(env, obj);
|
||||
auto arguments = cthis(wrap_alias(args));
|
||||
try {
|
||||
@ -301,8 +301,7 @@ static void callFunction(JNIEnv* env, jobject obj, JExecutorToken::jhybridobject
|
||||
cthis(wrap_alias(jExecutorToken))->getExecutorToken(wrap_alias(jExecutorToken)),
|
||||
fromJString(env, module),
|
||||
fromJString(env, method),
|
||||
std::move(arguments->array),
|
||||
fromJString(env, tracingName)
|
||||
std::move(arguments->array)
|
||||
);
|
||||
} catch (...) {
|
||||
translatePendingCppExceptionToJavaException();
|
||||
|
@ -288,8 +288,7 @@ void CatalystInstanceImpl::loadScriptFromFile(jni::alias_ref<jstring> fileName,
|
||||
}
|
||||
|
||||
void CatalystInstanceImpl::callJSFunction(
|
||||
JExecutorToken* token, std::string module, std::string method, NativeArray* arguments,
|
||||
const std::string& tracingName) {
|
||||
JExecutorToken* token, std::string module, std::string method, NativeArray* arguments) {
|
||||
// We want to share the C++ code, and on iOS, modules pass module/method
|
||||
// names as strings all the way through to JS, and there's no way to do
|
||||
// string -> id mapping on the objc side. So on Android, we convert the
|
||||
@ -300,8 +299,7 @@ void CatalystInstanceImpl::callJSFunction(
|
||||
instance_->callJSFunction(token->getExecutorToken(nullptr),
|
||||
module,
|
||||
method,
|
||||
std::move(arguments->array),
|
||||
tracingName);
|
||||
std::move(arguments->array));
|
||||
}
|
||||
|
||||
void CatalystInstanceImpl::callJSCallback(JExecutorToken* token, jint callbackId, NativeArray* arguments) {
|
||||
|
@ -49,8 +49,7 @@ class CatalystInstanceImpl : public jni::HybridClass<CatalystInstanceImpl> {
|
||||
ModuleRegistryHolder* mrh);
|
||||
void loadScriptFromAssets(jobject assetManager, const std::string& assetURL, bool useLazyBundle);
|
||||
void loadScriptFromFile(jni::alias_ref<jstring> fileName, const std::string& sourceURL);
|
||||
void callJSFunction(JExecutorToken* token, std::string module, std::string method, NativeArray* arguments,
|
||||
const std::string& tracingName);
|
||||
void callJSFunction(JExecutorToken* token, std::string module, std::string method, NativeArray* arguments);
|
||||
void callJSCallback(JExecutorToken* token, jint callbackId, NativeArray* arguments);
|
||||
local_ref<JExecutorToken::JavaPart> getMainExecutorToken();
|
||||
void setGlobalVariable(std::string propName,
|
||||
|
@ -102,10 +102,9 @@ void Instance::setGlobalVariable(std::string propName,
|
||||
}
|
||||
|
||||
void Instance::callJSFunction(ExecutorToken token, const std::string& module, const std::string& method,
|
||||
folly::dynamic&& params, const std::string& tracingName) {
|
||||
SystraceSection s(tracingName.c_str());
|
||||
folly::dynamic&& params) {
|
||||
callback_->incrementPendingJSCalls();
|
||||
nativeToJsBridge_->callFunction(token, module, method, std::move(params), tracingName);
|
||||
nativeToJsBridge_->callFunction(token, module, method, std::move(params));
|
||||
}
|
||||
|
||||
void Instance::callJSCallback(ExecutorToken token, uint64_t callbackId, folly::dynamic&& params) {
|
||||
|
@ -45,7 +45,7 @@ class Instance {
|
||||
void stopProfiler(const std::string& title, const std::string& filename);
|
||||
void setGlobalVariable(std::string propName, std::unique_ptr<const JSBigString> jsonValue);
|
||||
void callJSFunction(ExecutorToken token, const std::string& module, const std::string& method,
|
||||
folly::dynamic&& params, const std::string& tracingName);
|
||||
folly::dynamic&& params);
|
||||
void callJSCallback(ExecutorToken token, uint64_t callbackId, folly::dynamic&& params);
|
||||
MethodCallResult callSerializableNativeHook(ExecutorToken token, unsigned int moduleId,
|
||||
unsigned int methodId, folly::dynamic&& args);
|
||||
|
@ -145,18 +145,22 @@ void NativeToJsBridge::callFunction(
|
||||
ExecutorToken executorToken,
|
||||
const std::string& moduleId,
|
||||
const std::string& methodId,
|
||||
const folly::dynamic& arguments,
|
||||
const std::string& tracingName) {
|
||||
const folly::dynamic& arguments) {
|
||||
int systraceCookie = -1;
|
||||
#ifdef WITH_FBSYSTRACE
|
||||
systraceCookie = m_systraceCookie++;
|
||||
std::string tracingName = fbsystrace_is_tracing(TRACE_TAG_REACT_CXX_BRIDGE) ?
|
||||
folly::to<std::string>("JSCall__", moduleId, '_', methodId) : std::string();
|
||||
SystraceSection s(tracingName.c_str());
|
||||
FbSystraceAsyncFlow::begin(
|
||||
TRACE_TAG_REACT_CXX_BRIDGE,
|
||||
tracingName.c_str(),
|
||||
systraceCookie);
|
||||
#else
|
||||
std::string tracingName;
|
||||
#endif
|
||||
|
||||
runOnExecutorQueue(executorToken, [moduleId, methodId, arguments, tracingName, systraceCookie] (JSExecutor* executor) {
|
||||
runOnExecutorQueue(executorToken, [moduleId, methodId, arguments, tracingName = std::move(tracingName), systraceCookie] (JSExecutor* executor) {
|
||||
#ifdef WITH_FBSYSTRACE
|
||||
FbSystraceAsyncFlow::end(
|
||||
TRACE_TAG_REACT_CXX_BRIDGE,
|
||||
|
@ -70,8 +70,7 @@ public:
|
||||
ExecutorToken executorToken,
|
||||
const std::string& moduleId,
|
||||
const std::string& methodId,
|
||||
const folly::dynamic& args,
|
||||
const std::string& tracingName);
|
||||
const folly::dynamic& args);
|
||||
|
||||
/**
|
||||
* Invokes a callback with the cbID, and optional additional arguments in JS.
|
||||
|
Loading…
x
Reference in New Issue
Block a user