diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a813a8e7b..c70f025b7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ ### Fixes +- Fix performance collector scheduling many tasks in a row ([#5524](https://github.com/getsentry/sentry-java/pull/5524)) - Session Replay: Fix `VerifyError` in Compose masking under DexGuard/R8 obfuscation ([#5507](https://github.com/getsentry/sentry-java/pull/5507)) - Session Replay: Fix Compose view masking not working on obfuscated/minified builds ([#5503](https://github.com/getsentry/sentry-java/pull/5503)) diff --git a/sentry/src/main/java/io/sentry/DefaultCompositePerformanceCollector.java b/sentry/src/main/java/io/sentry/DefaultCompositePerformanceCollector.java index 1861381a85..4736ab8fac 100644 --- a/sentry/src/main/java/io/sentry/DefaultCompositePerformanceCollector.java +++ b/sentry/src/main/java/io/sentry/DefaultCompositePerformanceCollector.java @@ -27,7 +27,6 @@ public final class DefaultCompositePerformanceCollector implements CompositePerf private final @NotNull SentryOptions options; private final @NotNull AtomicBoolean isStarted = new AtomicBoolean(false); - private long lastCollectionTimestamp = 0; public DefaultCompositePerformanceCollector(final @NotNull SentryOptions options) { this.options = Objects.requireNonNull(options, "The options object is required."); @@ -112,16 +111,8 @@ public void run() { new TimerTask() { @Override public void run() { - long now = System.currentTimeMillis(); - // The timer is scheduled to run every 100ms on average. In case it takes longer, - // subsequent tasks are executed more quickly. If two tasks are scheduled to run in - // less than 10ms, the measurement that we collect is not meaningful, so we skip it - if (now - lastCollectionTimestamp <= 10) { - return; - } timedOutTransactions.clear(); - lastCollectionTimestamp = now; final @NotNull PerformanceCollectionData tempData = new PerformanceCollectionData(options.getDateProvider().now().nanoTimestamp()); @@ -147,7 +138,7 @@ public void run() { } } }; - timer.scheduleAtFixedRate( + timer.schedule( timerTask, TRANSACTION_COLLECTION_INTERVAL_MILLIS, TRANSACTION_COLLECTION_INTERVAL_MILLIS); diff --git a/sentry/src/test/java/io/sentry/DefaultCompositePerformanceCollectorTest.kt b/sentry/src/test/java/io/sentry/DefaultCompositePerformanceCollectorTest.kt index 46c304358d..ceec3571eb 100644 --- a/sentry/src/test/java/io/sentry/DefaultCompositePerformanceCollectorTest.kt +++ b/sentry/src/test/java/io/sentry/DefaultCompositePerformanceCollectorTest.kt @@ -86,7 +86,7 @@ class DefaultCompositePerformanceCollectorTest { val collector = fixture.getSut(null, null) assertTrue(fixture.options.performanceCollectors.isEmpty()) collector.start(fixture.transaction1) - verify(fixture.mockTimer, never())!!.scheduleAtFixedRate(any(), any(), any()) + verify(fixture.mockTimer, never())!!.schedule(any(), any(), any()) } @Test @@ -104,14 +104,14 @@ class DefaultCompositePerformanceCollectorTest { fun `when start, timer is scheduled every 100 milliseconds`() { val collector = fixture.getSut() collector.start(fixture.transaction1) - verify(fixture.mockTimer)!!.scheduleAtFixedRate(any(), any(), eq(100)) + verify(fixture.mockTimer)!!.schedule(any(), any(), eq(100)) } @Test fun `when start with a string, timer is scheduled every 100 milliseconds`() { val collector = fixture.getSut() collector.start(fixture.id1) - verify(fixture.mockTimer)!!.scheduleAtFixedRate(any(), any(), eq(100)) + verify(fixture.mockTimer)!!.schedule(any(), any(), eq(100)) } @Test @@ -119,7 +119,7 @@ class DefaultCompositePerformanceCollectorTest { val collector = fixture.getSut() collector.start(fixture.transaction1) collector.stop(fixture.transaction1) - verify(fixture.mockTimer)!!.scheduleAtFixedRate(any(), any(), eq(100)) + verify(fixture.mockTimer)!!.schedule(any(), any(), eq(100)) verify(fixture.mockTimer)!!.cancel() } @@ -128,7 +128,7 @@ class DefaultCompositePerformanceCollectorTest { val collector = fixture.getSut() collector.start(fixture.id1) collector.stop(fixture.id1) - verify(fixture.mockTimer)!!.scheduleAtFixedRate(any(), any(), eq(100)) + verify(fixture.mockTimer)!!.schedule(any(), any(), eq(100)) verify(fixture.mockTimer)!!.cancel() } @@ -136,7 +136,7 @@ class DefaultCompositePerformanceCollectorTest { fun `stopping a not collected transaction return null`() { val collector = fixture.getSut() val data = collector.stop(fixture.transaction1) - verify(fixture.mockTimer, never())!!.scheduleAtFixedRate(any(), any(), eq(100)) + verify(fixture.mockTimer, never())!!.schedule(any(), any(), eq(100)) verify(fixture.mockTimer, never())!!.cancel() assertNull(data) } @@ -145,7 +145,7 @@ class DefaultCompositePerformanceCollectorTest { fun `stopping a not collected id return null`() { val collector = fixture.getSut() val data = collector.stop(fixture.id1) - verify(fixture.mockTimer, never())!!.scheduleAtFixedRate(any(), any(), eq(100)) + verify(fixture.mockTimer, never())!!.schedule(any(), any(), eq(100)) verify(fixture.mockTimer, never())!!.cancel() assertNull(data) } @@ -316,7 +316,7 @@ class DefaultCompositePerformanceCollectorTest { collector.close() // Timer was canceled - verify(fixture.mockTimer)!!.scheduleAtFixedRate(any(), any(), eq(100)) + verify(fixture.mockTimer)!!.schedule(any(), any(), eq(100)) verify(fixture.mockTimer)!!.cancel() // Data was cleared