Skip to content

Commit 051ce9b

Browse files
authored
Remove profiling timeout logic and disable profiling on API 21 (#3478)
* removed timeout logic from AndroidProfiler, as unused by the backend anyway, to fix potential profiling always or never running when one times out * removed API 21 from supported profiling versions, due to a crash
1 parent 1e646ca commit 051ce9b

File tree

6 files changed

+19
-24
lines changed

6 files changed

+19
-24
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Fixes
6+
7+
- Remove profiling timeout logic and disable profiling on API 21 ([#3478](https://github.com/getsentry/sentry-java/pull/3478))
38

49
## 7.10.0
510

sentry-android-core/src/main/java/io/sentry/android/core/AndroidProfiler.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ public ProfileEndData(
7979
private @Nullable Future<?> scheduledFinish = null;
8080
private @Nullable File traceFile = null;
8181
private @Nullable String frameMetricsCollectorId;
82-
private volatile @Nullable ProfileEndData timedOutProfilingData = null;
8382
private final @NotNull SentryFrameMetricsCollector frameMetricsCollector;
8483
private final @NotNull ArrayDeque<ProfileMeasurementValue> screenFrameRateMeasurements =
8584
new ArrayDeque<>();
@@ -182,8 +181,7 @@ public void onFrameMetricCollected(
182181
// We stop profiling after a timeout to avoid huge profiles to be sent
183182
try {
184183
scheduledFinish =
185-
executorService.schedule(
186-
() -> timedOutProfilingData = endAndCollect(true, null), PROFILING_TIMEOUT_MILLIS);
184+
executorService.schedule(() -> endAndCollect(true, null), PROFILING_TIMEOUT_MILLIS);
187185
} catch (RejectedExecutionException e) {
188186
logger.log(
189187
SentryLevel.ERROR,
@@ -216,10 +214,6 @@ public void onFrameMetricCollected(
216214
public synchronized @Nullable ProfileEndData endAndCollect(
217215
final boolean isTimeout,
218216
final @Nullable List<PerformanceCollectionData> performanceCollectionData) {
219-
// check if profiling timed out
220-
if (timedOutProfilingData != null) {
221-
return timedOutProfilingData;
222-
}
223217

224218
if (!isRunning) {
225219
logger.log(SentryLevel.WARNING, "Profiler not running");

sentry-android-core/src/main/java/io/sentry/android/core/AndroidTransactionProfiler.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,9 @@ private void init() {
133133

134134
@Override
135135
public synchronized void start() {
136-
// Debug.startMethodTracingSampling() is only available since Lollipop
137-
if (buildInfoProvider.getSdkInfoVersion() < Build.VERSION_CODES.LOLLIPOP) return;
136+
// Debug.startMethodTracingSampling() is only available since Lollipop, but Android Profiler
137+
// causes crashes on api 21 -> https://github.com/getsentry/sentry-java/issues/3392
138+
if (buildInfoProvider.getSdkInfoVersion() < Build.VERSION_CODES.LOLLIPOP_MR1) return;
138139

139140
// Let's initialize trace folder and profiling interval
140141
init();
@@ -204,9 +205,9 @@ public synchronized void bindTransaction(final @NotNull ITransaction transaction
204205
return null;
205206
}
206207

207-
// onTransactionStart() is only available since Lollipop
208+
// onTransactionStart() is only available since Lollipop_MR1
208209
// and SystemClock.elapsedRealtimeNanos() since Jelly Bean
209-
if (buildInfoProvider.getSdkInfoVersion() < Build.VERSION_CODES.LOLLIPOP) return null;
210+
if (buildInfoProvider.getSdkInfoVersion() < Build.VERSION_CODES.LOLLIPOP_MR1) return null;
210211

211212
// Transaction finished, but it's not in the current profile
212213
if (currentProfilingTransactionData == null

sentry-android-core/src/test/java/io/sentry/android/core/AndroidProfilerTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ class AndroidProfilerTest {
218218
}
219219

220220
@Test
221-
fun `timedOutData has timeout flag`() {
221+
fun `timedOutData is not recorded`() {
222222
val profiler = fixture.getSut()
223223

224224
// Start and finish first transaction profiling
@@ -229,7 +229,7 @@ class AndroidProfilerTest {
229229

230230
// First transaction finishes: timed out data is returned
231231
val endData = profiler.endAndCollect(false, null)
232-
assert(endData!!.didTimeout)
232+
assertNull(endData)
233233
}
234234

235235
@Test

sentry-android-core/src/test/java/io/sentry/android/core/AndroidTransactionProfilerTest.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class AndroidTransactionProfilerTest {
5353
private class Fixture {
5454
private val mockDsn = "http://key@localhost/proj"
5555
val buildInfo = mock<BuildInfoProvider> {
56-
whenever(it.sdkInfoVersion).thenReturn(Build.VERSION_CODES.LOLLIPOP)
56+
whenever(it.sdkInfoVersion).thenReturn(Build.VERSION_CODES.LOLLIPOP_MR1)
5757
}
5858
val mockLogger = mock<ILogger>()
5959
var lastScheduledRunnable: Runnable? = null
@@ -224,9 +224,9 @@ class AndroidTransactionProfilerTest {
224224
}
225225

226226
@Test
227-
fun `profiler works only on api 21+`() {
227+
fun `profiler works only on api 22+`() {
228228
val buildInfo = mock<BuildInfoProvider> {
229-
whenever(it.sdkInfoVersion).thenReturn(Build.VERSION_CODES.KITKAT)
229+
whenever(it.sdkInfoVersion).thenReturn(Build.VERSION_CODES.LOLLIPOP)
230230
}
231231
val profiler = fixture.getSut(context, buildInfo)
232232
profiler.start()
@@ -379,7 +379,7 @@ class AndroidTransactionProfilerTest {
379379
}
380380

381381
@Test
382-
fun `timedOutData has timeout truncation reason`() {
382+
fun `timedOutData is not recorded`() {
383383
val profiler = fixture.getSut(context)
384384

385385
// Start and finish first transaction profiling
@@ -391,8 +391,7 @@ class AndroidTransactionProfilerTest {
391391

392392
// First transaction finishes: timed out data is returned
393393
val profilingTraceData = profiler.onTransactionFinish(fixture.transaction1, null, fixture.options)
394-
assertEquals(profilingTraceData!!.transactionId, fixture.transaction1.eventId.toString())
395-
assertEquals(ProfilingTraceData.TRUNCATION_REASON_TIMEOUT, profilingTraceData.truncationReason)
394+
assertNull(profilingTraceData)
396395
}
397396

398397
@Test

sentry-android-integration-tests/sentry-uitest-android/src/androidTest/java/io/sentry/uitest/android/EnvelopeTests.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,9 @@ class EnvelopeTests : BaseUiTest() {
201201
assertEnvelopeTransaction(it.items.toList(), AndroidLogger()).transaction == "timedOutProfile"
202202
}.assert {
203203
val transactionItem: SentryTransaction = it.assertTransaction()
204-
val profilingTraceData: ProfilingTraceData = it.assertProfile()
204+
// Profile should not be present, as it timed out and is discarded
205205
it.assertNoOtherItems()
206206
assertEquals("timedOutProfile", transactionItem.transaction)
207-
assertEquals("timedOutProfile", profilingTraceData.transactionName)
208-
// The profile should timeout after 30 seconds
209-
assertTrue(profilingTraceData.durationNs.toLong() < TimeUnit.SECONDS.toNanos(31), "Profile duration expected to be less than 31 seconds. It was ${profilingTraceData.durationNs.toLong()} ns")
210-
assertEquals(ProfilingTraceData.TRUNCATION_REASON_TIMEOUT, profilingTraceData.truncationReason)
211207
}
212208
assertNoOtherEnvelopes()
213209
}

0 commit comments

Comments
 (0)