timer markings from JS JNI

Differential Revision: D2545138

fb-gh-sync-id: f93670ad929dbe37d641968e506108c6aac0cac2
This commit is contained in:
Mike Armstrong 2015-10-15 05:50:44 -07:00 committed by facebook-github-bot-7
parent 8ddd3e864e
commit 4ec5161685
3 changed files with 49 additions and 0 deletions

View File

@ -84,6 +84,8 @@ public class NativeModuleRegistry {
/* package */ void notifyCatalystInstanceInitialized() { /* package */ void notifyCatalystInstanceInitialized() {
UiThreadUtil.assertOnUiThread(); UiThreadUtil.assertOnUiThread();
ReactMarker.logMarker("NativeModule_start");
Systrace.beginSection( Systrace.beginSection(
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
"NativeModuleRegistry_notifyCatalystInstanceInitialized"); "NativeModuleRegistry_notifyCatalystInstanceInitialized");
@ -93,6 +95,7 @@ public class NativeModuleRegistry {
} }
} finally { } finally {
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE); Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
ReactMarker.logMarker("NativeModule_end");
} }
} }

View File

@ -0,0 +1,30 @@
// Copyright 2004-present Facebook. All Rights Reserved.
package com.facebook.react.bridge;
import javax.annotation.Nullable;
import com.facebook.proguard.annotations.DoNotStrip;
/**
* Static class that allows markers to be placed in React code and responded to in a
* configurable way
*/
public class ReactMarker {
public interface MarkerListener {
void logMarker(String name);
};
@Nullable static private MarkerListener sMarkerListener = null;
static public void setMarkerListener(MarkerListener listener) {
sMarkerListener = listener;
}
@DoNotStrip
static public void logMarker(String name) {
if (sMarkerListener != null) {
sMarkerListener.logMarker(name);
}
}
}

View File

@ -552,6 +552,7 @@ namespace bridge {
static jmethodID gCallbackMethod; static jmethodID gCallbackMethod;
static jmethodID gOnBatchCompleteMethod; static jmethodID gOnBatchCompleteMethod;
static jmethodID gLogMarkerMethod;
static void makeJavaCall(JNIEnv* env, jobject callback, MethodCall&& call) { static void makeJavaCall(JNIEnv* env, jobject callback, MethodCall&& call) {
if (call.arguments.isNull()) { if (call.arguments.isNull()) {
@ -619,21 +620,31 @@ static void create(JNIEnv* env, jobject obj, jobject executor, jobject callback,
static void loadScriptFromAssets(JNIEnv* env, jobject obj, jobject assetManager, static void loadScriptFromAssets(JNIEnv* env, jobject obj, jobject assetManager,
jstring assetName) { jstring assetName) {
jclass markerClass = env->FindClass("com/facebook/react/bridge/ReactMarker");
auto bridge = extractRefPtr<Bridge>(env, obj); auto bridge = extractRefPtr<Bridge>(env, obj);
auto assetNameStr = fromJString(env, assetName); auto assetNameStr = fromJString(env, assetName);
env->CallStaticVoidMethod(markerClass, gLogMarkerMethod, env->NewStringUTF("loadScriptFromNetworkCached_start"));
auto script = react::loadScriptFromAssets(env, assetManager, assetNameStr); auto script = react::loadScriptFromAssets(env, assetManager, assetNameStr);
#ifdef WITH_FBSYSTRACE #ifdef WITH_FBSYSTRACE
FbSystraceSection s(TRACE_TAG_REACT_CXX_BRIDGE, "reactbridge_jni_" FbSystraceSection s(TRACE_TAG_REACT_CXX_BRIDGE, "reactbridge_jni_"
"executeApplicationScript", "executeApplicationScript",
"assetName", assetNameStr); "assetName", assetNameStr);
#endif #endif
env->CallStaticVoidMethod(markerClass, gLogMarkerMethod, env->NewStringUTF("loadScriptFromNetworkCached_read"));
bridge->executeApplicationScript(script, assetNameStr); bridge->executeApplicationScript(script, assetNameStr);
env->CallStaticVoidMethod(markerClass, gLogMarkerMethod, env->NewStringUTF("loadScriptFromNetworkCached_done"));
} }
static void loadScriptFromNetworkCached(JNIEnv* env, jobject obj, jstring sourceURL, static void loadScriptFromNetworkCached(JNIEnv* env, jobject obj, jstring sourceURL,
jstring tempFileName) { jstring tempFileName) {
jclass markerClass = env->FindClass("com/facebook/react/bridge/ReactMarker");
auto bridge = jni::extractRefPtr<Bridge>(env, obj); auto bridge = jni::extractRefPtr<Bridge>(env, obj);
std::string script = ""; std::string script = "";
env->CallStaticVoidMethod(markerClass, gLogMarkerMethod, env->NewStringUTF("loadScriptFromNetworkCached_start"));
if (tempFileName != NULL) { if (tempFileName != NULL) {
script = react::loadScriptFromFile(jni::fromJString(env, tempFileName)); script = react::loadScriptFromFile(jni::fromJString(env, tempFileName));
} }
@ -643,7 +654,9 @@ static void loadScriptFromNetworkCached(JNIEnv* env, jobject obj, jstring source
"executeApplicationScript", "executeApplicationScript",
"sourceURL", sourceURLStr); "sourceURL", sourceURLStr);
#endif #endif
env->CallStaticVoidMethod(markerClass, gLogMarkerMethod, env->NewStringUTF("loadScriptFromNetworkCached_read"));
bridge->executeApplicationScript(script, jni::fromJString(env, sourceURL)); bridge->executeApplicationScript(script, jni::fromJString(env, sourceURL));
env->CallStaticVoidMethod(markerClass, gLogMarkerMethod, env->NewStringUTF("loadScriptFromNetworkCached_exec"));
} }
static void callFunction(JNIEnv* env, jobject obj, jint moduleId, jint methodId, static void callFunction(JNIEnv* env, jobject obj, jint moduleId, jint methodId,
@ -787,6 +800,9 @@ extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
bridge::gCallbackMethod = env->GetMethodID(callbackClass, "call", "(IILcom/facebook/react/bridge/ReadableNativeArray;)V"); bridge::gCallbackMethod = env->GetMethodID(callbackClass, "call", "(IILcom/facebook/react/bridge/ReadableNativeArray;)V");
bridge::gOnBatchCompleteMethod = env->GetMethodID(callbackClass, "onBatchComplete", "()V"); bridge::gOnBatchCompleteMethod = env->GetMethodID(callbackClass, "onBatchComplete", "()V");
jclass markerClass = env->FindClass("com/facebook/react/bridge/ReactMarker");
bridge::gLogMarkerMethod = env->GetStaticMethodID(markerClass, "logMarker", "(Ljava/lang/String;)V");
registerNatives("com/facebook/react/bridge/ReactBridge", { registerNatives("com/facebook/react/bridge/ReactBridge", {
makeNativeMethod("initialize", "(Lcom/facebook/react/bridge/JavaScriptExecutor;Lcom/facebook/react/bridge/ReactCallback;Lcom/facebook/react/bridge/queue/MessageQueueThread;)V", bridge::create), makeNativeMethod("initialize", "(Lcom/facebook/react/bridge/JavaScriptExecutor;Lcom/facebook/react/bridge/ReactCallback;Lcom/facebook/react/bridge/queue/MessageQueueThread;)V", bridge::create),
makeNativeMethod( makeNativeMethod(