Skip to content

Commit

Permalink
Convert ReactMarkerConsts back to enum, use @CountEnum
Browse files Browse the repository at this point in the history
Summary: Reverting D9304307 and also adding CountEnum annotation to ReactMarkerConstants. This way we get the typesafety of the enum with the optimization of converting to int in production builds. More on the count: https://our.intern.facebook.com/intern/wiki/Android-java-transforms/the-count/

Reviewed By: achen1

Differential Revision: D9623235

fbshipit-source-id: ab992e7edb6cf999f5f122faee31075a63782411
  • Loading branch information
Emily Janzer authored and gengjiawen committed Sep 14, 2018
1 parent d1e3e06 commit 9916017
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 168 deletions.
1 change: 1 addition & 0 deletions ReactAndroid/src/main/java/com/facebook/react/bridge/BUCK
Expand Up @@ -30,6 +30,7 @@ rn_android_library(
deps = [
react_native_dep("java/com/facebook/debug/debugoverlay/model:model"),
react_native_dep("java/com/facebook/systrace:systrace"),
react_native_dep("java/com/facebook/thecount:thecount"),
react_native_dep("libraries/fbcore/src/main/java/com/facebook/common/logging:logging"),
react_native_dep("libraries/soloader/java/com/facebook/soloader:soloader"),
react_native_dep("third-party/java/infer-annotations:infer-annotations"),
Expand Down
Expand Up @@ -20,7 +20,7 @@
public class ReactMarker {

public interface MarkerListener {
void logMarker(@ReactMarkerConstants String name, @Nullable String tag, int instanceKey);
void logMarker(ReactMarkerConstants name, @Nullable String tag, int instanceKey);
};

// Use a list instead of a set here because we expect the number of listeners
Expand Down Expand Up @@ -52,22 +52,43 @@ public static void clearMarkerListeners() {
}

@DoNotStrip
public static void logMarker(@ReactMarkerConstants String name) {
public static void logMarker(String name) {
logMarker(name, null);
}

@DoNotStrip
public static void logMarker(String name, int instanceKey) {
logMarker(name, null, instanceKey);
}

@DoNotStrip
public static void logMarker(String name, @Nullable String tag) {
logMarker(name, tag, 0);
}

@DoNotStrip
public static void logMarker(String name, @Nullable String tag, int instanceKey) {
ReactMarkerConstants marker = ReactMarkerConstants.valueOf(name);
logMarker(marker, tag, instanceKey);
}

@DoNotStrip
public static void logMarker(ReactMarkerConstants name) {
logMarker(name, null, 0);
}

@DoNotStrip
public static void logMarker(@ReactMarkerConstants String name, int instanceKey) {
public static void logMarker(ReactMarkerConstants name, int instanceKey) {
logMarker(name, null, instanceKey);
}

@DoNotStrip
public static void logMarker(@ReactMarkerConstants String name, @Nullable String tag) {
public static void logMarker(ReactMarkerConstants name, @Nullable String tag) {
logMarker(name, tag, 0);
}

@DoNotStrip
public static void logMarker(@ReactMarkerConstants String name, @Nullable String tag, int instanceKey) {
public static void logMarker(ReactMarkerConstants name, @Nullable String tag, int instanceKey) {
synchronized(sListeners) {
for (MarkerListener listener : sListeners) {
listener.logMarker(name, tag, instanceKey);
Expand Down
Expand Up @@ -5,171 +5,89 @@

package com.facebook.react.bridge;

import android.support.annotation.StringDef;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import com.facebook.thecount.api.CountEnum;

/**
* Constants used by ReactMarker.
*/
@StringDef({
ReactMarkerConstants.CREATE_REACT_CONTEXT_START,
ReactMarkerConstants.CREATE_REACT_CONTEXT_END,
ReactMarkerConstants.PROCESS_PACKAGES_START,
ReactMarkerConstants.PROCESS_PACKAGES_END,
ReactMarkerConstants.BUILD_NATIVE_MODULE_REGISTRY_START,
ReactMarkerConstants.BUILD_NATIVE_MODULE_REGISTRY_END,
ReactMarkerConstants.CREATE_CATALYST_INSTANCE_START,
ReactMarkerConstants.CREATE_CATALYST_INSTANCE_END,
ReactMarkerConstants.DESTROY_CATALYST_INSTANCE_START,
ReactMarkerConstants.DESTROY_CATALYST_INSTANCE_END,
ReactMarkerConstants.RUN_JS_BUNDLE_START,
ReactMarkerConstants.RUN_JS_BUNDLE_END,
ReactMarkerConstants.NATIVE_MODULE_INITIALIZE_START,
ReactMarkerConstants.NATIVE_MODULE_INITIALIZE_END,
ReactMarkerConstants.SETUP_REACT_CONTEXT_START,
ReactMarkerConstants.SETUP_REACT_CONTEXT_END,
ReactMarkerConstants.CREATE_UI_MANAGER_MODULE_START,
ReactMarkerConstants.CREATE_UI_MANAGER_MODULE_END,
ReactMarkerConstants.CREATE_VIEW_MANAGERS_START,
ReactMarkerConstants.CREATE_VIEW_MANAGERS_END,
ReactMarkerConstants.CREATE_UI_MANAGER_MODULE_CONSTANTS_START,
ReactMarkerConstants.CREATE_UI_MANAGER_MODULE_CONSTANTS_END,
ReactMarkerConstants.NATIVE_MODULE_SETUP_START,
ReactMarkerConstants.NATIVE_MODULE_SETUP_END,
ReactMarkerConstants.CREATE_MODULE_START,
ReactMarkerConstants.CREATE_MODULE_END,
ReactMarkerConstants.PROCESS_CORE_REACT_PACKAGE_START,
ReactMarkerConstants.PROCESS_CORE_REACT_PACKAGE_END,
ReactMarkerConstants.CREATE_I18N_MODULE_CONSTANTS_START,
ReactMarkerConstants.CREATE_I18N_MODULE_CONSTANTS_END,
ReactMarkerConstants.I18N_MODULE_CONSTANTS_CONVERT_START,
ReactMarkerConstants.I18N_MODULE_CONSTANTS_CONVERT_END,
ReactMarkerConstants.CREATE_I18N_ASSETS_MODULE_START,
ReactMarkerConstants.CREATE_I18N_ASSETS_MODULE_END,
ReactMarkerConstants.GET_CONSTANTS_START,
ReactMarkerConstants.GET_CONSTANTS_END,
ReactMarkerConstants.INITIALIZE_MODULE_START,
ReactMarkerConstants.INITIALIZE_MODULE_END,
ReactMarkerConstants.ON_HOST_RESUME_START,
ReactMarkerConstants.ON_HOST_RESUME_END,
ReactMarkerConstants.ON_HOST_PAUSE_START,
ReactMarkerConstants.ON_HOST_PAUSE_END,
ReactMarkerConstants.CONVERT_CONSTANTS_START,
ReactMarkerConstants.CONVERT_CONSTANTS_END,
ReactMarkerConstants.PRE_REACT_CONTEXT_END,
ReactMarkerConstants.UNPACKING_JS_BUNDLE_LOADER_CHECK_START,
ReactMarkerConstants.UNPACKING_JS_BUNDLE_LOADER_CHECK_END,
ReactMarkerConstants.UNPACKING_JS_BUNDLE_LOADER_EXTRACTED,
ReactMarkerConstants.UNPACKING_JS_BUNDLE_LOADER_BLOCKED,
ReactMarkerConstants.LOAD_APPLICATION_SCRIPT_START_STRING_CONVERT,
ReactMarkerConstants.LOAD_APPLICATION_SCRIPT_END_STRING_CONVERT,
ReactMarkerConstants.PRE_SETUP_REACT_CONTEXT_START,
ReactMarkerConstants.PRE_SETUP_REACT_CONTEXT_END,
ReactMarkerConstants.PRE_RUN_JS_BUNDLE_START,
ReactMarkerConstants.ATTACH_MEASURED_ROOT_VIEWS_START,
ReactMarkerConstants.ATTACH_MEASURED_ROOT_VIEWS_END,
ReactMarkerConstants.CONTENT_APPEARED,
ReactMarkerConstants.RELOAD,
ReactMarkerConstants.DOWNLOAD_START,
ReactMarkerConstants.DOWNLOAD_END,
ReactMarkerConstants.REACT_CONTEXT_THREAD_START,
ReactMarkerConstants.REACT_CONTEXT_THREAD_END,
ReactMarkerConstants.GET_REACT_INSTANCE_MANAGER_START,
ReactMarkerConstants.GET_REACT_INSTANCE_MANAGER_END,
ReactMarkerConstants.GET_REACT_INSTANCE_HOLDER_SPEC_START,
ReactMarkerConstants.GET_REACT_INSTANCE_HOLDER_SPEC_END,
ReactMarkerConstants.BUILD_REACT_INSTANCE_MANAGER_START,
ReactMarkerConstants.BUILD_REACT_INSTANCE_MANAGER_END,
ReactMarkerConstants.PROCESS_INFRA_PACKAGE_START,
ReactMarkerConstants.PROCESS_INFRA_PACKAGE_END,
ReactMarkerConstants.PROCESS_PRODUCT_PACKAGE_START,
ReactMarkerConstants.PROCESS_PRODUCT_PACKAGE_END,
ReactMarkerConstants.CREATE_MC_MODULE_START,
ReactMarkerConstants.CREATE_MC_MODULE_END,
ReactMarkerConstants.CREATE_MC_MODULE_GET_METADATA_START,
ReactMarkerConstants.CREATE_MC_MODULE_GET_METADATA_END,
ReactMarkerConstants.REGISTER_JS_SEGMENT_START,
ReactMarkerConstants.REGISTER_JS_SEGMENT_STOP
})
@Retention(RetentionPolicy.SOURCE)
public @interface ReactMarkerConstants {
String CREATE_REACT_CONTEXT_START = "CREATE_REACT_CONTEXT_START";
String CREATE_REACT_CONTEXT_END = "CREATE_REACT_CONTEXT_END";
String PROCESS_PACKAGES_START = "PROCESS_PACKAGES_START";
String PROCESS_PACKAGES_END = "PROCESS_PACKAGES_END";
String BUILD_NATIVE_MODULE_REGISTRY_START = "BUILD_NATIVE_MODULE_REGISTRY_START";
String BUILD_NATIVE_MODULE_REGISTRY_END = "BUILD_NATIVE_MODULE_REGISTRY_END";
String CREATE_CATALYST_INSTANCE_START = "CREATE_CATALYST_INSTANCE_START";
String CREATE_CATALYST_INSTANCE_END = "CREATE_CATALYST_INSTANCE_END";
String DESTROY_CATALYST_INSTANCE_START = "DESTROY_CATALYST_INSTANCE_START";
String DESTROY_CATALYST_INSTANCE_END = "DESTROY_CATALYST_INSTANCE_END";
String RUN_JS_BUNDLE_START = "RUN_JS_BUNDLE_START";
String RUN_JS_BUNDLE_END = "RUN_JS_BUNDLE_END";
String NATIVE_MODULE_INITIALIZE_START = "NATIVE_MODULE_INITIALIZE_START";
String NATIVE_MODULE_INITIALIZE_END = "NATIVE_MODULE_INITIALIZE_END";
String SETUP_REACT_CONTEXT_START = "SETUP_REACT_CONTEXT_START";
String SETUP_REACT_CONTEXT_END = "SETUP_REACT_CONTEXT_END";
String CREATE_UI_MANAGER_MODULE_START = "CREATE_UI_MANAGER_MODULE_START";
String CREATE_UI_MANAGER_MODULE_END = "CREATE_UI_MANAGER_MODULE_END";
String CREATE_VIEW_MANAGERS_START = "CREATE_VIEW_MANAGERS_START";
String CREATE_VIEW_MANAGERS_END = "CREATE_VIEW_MANAGERS_END";
String CREATE_UI_MANAGER_MODULE_CONSTANTS_START = "CREATE_UI_MANAGER_MODULE_CONSTANTS_START";
String CREATE_UI_MANAGER_MODULE_CONSTANTS_END = "CREATE_UI_MANAGER_MODULE_CONSTANTS_END";
String NATIVE_MODULE_SETUP_START = "NATIVE_MODULE_SETUP_START";
String NATIVE_MODULE_SETUP_END = "NATIVE_MODULE_SETUP_END";
String CREATE_MODULE_START = "CREATE_MODULE_START";
String CREATE_MODULE_END = "CREATE_MODULE_END";
String PROCESS_CORE_REACT_PACKAGE_START = "PROCESS_CORE_REACT_PACKAGE_START";
String PROCESS_CORE_REACT_PACKAGE_END = "PROCESS_CORE_REACT_PACKAGE_END";
String CREATE_I18N_MODULE_CONSTANTS_START = "CREATE_I18N_MODULE_CONSTANTS_START";
String CREATE_I18N_MODULE_CONSTANTS_END = "CREATE_I18N_MODULE_CONSTANTS_END";
String I18N_MODULE_CONSTANTS_CONVERT_START = "I18N_MODULE_CONSTANTS_CONVERT_START";
String I18N_MODULE_CONSTANTS_CONVERT_END = "I18N_MODULE_CONSTANTS_CONVERT_END";
String CREATE_I18N_ASSETS_MODULE_START = "CREATE_I18N_ASSETS_MODULE_START";
String CREATE_I18N_ASSETS_MODULE_END = "CREATE_I18N_ASSETS_MODULE_END";
String GET_CONSTANTS_START = "GET_CONSTANTS_START";
String GET_CONSTANTS_END = "GET_CONSTANTS_END";
String INITIALIZE_MODULE_START = "INITIALIZE_MODULE_START";
String INITIALIZE_MODULE_END = "INITIALIZE_MODULE_END";
String ON_HOST_RESUME_START = "ON_HOST_RESUME_START";
String ON_HOST_RESUME_END = "ON_HOST_RESUME_END";
String ON_HOST_PAUSE_START = "ON_HOST_PAUSE_START";
String ON_HOST_PAUSE_END = "ON_HOST_PAUSE_END";
String CONVERT_CONSTANTS_START = "CONVERT_CONSTANTS_START";
String CONVERT_CONSTANTS_END = "CONVERT_CONSTANTS_END";
String PRE_REACT_CONTEXT_END = "PRE_REACT_CONTEXT_END";
String UNPACKING_JS_BUNDLE_LOADER_CHECK_START = "UNPACKING_JS_BUNDLE_LOADER_CHECK_START";
String UNPACKING_JS_BUNDLE_LOADER_CHECK_END = "UNPACKING_JS_BUNDLE_LOADER_CHECK_END";
String UNPACKING_JS_BUNDLE_LOADER_EXTRACTED = "UNPACKING_JS_BUNDLE_LOADER_EXTRACTED";
String UNPACKING_JS_BUNDLE_LOADER_BLOCKED = "UNPACKING_JS_BUNDLE_LOADER_BLOCKED";
String LOAD_APPLICATION_SCRIPT_START_STRING_CONVERT = "loadApplicationScript_startStringConvert";
String LOAD_APPLICATION_SCRIPT_END_STRING_CONVERT = "loadApplicationScript_endStringConvert";
String PRE_SETUP_REACT_CONTEXT_START = "PRE_SETUP_REACT_CONTEXT_START";
String PRE_SETUP_REACT_CONTEXT_END = "PRE_SETUP_REACT_CONTEXT_END";
String PRE_RUN_JS_BUNDLE_START = "PRE_RUN_JS_BUNDLE_START";
String ATTACH_MEASURED_ROOT_VIEWS_START = "ATTACH_MEASURED_ROOT_VIEWS_START";
String ATTACH_MEASURED_ROOT_VIEWS_END = "ATTACH_MEASURED_ROOT_VIEWS_END";
String CONTENT_APPEARED = "CONTENT_APPEARED";
String RELOAD = "RELOAD";
String DOWNLOAD_START = "DOWNLOAD_START";
String DOWNLOAD_END = "DOWNLOAD_END";
String REACT_CONTEXT_THREAD_START = "REACT_CONTEXT_THREAD_START";
String REACT_CONTEXT_THREAD_END = "REACT_CONTEXT_THREAD_END";
String GET_REACT_INSTANCE_MANAGER_START = "GET_REACT_INSTANCE_MANAGER_START";
String GET_REACT_INSTANCE_MANAGER_END = "GET_REACT_INSTANCE_MANAGER_END";
String GET_REACT_INSTANCE_HOLDER_SPEC_START = "GET_REACT_INSTANCE_HOLDER_SPEC_START";
String GET_REACT_INSTANCE_HOLDER_SPEC_END = "GET_REACT_INSTANCE_HOLDER_SPEC_END";
String BUILD_REACT_INSTANCE_MANAGER_START = "BUILD_REACT_INSTANCE_MANAGER_START";
String BUILD_REACT_INSTANCE_MANAGER_END = "BUILD_REACT_INSTANCE_MANAGER_END";
String PROCESS_INFRA_PACKAGE_START = "PROCESS_INFRA_PACKAGE_START";
String PROCESS_INFRA_PACKAGE_END = "PROCESS_INFRA_PACKAGE_END";
String PROCESS_PRODUCT_PACKAGE_START = "PROCESS_PRODUCT_PACKAGE_START";
String PROCESS_PRODUCT_PACKAGE_END = "PROCESS_PRODUCT_PACKAGE_END";
String CREATE_MC_MODULE_START = "CREATE_MC_MODULE_START";
String CREATE_MC_MODULE_END = "CREATE_MC_MODULE_END";
String CREATE_MC_MODULE_GET_METADATA_START = "CREATE_MC_MODULE_GET_METADATA_START";
String CREATE_MC_MODULE_GET_METADATA_END = "CREATE_MC_MODULE_GET_METADATA_END";
String REGISTER_JS_SEGMENT_START = "REGISTER_JS_SEGMENT_START";
String REGISTER_JS_SEGMENT_STOP = "REGISTER_JS_SEGMENT_STOP";
@CountEnum
public enum ReactMarkerConstants {
CREATE_REACT_CONTEXT_START,
CREATE_REACT_CONTEXT_END,
PROCESS_PACKAGES_START,
PROCESS_PACKAGES_END,
BUILD_NATIVE_MODULE_REGISTRY_START,
BUILD_NATIVE_MODULE_REGISTRY_END,
CREATE_CATALYST_INSTANCE_START,
CREATE_CATALYST_INSTANCE_END,
DESTROY_CATALYST_INSTANCE_START,
DESTROY_CATALYST_INSTANCE_END,
RUN_JS_BUNDLE_START,
RUN_JS_BUNDLE_END,
NATIVE_MODULE_INITIALIZE_START,
NATIVE_MODULE_INITIALIZE_END,
SETUP_REACT_CONTEXT_START,
SETUP_REACT_CONTEXT_END,
CREATE_UI_MANAGER_MODULE_START,
CREATE_UI_MANAGER_MODULE_END,
CREATE_VIEW_MANAGERS_START,
CREATE_VIEW_MANAGERS_END,
CREATE_UI_MANAGER_MODULE_CONSTANTS_START,
CREATE_UI_MANAGER_MODULE_CONSTANTS_END,
NATIVE_MODULE_SETUP_START,
NATIVE_MODULE_SETUP_END,
CREATE_MODULE_START,
CREATE_MODULE_END,
PROCESS_CORE_REACT_PACKAGE_START,
PROCESS_CORE_REACT_PACKAGE_END,
CREATE_I18N_MODULE_CONSTANTS_START,
CREATE_I18N_MODULE_CONSTANTS_END,
I18N_MODULE_CONSTANTS_CONVERT_START,
I18N_MODULE_CONSTANTS_CONVERT_END,
CREATE_I18N_ASSETS_MODULE_START,
CREATE_I18N_ASSETS_MODULE_END,
GET_CONSTANTS_START,
GET_CONSTANTS_END,
INITIALIZE_MODULE_START,
INITIALIZE_MODULE_END,
ON_HOST_RESUME_START,
ON_HOST_RESUME_END,
ON_HOST_PAUSE_START,
ON_HOST_PAUSE_END,
CONVERT_CONSTANTS_START,
CONVERT_CONSTANTS_END,
PRE_REACT_CONTEXT_END,
UNPACKING_JS_BUNDLE_LOADER_CHECK_START,
UNPACKING_JS_BUNDLE_LOADER_CHECK_END,
UNPACKING_JS_BUNDLE_LOADER_EXTRACTED,
UNPACKING_JS_BUNDLE_LOADER_BLOCKED,
loadApplicationScript_startStringConvert,
loadApplicationScript_endStringConvert,
PRE_SETUP_REACT_CONTEXT_START,
PRE_SETUP_REACT_CONTEXT_END,
PRE_RUN_JS_BUNDLE_START,
ATTACH_MEASURED_ROOT_VIEWS_START,
ATTACH_MEASURED_ROOT_VIEWS_END,
CONTENT_APPEARED,
RELOAD,
DOWNLOAD_START,
DOWNLOAD_END,
REACT_CONTEXT_THREAD_START,
REACT_CONTEXT_THREAD_END,
GET_REACT_INSTANCE_MANAGER_START,
GET_REACT_INSTANCE_MANAGER_END,
GET_REACT_INSTANCE_HOLDER_SPEC_START,
GET_REACT_INSTANCE_HOLDER_SPEC_END,
BUILD_REACT_INSTANCE_MANAGER_START,
BUILD_REACT_INSTANCE_MANAGER_END,
PROCESS_INFRA_PACKAGE_START,
PROCESS_INFRA_PACKAGE_END,
PROCESS_PRODUCT_PACKAGE_START,
PROCESS_PRODUCT_PACKAGE_END,
CREATE_MC_MODULE_START,
CREATE_MC_MODULE_END,
CREATE_MC_MODULE_GET_METADATA_START,
CREATE_MC_MODULE_GET_METADATA_END,
REGISTER_JS_SEGMENT_START,
REGISTER_JS_SEGMENT_STOP,
}

0 comments on commit 9916017

Please sign in to comment.