Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto committed Jul 28, 2021
1 parent cb9c3c9 commit 5871e7c
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 8 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

## Unreleased

* Feat: Slow/Frozen frames metrics (#1609)

## 5.1.0-beta.6

* Fix: set min sdk version of sentry-android-fragment to API 14 (#1608)
* Feat: Slow/Frozen frames metrics (#1609)
* Fix: Ser/Deser of the UserFeedback from cached envelope (#1611)
* Feat: Add request body extraction for Spring MVC integration (#1595)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ void setMetrics(final @NotNull Activity activity, final @NotNull SentryId sentry
if (frameTime > 700) {
// frozen frames, threshold is 700ms
frozenFrames += numFrames;
}
if (frameTime > 16 && frameTime <= 700) {
} else if (frameTime > 16) {
// slow frames, above 16ms, 60 frames/second
slowFrames += numFrames;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,11 @@ public synchronized void onActivityPreCreated(

// only executed if API >= 29 otherwise it happens on onActivityCreated
if (isAllActivityCallbacksAvailable) {
setColdStart(savedInstanceState);

// start collecting frame metrics for transaction
activityFramesTracker.addActivity(activity);

setColdStart(savedInstanceState);

// if activity has global fields being init. and
// they are slow, this won't count the whole fields/ctor initialization time, but only
// when onCreate is actually called.
Expand All @@ -246,16 +246,16 @@ public synchronized void onActivityPreCreated(
public synchronized void onActivityCreated(
final @NonNull Activity activity, final @Nullable Bundle savedInstanceState) {
if (!isAllActivityCallbacksAvailable) {
// start collecting frame metrics for transaction
activityFramesTracker.addActivity(activity);

setColdStart(savedInstanceState);
}

addBreadcrumb(activity, "created");

// fallback call for API < 29 compatibility, otherwise it happens on onActivityPreCreated
if (!isAllActivityCallbacksAvailable) {
// start collecting frame metrics for transaction
activityFramesTracker.addActivity(activity);

startTracing(activity);
}
firstActivityCreated = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ final class PerformanceAndroidEventProcessor implements EventProcessor {
final SpanContext spanContext = transaction.getContexts().getTrace();

// only add slow/frozen frames to transactions created by ActivityLifecycleIntegration
// which have the operation UI_LOAD_OP. If a user-defined (or hybrid SDK) transaction
// users it, we'll also add the metrics if available
if (eventId != null
&& spanContext != null
&& spanContext.getOperation().contentEquals(UI_LOAD_OP)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.nhaarman.mockitokotlin2.whenever
import io.sentry.protocol.SentryId
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNull
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
Expand Down Expand Up @@ -96,6 +97,22 @@ class ActivityFramesTrackerTest {
assertEquals(slowFrames!!.value, 5f)
}

@Test
fun `do not set metrics if values are zeroes`() {
val sut = fixture.getSut()
val arrayAll = SparseIntArray()
arrayAll.put(0, 0)
val array = arrayOf(arrayAll)

whenever(fixture.aggregator.remove(any())).thenReturn(array)

sut.setMetrics(fixture.activity, fixture.sentryId)

val metrics = sut.takeMetrics(fixture.sentryId)

assertNull(metrics)
}

private fun getArray(frameTime: Int = 1, numFrames: Int = 1): Array<SparseIntArray?> {
val totalArray = SparseIntArray()
totalArray.put(frameTime, numFrames)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ class PerformanceAndroidEventProcessorTest {
assertTrue(tr.measurements.isEmpty())
}

@Test
fun `do not add slow and frozen frames if tracing is disabled`() {
val sut = fixture.getSut(null)
var tr = getTransaction("task")

tr = sut.process(tr, null)

assertTrue(tr.measurements.isEmpty())
}

@Test
fun `add slow and frozen frames if auto transaction`() {
val sut = fixture.getSut()
Expand Down

0 comments on commit 5871e7c

Please sign in to comment.