Skip to content

Commit

Permalink
Calculate frame delay on a span level (#3197)
Browse files Browse the repository at this point in the history
* Calculate frame delay on a span level

* Include pending renders into span delay calculation

* Add more tests, use better performing data structures

* Update Changelog

* Re-structure code, improve readability

* Address PR feedback, extend tests

* Remove inner NanoTimeStamp classes in favor of using SentryDate

* Fix typo

* Mark inner Frame class private
  • Loading branch information
markushi authored Feb 16, 2024
1 parent f33a11d commit 95a98b5
Show file tree
Hide file tree
Showing 16 changed files with 788 additions and 162 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Add new threshold parameters to monitor config ([#3181](https://github.com/getsentry/sentry-java/pull/3181))
- Report process init time as a span for app start performance ([#3159](https://github.com/getsentry/sentry-java/pull/3159))
- (perf-v2): Calculate frame delay on a span level ([#3197](https://github.com/getsentry/sentry-java/pull/3197))

### Fixes

Expand Down
2 changes: 1 addition & 1 deletion sentry-android-core/api/sentry-android-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ public final class io/sentry/android/core/SentryPerformanceProvider {
}

public class io/sentry/android/core/SpanFrameMetricsCollector : io/sentry/IPerformanceContinuousCollector, io/sentry/android/core/internal/util/SentryFrameMetricsCollector$FrameMetricsCollectorListener {
public fun <init> (Lio/sentry/android/core/SentryAndroidOptions;)V
public fun <init> (Lio/sentry/android/core/SentryAndroidOptions;Lio/sentry/android/core/internal/util/SentryFrameMetricsCollector;)V
public fun clear ()V
public fun onFrameMetricCollected (JJJJZZF)V
public fun onSpanFinished (Lio/sentry/ISpan;)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,12 @@ static void initializeIntegrationsAndProcessors(
new AndroidCpuCollector(options.getLogger(), buildInfoProvider));

if (options.isEnablePerformanceV2()) {
options.addPerformanceCollector(new SpanFrameMetricsCollector(options));
options.addPerformanceCollector(
new SpanFrameMetricsCollector(
options,
Objects.requireNonNull(
options.getFrameMetricsCollector(),
"options.getFrameMetricsCollector is required")));
}
}
options.setTransactionPerformanceCollector(new DefaultTransactionPerformanceCollector(options));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public SentryFrameMetrics(
final int frozenFrameCount,
final long frozenFrameDelayNanos,
final long totalDurationNanos) {

this.normalFrameCount = normalFrameCount;

this.slowFrameCount = slowFrameCount;
Expand All @@ -34,21 +35,21 @@ public SentryFrameMetrics(
this.totalDurationNanos = totalDurationNanos;
}

public void addSlowFrame(final long durationNanos, final long delayNanos) {
totalDurationNanos += durationNanos;
slowFrameDelayNanos += delayNanos;
slowFrameCount++;
}

public void addFrozenFrame(final long durationNanos, final long delayNanos) {
totalDurationNanos += durationNanos;
frozenFrameDelayNanos += delayNanos;
frozenFrameCount++;
}

public void addNormalFrame(final long durationNanos) {
public void addFrame(
final long durationNanos,
final long delayNanos,
final boolean isSlow,
final boolean isFrozen) {
totalDurationNanos += durationNanos;
normalFrameCount++;
if (isFrozen) {
frozenFrameDelayNanos += delayNanos;
frozenFrameCount += 1;
} else if (isSlow) {
slowFrameDelayNanos += delayNanos;
slowFrameCount += 1;
} else {
normalFrameCount += 1;
}
}

public int getNormalFrameCount() {
Expand Down
Loading

0 comments on commit 95a98b5

Please sign in to comment.