Skip to content

Commit

Permalink
Merge branch 'main' into feat/logcat-integration
Browse files Browse the repository at this point in the history
  • Loading branch information
buenaflor authored Mar 27, 2023
2 parents 9f44057 + 0f96fc3 commit d247b8a
Show file tree
Hide file tree
Showing 16 changed files with 190 additions and 48 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Features

- Add time-to-initial-display and time-to-full-display measurements to Activity transactions ([#2611](https://github.com/getsentry/sentry-java/pull/2611))
- Read integration list written by sentry gradle plugin from manifest ([#2598](https://github.com/getsentry/sentry-java/pull/2598))
- Add Logcat adapter ([#2620](https://github.com/getsentry/sentry-java/pull/2620))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ public synchronized void setMetrics(
final MeasurementValue ffValues =
new MeasurementValue(frameCounts.frozenFrames, MeasurementUnit.NONE);
final Map<String, @NotNull MeasurementValue> measurements = new HashMap<>();
measurements.put("frames_total", tfValues);
measurements.put("frames_slow", sfValues);
measurements.put("frames_frozen", ffValues);
measurements.put(MeasurementValue.KEY_FRAMES_TOTAL, tfValues);
measurements.put(MeasurementValue.KEY_FRAMES_SLOW, sfValues);
measurements.put(MeasurementValue.KEY_FRAMES_FROZEN, ffValues);

activityMeasurements.put(transactionId, measurements);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.sentry.android.core;

import static io.sentry.MeasurementUnit.Duration.MILLISECOND;
import static io.sentry.TypeCheckHint.ANDROID_ACTIVITY;

import android.annotation.SuppressLint;
Expand Down Expand Up @@ -27,6 +28,7 @@
import io.sentry.TransactionContext;
import io.sentry.TransactionOptions;
import io.sentry.android.core.internal.util.FirstDrawDoneListener;
import io.sentry.protocol.MeasurementValue;
import io.sentry.protocol.TransactionNameSource;
import io.sentry.util.Objects;
import java.io.Closeable;
Expand All @@ -35,6 +37,7 @@
import java.util.Map;
import java.util.WeakHashMap;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
Expand Down Expand Up @@ -348,11 +351,7 @@ public synchronized void onActivityCreated(
firstActivityCreated = true;

if (fullyDisplayedReporter != null) {
fullyDisplayedReporter.registerFullyDrawnListener(
() -> {
finishSpan(ttfdSpan);
cancelTtfdAutoClose();
});
fullyDisplayedReporter.registerFullyDrawnListener(() -> onFullFrameDrawn());
}
}

Expand Down Expand Up @@ -499,15 +498,39 @@ private void cancelTtfdAutoClose() {
}

private void onFirstFrameDrawn(final @Nullable ISpan ttidSpan) {
if (options != null && ttfdSpan != null && ttfdSpan.isFinished()) {
if (options != null && ttidSpan != null) {
final SentryDate endDate = options.getDateProvider().now();
ttfdSpan.updateEndDate(endDate);
final long durationNanos = endDate.diff(ttidSpan.getStartDate());
final long durationMillis = TimeUnit.NANOSECONDS.toMillis(durationNanos);
ttidSpan.setMeasurement(
MeasurementValue.KEY_TIME_TO_INITIAL_DISPLAY, durationMillis, MILLISECOND);

if (ttfdSpan != null && ttfdSpan.isFinished()) {
ttfdSpan.updateEndDate(endDate);
// If the ttfd span was finished before the first frame we adjust the measurement, too
ttidSpan.setMeasurement(
MeasurementValue.KEY_TIME_TO_FULL_DISPLAY, durationMillis, MILLISECOND);
}
finishSpan(ttidSpan, endDate);
} else {
finishSpan(ttidSpan);
}
}

private void onFullFrameDrawn() {
if (options != null && ttfdSpan != null) {
final SentryDate endDate = options.getDateProvider().now();
final long durationNanos = endDate.diff(ttfdSpan.getStartDate());
final long durationMillis = TimeUnit.NANOSECONDS.toMillis(durationNanos);
ttfdSpan.setMeasurement(
MeasurementValue.KEY_TIME_TO_FULL_DISPLAY, durationMillis, MILLISECOND);
finishSpan(ttfdSpan, endDate);
} else {
finishSpan(ttfdSpan);
}
cancelTtfdAutoClose();
}

@TestOnly
@NotNull
WeakHashMap<Activity, ITransaction> getActivitiesWithOngoingTransactions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ public SentryEvent process(@NotNull SentryEvent event, @NotNull Hint hint) {
(float) appStartUpInterval, MeasurementUnit.Duration.MILLISECOND.apiName());

final String appStartKey =
AppStartState.getInstance().isColdStart() ? "app_start_cold" : "app_start_warm";
AppStartState.getInstance().isColdStart()
? MeasurementValue.KEY_APP_START_COLD
: MeasurementValue.KEY_APP_START_WARM;

transaction.getMeasurements().put(appStartKey, value);
sentStartMeasurement = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.util.SparseIntArray
import androidx.core.app.FrameMetricsAggregator
import androidx.test.ext.junit.runners.AndroidJUnit4
import io.sentry.ILogger
import io.sentry.protocol.MeasurementValue
import io.sentry.protocol.SentryId
import org.junit.runner.RunWith
import org.mockito.kotlin.any
Expand Down Expand Up @@ -48,7 +49,7 @@ class ActivityFramesTrackerTest {
sut.setMetrics(fixture.activity, fixture.sentryId)

val metrics = sut.takeMetrics(fixture.sentryId)
val totalFrames = metrics!!["frames_total"]
val totalFrames = metrics!![MeasurementValue.KEY_FRAMES_TOTAL]

assertEquals(totalFrames!!.value, 1)
assertEquals(totalFrames.unit, "none")
Expand All @@ -66,7 +67,7 @@ class ActivityFramesTrackerTest {
sut.setMetrics(fixture.activity, fixture.sentryId)

val metrics = sut.takeMetrics(fixture.sentryId)
val frozenFrames = metrics!!["frames_frozen"]
val frozenFrames = metrics!![MeasurementValue.KEY_FRAMES_FROZEN]

assertEquals(frozenFrames!!.value, 5)
assertEquals(frozenFrames.unit, "none")
Expand All @@ -84,7 +85,7 @@ class ActivityFramesTrackerTest {
sut.setMetrics(fixture.activity, fixture.sentryId)

val metrics = sut.takeMetrics(fixture.sentryId)
val slowFrames = metrics!!["frames_slow"]
val slowFrames = metrics!![MeasurementValue.KEY_FRAMES_SLOW]

assertEquals(slowFrames!!.value, 5)
assertEquals(slowFrames.unit, "none")
Expand All @@ -106,13 +107,13 @@ class ActivityFramesTrackerTest {

val metrics = sut.takeMetrics(fixture.sentryId)

val totalFrames = metrics!!["frames_total"]
val totalFrames = metrics!![MeasurementValue.KEY_FRAMES_TOTAL]
assertEquals(totalFrames!!.value, 111)

val frozenFrames = metrics["frames_frozen"]
val frozenFrames = metrics[MeasurementValue.KEY_FRAMES_FROZEN]
assertEquals(frozenFrames!!.value, 6)

val slowFrames = metrics["frames_slow"]
val slowFrames = metrics[MeasurementValue.KEY_FRAMES_SLOW]
assertEquals(slowFrames!!.value, 5)
}

Expand All @@ -132,13 +133,13 @@ class ActivityFramesTrackerTest {

val metrics = sut.takeMetrics(fixture.sentryId)

val totalFrames = metrics!!["frames_total"]
val totalFrames = metrics!![MeasurementValue.KEY_FRAMES_TOTAL]
assertEquals(totalFrames!!.value, 111)

val frozenFrames = metrics["frames_frozen"]
val frozenFrames = metrics[MeasurementValue.KEY_FRAMES_FROZEN]
assertEquals(frozenFrames!!.value, 6)

val slowFrames = metrics["frames_slow"]
val slowFrames = metrics[MeasurementValue.KEY_FRAMES_SLOW]
assertEquals(slowFrames!!.value, 5)
}

Expand Down Expand Up @@ -185,22 +186,22 @@ class ActivityFramesTrackerTest {
val metricsA = sut.takeMetrics(sentryIdA)!!
val metricsB = sut.takeMetrics(sentryIdB)!!

val totalFramesA = metricsA!!["frames_total"]
val totalFramesA = metricsA!![MeasurementValue.KEY_FRAMES_TOTAL]
assertEquals(totalFramesA!!.value, 21) // 15 + 3 + 3 (diff counts for activityA)

val frozenFramesA = metricsA["frames_frozen"]
val frozenFramesA = metricsA[MeasurementValue.KEY_FRAMES_FROZEN]
assertEquals(frozenFramesA!!.value, 3)

val slowFramesA = metricsA["frames_slow"]
val slowFramesA = metricsA[MeasurementValue.KEY_FRAMES_SLOW]
assertEquals(slowFramesA!!.value, 3)

val totalFramesB = metricsB!!["frames_total"]
val totalFramesB = metricsB!![MeasurementValue.KEY_FRAMES_TOTAL]
assertEquals(totalFramesB!!.value, 35) // 25 + 5 + 5 (diff counts for activityB)

val frozenFramesB = metricsB["frames_frozen"]
val frozenFramesB = metricsB[MeasurementValue.KEY_FRAMES_FROZEN]
assertEquals(frozenFramesB!!.value, 5)

val slowFramesB = metricsB["frames_slow"]
val slowFramesB = metricsB[MeasurementValue.KEY_FRAMES_SLOW]
assertEquals(slowFramesB!!.value, 5)
}

Expand Down Expand Up @@ -239,22 +240,22 @@ class ActivityFramesTrackerTest {
val metrics = sut.takeMetrics(fixture.sentryId)
val secondMetrics = sut.takeMetrics(secondSentryId)

val totalFrames = metrics!!["frames_total"]
val totalFrames = metrics!![MeasurementValue.KEY_FRAMES_TOTAL]
assertEquals(totalFrames!!.value, 12) // 10 + 1 + 1 (diff counts for first invocation)

val frozenFrames = metrics["frames_frozen"]
val frozenFrames = metrics[MeasurementValue.KEY_FRAMES_FROZEN]
assertEquals(frozenFrames!!.value, 1)

val slowFrames = metrics["frames_slow"]
val slowFrames = metrics[MeasurementValue.KEY_FRAMES_SLOW]
assertEquals(slowFrames!!.value, 1)

val totalFramesSecond = secondMetrics!!["frames_total"]
val totalFramesSecond = secondMetrics!![MeasurementValue.KEY_FRAMES_TOTAL]
assertEquals(totalFramesSecond!!.value, 26) // 20 + 3 + 3 (diff counts for second invocation)

val frozenFramesSecond = secondMetrics["frames_frozen"]
val frozenFramesSecond = secondMetrics[MeasurementValue.KEY_FRAMES_FROZEN]
assertEquals(frozenFramesSecond!!.value, 3)

val slowFramesSecond = secondMetrics["frames_slow"]
val slowFramesSecond = secondMetrics[MeasurementValue.KEY_FRAMES_SLOW]
assertEquals(slowFramesSecond!!.value, 3)
}

Expand Down
Loading

0 comments on commit d247b8a

Please sign in to comment.