Java Code Examples for com.facebook.systrace.Systrace

The following are top voted examples for showing how to use com.facebook.systrace.Systrace. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: RNLearn_Project1   File: SystraceRequestListener.java   View source code 6 votes vote down vote up
@Override
public void onProducerStart(String requestId, String producerName) {
  if (!Systrace.isTracing(Systrace.TRACE_TAG_REACT_FRESCO)) {
    return;
  }

  StringBuilder entryName = new StringBuilder();
  entryName.append("FRESCO_PRODUCER_");
  entryName.append(producerName.replace(':', '_'));

  Pair<Integer,String> requestPair = Pair.create(mCurrentID, entryName.toString());
  Systrace.beginAsyncSection(
      Systrace.TRACE_TAG_REACT_FRESCO,
      requestPair.second,
      mCurrentID);
  mProducerID.put(requestId, requestPair);
  mCurrentID++;
}
 
Example 2
Project: RNLearn_Project1   File: SystraceRequestListener.java   View source code 6 votes vote down vote up
@Override
public void onProducerFinishWithSuccess(
    String requestId,
    String producerName,
    Map<String, String> extraMap) {
  if (!Systrace.isTracing(Systrace.TRACE_TAG_REACT_FRESCO)) {
    return;
  }

  if (mProducerID.containsKey(requestId)) {
    Pair<Integer, String> entry = mProducerID.get(requestId);
    Systrace.endAsyncSection(
        Systrace.TRACE_TAG_REACT_FRESCO,
        entry.second,
        entry.first);
    mProducerID.remove(requestId);
  }
}
 
Example 3
Project: RNLearn_Project1   File: SystraceRequestListener.java   View source code 6 votes vote down vote up
@Override
public void onProducerFinishWithFailure(
    String requestId,
    String producerName,
    Throwable throwable,
    Map<String, String> extraMap) {
  if (!Systrace.isTracing(Systrace.TRACE_TAG_REACT_FRESCO)) {
    return;
  }

  if (mProducerID.containsKey(requestId)) {
    Pair<Integer, String> entry = mProducerID.get(requestId);
    Systrace.endAsyncSection(
        Systrace.TRACE_TAG_REACT_FRESCO,
        entry.second,
        entry.first);
    mProducerID.remove(requestId);
  }
}
 
Example 4
Project: RNLearn_Project1   File: SystraceRequestListener.java   View source code 6 votes vote down vote up
@Override
public void onProducerFinishWithCancellation(
    String requestId, String producerName, Map<String, String> extraMap) {
  if (!Systrace.isTracing(Systrace.TRACE_TAG_REACT_FRESCO)) {
    return;
  }

  if (mProducerID.containsKey(requestId)) {
    Pair<Integer, String> entry = mProducerID.get(requestId);
    Systrace.endAsyncSection(
        Systrace.TRACE_TAG_REACT_FRESCO,
        entry.second,
        entry.first);
    mProducerID.remove(requestId);
  }
}
 
Example 5
Project: RNLearn_Project1   File: SystraceRequestListener.java   View source code 6 votes vote down vote up
@Override
public void onProducerEvent(String requestId, String producerName, String producerEventName) {
  if (!Systrace.isTracing(Systrace.TRACE_TAG_REACT_FRESCO)) {
    return;
  }

  StringBuilder entryName = new StringBuilder();
  entryName.append("FRESCO_PRODUCER_EVENT_");
  entryName.append(requestId.replace(':', '_'));
  entryName.append("_");
  entryName.append(producerName.replace(':', '_'));
  entryName.append("_");
  entryName.append(producerEventName.replace(':', '_'));
  Systrace.traceInstant(
      Systrace.TRACE_TAG_REACT_FRESCO,
      entryName.toString(),
      Systrace.EventScope.THREAD);
}
 
Example 6
Project: RNLearn_Project1   File: SystraceRequestListener.java   View source code 6 votes vote down vote up
@Override
public void onRequestStart(
    ImageRequest request,
    Object callerContext,
    String requestId,
    boolean isPrefetch) {
  if (!Systrace.isTracing(Systrace.TRACE_TAG_REACT_FRESCO)) {
    return;
  }

  StringBuilder entryName = new StringBuilder();
  entryName.append("FRESCO_REQUEST_");
  entryName.append(request.getSourceUri().toString().replace(':', '_'));

  Pair<Integer,String> requestPair = Pair.create(mCurrentID, entryName.toString());
  Systrace.beginAsyncSection(
      Systrace.TRACE_TAG_REACT_FRESCO,
      requestPair.second,
      mCurrentID);
  mRequestsID.put(requestId, requestPair);
  mCurrentID++;
}
 
Example 7
Project: RNLearn_Project1   File: SystraceRequestListener.java   View source code 6 votes vote down vote up
@Override
public void onRequestFailure(
    ImageRequest request,
    String requestId,
    Throwable throwable,
    boolean isPrefetch) {
  if (!Systrace.isTracing(Systrace.TRACE_TAG_REACT_FRESCO)) {
    return;
  }

  if (mRequestsID.containsKey(requestId)) {
    Pair<Integer, String> entry = mRequestsID.get(requestId);
    Systrace.endAsyncSection(
        Systrace.TRACE_TAG_REACT_FRESCO,
        entry.second,
        entry.first);
    mRequestsID.remove(requestId);
  }
}
 
Example 8
Project: RNLearn_Project1   File: LazyReactPackage.java   View source code 6 votes vote down vote up
@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 9
Project: RNLearn_Project1   File: ReactInstanceManager.java   View source code 6 votes vote down vote up
/**
 * 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 10
Project: RNLearn_Project1   File: ReactInstanceManager.java   View source code 6 votes vote down vote up
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 11
Project: RNLearn_Project1   File: ReactInstanceManager.java   View source code 6 votes vote down vote up
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 12
Project: RNLearn_Project1   File: UIViewOperationQueue.java   View source code 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 13
Project: RNLearn_Project1   File: EventDispatcher.java   View source code 6 votes vote down vote up
/**
 * Sends the given Event to JS, coalescing eligible events if JS is backed up.
 */
public void dispatchEvent(Event event) {
  Assertions.assertCondition(event.isInitialized(), "Dispatched event hasn't been initialized");

  for (EventDispatcherListener listener : mListeners) {
    listener.onEventDispatch(event);
  }

  synchronized (mEventsStagingLock) {
    mEventStaging.add(event);
    Systrace.startAsyncFlow(
        Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
        event.getEventName(),
        event.getUniqueID());
  }
  if (mRCTEventEmitter != null) {
    // If the host activity is paused, the frame callback may not be currently
    // posted. Ensure that it is so that this event gets delivered promptly.
    mCurrentFrameCallback.maybePostFromNonUI();
  } else {
    // No JS application has started yet, or resumed. This can happen when a ReactRootView is
    // added to view hierarchy, but ReactContext creation has not completed yet. In this case, any
    // touch event dispatch will hit this codepath, and we simply queue them so that they
    // are dispatched once ReactContext creation completes and JS app is running.
  }
}
 
Example 14
Project: RNLearn_Project1   File: EventDispatcher.java   View source code 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 (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 15
Project: RNLearn_Project1   File: ModuleHolder.java   View source code 6 votes vote down vote up
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 16
Project: RNLearn_Project1   File: CatalystInstanceImpl.java   View source code 6 votes vote down vote up
@Override
public void runJSBundle() {
  Assertions.assertCondition(!mJSBundleHasLoaded, "JS bundle was already loaded!");
  mJSBundleHasLoaded = true;

  // incrementPendingJSCalls();
  mJSBundleLoader.loadScript(CatalystInstanceImpl.this);

  synchronized (mJSCallsPendingInitLock) {
    // Loading the bundle is queued on the JS thread, but may not have
    // run yet.  It's safe to set this here, though, since any work it
    // gates will be queued on the JS thread behind the load.
    mAcceptCalls = true;

    for (PendingJSCall call : mJSCallsPendingInit) {
      jniCallJSFunction(call.mExecutorToken, call.mModule, call.mMethod, call.mArguments);
    }
    mJSCallsPendingInit.clear();
  }

  // This is registered after JS starts since it makes a JS call
  Systrace.registerListener(mTraceListener);
}
 
Example 17
Project: RNLearn_Project1   File: CatalystInstanceImpl.java   View source code 6 votes vote down vote up
private void incrementPendingJSCalls() {
  int oldPendingCalls = mPendingJSCalls.getAndIncrement();
  boolean wasIdle = oldPendingCalls == 0;
  Systrace.traceCounter(
      Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
      mJsPendingCallsTitleForTrace,
      oldPendingCalls + 1);
  if (wasIdle && !mBridgeIdleListeners.isEmpty()) {
    mNativeModulesQueueThread.runOnQueue(new Runnable() {
      @Override
      public void run() {
        for (NotThreadSafeBridgeIdleDebugListener listener : mBridgeIdleListeners) {
          listener.onTransitionToBridgeBusy();
        }
      }
    });
  }
}
 
Example 18
Project: RNLearn_Project1   File: CatalystInstanceImpl.java   View source code 6 votes vote down vote up
private void decrementPendingJSCalls() {
  int newPendingCalls = mPendingJSCalls.decrementAndGet();
  // TODO(9604406): handle case of web workers injecting messages to main thread
  //Assertions.assertCondition(newPendingCalls >= 0);
  boolean isNowIdle = newPendingCalls == 0;
  Systrace.traceCounter(
      Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
      mJsPendingCallsTitleForTrace,
      newPendingCalls);

  if (isNowIdle && !mBridgeIdleListeners.isEmpty()) {
    mNativeModulesQueueThread.runOnQueue(new Runnable() {
      @Override
      public void run() {
        for (NotThreadSafeBridgeIdleDebugListener listener : mBridgeIdleListeners) {
          listener.onTransitionToBridgeIdle();
        }
      }
    });
  }
}
 
Example 19
Project: RNLearn_Project1   File: NativeModuleRegistry.java   View source code 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.initialize();
    }
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
    ReactMarker.logMarker(ReactMarkerConstants.NATIVE_MODULE_INITIALIZE_END);
  }
}
 
Example 20
Project: RNLearn_Project1   File: JavaMethodWrapper.java   View source code 6 votes vote down vote up
private void processArguments() {
  if (mArgumentsProcessed) {
    return;
  }
  SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "processArguments")
    .arg("method", mModuleWrapper.getName() + "." + mMethod.getName())
    .flush();
  mArgumentsProcessed = true;
  mArgumentExtractors = buildArgumentExtractors(mParameterTypes);
  mSignature = buildSignature(mMethod, mParameterTypes, (mType.equals(BaseJavaModule.METHOD_TYPE_SYNC)));
  // Since native methods are invoked from a message queue executed on a single thread, it is
  // safe to allocate only one arguments object per method that can be reused across calls
  mArguments = new Object[mParameterTypes.length];
  mJSArgumentsNeeded = calculateJSArgumentsNeeded();
  com.facebook.systrace.Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
}
 
Example 21
Project: RNLearn_Project1   File: CoreModulesPackage.java   View source code 6 votes vote down vote up
@Override
public List<Class<? extends JavaScriptModule>> createJSModules() {
  List<Class<? extends JavaScriptModule>> jsModules = new ArrayList<>(Arrays.asList(
      DeviceEventManagerModule.RCTDeviceEventEmitter.class,
      JSTimersExecution.class,
      RCTEventEmitter.class,
      RCTNativeAppEventEmitter.class,
      AppRegistry.class,
      com.facebook.react.bridge.Systrace.class,
      HMRClient.class));

  if (ReactBuildConfig.DEBUG) {
    jsModules.add(DebugComponentOwnershipModule.RCTDebugComponentOwnership.class);
    jsModules.add(JSCHeapCapture.HeapCapture.class);
    jsModules.add(JSCSamplingProfiler.SamplingProfiler.class);
  }

  return jsModules;
}
 
Example 22
Project: RNLearn_Project1   File: CoreModulesPackage.java   View source code 6 votes vote down vote up
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 23
Project: RNLearn_Project1   File: SystraceRequestListener.java   View source code 6 votes vote down vote up
@Override
public void onProducerStart(String requestId, String producerName) {
  if (!Systrace.isTracing(Systrace.TRACE_TAG_REACT_FRESCO)) {
    return;
  }

  StringBuilder entryName = new StringBuilder();
  entryName.append("FRESCO_PRODUCER_");
  entryName.append(producerName.replace(':', '_'));

  Pair<Integer,String> requestPair = Pair.create(mCurrentID, entryName.toString());
  Systrace.beginAsyncSection(
      Systrace.TRACE_TAG_REACT_FRESCO,
      requestPair.second,
      mCurrentID);
  mProducerID.put(requestId, requestPair);
  mCurrentID++;
}
 
Example 24
Project: RNLearn_Project1   File: SystraceRequestListener.java   View source code 6 votes vote down vote up
@Override
public void onProducerFinishWithSuccess(
    String requestId,
    String producerName,
    Map<String, String> extraMap) {
  if (!Systrace.isTracing(Systrace.TRACE_TAG_REACT_FRESCO)) {
    return;
  }

  if (mProducerID.containsKey(requestId)) {
    Pair<Integer, String> entry = mProducerID.get(requestId);
    Systrace.endAsyncSection(
        Systrace.TRACE_TAG_REACT_FRESCO,
        entry.second,
        entry.first);
    mProducerID.remove(requestId);
  }
}
 
Example 25
Project: RNLearn_Project1   File: SystraceRequestListener.java   View source code 6 votes vote down vote up
@Override
public void onProducerFinishWithFailure(
    String requestId,
    String producerName,
    Throwable throwable,
    Map<String, String> extraMap) {
  if (!Systrace.isTracing(Systrace.TRACE_TAG_REACT_FRESCO)) {
    return;
  }

  if (mProducerID.containsKey(requestId)) {
    Pair<Integer, String> entry = mProducerID.get(requestId);
    Systrace.endAsyncSection(
        Systrace.TRACE_TAG_REACT_FRESCO,
        entry.second,
        entry.first);
    mProducerID.remove(requestId);
  }
}
 
Example 26
Project: RNLearn_Project1   File: SystraceRequestListener.java   View source code 6 votes vote down vote up
@Override
public void onProducerFinishWithCancellation(
    String requestId, String producerName, Map<String, String> extraMap) {
  if (!Systrace.isTracing(Systrace.TRACE_TAG_REACT_FRESCO)) {
    return;
  }

  if (mProducerID.containsKey(requestId)) {
    Pair<Integer, String> entry = mProducerID.get(requestId);
    Systrace.endAsyncSection(
        Systrace.TRACE_TAG_REACT_FRESCO,
        entry.second,
        entry.first);
    mProducerID.remove(requestId);
  }
}
 
Example 27
Project: RNLearn_Project1   File: SystraceRequestListener.java   View source code 6 votes vote down vote up
@Override
public void onProducerEvent(String requestId, String producerName, String producerEventName) {
  if (!Systrace.isTracing(Systrace.TRACE_TAG_REACT_FRESCO)) {
    return;
  }

  StringBuilder entryName = new StringBuilder();
  entryName.append("FRESCO_PRODUCER_EVENT_");
  entryName.append(requestId.replace(':', '_'));
  entryName.append("_");
  entryName.append(producerName.replace(':', '_'));
  entryName.append("_");
  entryName.append(producerEventName.replace(':', '_'));
  Systrace.traceInstant(
      Systrace.TRACE_TAG_REACT_FRESCO,
      entryName.toString(),
      Systrace.EventScope.THREAD);
}
 
Example 28
Project: RNLearn_Project1   File: SystraceRequestListener.java   View source code 6 votes vote down vote up
@Override
public void onRequestStart(
    ImageRequest request,
    Object callerContext,
    String requestId,
    boolean isPrefetch) {
  if (!Systrace.isTracing(Systrace.TRACE_TAG_REACT_FRESCO)) {
    return;
  }

  StringBuilder entryName = new StringBuilder();
  entryName.append("FRESCO_REQUEST_");
  entryName.append(request.getSourceUri().toString().replace(':', '_'));

  Pair<Integer,String> requestPair = Pair.create(mCurrentID, entryName.toString());
  Systrace.beginAsyncSection(
      Systrace.TRACE_TAG_REACT_FRESCO,
      requestPair.second,
      mCurrentID);
  mRequestsID.put(requestId, requestPair);
  mCurrentID++;
}
 
Example 29
Project: RNLearn_Project1   File: SystraceRequestListener.java   View source code 6 votes vote down vote up
@Override
public void onRequestFailure(
    ImageRequest request,
    String requestId,
    Throwable throwable,
    boolean isPrefetch) {
  if (!Systrace.isTracing(Systrace.TRACE_TAG_REACT_FRESCO)) {
    return;
  }

  if (mRequestsID.containsKey(requestId)) {
    Pair<Integer, String> entry = mRequestsID.get(requestId);
    Systrace.endAsyncSection(
        Systrace.TRACE_TAG_REACT_FRESCO,
        entry.second,
        entry.first);
    mRequestsID.remove(requestId);
  }
}
 
Example 30
Project: RNLearn_Project1   File: BaseJavaModule.java   View source code 6 votes vote down vote up
public JavaMethod(Method method, boolean isSync) {
  mMethod = method;
  mMethod.setAccessible(true);
  Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "callGetParameterTypes");
  mParameterTypes = mMethod.getParameterTypes();
  Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
  mParamLength = mParameterTypes.length;

  if (isSync) {
    mType = METHOD_TYPE_SYNC;
  } else if (mParamLength > 0 && (mParameterTypes[mParamLength - 1] == Promise.class)) {
    mType = METHOD_TYPE_PROMISE;
  }
  mTraceName = BaseJavaModule.this.getName() + "." + mMethod.getName();

}
 
Example 31
Project: RNLearn_Project1   File: BaseJavaModule.java   View source code 6 votes vote down vote up
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 32
Project: RNLearn_Project1   File: LazyReactPackage.java   View source code 6 votes vote down vote up
@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 33
Project: RNLearn_Project1   File: ReactInstanceManager.java   View source code 6 votes vote down vote up
/**
 * 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 34
Project: RNLearn_Project1   File: ReactInstanceManager.java   View source code 6 votes vote down vote up
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 35
Project: RNLearn_Project1   File: ReactInstanceManager.java   View source code 6 votes vote down vote up
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 36
Project: RNLearn_Project1   File: UIViewOperationQueue.java   View source code 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 37
Project: RNLearn_Project1   File: EventDispatcher.java   View source code 6 votes vote down vote up
/**
 * Sends the given Event to JS, coalescing eligible events if JS is backed up.
 */
public void dispatchEvent(Event event) {
  Assertions.assertCondition(event.isInitialized(), "Dispatched event hasn't been initialized");

  for (EventDispatcherListener listener : mListeners) {
    listener.onEventDispatch(event);
  }

  synchronized (mEventsStagingLock) {
    mEventStaging.add(event);
    Systrace.startAsyncFlow(
        Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
        event.getEventName(),
        event.getUniqueID());
  }
  if (mRCTEventEmitter != null) {
    // If the host activity is paused, the frame callback may not be currently
    // posted. Ensure that it is so that this event gets delivered promptly.
    mCurrentFrameCallback.maybePostFromNonUI();
  } else {
    // No JS application has started yet, or resumed. This can happen when a ReactRootView is
    // added to view hierarchy, but ReactContext creation has not completed yet. In this case, any
    // touch event dispatch will hit this codepath, and we simply queue them so that they
    // are dispatched once ReactContext creation completes and JS app is running.
  }
}
 
Example 38
Project: RNLearn_Project1   File: EventDispatcher.java   View source code 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 (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 39
Project: RNLearn_Project1   File: ModuleHolder.java   View source code 6 votes vote down vote up
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 40
Project: RNLearn_Project1   File: CatalystInstanceImpl.java   View source code 6 votes vote down vote up
@Override
public void runJSBundle() {
  Assertions.assertCondition(!mJSBundleHasLoaded, "JS bundle was already loaded!");
  mJSBundleHasLoaded = true;

  // incrementPendingJSCalls();
  mJSBundleLoader.loadScript(CatalystInstanceImpl.this);

  synchronized (mJSCallsPendingInitLock) {
    // Loading the bundle is queued on the JS thread, but may not have
    // run yet.  It's safe to set this here, though, since any work it
    // gates will be queued on the JS thread behind the load.
    mAcceptCalls = true;

    for (PendingJSCall call : mJSCallsPendingInit) {
      jniCallJSFunction(call.mExecutorToken, call.mModule, call.mMethod, call.mArguments);
    }
    mJSCallsPendingInit.clear();
  }

  // This is registered after JS starts since it makes a JS call
  Systrace.registerListener(mTraceListener);
}