Skip to content

Commit 04f92d7

Browse files
runningcodeclaude
andauthored
ref(android): Remove unused TimeSpan.start() (#6089)
TimeSpan.start() had no production callers. Every start time in the SDK is set through setStartedAt(uptimeMs), which does the same thing for a caller passing SystemClock.uptimeMillis(). The tests that used it now call setStartedAt directly. Three AppStartMetricsTest cases also called start() and stop() immediately before overwriting both with setStartedAt/setStoppedAt; those calls were dead and are dropped. Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
1 parent 5c1467e commit 04f92d7

5 files changed

Lines changed: 16 additions & 27 deletions

File tree

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,6 @@ public class io/sentry/android/core/performance/TimeSpan : java/lang/Comparable
883883
public fun setStartedAt (J)V
884884
public fun setStoppedAt (J)V
885885
public fun setup (Ljava/lang/String;JJJ)V
886-
public fun start ()V
887886
public fun stop ()V
888887
}
889888

‎sentry-android-core/src/main/java/io/sentry/android/core/performance/TimeSpan.java‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,6 @@ public void setup(
3535
this.stopUptimeMs = stopUptimeMs;
3636
}
3737

38-
/** Start the time span */
39-
public void start() {
40-
startUptimeMs = SystemClock.uptimeMillis();
41-
startUnixTimeMs = System.currentTimeMillis();
42-
}
43-
4438
/**
4539
* @param uptimeMs the uptime in ms, provided by {@link SystemClock#uptimeMillis()}
4640
*/

‎sentry-android-core/src/test/java/io/sentry/android/core/ActivityLifecycleIntegrationTest.kt‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import android.os.Build
1010
import android.os.Bundle
1111
import android.os.Handler
1212
import android.os.Looper
13+
import android.os.SystemClock
1314
import android.view.View
1415
import android.view.ViewTreeObserver
1516
import androidx.test.core.app.ApplicationProvider
@@ -106,7 +107,7 @@ class ActivityLifecycleIntegrationTest {
106107

107108
val metrics = AppStartMetrics.getInstance()
108109
metrics.isAppLaunchedInForeground = true
109-
metrics.appStartTimeSpan.start()
110+
metrics.appStartTimeSpan.setStartedAt(SystemClock.uptimeMillis())
110111

111112
// We let the ActivityLifecycleIntegration create the proper transaction here
112113
val optionCaptor = argumentCaptor<TransactionOptions>()

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

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ class AppStartMetricsTest {
6161
@Test
6262
fun `metrics are properly cleared`() {
6363
val metrics = AppStartMetrics.getInstance()
64-
metrics.appStartTimeSpan.start()
65-
metrics.sdkInitTimeSpan.start()
64+
metrics.appStartTimeSpan.setStartedAt(SystemClock.uptimeMillis())
65+
metrics.sdkInitTimeSpan.setStartedAt(SystemClock.uptimeMillis())
6666
metrics.appStartType = AppStartMetrics.AppStartType.WARM
67-
metrics.applicationOnCreateTimeSpan.start()
67+
metrics.applicationOnCreateTimeSpan.setStartedAt(SystemClock.uptimeMillis())
6868
metrics.addActivityLifecycleTimeSpans(ActivityLifecycleTimeSpan())
6969
AppStartMetrics.onApplicationCreate(mock<Application>())
7070
AppStartMetrics.onContentProviderCreate(mock<ContentProvider>())
@@ -92,7 +92,7 @@ class AppStartMetricsTest {
9292
fun `if perf-2 is enabled and app start time span is started, appStartTimeSpanWithFallback returns it`() {
9393
val appStartTimeSpan = AppStartMetrics.getInstance().appStartTimeSpan
9494
AppStartMetrics.getInstance().appStartType = AppStartMetrics.AppStartType.WARM
95-
appStartTimeSpan.start()
95+
appStartTimeSpan.setStartedAt(SystemClock.uptimeMillis())
9696

9797
val options = SentryAndroidOptions().apply { isEnablePerformanceV2 = true }
9898

@@ -143,7 +143,7 @@ class AppStartMetricsTest {
143143
AppStartMetrics.getInstance().appStartType = AppStartMetrics.AppStartType.COLD
144144

145145
val appStartTimeSpan = AppStartMetrics.getInstance().appStartTimeSpan
146-
appStartTimeSpan.start()
146+
appStartTimeSpan.setStartedAt(SystemClock.uptimeMillis())
147147
assertTrue(appStartTimeSpan.hasStarted())
148148
AppStartMetrics.getInstance().onActivityCreated(mock(), mock())
149149
waitForMainLooperIdle()
@@ -198,8 +198,8 @@ class AppStartMetricsTest {
198198
@Test
199199
fun `if app is launched in background, the first created activity assumes a warm start`() {
200200
val metrics = AppStartMetrics.getInstance()
201-
metrics.appStartTimeSpan.start()
202-
metrics.sdkInitTimeSpan.start()
201+
metrics.appStartTimeSpan.setStartedAt(SystemClock.uptimeMillis())
202+
metrics.sdkInitTimeSpan.setStartedAt(SystemClock.uptimeMillis())
203203
metrics.registerLifecycleCallbacks(mock<Application>())
204204

205205
// when the handler callback is executed and the start is headless
@@ -390,8 +390,6 @@ class AppStartMetricsTest {
390390
@Test
391391
fun `if app start span is at most 1 minute, appStartTimeSpanWithFallback returns the app start span`() {
392392
val appStartTimeSpan = AppStartMetrics.getInstance().appStartTimeSpan
393-
appStartTimeSpan.start()
394-
appStartTimeSpan.stop()
395393
appStartTimeSpan.setStartedAt(1)
396394
appStartTimeSpan.setStoppedAt(TimeUnit.MINUTES.toMillis(1) + 1)
397395
assertTrue(appStartTimeSpan.hasStarted())
@@ -475,8 +473,6 @@ class AppStartMetricsTest {
475473
@Test
476474
fun `if app start span is longer than 1 minute, appStartTimeSpanWithFallback returns an empty span`() {
477475
val appStartTimeSpan = AppStartMetrics.getInstance().appStartTimeSpan
478-
appStartTimeSpan.start()
479-
appStartTimeSpan.stop()
480476
appStartTimeSpan.setStartedAt(1)
481477
appStartTimeSpan.setStoppedAt(TimeUnit.MINUTES.toMillis(1) + 2)
482478
assertTrue(appStartTimeSpan.hasStarted())
@@ -531,8 +527,6 @@ class AppStartMetricsTest {
531527
@Test
532528
fun `isColdStartValid is false if app launched in more than 1 minute`() {
533529
val appStartTimeSpan = AppStartMetrics.getInstance().appStartTimeSpan
534-
appStartTimeSpan.start()
535-
appStartTimeSpan.stop()
536530
appStartTimeSpan.setStartedAt(1)
537531
appStartTimeSpan.setStoppedAt(TimeUnit.MINUTES.toMillis(1) + 2)
538532
AppStartMetrics.getInstance().onActivityCreated(mock(), mock())
@@ -578,8 +572,8 @@ class AppStartMetricsTest {
578572
@Test
579573
fun `provider sets both appstart and sdk init start + end times`() {
580574
val metrics = AppStartMetrics.getInstance()
581-
metrics.appStartTimeSpan.start()
582-
metrics.sdkInitTimeSpan.start()
575+
metrics.appStartTimeSpan.setStartedAt(SystemClock.uptimeMillis())
576+
metrics.sdkInitTimeSpan.setStartedAt(SystemClock.uptimeMillis())
583577

584578
assertFalse(metrics.appStartTimeSpan.hasStopped())
585579
assertFalse(metrics.sdkInitTimeSpan.hasStopped())
@@ -614,7 +608,8 @@ class AppStartMetricsTest {
614608
val metrics = AppStartMetrics.getInstance()
615609
assertEquals(AppStartMetrics.AppStartType.UNKNOWN, AppStartMetrics.getInstance().appStartType)
616610
val app = mock<Application>()
617-
metrics.appStartTimeSpan.start() // Need to start the span for timeout check to work
611+
// the span needs to be started for the timeout check to work
612+
metrics.appStartTimeSpan.setStartedAt(SystemClock.uptimeMillis())
618613
metrics.registerLifecycleCallbacks(app)
619614

620615
// when an activity is created later with a null bundle

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ class TimeSpanTest {
122122
}
123123

124124
@Test
125-
fun `span start starts the timespan`() {
125+
fun `setStartedAt starts the timespan`() {
126126
val span = TimeSpan()
127-
span.start()
127+
span.setStartedAt(1)
128128

129129
assertTrue(span.hasStarted())
130130
assertFalse(span.hasNotStarted())
@@ -133,7 +133,7 @@ class TimeSpanTest {
133133
@Test
134134
fun `span stop stops the timespan`() {
135135
val span = TimeSpan()
136-
span.start()
136+
span.setStartedAt(1)
137137

138138
assertFalse(span.hasStopped())
139139

0 commit comments

Comments
 (0)