Skip to content
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
### Fixes

- Fix the issue with uploading iOS Debug Symbols in EAS Build when using pnpm ([#6076](https://github.com/getsentry/sentry-react-native/issues/6076))
- Improve frame delay collection performance by using sentry-java `getFramesDelay` API ([#6074](https://github.com/getsentry/sentry-react-native/pull/6074))

### Dependencies

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import io.sentry.android.core.InternalSentrySdk;
import io.sentry.android.core.SentryAndroidDateProvider;
import io.sentry.android.core.SentryAndroidOptions;
import io.sentry.android.core.SentryFramesDelayResult;
import io.sentry.android.core.SentryShakeDetector;
import io.sentry.android.core.ViewHierarchyEventProcessor;
import io.sentry.android.core.internal.debugmeta.AssetsDebugMetaLoader;
Expand Down Expand Up @@ -98,7 +99,8 @@ public class RNSentryModuleImpl {
private final ReactApplicationContext reactApplicationContext;
private final PackageInfo packageInfo;
private FrameMetricsAggregator frameMetricsAggregator = null;
private final RNSentryFrameDelayCollector frameDelayCollector = new RNSentryFrameDelayCollector();
private @Nullable SentryFrameMetricsCollector frameMetricsCollector = null;
private @Nullable String frameMetricsListenerId = null;
private boolean androidXAvailable;

@VisibleForTesting static long lastStartTimestampMs = -1;
Expand Down Expand Up @@ -413,9 +415,14 @@ public void fetchNativeFramesDelay(
long startNanos = nowNanos - (long) (startOffsetSeconds * 1e9);
long endNanos = nowNanos - (long) (endOffsetSeconds * 1e9);

double delaySeconds = frameDelayCollector.getFramesDelay(startNanos, endNanos);
if (delaySeconds >= 0) {
promise.resolve(delaySeconds);
if (frameMetricsCollector == null) {
promise.resolve(null);
return;
}

SentryFramesDelayResult result = frameMetricsCollector.getFramesDelay(startNanos, endNanos);
if (result.getDelaySeconds() >= 0) {
Comment thread
antonis marked this conversation as resolved.
Outdated
promise.resolve(result.getDelaySeconds());
Comment thread
antonis marked this conversation as resolved.
} else {
promise.resolve(null);
}
Expand Down Expand Up @@ -747,12 +754,27 @@ public void enableNativeFramesTracking() {
if (options instanceof SentryAndroidOptions) {
final SentryFrameMetricsCollector collector =
((SentryAndroidOptions) options).getFrameMetricsCollector();
if (frameDelayCollector.start(collector)) {
logger.log(SentryLevel.INFO, "RNSentryFrameDelayCollector installed.");
if (collector != null) {
// Register a no-op listener to ensure frame metrics collection is active.
// This is needed so that getFramesDelay() has data to query.
stopFrameMetricsCollection();
frameMetricsCollector = collector;
frameMetricsListenerId =
collector.startCollection(
(startNanos,
endNanos,
Comment thread
antonis marked this conversation as resolved.
durationNanos,
delayNanos,
isSlow,
isFrozen,
refreshRate) -> {});
if (frameMetricsListenerId != null) {
logger.log(SentryLevel.INFO, "SentryFrameMetricsCollector listener installed.");
}
}
Comment thread
antonis marked this conversation as resolved.
Outdated
}
} catch (Throwable ignored) { // NOPMD - We don't want to crash in any case
logger.log(SentryLevel.WARNING, "Error starting RNSentryFrameDelayCollector.");
logger.log(SentryLevel.WARNING, "Error starting frame metrics collection.");
}
}

Expand All @@ -761,7 +783,15 @@ public void disableNativeFramesTracking() {
frameMetricsAggregator.stop();
frameMetricsAggregator = null;
}
frameDelayCollector.stop();
stopFrameMetricsCollection();
}

private void stopFrameMetricsCollection() {
if (frameMetricsCollector != null && frameMetricsListenerId != null) {
frameMetricsCollector.stopCollection(frameMetricsListenerId);
}
frameMetricsCollector = null;
frameMetricsListenerId = null;
}

public void getNewScreenTimeToDisplay(Promise promise) {
Expand Down
Loading