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

The following examples show how to use com.facebook.systrace.Systrace#endSection() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EventDispatcher.java    From react-native-GPay with MIT License 6 votes vote down vote up
@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 (!mHasDispatchScheduled) {
      mHasDispatchScheduled = true;
      Systrace.startAsyncFlow(
          Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
          "ScheduleDispatchFrameCallback",
          mHasDispatchScheduledCount.get());
      mReactContext.runOnJSQueueThread(mDispatchEventsRunnable);
    }
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 2
Source File: NativeModuleRegistry.java    From react-native-GPay with MIT License 6 votes vote down vote up
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.markInitializable();
    }
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
    ReactMarker.logMarker(ReactMarkerConstants.NATIVE_MODULE_INITIALIZE_END);
  }
}
 
Example 3
Source File: UIManagerModule.java    From react-native-GPay with MIT License 6 votes vote down vote up
/**
 * 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();
  for (UIManagerModuleListener listener : mListeners) {
    listener.willDispatchViewUpdates(this);
  }
  try {
    mUIImplementation.dispatchViewUpdates(batchId);
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 4
Source File: UIViewOperationQueue.java    From react-native-GPay with MIT License 6 votes vote down vote up
@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
Source File: FabricUIManager.java    From react-native-GPay with MIT License 6 votes vote down vote up
/**
 * @return a clone of the {@link ReactShadowNode} received by parameter. The cloned
 *     ReactShadowNode will contain a copy of all the internal data of the original node, but its
 *     children set will be empty.
 */
@Nullable
@DoNotStrip
public ReactShadowNode cloneNodeWithNewChildren(ReactShadowNode node) {
  if (DEBUG) {
    FLog.d(TAG, "cloneNodeWithNewChildren \n\tnode: " + node);
  }
  SystraceMessage.beginSection(
    Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
    "FabricUIManager.cloneNodeWithNewChildren")
    .flush();
  try {
    ReactShadowNode clone = node.mutableCopyWithNewChildren(node.getInstanceHandle());
    assertReactShadowNodeCopy(node, clone);
    return clone;
  } catch (Throwable t) {
    handleException(node, t);
    return null;
  } finally{
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 6
Source File: FabricUIManager.java    From react-native-GPay with MIT License 6 votes vote down vote up
/**
 * @return a clone of the {@link ReactShadowNode} received by parameter. The cloned
 *     ReactShadowNode will contain a copy of all the internal data of the original node, but its
 *     props will be overridden with the {@link ReadableMap} received by parameter.
 */
@Nullable
@DoNotStrip
public ReactShadowNode cloneNodeWithNewProps(
    ReactShadowNode node, @Nullable ReadableNativeMap newProps) {
  if (DEBUG) {
    FLog.d(TAG, "cloneNodeWithNewProps \n\tnode: " + node + "\n\tprops: " + newProps);
  }
  SystraceMessage.beginSection(
    Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
    "FabricUIManager.cloneNodeWithNewProps")
    .flush();
  try {
    ReactShadowNode clone = node.mutableCopyWithNewProps(node.getInstanceHandle(),
          newProps == null ? null : new ReactStylesDiffMap(newProps));
    assertReactShadowNodeCopy(node, clone);
    return clone;
  } catch (Throwable t) {
    handleException(node, t);
    return null;
  } finally{
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 7
Source File: FabricUIManager.java    From react-native-GPay with MIT License 6 votes vote down vote up
/**
 * @return a clone of the {@link ReactShadowNode} received by parameter. The cloned
 *     ReactShadowNode will contain a copy of all the internal data of the original node, but its
 *     props will be overridden with the {@link ReadableMap} received by parameter and its
 *     children set will be empty.
 */
@Nullable
@DoNotStrip
public ReactShadowNode cloneNodeWithNewChildrenAndProps(
    ReactShadowNode node, ReadableNativeMap newProps) {
  if (DEBUG) {
    FLog.d(TAG, "cloneNodeWithNewChildrenAndProps \n\tnode: " + node + "\n\tnewProps: " + newProps);
  }
  SystraceMessage.beginSection(
    Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
    "FabricUIManager.cloneNodeWithNewChildrenAndProps")
    .flush();
  try {
    ReactShadowNode clone =
        node.mutableCopyWithNewChildrenAndProps(node.getInstanceHandle(),
            newProps == null ? null : new ReactStylesDiffMap(newProps));
    assertReactShadowNodeCopy(node, clone);
    return clone;
  } catch (Throwable t) {
    handleException(node, t);
    return null;
  } finally{
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 8
Source File: ReactInstanceManager.java    From react-native-GPay with MIT License 6 votes vote down vote up
/**
 * Uses configured {@link ReactPackage} instances to create all view managers.
 */
public List<ViewManager> getOrCreateViewManagers(
    ReactApplicationContext catalystApplicationContext) {
  ReactMarker.logMarker(CREATE_VIEW_MANAGERS_START);
  Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "createAllViewManagers");
  try {
    if (mViewManagers == null) {
      synchronized (mPackages) {
        if (mViewManagers == null) {
          mViewManagers = new ArrayList<>();
          for (ReactPackage reactPackage : mPackages) {
            mViewManagers.addAll(reactPackage.createViewManagers(catalystApplicationContext));
          }
          return mViewManagers;
        }
      }
    }
    return mViewManagers;
  } finally {
    Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
    ReactMarker.logMarker(CREATE_VIEW_MANAGERS_END);
  }
}
 
Example 9
Source File: UIImplementation.java    From react-native-GPay with MIT License 6 votes vote down vote up
/**
 * Invoked at the end of the transaction to commit any updates to the node hierarchy.
 */
public void dispatchViewUpdates(int batchId) {
  SystraceMessage.beginSection(
    Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
    "UIImplementation.dispatchViewUpdates")
    .arg("batchId", batchId)
    .flush();
  final long commitStartTime = SystemClock.uptimeMillis();
  try {
    updateViewHierarchy();
    mNativeViewHierarchyOptimizer.onBatchComplete();
    mOperationsQueue.dispatchViewUpdates(batchId, commitStartTime, mLastCalculateLayoutTime);
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 10
Source File: FabricUIManager.java    From react-native-GPay with MIT License 5 votes vote down vote up
@DoNotStrip
public synchronized void completeRoot(int rootTag, @Nullable List<ReactShadowNode> childList) {
  SystraceMessage.beginSection(
    Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
    "FabricUIManager.completeRoot")
    .flush();
  try {
    long startTime = SystemClock.uptimeMillis();
    childList = childList == null ? new LinkedList<ReactShadowNode>() : childList;
    if (DEBUG) {
      FLog.d(TAG, "completeRoot rootTag: " + rootTag + ", childList: " + childList);
    }
    ReactShadowNode currentRootShadowNode = getRootNode(rootTag);
    Assertions.assertNotNull(
        currentRootShadowNode,
        "Root view with tag " + rootTag + " must be added before completeRoot is called");

    currentRootShadowNode = calculateDiffingAndCreateNewRootNode(currentRootShadowNode, childList);

    if (DEBUG) {
      FLog.d(
        TAG,
        "ReactShadowNodeHierarchy after diffing: " + currentRootShadowNode.getHierarchyInfo());
    }

    applyUpdatesRecursive(currentRootShadowNode);
    mUIViewOperationQueue.dispatchViewUpdates(
      mCurrentBatch++, startTime, mLastCalculateLayoutTime);

    mRootShadowNodeRegistry.replaceNode(currentRootShadowNode);
  } catch (Exception e) {
    handleException(getRootNode(rootTag), e);
  } finally{
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 11
Source File: ReactRootView.java    From react-native-GPay with MIT License 5 votes vote down vote up
/**
 * Schedule rendering of the react component rendered by the JS application from the given JS
 * module (@{param moduleName}) using provided {@param reactInstanceManager} to attach to the
 * JS context of that manager. Extra parameter {@param launchOptions} can be used to pass initial
 * properties for the react component.
 */
public void startReactApplication(
    ReactInstanceManager reactInstanceManager,
    String moduleName,
    @Nullable Bundle initialProperties) {
  Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "startReactApplication");
  try {
    UiThreadUtil.assertOnUiThread();

    // TODO(6788889): Use POJO instead of bundle here, apparently we can't just use WritableMap
    // here as it may be deallocated in native after passing via JNI bridge, but we want to reuse
    // it in the case of re-creating the catalyst instance
    Assertions.assertCondition(
      mReactInstanceManager == null,
      "This root view has already been attached to a catalyst instance manager");

    mReactInstanceManager = reactInstanceManager;
    mJSModuleName = moduleName;
    mAppProperties = initialProperties;

    if (!mReactInstanceManager.hasStartedCreatingInitialContext()) {
      mReactInstanceManager.createReactContextInBackground();
    }

    attachToReactInstanceManager();

  } finally {
    Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 12
Source File: ReactRootView.java    From react-native-GPay with MIT License 5 votes vote down vote up
private void attachToReactInstanceManager() {
  Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "attachToReactInstanceManager");
  try {
    if (mIsAttachedToInstance) {
      return;
    }

    mIsAttachedToInstance = true;
    Assertions.assertNotNull(mReactInstanceManager).attachRootView(this);
    getViewTreeObserver().addOnGlobalLayoutListener(getCustomGlobalLayoutListener());
  } finally {
    Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 13
Source File: FabricUIManager.java    From react-native-GPay with MIT License 5 votes vote down vote up
private void calculateLayout(ReactShadowNode newRootShadowNode) {
  SystraceMessage.beginSection(
    Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
    "FabricUIManager.calculateLayout")
    .flush();
  long startTime = SystemClock.uptimeMillis();
  try {
    newRootShadowNode.calculateLayout();
  } finally{
    mLastCalculateLayoutTime = SystemClock.uptimeMillis() - startTime;
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 14
Source File: JavaModuleWrapper.java    From react-native-GPay with MIT License 5 votes vote down vote up
@DoNotStrip
private void findMethods() {
  Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "findMethods");
  Set<String> methodNames = new HashSet<>();

  Class<? extends NativeModule> classForMethods = mModuleHolder.getModule().getClass();
  Class<? extends NativeModule> superClass =
      (Class<? extends NativeModule>) classForMethods.getSuperclass();
  if (ReactModuleWithSpec.class.isAssignableFrom(superClass)) {
    // For java module that is based on generated flow-type spec, inspect the
    // spec abstract class instead, which is the super class of the given java
    // module.
    classForMethods = superClass;
  }
  Method[] targetMethods = classForMethods.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 15
Source File: UIImplementation.java    From react-native-GPay with MIT License 5 votes vote down vote up
protected void calculateRootLayout(ReactShadowNode cssRoot) {
  SystraceMessage.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "cssRoot.calculateLayout")
      .arg("rootTag", cssRoot.getReactTag())
      .flush();
  long startTime = SystemClock.uptimeMillis();
  try {
    cssRoot.calculateLayout();
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
    mLastCalculateLayoutTime = SystemClock.uptimeMillis() - startTime;
  }
}
 
Example 16
Source File: UIManagerModule.java    From react-native-GPay with MIT License 5 votes vote down vote up
private static Map<String, Object> createConstants(
    List<ViewManager> viewManagers,
    @Nullable Map<String, Object> customBubblingEvents,
    @Nullable Map<String, Object> customDirectEvents) {
  ReactMarker.logMarker(CREATE_UI_MANAGER_MODULE_CONSTANTS_START);
  Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "CreateUIManagerConstants");
  try {
    return UIManagerModuleConstantsHelper.createConstants(
        viewManagers, customBubblingEvents, customDirectEvents);
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
    ReactMarker.logMarker(CREATE_UI_MANAGER_MODULE_CONSTANTS_END);
  }
}
 
Example 17
Source File: CoreModulesPackage.java    From react-native-GPay with MIT License 5 votes vote down vote up
private UIManagerModule createUIManager(final ReactApplicationContext reactContext) {
  ReactMarker.logMarker(CREATE_UI_MANAGER_MODULE_START);
  Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "createUIManagerModule");
  try {
    if (mLazyViewManagersEnabled) {
      UIManagerModule.ViewManagerResolver resolver = new UIManagerModule.ViewManagerResolver() {
        @Override
        public @Nullable ViewManager getViewManager(String viewManagerName) {
          return mReactInstanceManager.createViewManager(viewManagerName);
        }
        @Override
        public List<String> getViewManagerNames() {
          return mReactInstanceManager.getViewManagerNames();
        }
      };

      return new UIManagerModule(
          reactContext,
          resolver,
          mMinTimeLeftInFrameForNonBatchedOperationMs);
    } else {
      return new UIManagerModule(
          reactContext,
          mReactInstanceManager.getOrCreateViewManagers(reactContext),
          mMinTimeLeftInFrameForNonBatchedOperationMs);
    }
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
    ReactMarker.logMarker(CREATE_UI_MANAGER_MODULE_END);
  }
}
 
Example 18
Source File: UIManagerModule.java    From react-native-GPay with MIT License 5 votes vote down vote up
private static Map<String, Object> createConstants(ViewManagerResolver viewManagerResolver) {
  ReactMarker.logMarker(CREATE_UI_MANAGER_MODULE_CONSTANTS_START);
  Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "CreateUIManagerConstants");
  try {
    return UIManagerModuleConstantsHelper.createConstants(viewManagerResolver);
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
    ReactMarker.logMarker(CREATE_UI_MANAGER_MODULE_CONSTANTS_END);
  }
}
 
Example 19
Source File: ReactInstanceManager.java    From react-native-GPay with MIT License 4 votes vote down vote up
private void setupReactContext(final ReactApplicationContext reactContext) {
  Log.d(ReactConstants.TAG, "ReactInstanceManager.setupReactContext()");
  ReactMarker.logMarker(PRE_SETUP_REACT_CONTEXT_END);
  ReactMarker.logMarker(SETUP_REACT_CONTEXT_START);
  Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "setupReactContext");
  synchronized (mReactContextLock) {
    mCurrentReactContext = Assertions.assertNotNull(reactContext);
  }
  CatalystInstance catalystInstance =
    Assertions.assertNotNull(reactContext.getCatalystInstance());

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

  ReactMarker.logMarker(ATTACH_MEASURED_ROOT_VIEWS_START);
  synchronized (mAttachedRootViews) {
    for (ReactRootView rootView : mAttachedRootViews) {
      attachRootViewToInstance(rootView);
    }
  }
  ReactMarker.logMarker(ATTACH_MEASURED_ROOT_VIEWS_END);

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

  UiThreadUtil.runOnUiThread(
      new Runnable() {
        @Override
        public void run() {
          for (ReactInstanceEventListener listener : finalListeners) {
            listener.onReactContextInitialized(reactContext);
          }
        }
      });
  Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
  ReactMarker.logMarker(SETUP_REACT_CONTEXT_END);
  reactContext.runOnJSQueueThread(
      new Runnable() {
        @Override
        public void run() {
          Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT);
        }
      });
  reactContext.runOnNativeModulesQueueThread(
      new Runnable() {
        @Override
        public void run() {
          Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT);
        }
      });
}
 
Example 20
Source File: ReactInstanceManager.java    From react-native-GPay with MIT License 4 votes vote down vote up
private NativeModuleRegistry processPackages(
  ReactApplicationContext reactContext,
  List<ReactPackage> packages,
  boolean checkAndUpdatePackageMembership) {
  NativeModuleRegistryBuilder nativeModuleRegistryBuilder = new NativeModuleRegistryBuilder(
    reactContext,
    this);

  ReactMarker.logMarker(PROCESS_PACKAGES_START);

  // TODO(6818138): Solve use-case of native modules overriding
  synchronized (mPackages) {
    for (ReactPackage reactPackage : packages) {
      if (checkAndUpdatePackageMembership && mPackages.contains(reactPackage)) {
        continue;
      }
      Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "createAndProcessCustomReactPackage");
      try {
        if (checkAndUpdatePackageMembership) {
          mPackages.add(reactPackage);
        }
        processPackage(reactPackage, nativeModuleRegistryBuilder);
      } finally {
        Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
      }
    }
  }
  ReactMarker.logMarker(PROCESS_PACKAGES_END);

  ReactMarker.logMarker(BUILD_NATIVE_MODULE_REGISTRY_START);
  Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "buildNativeModuleRegistry");
  NativeModuleRegistry nativeModuleRegistry;
  try {
    nativeModuleRegistry = nativeModuleRegistryBuilder.build();
  } finally {
    Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
    ReactMarker.logMarker(BUILD_NATIVE_MODULE_REGISTRY_END);
  }

  return nativeModuleRegistry;
}