add more Systrace to native module / view manager constants

Reviewed By: lexs

Differential Revision: D3739966

fbshipit-source-id: 4ba31aade00852132e528f96252197b823bb58a3
This commit is contained in:
Aaron Chiu 2016-08-19 11:54:22 -07:00 committed by Facebook Github Bot 9
parent 14188289fc
commit 924187eb9a
5 changed files with 71 additions and 38 deletions

View File

@ -15,6 +15,10 @@ import java.util.List;
import com.facebook.react.bridge.ModuleSpec;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.systrace.Systrace;
import com.facebook.systrace.SystraceMessage;
import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
/**
* React package supporting lazy creation of native modules.
@ -33,7 +37,14 @@ public abstract class LazyReactPackage implements ReactPackage {
public final List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
List<NativeModule> modules = new ArrayList<>();
for (ModuleSpec holder : getNativeModules(reactContext)) {
SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "createNativeModule")
.arg("module", holder.getType())
.flush();
try {
modules.add(holder.getProvider().get());
} finally {
Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
}
}
return modules;
}

View File

@ -15,13 +15,17 @@ import java.util.List;
import java.util.Map;
import com.facebook.proguard.annotations.DoNotStrip;
import com.facebook.react.bridge.BaseJavaModule;
import com.facebook.react.bridge.CatalystInstance;
import com.facebook.react.bridge.ExecutorToken;
import com.facebook.react.bridge.NativeArray;
import com.facebook.react.bridge.ReadableNativeArray;
import com.facebook.react.bridge.WritableNativeArray;
import com.facebook.react.bridge.WritableNativeMap;
import com.facebook.systrace.Systrace;
import com.facebook.systrace.SystraceMessage;
import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
/**
* This is part of the glue which wraps a java BaseJavaModule in a C++
@ -120,8 +124,23 @@ import com.facebook.react.bridge.WritableNativeArray;
// NativeMap out of OnLoad.
@DoNotStrip
public NativeArray getConstants() {
SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "Map constants")
.arg("moduleName", getName())
.flush();
Map<String, Object> map = mModule.getConstants();
Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "WritableNativeMap constants")
.arg("moduleName", getName())
.flush();
WritableNativeMap writableNativeMap;
try {
writableNativeMap = Arguments.makeNativeMap(map);
} finally {
Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
}
WritableNativeArray array = new WritableNativeArray();
array.pushMap(Arguments.makeNativeMap(mModule.getConstants()));
array.pushMap(writableNativeMap);
return array;
}

View File

@ -17,9 +17,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import android.content.ContentResolver;
import android.content.Context;
@ -103,11 +101,6 @@ public class CameraRollManager extends ReactContextBaseJavaModule {
return "RKCameraRollManager";
}
@Override
public Map<String, Object> getConstants() {
return Collections.emptyMap();
}
/**
* Save an image to the gallery (i.e. {@link MediaStore.Images}). This copies the original file
* from wherever it may be to the external storage pictures directory, so that it can be scanned
@ -440,5 +433,4 @@ public class CameraRollManager extends ReactContextBaseJavaModule {
node.putMap("location", location);
}
}
}

View File

@ -13,6 +13,10 @@ import java.util.List;
import java.util.Map;
import com.facebook.react.common.MapBuilder;
import com.facebook.systrace.Systrace;
import com.facebook.systrace.SystraceMessage;
import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
/**
* Helps generate constants map for {@link UIManagerModule} by collecting and merging constants from
@ -42,6 +46,10 @@ import com.facebook.react.common.MapBuilder;
Map directEventTypesConstants = UIManagerModuleConstants.getDirectEventTypeConstants();
for (ViewManager viewManager : viewManagers) {
SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "constants for ViewManager")
.arg("ViewManager", viewManager.getName())
.flush();
try {
Map viewManagerBubblingEvents = viewManager.getExportedCustomBubblingEventTypeConstants();
if (viewManagerBubblingEvents != null) {
recursiveMerge(bubblingEventTypesConstants, viewManagerBubblingEvents);
@ -66,6 +74,9 @@ import com.facebook.react.common.MapBuilder;
if (!viewManagerConstants.isEmpty()) {
constants.put(viewManager.getName(), viewManagerConstants);
}
} finally {
Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
}
}
constants.put(CUSTOM_BUBBLING_EVENT_TYPES_KEY, bubblingEventTypesConstants);