Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public void startProfiler(
final @NotNull ProfileLifecycle profileLifecycle,
final @NotNull TracesSampler tracesSampler) {
try (final @NotNull ISentryLifecycleToken ignored = lock.acquire()) {
shouldStop = false;
if (shouldSample) {
isSampled = tracesSampler.sampleSessionProfile(SentryRandom.current().nextDouble());
shouldSample = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,24 @@ class AndroidContinuousProfilerTest {
.log(eq(SentryLevel.WARNING), eq("Device is offline. Stopping profiler."))
}

@Test
fun `manual profiler can be started again after a full start-stop cycle`() {
val profiler = fixture.getSut()

profiler.startProfiler(ProfileLifecycle.MANUAL, fixture.mockTracesSampler)
assertTrue(profiler.isRunning)
profiler.stopProfiler(ProfileLifecycle.MANUAL)
// Triggers the scheduled executor task that collects perf metrics and finalizes the chunk
fixture.executor.runAll()
assertFalse(profiler.isRunning)

profiler.startProfiler(ProfileLifecycle.MANUAL, fixture.mockTracesSampler)
assertTrue(profiler.isRunning)
// Triggers the scheduled executor task that collects perf metrics and finalizes the chunk
fixture.executor.runAll()
assertTrue(profiler.isRunning, "shouldStop must be reset on start")
}

fun withMockScopes(closure: () -> Unit) =
Mockito.mockStatic(Sentry::class.java).use {
it.`when`<Any> { Sentry.getCurrentScopes() }.thenReturn(fixture.scopes)
Expand Down
Loading