Skip to content

Commit 8283fc0

Browse files
committed
removed AndroidContinuousProfiler.stopAllProfiles
added AndroidContinuousProfiler.close param isTerminating
1 parent 68eb091 commit 8283fc0

File tree

16 files changed

+34
-47
lines changed

16 files changed

+34
-47
lines changed

sentry-android-core/api/sentry-android-core.api

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,13 @@ public final class io/sentry/android/core/ActivityLifecycleIntegration : android
4242

4343
public class io/sentry/android/core/AndroidContinuousProfiler : io/sentry/IContinuousProfiler, io/sentry/transport/RateLimiter$IRateLimitObserver {
4444
public fun <init> (Lio/sentry/android/core/BuildInfoProvider;Lio/sentry/android/core/internal/util/SentryFrameMetricsCollector;Lio/sentry/ILogger;Ljava/lang/String;ILio/sentry/ISentryExecutorService;)V
45-
public fun close ()V
45+
public fun close (Z)V
4646
public fun getProfilerId ()Lio/sentry/protocol/SentryId;
4747
public fun getRootSpanCounter ()I
4848
public fun isRunning ()Z
4949
public fun onRateLimitChanged (Lio/sentry/transport/RateLimiter;)V
5050
public fun reevaluateSampling ()V
5151
public fun startProfiler (Lio/sentry/ProfileLifecycle;Lio/sentry/TracesSampler;)V
52-
public fun stopAllProfiles ()V
5352
public fun stopProfiler (Lio/sentry/ProfileLifecycle;)V
5453
}
5554

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -323,20 +323,14 @@ public void reevaluateSampling() {
323323
}
324324

325325
@Override
326-
public void stopAllProfiles() {
326+
public void close(final boolean isTerminating) {
327327
try (final @NotNull ISentryLifecycleToken ignored = lock.acquire()) {
328328
rootSpanCounter = 0;
329329
shouldStop = true;
330-
}
331-
}
332-
333-
@Override
334-
public void close() {
335-
try (final @NotNull ISentryLifecycleToken ignored = lock.acquire()) {
336-
rootSpanCounter = 0;
337-
shouldStop = true;
338-
stop(false);
339-
isClosed.set(true);
330+
if (isTerminating) {
331+
stop(false);
332+
isClosed.set(true);
333+
}
340334
}
341335
}
342336

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ private static void setupProfiler(
268268
// This is a safeguard, but it should never happen, as the app start profiler should be the
269269
// continuous one.
270270
if (appStartContinuousProfiler != null) {
271-
appStartContinuousProfiler.close();
271+
appStartContinuousProfiler.close(true);
272272
}
273273
if (appStartTransactionProfiler != null) {
274274
options.setTransactionProfiler(appStartTransactionProfiler);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public void run() {
122122
scopes.endSession();
123123
}
124124
scopes.getOptions().getReplayController().stop();
125-
scopes.getOptions().getContinuousProfiler().stopAllProfiles();
125+
scopes.getOptions().getContinuousProfiler().close(false);
126126
}
127127
};
128128

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public void shutdown() {
9595
final @Nullable IContinuousProfiler appStartContinuousProfiler =
9696
AppStartMetrics.getInstance().getAppStartContinuousProfiler();
9797
if (appStartContinuousProfiler != null) {
98-
appStartContinuousProfiler.close();
98+
appStartContinuousProfiler.close(true);
9999
}
100100
}
101101
}

sentry-android-core/src/main/java/io/sentry/android/core/performance/AppStartMetrics.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public void clear() {
225225
}
226226
appStartProfiler = null;
227227
if (appStartContinuousProfiler != null) {
228-
appStartContinuousProfiler.close();
228+
appStartContinuousProfiler.close(true);
229229
}
230230
appStartContinuousProfiler = null;
231231
appStartSamplingDecision = null;
@@ -333,7 +333,7 @@ private void checkCreateTimeOnMain() {
333333
appStartProfiler = null;
334334
}
335335
if (appStartContinuousProfiler != null && appStartContinuousProfiler.isRunning()) {
336-
appStartContinuousProfiler.close();
336+
appStartContinuousProfiler.close(true);
337337
appStartContinuousProfiler = null;
338338
}
339339
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ class AndroidContinuousProfilerTest {
389389
profiler.startProfiler(ProfileLifecycle.MANUAL, fixture.mockTracesSampler)
390390
assertTrue(profiler.isRunning)
391391

392-
profiler.close()
392+
profiler.close(true)
393393
assertFalse(profiler.isRunning)
394394

395395
// The timeout scheduled job should be cleared
@@ -471,15 +471,15 @@ class AndroidContinuousProfilerTest {
471471
}
472472

473473
@Test
474-
fun `stopAllProfiles stops all profiles after chunk is finished`() {
474+
fun `close without terminating stops all profiles after chunk is finished`() {
475475
val profiler = fixture.getSut()
476476
profiler.startProfiler(ProfileLifecycle.MANUAL, fixture.mockTracesSampler)
477477
profiler.startProfiler(ProfileLifecycle.TRACE, fixture.mockTracesSampler)
478478
assertTrue(profiler.isRunning)
479479
// We are scheduling the profiler to stop at the end of the chunk, so it should still be running
480-
profiler.stopAllProfiles()
480+
profiler.close(false)
481481
assertTrue(profiler.isRunning)
482-
// However, stopAllProfiles already resets the rootSpanCounter
482+
// However, close() already resets the rootSpanCounter
483483
assertEquals(0, profiler.rootSpanCounter)
484484

485485
// We run the executor service to trigger the chunk finish, and the profiler shouldn't restart
@@ -494,7 +494,7 @@ class AndroidContinuousProfilerTest {
494494
assertTrue(profiler.isRunning)
495495

496496
// We close the profiler, which should prevent sending additional chunks
497-
profiler.close()
497+
profiler.close(true)
498498

499499
// The executor used to send the chunk doesn't do anything
500500
fixture.executor.runAll()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ class AndroidOptionsInitializerTest {
446446
assertEquals(fixture.sentryOptions.continuousProfiler, NoOpContinuousProfiler.getInstance())
447447

448448
// app start profiler is closed, because it will never be used
449-
verify(appStartContinuousProfiler).close()
449+
verify(appStartContinuousProfiler).close(eq(true))
450450

451451
// AppStartMetrics should be cleared
452452
assertNull(AppStartMetrics.getInstance().appStartProfiler)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import io.sentry.transport.ICurrentDateProvider
1616
import org.mockito.ArgumentCaptor
1717
import org.mockito.kotlin.any
1818
import org.mockito.kotlin.check
19+
import org.mockito.kotlin.eq
1920
import org.mockito.kotlin.mock
2021
import org.mockito.kotlin.never
2122
import org.mockito.kotlin.timeout
@@ -109,7 +110,7 @@ class LifecycleWatcherTest {
109110
watcher.onStop(fixture.ownerMock)
110111
verify(fixture.scopes, timeout(10000)).endSession()
111112
verify(fixture.replayController, timeout(10000)).stop()
112-
verify(fixture.continuousProfiler, timeout(10000)).stopAllProfiles()
113+
verify(fixture.continuousProfiler, timeout(10000)).close(eq(false))
113114
}
114115

115116
@Test

sentry-android-core/src/test/java/io/sentry/android/core/performance/AppStartMetricsTest.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import io.sentry.android.core.SentryAndroidOptions
1616
import io.sentry.android.core.SentryShadowProcess
1717
import org.junit.Before
1818
import org.junit.runner.RunWith
19+
import org.mockito.kotlin.any
1920
import org.mockito.kotlin.eq
2021
import org.mockito.kotlin.mock
2122
import org.mockito.kotlin.never
@@ -273,7 +274,7 @@ class AppStartMetricsTest {
273274
// Job on main thread checks if activity was launched
274275
Shadows.shadowOf(Looper.getMainLooper()).idle()
275276

276-
verify(profiler).close()
277+
verify(profiler).close(eq(true))
277278
}
278279

279280
@Test
@@ -301,7 +302,7 @@ class AppStartMetricsTest {
301302
// Job on main thread checks if activity was launched
302303
Shadows.shadowOf(Looper.getMainLooper()).idle()
303304

304-
verify(profiler, never()).close()
305+
verify(profiler, never()).close(any())
305306
}
306307

307308
@Test

0 commit comments

Comments
 (0)