Java Code Examples for com.facebook.systrace.Systrace.endSection()

The following are Jave code examples for showing how to use endSection() of the com.facebook.systrace.Systrace class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: RNLearn_Project1   File: LazyReactPackage.java   Source Code and License Vote up 6 votes
@Override
public final List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
  List<NativeModule> modules = new ArrayList<>();
  for (ModuleSpec holder : getNativeModules(reactContext)) {
    NativeModule nativeModule;
    SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "createNativeModule")
      .arg("module", holder.getType())
      .flush();
    try {
      ReactMarker.logMarker(
        ReactMarkerConstants.CREATE_MODULE_START,
        holder.getType().getSimpleName());
      nativeModule = holder.getProvider().get();
      ReactMarker.logMarker(ReactMarkerConstants.CREATE_MODULE_END);
    } finally {
      Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
    }
    modules.add(nativeModule);
  }
  return modules;
}
 
Example 2
Project: RNLearn_Project1   File: ReactInstanceManager.java   Source Code and License Vote up 6 votes
/**
 * Uses configured {@link ReactPackage} instances to create all view managers.
 */
public List<ViewManager> createAllViewManagers(
    ReactApplicationContext catalystApplicationContext) {
  ReactMarker.logMarker(CREATE_VIEW_MANAGERS_START);
  Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "createAllViewManagers");
  try {
    List<ViewManager> allViewManagers = new ArrayList<>();
    for (ReactPackage reactPackage : mPackages) {
      allViewManagers.addAll(reactPackage.createViewManagers(catalystApplicationContext));
    }
    return allViewManagers;
  } finally {
    Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
    ReactMarker.logMarker(CREATE_VIEW_MANAGERS_END);
  }
}
 
Example 3
Project: RNLearn_Project1   File: EventDispatcher.java   Source Code and License Vote up 6 votes
@Override
public void doFrame(long frameTimeNanos) {
  UiThreadUtil.assertOnUiThread();

  if (mShouldStop) {
    mIsPosted = false;
  } else {
    post();
  }

  Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "ScheduleDispatchFrameCallback");
  try {
    moveStagedEventsToDispatchQueue();

    if (mEventsToDispatchSize > 0 && !mHasDispatchScheduled) {
      mHasDispatchScheduled = true;
      Systrace.startAsyncFlow(
          Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
          "ScheduleDispatchFrameCallback",
          mHasDispatchScheduledCount);
      mReactContext.runOnJSQueueThread(mDispatchEventsRunnable);
    }
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 4
Project: RNLearn_Project1   File: ReactInstanceManager.java   Source Code and License Vote up 6 votes
private void processPackage(
  ReactPackage reactPackage,
  NativeModuleRegistryBuilder nativeModuleRegistryBuilder,
  JavaScriptModuleRegistry.Builder jsModulesBuilder) {
  SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "processPackage")
    .arg("className", reactPackage.getClass().getSimpleName())
    .flush();
  if (reactPackage instanceof ReactPackageLogger) {
    ((ReactPackageLogger) reactPackage).startProcessPackage();
  }
  nativeModuleRegistryBuilder.processPackage(reactPackage);

  for (Class<? extends JavaScriptModule> jsModuleClass : reactPackage.createJSModules()) {
    jsModulesBuilder.add(jsModuleClass);
  }
  if (reactPackage instanceof ReactPackageLogger) {
    ((ReactPackageLogger) reactPackage).endProcessPackage();
  }
  Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
}
 
Example 5
Project: RNLearn_Project1   File: UIViewOperationQueue.java   Source Code and License Vote up 6 votes
@Override
public void doFrameGuarded(long frameTimeNanos) {
  if (mIsInIllegalUIState) {
    FLog.w(
      ReactConstants.TAG,
      "Not flushing pending UI operations because of previously thrown Exception");
    return;
  }

  Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "dispatchNonBatchedUIOperations");
  try {
    dispatchPendingNonBatchedOperations(frameTimeNanos);
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }

  flushPendingBatches();

  ReactChoreographer.getInstance().postFrameCallback(
    ReactChoreographer.CallbackType.DISPATCH_UI, this);
}
 
Example 6
Project: RNLearn_Project1   File: BaseJavaModule.java   Source Code and License Vote up 6 votes
private void findMethods() {
  if (mMethods == null) {
    Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "findMethods");
    mMethods = new HashMap<>();

    Method[] targetMethods = getClass().getDeclaredMethods();
    for (Method targetMethod : targetMethods) {
      ReactMethod annotation = targetMethod.getAnnotation(ReactMethod.class);
      if (annotation != null) {
        String methodName = targetMethod.getName();
        if (mMethods.containsKey(methodName)) {
          // We do not support method overloading since js sees a function as an object regardless
          // of number of params.
          throw new IllegalArgumentException(
            "Java Module " + getName() + " method name already registered: " + methodName);
        }
        mMethods.put(
            methodName,
            new JavaMethod(targetMethod,
          annotation.isBlockingSynchronousMethod()));
      }
    }
    Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 7
Project: RNLearn_Project1   File: LazyReactPackage.java   Source Code and License Vote up 6 votes
@Override
public final List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
  List<NativeModule> modules = new ArrayList<>();
  for (ModuleSpec holder : getNativeModules(reactContext)) {
    NativeModule nativeModule;
    SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "createNativeModule")
      .arg("module", holder.getType())
      .flush();
    try {
      ReactMarker.logMarker(
        ReactMarkerConstants.CREATE_MODULE_START,
        holder.getType().getSimpleName());
      nativeModule = holder.getProvider().get();
      ReactMarker.logMarker(ReactMarkerConstants.CREATE_MODULE_END);
    } finally {
      Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
    }
    modules.add(nativeModule);
  }
  return modules;
}
 
Example 8
Project: RNLearn_Project1   File: CoreModulesPackage.java   Source Code and License Vote up 6 votes
private UIManagerModule createUIManager(ReactApplicationContext reactContext) {
  ReactMarker.logMarker(CREATE_UI_MANAGER_MODULE_START);
  Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "createUIManagerModule");
  try {
    List<ViewManager> viewManagersList = mReactInstanceManager.createAllViewManagers(
      reactContext);
    return new UIManagerModule(
      reactContext,
      viewManagersList,
      mUIImplementationProvider,
      mLazyViewManagersEnabled);
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
    ReactMarker.logMarker(CREATE_UI_MANAGER_MODULE_END);
  }
}
 
Example 9
Project: RNLearn_Project1   File: ModuleHolder.java   Source Code and License Vote up 6 votes
private NativeModule create() {
  SoftAssertions.assertCondition(mModule == null, "Creating an already created module.");
  ReactMarker.logMarker(CREATE_MODULE_START, mName);
  SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "createModule")
    .arg("name", mName)
    .flush();
  NativeModule module = assertNotNull(mProvider).get();
  mProvider = null;
  if (mInitializeNeeded) {
    doInitialize(module);
    mInitializeNeeded = false;
  }
  Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
  ReactMarker.logMarker(CREATE_MODULE_END);
  return module;
}
 
Example 10
Project: RNLearn_Project1   File: NativeModuleRegistry.java   Source Code and License Vote up 6 votes
void notifyJSInstanceInitialized() {
  mReactApplicationContext.assertOnNativeModulesQueueThread("From version React Native v0.44, " +
    "native modules are explicitly not initialized on the UI thread. See " +
    "https://github.com/facebook/react-native/wiki/Breaking-Changes#d4611211-reactnativeandroidbreaking-move-nativemodule-initialization-off-ui-thread---aaachiuuu " +
    " for more details.");
  ReactMarker.logMarker(ReactMarkerConstants.NATIVE_MODULE_INITIALIZE_START);
  Systrace.beginSection(
      Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
      "NativeModuleRegistry_notifyJSInstanceInitialized");
  try {
    for (ModuleHolder module : mModules.values()) {
      module.initialize();
    }
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
    ReactMarker.logMarker(ReactMarkerConstants.NATIVE_MODULE_INITIALIZE_END);
  }
}
 
Example 11
Project: ReactNativeSignatureExample   File: CatalystInstanceImpl.java   Source Code and License Vote up 6 votes
@Override
public void onExecutorUnregistered(ExecutorToken executorToken) {
  mReactQueueConfiguration.getNativeModulesQueueThread().assertIsOnThread();

  // Since onCatalystInstanceDestroy happens on the UI thread, we don't want to also execute
  // this callback on the native modules thread at the same time. Longer term, onCatalystInstanceDestroy
  // should probably be executed on the native modules thread as well instead.
  synchronized (mJSToJavaCallsTeardownLock) {
    if (!mDestroyed) {
      Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "onExecutorUnregistered");
      try {
        mJavaRegistry.onExecutorUnregistered(executorToken);
      } finally {
        Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
      }
    }
  }
}
 
Example 12
Project: react-native-box-loaders   File: UIViewOperationQueue.java   Source Code and License Vote up 6 votes
@Override
public void doFrameGuarded(long frameTimeNanos) {
  Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "dispatchNonBatchedUIOperations");
  try {
    dispatchPendingNonBatchedOperations(frameTimeNanos);
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }

  synchronized (mDispatchRunnablesLock) {
    for (int i = 0; i < mDispatchUIRunnables.size(); i++) {
      mDispatchUIRunnables.get(i).run();
    }
    mDispatchUIRunnables.clear();
  }

  ReactChoreographer.getInstance().postFrameCallback(
    ReactChoreographer.CallbackType.DISPATCH_UI, this);
}
 
Example 13
Project: react-native-box-loaders   File: EventDispatcher.java   Source Code and License Vote up 6 votes
@Override
public void doFrame(long frameTimeNanos) {
  UiThreadUtil.assertOnUiThread();

  if (mShouldStop) {
    mIsPosted = false;
  } else {
    post();
  }

  Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "ScheduleDispatchFrameCallback");
  try {
    moveStagedEventsToDispatchQueue();

    if (mEventsToDispatchSize > 0 && !mHasDispatchScheduled) {
      mHasDispatchScheduled = true;
      Systrace.startAsyncFlow(
          Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
          "ScheduleDispatchFrameCallback",
          mHasDispatchScheduledCount);
      mReactContext.runOnJSQueueThread(mDispatchEventsRunnable);
    }
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 14
Project: RNLearn_Project1   File: ModuleHolder.java   Source Code and License Vote up 5 votes
private void doInitialize(NativeModule module) {
  SystraceMessage.Builder section =
    SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "initialize");
  if (module instanceof CxxModuleWrapper) {
    section.arg("className", module.getClass().getSimpleName());
  } else {
    section.arg("name", mName);
  }
  section.flush();
  ReactMarker.logMarker(ReactMarkerConstants.INITIALIZE_MODULE_START, mName);
  module.initialize();
  ReactMarker.logMarker(ReactMarkerConstants.INITIALIZE_MODULE_END);
  Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
}
 
Example 15
Project: RNLearn_Project1   File: EventDispatcher.java   Source Code and License Vote up 5 votes
@Override
public void run() {
  Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "DispatchEventsRunnable");
  try {
    Systrace.endAsyncFlow(
        Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
        "ScheduleDispatchFrameCallback",
        mHasDispatchScheduledCount);
    mHasDispatchScheduled = false;
    mHasDispatchScheduledCount++;
    Assertions.assertNotNull(mRCTEventEmitter);
    synchronized (mEventsToDispatchLock) {
      // We avoid allocating an array and iterator, and "sorting" if we don't need to.
      // This occurs when the size of mEventsToDispatch is zero or one.
      if (mEventsToDispatchSize > 1) {
        Arrays.sort(mEventsToDispatch, 0, mEventsToDispatchSize, EVENT_COMPARATOR);
      }
      for (int eventIdx = 0; eventIdx < mEventsToDispatchSize; eventIdx++) {
        Event event = mEventsToDispatch[eventIdx];
        // Event can be null if it has been coalesced into another event.
        if (event == null) {
          continue;
        }
        Systrace.endAsyncFlow(
            Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
            event.getEventName(),
            event.getUniqueID());
        event.dispatch(mRCTEventEmitter);
        event.dispose();
      }
      clearEventsToDispatch();
      mEventCookieToLastEventIdx.clear();
    }
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 16
Project: RNLearn_Project1   File: UIImplementation.java   Source Code and License Vote up 5 votes
protected void calculateRootLayout(ReactShadowNode cssRoot) {
  SystraceMessage.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "cssRoot.calculateLayout")
      .arg("rootTag", cssRoot.getReactTag())
      .flush();
  double startTime = (double) System.nanoTime();
  try {
    cssRoot.calculateLayout();
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
    mLayoutTimer = mLayoutTimer + ((double)System.nanoTime() - startTime) / 1000000.0;
    mLayoutCount = mLayoutCount + 1;
  }
}
 
Example 17
Project: RNLearn_Project1   File: UIManagerModule.java   Source Code and License Vote up 5 votes
private static Map<String, Object> createConstants(
  List<ViewManager> viewManagerList,
  boolean lazyViewManagersEnabled) {
  ReactMarker.logMarker(CREATE_UI_MANAGER_MODULE_CONSTANTS_START);
  Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "CreateUIManagerConstants");
  try {
    return UIManagerModuleConstantsHelper.createConstants(
      viewManagerList,
      lazyViewManagersEnabled);
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
    ReactMarker.logMarker(CREATE_UI_MANAGER_MODULE_CONSTANTS_END);
  }
}
 
Example 18
Project: RNLearn_Project1   File: NativeViewHierarchyManager.java   Source Code and License Vote up 5 votes
public void createView(
    ThemedReactContext themedContext,
    int tag,
    String className,
    @Nullable ReactStylesDiffMap initialProps) {
  UiThreadUtil.assertOnUiThread();
  SystraceMessage.beginSection(
      Systrace.TRACE_TAG_REACT_VIEW,
      "NativeViewHierarchyManager_createView")
      .arg("tag", tag)
      .arg("className", className)
      .flush();
  try {
    ViewManager viewManager = mViewManagers.get(className);

    View view = viewManager.createView(themedContext, mJSResponderHandler);
    mTagsToViews.put(tag, view);
    mTagsToViewManagers.put(tag, viewManager);

    // Use android View id field to store React tag. This is possible since we don't inflate
    // React views from layout xmls. Thus it is easier to just reuse that field instead of
    // creating another (potentially much more expensive) mapping from view to React tag
    view.setId(tag);
    if (initialProps != null) {
      viewManager.updateProperties(view, initialProps);
    }
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_VIEW);
  }
}
 
Example 19
Project: RNLearn_Project1   File: ModuleHolder.java   Source Code and License Vote up 5 votes
private void doInitialize(NativeModule module) {
  SystraceMessage.Builder section =
    SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "initialize");
  if (module instanceof CxxModuleWrapper) {
    section.arg("className", module.getClass().getSimpleName());
  } else {
    section.arg("name", mName);
  }
  section.flush();
  ReactMarker.logMarker(ReactMarkerConstants.INITIALIZE_MODULE_START, mName);
  module.initialize();
  ReactMarker.logMarker(ReactMarkerConstants.INITIALIZE_MODULE_END);
  Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
}
 
Example 20
Project: RNLearn_Project1   File: ReactInstanceManager.java   Source Code and License Vote up 5 votes
private void setupReactContext(ReactApplicationContext reactContext) {
  ReactMarker.logMarker(PRE_SETUP_REACT_CONTEXT_END);
  ReactMarker.logMarker(SETUP_REACT_CONTEXT_START);
  Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "setupReactContext");
  UiThreadUtil.assertOnUiThread();
  Assertions.assertCondition(mCurrentReactContext == null);
  mCurrentReactContext = Assertions.assertNotNull(reactContext);
  CatalystInstance catalystInstance =
      Assertions.assertNotNull(reactContext.getCatalystInstance());

  catalystInstance.initialize();
  mDevSupportManager.onNewReactContextCreated(reactContext);
  mMemoryPressureRouter.addMemoryPressureListener(catalystInstance);
  moveReactContextToCurrentLifecycleState();

  for (ReactRootView rootView : mAttachedRootViews) {
    attachMeasuredRootViewToInstance(rootView, catalystInstance);
  }

  ReactInstanceEventListener[] listeners =
    new ReactInstanceEventListener[mReactInstanceEventListeners.size()];
  listeners = mReactInstanceEventListeners.toArray(listeners);

  for (ReactInstanceEventListener listener : listeners) {
    listener.onReactContextInitialized(reactContext);
  }
  Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
  ReactMarker.logMarker(SETUP_REACT_CONTEXT_END);
}
 
Example 21
Project: react-native-box-loaders   File: NativeModuleRegistry.java   Source Code and License Vote up 5 votes
void notifyCatalystInstanceDestroy() {
  UiThreadUtil.assertOnUiThread();
  Systrace.beginSection(
      Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
      "NativeModuleRegistry_notifyCatalystInstanceDestroy");
  try {
    for (NativeModule nativeModule : mModuleInstances.values()) {
      nativeModule.onCatalystInstanceDestroy();
    }
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 22
Project: react-native-box-loaders   File: UIManagerModule.java   Source Code and License Vote up 5 votes
/**
 * To implement the transactional requirement mentioned in the class javadoc, we only commit
 * UI changes to the actual view hierarchy once a batch of JS->Java calls have been completed.
 * We know this is safe because all JS->Java calls that are triggered by a Java->JS call (e.g.
 * the delivery of a touch event or execution of 'renderApplication') end up in a single
 * JS->Java transaction.
 *
 * A better way to do this would be to have JS explicitly signal to this module when a UI
 * transaction is done. Right now, though, this is how iOS does it, and we should probably
 * update the JS and native code and make this change at the same time.
 *
 * TODO(5279396): Make JS UI library explicitly notify the native UI module of the end of a UI
 *                transaction using a standard native call
 */
@Override
public void onBatchComplete() {
  int batchId = mBatchId;
  mBatchId++;

  SystraceMessage.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "onBatchCompleteUI")
        .arg("BatchId", batchId)
        .flush();
  try {
    mUIImplementation.dispatchViewUpdates(mEventDispatcher, batchId);
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 23
Project: react-native-box-loaders   File: EventDispatcher.java   Source Code and License Vote up 5 votes
@Override
public void run() {
  Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "DispatchEventsRunnable");
  try {
    Systrace.endAsyncFlow(
        Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
        "ScheduleDispatchFrameCallback",
        mHasDispatchScheduledCount);
    mHasDispatchScheduled = false;
    mHasDispatchScheduledCount++;
    Assertions.assertNotNull(mRCTEventEmitter);
    synchronized (mEventsToDispatchLock) {
      // We avoid allocating an array and iterator, and "sorting" if we don't need to.
      // This occurs when the size of mEventsToDispatch is zero or one.
      if (mEventsToDispatchSize > 1) {
        Arrays.sort(mEventsToDispatch, 0, mEventsToDispatchSize, EVENT_COMPARATOR);
      }
      for (int eventIdx = 0; eventIdx < mEventsToDispatchSize; eventIdx++) {
        Event event = mEventsToDispatch[eventIdx];
        // Event can be null if it has been coalesced into another event.
        if (event == null) {
          continue;
        }
        Systrace.endAsyncFlow(
            Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
            event.getEventName(),
            event.getUniqueID());
        event.dispatch(mRCTEventEmitter);
        event.dispose();
      }
      clearEventsToDispatch();
      mEventCookieToLastEventIdx.clear();
    }
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 24
Project: ReactNativeSignatureExample   File: NativeModuleRegistry.java   Source Code and License Vote up 5 votes
void notifyCatalystInstanceDestroy() {
  UiThreadUtil.assertOnUiThread();
  Systrace.beginSection(
      Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
      "NativeModuleRegistry_notifyCatalystInstanceDestroy");
  try {
    for (NativeModule nativeModule : mModuleInstances.values()) {
      nativeModule.onCatalystInstanceDestroy();
    }
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 25
Project: react-native-ibeacon-android   File: ReactInstanceManagerImpl.java   Source Code and License Vote up 5 votes
/**
 * Uses configured {@link ReactPackage} instances to create all view managers
 */
@Override
public List<ViewManager> createAllViewManagers(
    ReactApplicationContext catalystApplicationContext) {
  Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "createAllViewManagers");
  try {
    List<ViewManager> allViewManagers = new ArrayList<>();
    for (ReactPackage reactPackage : mPackages) {
      allViewManagers.addAll(reactPackage.createViewManagers(catalystApplicationContext));
    }
    return allViewManagers;
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 26
Project: react-native-ibeacon-android   File: CoreModulesPackage.java   Source Code and License Vote up 5 votes
@Override
public List<NativeModule> createNativeModules(
    ReactApplicationContext catalystApplicationContext) {
  Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "createUIManagerModule");
  UIManagerModule uiManagerModule;
  try {
    List<ViewManager> viewManagersList = mReactInstanceManager.createAllViewManagers(
        catalystApplicationContext);
    uiManagerModule = new UIManagerModule(
        catalystApplicationContext,
        viewManagersList,
        mUIImplementationProvider.createUIImplementation(
            catalystApplicationContext,
            viewManagersList));
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }

  return Arrays.<NativeModule>asList(
      new AnimationsDebugModule(
          catalystApplicationContext,
          mReactInstanceManager.getDevSupportManager().getDevSettings()),
      new AndroidInfoModule(),
      new DeviceEventManagerModule(catalystApplicationContext, mHardwareBackBtnHandler),
      new ExceptionsManagerModule(mReactInstanceManager.getDevSupportManager()),
      new Timing(catalystApplicationContext),
      new SourceCodeModule(
          mReactInstanceManager.getSourceUrl(),
          mReactInstanceManager.getDevSupportManager().getSourceMapUrl()),
      uiManagerModule,
      new DebugComponentOwnershipModule(catalystApplicationContext));
}
 
Example 27
Project: react-native-ibeacon-android   File: UIImplementation.java   Source Code and License Vote up 5 votes
protected void calculateRootLayout(ReactShadowNode cssRoot) {
  SystraceMessage.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "cssRoot.calculateLayout")
      .arg("rootTag", cssRoot.getReactTag())
      .flush();
  try {
    cssRoot.calculateLayout(mLayoutContext);
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 28
Project: ReactNativeSignatureExample   File: ReactInstanceManagerImpl.java   Source Code and License Vote up 5 votes
/**
 * Uses configured {@link ReactPackage} instances to create all view managers
 */
@Override
public List<ViewManager> createAllViewManagers(
    ReactApplicationContext catalystApplicationContext) {
  Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "createAllViewManagers");
  try {
    List<ViewManager> allViewManagers = new ArrayList<>();
    for (ReactPackage reactPackage : mPackages) {
      allViewManagers.addAll(reactPackage.createViewManagers(catalystApplicationContext));
    }
    return allViewManagers;
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 29
Project: react-native-box-loaders   File: CatalystInstanceImpl.java   Source Code and License Vote up 5 votes
private ReactBridge initializeBridge(
    JavaScriptExecutor jsExecutor,
    JavaScriptModulesConfig jsModulesConfig) {
  mReactQueueConfiguration.getJSQueueThread().assertIsOnThread();
  Assertions.assertCondition(mBridge == null, "initializeBridge should be called once");

  Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "ReactBridgeCtor");
  ReactBridge bridge;
  try {
    bridge = new ReactBridge(
        jsExecutor,
        new NativeModulesReactCallback(),
        mReactQueueConfiguration.getNativeModulesQueueThread());
    mMainExecutorToken = bridge.getMainExecutorToken();
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }

  Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "setBatchedBridgeConfig");
  try {
    bridge.setGlobalVariable(
        "__fbBatchedBridgeConfig",
        buildModulesConfigJSONProperty(mJavaRegistry, jsModulesConfig));
    bridge.setGlobalVariable(
        "__RCTProfileIsProfiling",
        Systrace.isTracing(Systrace.TRACE_TAG_REACT_APPS) ? "true" : "false");
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }

  mJavaRegistry.notifyReactBridgeInitialized(bridge);
  return bridge;
}
 
Example 30
Project: ReactNativeSignatureExample   File: UIImplementation.java   Source Code and License Vote up 5 votes
protected void calculateRootLayout(ReactShadowNode cssRoot) {
  SystraceMessage.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "cssRoot.calculateLayout")
      .arg("rootTag", cssRoot.getReactTag())
      .flush();
  try {
    cssRoot.calculateLayout(mLayoutContext);
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 31
Project: ReactNativeSignatureExample   File: EventDispatcher.java   Source Code and License Vote up 5 votes
@Override
public void doFrame(long frameTimeNanos) {
  UiThreadUtil.assertOnUiThread();

  if (mShouldStop) {
    return;
  }

  Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "ScheduleDispatchFrameCallback");
  try {
    moveStagedEventsToDispatchQueue();

    if (!mHasDispatchScheduled) {
      mHasDispatchScheduled = true;
      Systrace.startAsyncFlow(
          Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
          "ScheduleDispatchFrameCallback",
          mHasDispatchScheduledCount);
      mReactContext.runOnJSQueueThread(mDispatchEventsRunnable);
    }

    ReactChoreographer.getInstance()
        .postFrameCallback(ReactChoreographer.CallbackType.TIMERS_EVENTS, this);
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 32
Project: Ironman   File: UIViewOperationQueue.java   Source Code and License Vote up 5 votes
@Override
public void doFrameGuarded(long frameTimeNanos) {
  Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "dispatchNonBatchedUIOperations");
  try {
    dispatchPendingNonBatchedOperations(frameTimeNanos);
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }

  flushPendingBatches();

  ReactChoreographer.getInstance().postFrameCallback(
    ReactChoreographer.CallbackType.DISPATCH_UI, this);
}
 
Example 33
Project: react-native-ibeacon-android   File: NativeModuleRegistry.java   Source Code and License Vote up 5 votes
public void call(
    CatalystInstance catalystInstance,
    ExecutorToken executorToken,
    int methodId,
    ReadableNativeArray parameters) {
  MethodRegistration method = this.methods.get(methodId);
  Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, method.tracingName);
  try {
    this.methods.get(methodId).method.invoke(catalystInstance, executorToken, parameters);
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 34
Project: react-native-ibeacon-android   File: EventDispatcher.java   Source Code and License Vote up 5 votes
@Override
public void doFrame(long frameTimeNanos) {
  UiThreadUtil.assertOnUiThread();

  if (mShouldStop) {
    return;
  }

  Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "ScheduleDispatchFrameCallback");
  try {
    moveStagedEventsToDispatchQueue();

    if (!mHasDispatchScheduled) {
      mHasDispatchScheduled = true;
      Systrace.startAsyncFlow(
          Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
          "ScheduleDispatchFrameCallback",
          mHasDispatchScheduledCount);
      mReactContext.runOnJSQueueThread(mDispatchEventsRunnable);
    }

    ReactChoreographer.getInstance()
        .postFrameCallback(ReactChoreographer.CallbackType.TIMERS_EVENTS, this);
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 35
Project: react-native-ibeacon-android   File: CatalystInstanceImpl.java   Source Code and License Vote up 5 votes
private ReactBridge initializeBridge(
    JavaScriptExecutor jsExecutor,
    JavaScriptModulesConfig jsModulesConfig) {
  mReactQueueConfiguration.getJSQueueThread().assertIsOnThread();
  Assertions.assertCondition(mBridge == null, "initializeBridge should be called once");

  Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "ReactBridgeCtor");
  ReactBridge bridge;
  try {
    bridge = new ReactBridge(
        jsExecutor,
        new NativeModulesReactCallback(),
        mReactQueueConfiguration.getNativeModulesQueueThread());
    mMainExecutorToken = bridge.getMainExecutorToken();
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }

  Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "setBatchedBridgeConfig");
  try {
    bridge.setGlobalVariable(
        "__fbBatchedBridgeConfig",
        buildModulesConfigJSONProperty(mJavaRegistry, jsModulesConfig));
    bridge.setGlobalVariable(
        "__RCTProfileIsProfiling",
        Systrace.isTracing(Systrace.TRACE_TAG_REACT_APPS) ? "true" : "false");
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }

  mJavaRegistry.notifyReactBridgeInitialized(bridge);
  return bridge;
}
 
Example 36
Project: react-native-ibeacon-android   File: UIManagerModule.java   Source Code and License Vote up 5 votes
private static Map<String, Object> createConstants(List<ViewManager> viewManagerList) {
  Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "CreateUIManagerConstants");
  try {
    return UIManagerModuleConstantsHelper.createConstants(viewManagerList);
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 37
Project: RNLearn_Project1   File: UIManagerModuleConstantsHelper.java   Source Code and License Vote up 4 votes
/**
 * Generates map of constants that is then exposed by {@link UIManagerModule}. The constants map
 * contains the following predefined fields for 'customBubblingEventTypes' and
 * 'customDirectEventTypes'. Provided list of {@param viewManagers} is then used to populate
 * content of those predefined fields using
 * {@link ViewManager#getExportedCustomBubblingEventTypeConstants} and
 * {@link ViewManager#getExportedCustomDirectEventTypeConstants} respectively. Each view manager
 * is in addition allowed to expose viewmanager-specific constants that are placed under the key
 * that corresponds to the view manager's name (see {@link ViewManager#getName}). Constants are
 * merged into the map of {@link UIManagerModule} base constants that is stored in
 * {@link UIManagerModuleConstants}.
 * TODO(6845124): Create a test for this
 */
/* package */ static Map<String, Object> createConstants(
  List<ViewManager> viewManagers,
  boolean lazyViewManagersEnabled) {
  Map<String, Object> constants = UIManagerModuleConstants.getConstants();
  Map bubblingEventTypesConstants = UIManagerModuleConstants.getBubblingEventTypeConstants();
  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);
      }
      Map viewManagerDirectEvents = viewManager.getExportedCustomDirectEventTypeConstants();
      if (viewManagerDirectEvents != null) {
        recursiveMerge(directEventTypesConstants, viewManagerDirectEvents);
      }
      Map viewManagerConstants = MapBuilder.newHashMap();
      Map customViewConstants = viewManager.getExportedViewConstants();
      if (customViewConstants != null) {
        viewManagerConstants.put("Constants", customViewConstants);
      }
      Map viewManagerCommands = viewManager.getCommandsMap();
      if (viewManagerCommands != null) {
        viewManagerConstants.put("Commands", viewManagerCommands);
      }
      Map<String, String> viewManagerNativeProps = viewManager.getNativeProps();
      if (!viewManagerNativeProps.isEmpty()) {
        viewManagerConstants.put("NativeProps", viewManagerNativeProps);
      }
      if (!viewManagerConstants.isEmpty()) {
        constants.put(viewManager.getName(), viewManagerConstants);
      }
    } finally {
      Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
    }
  }

  constants.put(CUSTOM_BUBBLING_EVENT_TYPES_KEY, bubblingEventTypesConstants);
  constants.put(CUSTOM_DIRECT_EVENT_TYPES_KEY, directEventTypesConstants);
  constants.put("AndroidLazyViewManagersEnabled", lazyViewManagersEnabled);

  return constants;
}
 
Example 38
Project: RNLearn_Project1   File: BaseJavaModule.java   Source Code and License Vote up 4 votes
@Override
public void invoke(JSInstance jsInstance, ExecutorToken executorToken, ReadableNativeArray parameters) {
  SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "callJavaModuleMethod")
      .arg("method", mTraceName)
      .flush();
  try {
    if (!mArgumentsProcessed) {
      processArguments();
    }
    if (mArguments == null || mArgumentExtractors == null) {
      throw new Error("processArguments failed");
    }
    if (mJSArgumentsNeeded != parameters.size()) {
      throw new NativeArgumentsParseException(
          BaseJavaModule.this.getName() + "." + mMethod.getName() + " got " +
          parameters.size() + " arguments, expected " + mJSArgumentsNeeded);
    }

    // Modules that support web workers are expected to take an ExecutorToken as the first
    // parameter to all their @ReactMethod-annotated methods. We compensate for that here.
    int i = 0, jsArgumentsConsumed = 0;
    int executorTokenOffset = 0;
    if (BaseJavaModule.this.supportsWebWorkers()) {
      mArguments[0] = executorToken;
      executorTokenOffset = 1;
    }
    try {
      for (; i < mArgumentExtractors.length; i++) {
        mArguments[i + executorTokenOffset] = mArgumentExtractors[i].extractArgument(
            jsInstance, executorToken, parameters, jsArgumentsConsumed);
        jsArgumentsConsumed += mArgumentExtractors[i].getJSArgumentsNeeded();
      }
    } catch (UnexpectedNativeTypeException e) {
      throw new NativeArgumentsParseException(
          e.getMessage() + " (constructing arguments for " + BaseJavaModule.this.getName() +
          "." + mMethod.getName() + " at argument index " +
          getAffectedRange(jsArgumentsConsumed, mArgumentExtractors[i].getJSArgumentsNeeded()) +
          ")",
          e);
    }

    try {
      mMethod.invoke(BaseJavaModule.this, mArguments);
    } catch (IllegalArgumentException ie) {
      throw new RuntimeException(
          "Could not invoke " + BaseJavaModule.this.getName() + "." + mMethod.getName(), ie);
    } catch (IllegalAccessException iae) {
      throw new RuntimeException(
          "Could not invoke " + BaseJavaModule.this.getName() + "." + mMethod.getName(), iae);
    } catch (InvocationTargetException ite) {
      // Exceptions thrown from native module calls end up wrapped in InvocationTargetException
      // which just make traces harder to read and bump out useful information
      if (ite.getCause() instanceof RuntimeException) {
        throw (RuntimeException) ite.getCause();
      }
      throw new RuntimeException(
          "Could not invoke " + BaseJavaModule.this.getName() + "." + mMethod.getName(), ite);
    }
  } finally {
    Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 39
Project: RNLearn_Project1   File: UIManagerModuleConstantsHelper.java   Source Code and License Vote up 4 votes
/**
 * Generates map of constants that is then exposed by {@link UIManagerModule}. The constants map
 * contains the following predefined fields for 'customBubblingEventTypes' and
 * 'customDirectEventTypes'. Provided list of {@param viewManagers} is then used to populate
 * content of those predefined fields using
 * {@link ViewManager#getExportedCustomBubblingEventTypeConstants} and
 * {@link ViewManager#getExportedCustomDirectEventTypeConstants} respectively. Each view manager
 * is in addition allowed to expose viewmanager-specific constants that are placed under the key
 * that corresponds to the view manager's name (see {@link ViewManager#getName}). Constants are
 * merged into the map of {@link UIManagerModule} base constants that is stored in
 * {@link UIManagerModuleConstants}.
 * TODO(6845124): Create a test for this
 */
/* package */ static Map<String, Object> createConstants(
  List<ViewManager> viewManagers,
  boolean lazyViewManagersEnabled) {
  Map<String, Object> constants = UIManagerModuleConstants.getConstants();
  Map bubblingEventTypesConstants = UIManagerModuleConstants.getBubblingEventTypeConstants();
  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);
      }
      Map viewManagerDirectEvents = viewManager.getExportedCustomDirectEventTypeConstants();
      if (viewManagerDirectEvents != null) {
        recursiveMerge(directEventTypesConstants, viewManagerDirectEvents);
      }
      Map viewManagerConstants = MapBuilder.newHashMap();
      Map customViewConstants = viewManager.getExportedViewConstants();
      if (customViewConstants != null) {
        viewManagerConstants.put("Constants", customViewConstants);
      }
      Map viewManagerCommands = viewManager.getCommandsMap();
      if (viewManagerCommands != null) {
        viewManagerConstants.put("Commands", viewManagerCommands);
      }
      Map<String, String> viewManagerNativeProps = viewManager.getNativeProps();
      if (!viewManagerNativeProps.isEmpty()) {
        viewManagerConstants.put("NativeProps", viewManagerNativeProps);
      }
      if (!viewManagerConstants.isEmpty()) {
        constants.put(viewManager.getName(), viewManagerConstants);
      }
    } finally {
      Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
    }
  }

  constants.put(CUSTOM_BUBBLING_EVENT_TYPES_KEY, bubblingEventTypesConstants);
  constants.put(CUSTOM_DIRECT_EVENT_TYPES_KEY, directEventTypesConstants);
  constants.put("AndroidLazyViewManagersEnabled", lazyViewManagersEnabled);

  return constants;
}
 
Example 40
Project: Ironman   File: BaseJavaModule.java   Source Code and License Vote up 4 votes
@Override
public void invoke(CatalystInstance catalystInstance, ExecutorToken executorToken, ReadableNativeArray parameters) {
  SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "callJavaModuleMethod")
      .arg("method", mTraceName)
      .flush();
  try {
    if (mJSArgumentsNeeded != parameters.size()) {
      throw new NativeArgumentsParseException(
          BaseJavaModule.this.getName() + "." + mMethod.getName() + " got " +
          parameters.size() + " arguments, expected " + mJSArgumentsNeeded);
    }

    // Modules that support web workers are expected to take an ExecutorToken as the first
    // parameter to all their @ReactMethod-annotated methods. We compensate for that here.
    int i = 0, jsArgumentsConsumed = 0;
    int executorTokenOffset = 0;
    if (BaseJavaModule.this.supportsWebWorkers()) {
      mArguments[0] = executorToken;
      executorTokenOffset = 1;
    }
    try {
      for (; i < mArgumentExtractors.length; i++) {
        mArguments[i + executorTokenOffset] = mArgumentExtractors[i].extractArgument(
            catalystInstance, executorToken, parameters, jsArgumentsConsumed);
        jsArgumentsConsumed += mArgumentExtractors[i].getJSArgumentsNeeded();
      }
    } catch (UnexpectedNativeTypeException e) {
      throw new NativeArgumentsParseException(
          e.getMessage() + " (constructing arguments for " + BaseJavaModule.this.getName() +
          "." + mMethod.getName() + " at argument index " +
          getAffectedRange(jsArgumentsConsumed, mArgumentExtractors[i].getJSArgumentsNeeded()) +
          ")",
          e);
    }

    try {
      mMethod.invoke(BaseJavaModule.this, mArguments);
    } catch (IllegalArgumentException ie) {
      throw new RuntimeException(
          "Could not invoke " + BaseJavaModule.this.getName() + "." + mMethod.getName(), ie);
    } catch (IllegalAccessException iae) {
      throw new RuntimeException(
          "Could not invoke " + BaseJavaModule.this.getName() + "." + mMethod.getName(), iae);
    } catch (InvocationTargetException ite) {
      // Exceptions thrown from native module calls end up wrapped in InvocationTargetException
      // which just make traces harder to read and bump out useful information
      if (ite.getCause() instanceof RuntimeException) {
        throw (RuntimeException) ite.getCause();
      }
      throw new RuntimeException(
          "Could not invoke " + BaseJavaModule.this.getName() + "." + mMethod.getName(), ite);
    }
  } finally {
    Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}