From 0bfb4268773b5813a74bdcb844489355121b2170 Mon Sep 17 00:00:00 2001 From: Aaron Chiu Date: Thu, 26 Jan 2017 18:09:10 -0800 Subject: [PATCH] add some markers to breakdown ReactInstanceManager.processPackages Reviewed By: alexeylang Differential Revision: D4469884 fbshipit-source-id: 891a37aaf2fc472b2614e551c3564075a1a43484 --- .../facebook/react/CoreModulesPackage.java | 23 +++++++++++++++++-- .../facebook/react/ReactInstanceManager.java | 6 +++++ .../facebook/react/ReactPackageLogger.java | 12 ++++++++++ .../react/bridge/ReactMarkerConstants.java | 7 ++++++ 4 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 ReactAndroid/src/main/java/com/facebook/react/ReactPackageLogger.java diff --git a/ReactAndroid/src/main/java/com/facebook/react/CoreModulesPackage.java b/ReactAndroid/src/main/java/com/facebook/react/CoreModulesPackage.java index 7451ae6de..d31d05b7e 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/CoreModulesPackage.java +++ b/ReactAndroid/src/main/java/com/facebook/react/CoreModulesPackage.java @@ -20,6 +20,7 @@ import com.facebook.react.bridge.ModuleSpec; import com.facebook.react.bridge.NativeModule; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactMarker; +import com.facebook.react.bridge.ReactMarkerConstants; import com.facebook.react.common.build.ReactBuildConfig; import com.facebook.react.devsupport.HMRClient; import com.facebook.react.devsupport.JSCHeapCapture; @@ -46,6 +47,8 @@ import com.facebook.systrace.Systrace; import static com.facebook.react.bridge.ReactMarkerConstants.CREATE_UI_MANAGER_MODULE_END; import static com.facebook.react.bridge.ReactMarkerConstants.CREATE_UI_MANAGER_MODULE_START; +import static com.facebook.react.bridge.ReactMarkerConstants.PROCESS_CORE_REACT_PACKAGE_END; +import static com.facebook.react.bridge.ReactMarkerConstants.PROCESS_CORE_REACT_PACKAGE_START; /** * Package defining core framework modules (e.g. UIManager). It should be used for modules that @@ -68,7 +71,7 @@ import static com.facebook.react.bridge.ReactMarkerConstants.CREATE_UI_MANAGER_M JSCSamplingProfiler.class, } ) -/* package */ class CoreModulesPackage extends LazyReactPackage { +/* package */ class CoreModulesPackage extends LazyReactPackage implements ReactPackageLogger { private final ReactInstanceManager mReactInstanceManager; private final DefaultHardwareBackBtnHandler mHardwareBackBtnHandler; @@ -198,8 +201,14 @@ import static com.facebook.react.bridge.ReactMarkerConstants.CREATE_UI_MANAGER_M @Override public ReactModuleInfoProvider getReactModuleInfoProvider() { + ReactMarker.logMarker( + ReactMarkerConstants.CORE_REACT_PACKAGE_GET_REACT_MODULE_INFO_PROVIDER_START); // This has to be done via reflection or we break open source. - return LazyReactPackage.getReactModuleInfoProviderViaReflection(this); + ReactModuleInfoProvider reactModuleInfoProvider = + LazyReactPackage.getReactModuleInfoProviderViaReflection(this); + ReactMarker.logMarker( + ReactMarkerConstants.CORE_REACT_PACKAGE_GET_REACT_MODULE_INFO_PROVIDER_END); + return reactModuleInfoProvider; } private UIManagerModule createUIManager(ReactApplicationContext reactContext) { @@ -218,4 +227,14 @@ import static com.facebook.react.bridge.ReactMarkerConstants.CREATE_UI_MANAGER_M ReactMarker.logMarker(CREATE_UI_MANAGER_MODULE_END); } } + + @Override + public void startProcessPackage() { + ReactMarker.logMarker(PROCESS_CORE_REACT_PACKAGE_START); + } + + @Override + public void endProcessPackage() { + ReactMarker.logMarker(PROCESS_CORE_REACT_PACKAGE_END); + } } diff --git a/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java b/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java index b4215d77b..2fac9bd2e 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java @@ -965,6 +965,9 @@ public class ReactInstanceManager { SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "processPackage") .arg("className", reactPackage.getClass().getSimpleName()) .flush(); + if (reactPackage instanceof ReactPackageLogger) { + ((ReactPackageLogger) reactPackage).startProcessPackage(); + } if (mLazyNativeModulesEnabled && reactPackage instanceof LazyReactPackage) { LazyReactPackage lazyReactPackage = (LazyReactPackage) reactPackage; ReactModuleInfoProvider instance = lazyReactPackage.getReactModuleInfoProvider(); @@ -987,6 +990,9 @@ public class ReactInstanceManager { for (Class jsModuleClass : reactPackage.createJSModules()) { jsModulesBuilder.add(jsModuleClass); } + if (reactPackage instanceof ReactPackageLogger) { + ((ReactPackageLogger) reactPackage).endProcessPackage(); + } Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/ReactPackageLogger.java b/ReactAndroid/src/main/java/com/facebook/react/ReactPackageLogger.java new file mode 100644 index 000000000..50a4c05e9 --- /dev/null +++ b/ReactAndroid/src/main/java/com/facebook/react/ReactPackageLogger.java @@ -0,0 +1,12 @@ +// Copyright 2004-present Facebook. All Rights Reserved. + +package com.facebook.react; + +/** + * Interface for the bridge to call for TTI start and end markers. + */ +public interface ReactPackageLogger { + + void startProcessPackage(); + void endProcessPackage(); +} diff --git a/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactMarkerConstants.java b/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactMarkerConstants.java index 8aab2c73c..930186a56 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactMarkerConstants.java +++ b/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactMarkerConstants.java @@ -7,6 +7,7 @@ package com.facebook.react.bridge; */ public class ReactMarkerConstants { + // TODO convert to ints so we don't have to do String compares public static final String CREATE_REACT_CONTEXT_START = "CREATE_REACT_CONTEXT_START"; public static final String CREATE_REACT_CONTEXT_END = "CREATE_REACT_CONTEXT_END"; public static final String PROCESS_PACKAGES_START = "PROCESS_PACKAGES_START"; @@ -35,4 +36,10 @@ public class ReactMarkerConstants { "CREATE_UI_MANAGER_MODULE_CONSTANTS_END"; public static final String CREATE_MODULE_START = "CREATE_MODULE_START"; public static final String CREATE_MODULE_END = "CREATE_MODULE_END"; + public static final String PROCESS_CORE_REACT_PACKAGE_START = "PROCESS_CORE_REACT_PACKAGE_START"; + public static final String PROCESS_CORE_REACT_PACKAGE_END = "PROCESS_CORE_REACT_PACKAGE_END"; + public static final String CORE_REACT_PACKAGE_GET_REACT_MODULE_INFO_PROVIDER_START = + "CORE_REACT_PACKAGE_GET_REACT_MODULE_INFO_PROVIDER_START"; + public static final String CORE_REACT_PACKAGE_GET_REACT_MODULE_INFO_PROVIDER_END = + "CORE_REACT_PACKAGE_GET_REACT_MODULE_INFO_PROVIDER_END"; }