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

The following are Jave code examples for showing how to use beginSection() 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: 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 2
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 3
Project: RNLearn_Project1   File: ReactInstanceManager.java   Source Code and License Vote up 6 votes
private void attachMeasuredRootViewToInstance(
    ReactRootView rootView,
    CatalystInstance catalystInstance) {
  Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "attachMeasuredRootViewToInstance");
  UiThreadUtil.assertOnUiThread();

  // Reset view content as it's going to be populated by the application content from JS
  rootView.removeAllViews();
  rootView.setId(View.NO_ID);

  UIManagerModule uiManagerModule = catalystInstance.getNativeModule(UIManagerModule.class);
  int rootTag = uiManagerModule.addMeasuredRootView(rootView);
  rootView.setRootViewTag(rootTag);
  @Nullable Bundle launchOptions = rootView.getLaunchOptions();
  WritableMap initialProps = Arguments.makeNativeMap(launchOptions);
  String jsAppModuleName = rootView.getJSModuleName();

  WritableNativeMap appParams = new WritableNativeMap();
  appParams.putDouble("rootTag", rootTag);
  appParams.putMap("initialProps", initialProps);
  catalystInstance.getJSModule(AppRegistry.class).runApplication(jsAppModuleName, appParams);
  rootView.onAttachedToReactInstance();
  Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
}
 
Example 4
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 5
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 6
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 7
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 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: 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 10
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 11
Project: RNLearn_Project1   File: ReactInstanceManager.java   Source Code and License Vote up 6 votes
private void attachMeasuredRootViewToInstance(
    ReactRootView rootView,
    CatalystInstance catalystInstance) {
  Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "attachMeasuredRootViewToInstance");
  UiThreadUtil.assertOnUiThread();

  // Reset view content as it's going to be populated by the application content from JS
  rootView.removeAllViews();
  rootView.setId(View.NO_ID);

  UIManagerModule uiManagerModule = catalystInstance.getNativeModule(UIManagerModule.class);
  int rootTag = uiManagerModule.addMeasuredRootView(rootView);
  rootView.setRootViewTag(rootTag);
  @Nullable Bundle launchOptions = rootView.getLaunchOptions();
  WritableMap initialProps = Arguments.makeNativeMap(launchOptions);
  String jsAppModuleName = rootView.getJSModuleName();

  WritableNativeMap appParams = new WritableNativeMap();
  appParams.putDouble("rootTag", rootTag);
  appParams.putMap("initialProps", initialProps);
  catalystInstance.getJSModule(AppRegistry.class).runApplication(jsAppModuleName, appParams);
  rootView.onAttachedToReactInstance();
  Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
}
 
Example 12
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 13
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 14
Project: ReactNativeSignatureExample   File: CatalystInstanceImpl.java   Source Code and License Vote up 6 votes
@Override
public void onBatchComplete() {
  mReactQueueConfiguration.getNativeModulesQueueThread().assertIsOnThread();

  // The bridge may have been destroyed due to an exception during the batch. In that case
  // native modules could be in a bad state so we don't want to call anything on them. We
  // still want to trigger the debug listener since it allows instrumentation tests to end and
  // check their assertions without waiting for a timeout.
  synchronized (mJSToJavaCallsTeardownLock) {
    if (!mDestroyed) {
      Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "onBatchComplete");
      try {
        mJavaRegistry.onBatchComplete();
      } finally {
        Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
      }
    }
  }

  decrementPendingJSCalls();
}
 
Example 15
Project: react-native-box-loaders   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 16
Project: ReactNativeSignatureExample   File: NativeModuleRegistry.java   Source Code and License Vote up 6 votes
void writeModuleDescriptions(JsonGenerator jg) throws IOException {
  Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "CreateJSON");
  try {
    jg.writeStartObject();
    for (ModuleDefinition moduleDef : mModuleTable) {
      jg.writeObjectFieldStart(moduleDef.name);
      jg.writeNumberField("moduleID", moduleDef.id);
      jg.writeBooleanField("supportsWebWorkers", moduleDef.target.supportsWebWorkers());
      jg.writeObjectFieldStart("methods");
      for (int i = 0; i < moduleDef.methods.size(); i++) {
        MethodRegistration method = moduleDef.methods.get(i);
        jg.writeObjectFieldStart(method.name);
        jg.writeNumberField("methodID", i);
        jg.writeStringField("type", method.method.getType());
        jg.writeEndObject();
      }
      jg.writeEndObject();
      moduleDef.target.writeConstantsField(jg, "constants");
      jg.writeEndObject();
    }
    jg.writeEndObject();
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 17
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 18
Project: Ironman   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 19
Project: react-native-ibeacon-android   File: NativeModuleRegistry.java   Source Code and License Vote up 6 votes
void writeModuleDescriptions(JsonGenerator jg) throws IOException {
  Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "CreateJSON");
  try {
    jg.writeStartObject();
    for (ModuleDefinition moduleDef : mModuleTable) {
      jg.writeObjectFieldStart(moduleDef.name);
      jg.writeNumberField("moduleID", moduleDef.id);
      jg.writeBooleanField("supportsWebWorkers", moduleDef.target.supportsWebWorkers());
      jg.writeObjectFieldStart("methods");
      for (int i = 0; i < moduleDef.methods.size(); i++) {
        MethodRegistration method = moduleDef.methods.get(i);
        jg.writeObjectFieldStart(method.name);
        jg.writeNumberField("methodID", i);
        jg.writeStringField("type", method.method.getType());
        jg.writeEndObject();
      }
      jg.writeEndObject();
      moduleDef.target.writeConstantsField(jg, "constants");
      jg.writeEndObject();
    }
    jg.writeEndObject();
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 20
Project: Ironman   File: XReactInstanceManagerImpl.java   Source Code and License Vote up 6 votes
/**
 * Uses configured {@link ReactPackage} instances to create all view managers
 */
@Override
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 21
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 22
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 23
Project: RNLearn_Project1   File: JavaModuleWrapper.java   Source Code and License Vote up 5 votes
@DoNotStrip
private void findMethods() {
  Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "findMethods");
  Set<String> methodNames = new HashSet<>();

  Method[] targetMethods = mModuleClass.getDeclaredMethods();
  for (Method targetMethod : targetMethods) {
    ReactMethod annotation = targetMethod.getAnnotation(ReactMethod.class);
    if (annotation != null) {
      String methodName = targetMethod.getName();
      if (methodNames.contains(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);
      }
      MethodDescriptor md = new MethodDescriptor();
      JavaMethodWrapper method = new JavaMethodWrapper(this, targetMethod, annotation.isBlockingSynchronousMethod());
      md.name = methodName;
      md.type = method.getType();
      if (md.type == BaseJavaModule.METHOD_TYPE_SYNC) {
        md.signature = method.getSignature();
        md.method = targetMethod;
      }
      mMethods.add(method);
      mDescs.add(md);
    }
  }
  Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
}
 
Example 24
Project: RNLearn_Project1   File: NativeModuleRegistry.java   Source Code and License Vote up 5 votes
void notifyJSInstanceDestroy() {
  mReactApplicationContext.assertOnNativeModulesQueueThread();
  Systrace.beginSection(
      Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
      "NativeModuleRegistry_notifyJSInstanceDestroy");
  try {
    for (ModuleHolder module : mModules.values()) {
      module.destroy();
    }
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 25
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 26
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 27
Project: RNLearn_Project1   File: NativeModuleRegistry.java   Source Code and License Vote up 5 votes
void notifyJSInstanceDestroy() {
  mReactApplicationContext.assertOnNativeModulesQueueThread();
  Systrace.beginSection(
      Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
      "NativeModuleRegistry_notifyJSInstanceDestroy");
  try {
    for (ModuleHolder module : mModules.values()) {
      module.destroy();
    }
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 28
Project: ReactNativeSignatureExample   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 29
Project: react-native-box-loaders   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 JSCHeapCapture(catalystApplicationContext),
      new DebugComponentOwnershipModule(catalystApplicationContext));
}
 
Example 30
Project: Ironman   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 31
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 32
Project: Ironman   File: XReactInstanceManagerImpl.java   Source Code and License Vote up 5 votes
private void setupReactContext(ReactApplicationContext reactContext) {
  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 33
Project: react-native-box-loaders   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 34
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 35
Project: Ironman   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 (ModuleHolder module : mModules.values()) {
      module.destroy();
    }
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 36
Project: ReactNativeSignatureExample   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 37
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 38
Project: react-native-ibeacon-android   File: NativeModuleRegistry.java   Source Code and License Vote up 5 votes
void notifyReactBridgeInitialized(ReactBridge bridge) {
  Systrace.beginSection(
      Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
      "NativeModuleRegistry_notifyReactBridgeInitialized");
  try {
    for (NativeModule nativeModule : mModuleInstances.values()) {
      nativeModule.onReactBridgeInitialized(bridge);
    }
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 39
Project: react-native-ibeacon-android   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 40
Project: react-native-ibeacon-android   File: BaseJavaModule.java   Source Code and License Vote up 4 votes
@Override
public void invoke(CatalystInstance catalystInstance, ExecutorToken executorToken, ReadableNativeArray parameters) {
  Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "callJavaModuleMethod");
  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(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}