Skip to content

Commit 83b1f1a

Browse files
43jayclaude
andcommitted
fix(profiling): AndroidContinuousProfiler Reset shouldStop flag on startProfiler
Same fix as PerfettoContinuousProfiler — shouldStop was never reset to false after stopProfiler, so a stop/start cycle would leave shouldStop=true and silently stop the profiler after one chunk. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent b4f1c3b commit 83b1f1a

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ public void startProfiler(
134134
final @NotNull ProfileLifecycle profileLifecycle,
135135
final @NotNull TracesSampler tracesSampler) {
136136
try (final @NotNull ISentryLifecycleToken ignored = lock.acquire()) {
137+
shouldStop = false;
137138
if (shouldSample) {
138139
isSampled = tracesSampler.sampleSessionProfile(SentryRandom.current().nextDouble());
139140
shouldSample = false;

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,24 @@ class AndroidContinuousProfilerTest {
556556
.log(eq(SentryLevel.WARNING), eq("Device is offline. Stopping profiler."))
557557
}
558558

559+
@Test
560+
fun `manual profiler can be started again after a full start-stop cycle`() {
561+
val profiler = fixture.getSut()
562+
563+
profiler.startProfiler(ProfileLifecycle.MANUAL, fixture.mockTracesSampler)
564+
assertTrue(profiler.isRunning)
565+
profiler.stopProfiler(ProfileLifecycle.MANUAL)
566+
// Triggers the scheduled executor task that collects perf metrics and finalizes the chunk
567+
fixture.executor.runAll()
568+
assertFalse(profiler.isRunning)
569+
570+
profiler.startProfiler(ProfileLifecycle.MANUAL, fixture.mockTracesSampler)
571+
assertTrue(profiler.isRunning)
572+
// Triggers the scheduled executor task that collects perf metrics and finalizes the chunk
573+
fixture.executor.runAll()
574+
assertTrue(profiler.isRunning, "shouldStop must be reset on start")
575+
}
576+
559577
fun withMockScopes(closure: () -> Unit) =
560578
Mockito.mockStatic(Sentry::class.java).use {
561579
it.`when`<Any> { Sentry.getCurrentScopes() }.thenReturn(fixture.scopes)

0 commit comments

Comments
 (0)