12
12
import android .os .Process ;
13
13
import android .os .SystemClock ;
14
14
import androidx .annotation .NonNull ;
15
+ import io .sentry .IContinuousProfiler ;
15
16
import io .sentry .ILogger ;
16
17
import io .sentry .ISentryLifecycleToken ;
17
18
import io .sentry .ITransactionProfiler ;
@@ -100,6 +101,11 @@ public void shutdown() {
100
101
if (appStartProfiler != null ) {
101
102
appStartProfiler .close ();
102
103
}
104
+ final @ Nullable IContinuousProfiler appStartContinuousProfiler =
105
+ AppStartMetrics .getInstance ().getAppStartContinuousProfiler ();
106
+ if (appStartContinuousProfiler != null ) {
107
+ appStartContinuousProfiler .close ();
108
+ }
103
109
}
104
110
}
105
111
@@ -132,40 +138,18 @@ private void launchAppStartProfiler(final @NotNull AppStartMetrics appStartMetri
132
138
return ;
133
139
}
134
140
141
+ if (profilingOptions .isContinuousProfilingEnabled ()) {
142
+ createAndStartContinuousProfiler (context , profilingOptions , appStartMetrics );
143
+ return ;
144
+ }
145
+
135
146
if (!profilingOptions .isProfilingEnabled ()) {
136
147
logger .log (
137
148
SentryLevel .INFO , "Profiling is not enabled. App start profiling will not start." );
138
149
return ;
139
150
}
140
151
141
- final @ NotNull TracesSamplingDecision appStartSamplingDecision =
142
- new TracesSamplingDecision (
143
- profilingOptions .isTraceSampled (),
144
- profilingOptions .getTraceSampleRate (),
145
- profilingOptions .isProfileSampled (),
146
- profilingOptions .getProfileSampleRate ());
147
- // We store any sampling decision, so we can respect it when the first transaction starts
148
- appStartMetrics .setAppStartSamplingDecision (appStartSamplingDecision );
149
-
150
- if (!(appStartSamplingDecision .getProfileSampled ()
151
- && appStartSamplingDecision .getSampled ())) {
152
- logger .log (SentryLevel .DEBUG , "App start profiling was not sampled. It will not start." );
153
- return ;
154
- }
155
- logger .log (SentryLevel .DEBUG , "App start profiling started." );
156
-
157
- final @ NotNull ITransactionProfiler appStartProfiler =
158
- new AndroidTransactionProfiler (
159
- context ,
160
- buildInfoProvider ,
161
- new SentryFrameMetricsCollector (context , logger , buildInfoProvider ),
162
- logger ,
163
- profilingOptions .getProfilingTracesDirPath (),
164
- profilingOptions .isProfilingEnabled (),
165
- profilingOptions .getProfilingTracesHz (),
166
- new SentryExecutorService ());
167
- appStartMetrics .setAppStartProfiler (appStartProfiler );
168
- appStartProfiler .start ();
152
+ createAndStartTransactionProfiler (context , profilingOptions , appStartMetrics );
169
153
170
154
} catch (FileNotFoundException e ) {
171
155
logger .log (SentryLevel .ERROR , "App start profiling config file not found. " , e );
@@ -174,6 +158,59 @@ private void launchAppStartProfiler(final @NotNull AppStartMetrics appStartMetri
174
158
}
175
159
}
176
160
161
+ private void createAndStartContinuousProfiler (
162
+ final @ NotNull Context context ,
163
+ final @ NotNull SentryAppStartProfilingOptions profilingOptions ,
164
+ final @ NotNull AppStartMetrics appStartMetrics ) {
165
+ final @ NotNull IContinuousProfiler appStartContinuousProfiler =
166
+ new AndroidContinuousProfiler (
167
+ buildInfoProvider ,
168
+ new SentryFrameMetricsCollector (
169
+ context .getApplicationContext (), logger , buildInfoProvider ),
170
+ logger ,
171
+ profilingOptions .getProfilingTracesDirPath (),
172
+ profilingOptions .getProfilingTracesHz (),
173
+ new SentryExecutorService ());
174
+ appStartMetrics .setAppStartProfiler (null );
175
+ appStartMetrics .setAppStartContinuousProfiler (appStartContinuousProfiler );
176
+ logger .log (SentryLevel .DEBUG , "App start continuous profiling started." );
177
+ appStartContinuousProfiler .start ();
178
+ }
179
+
180
+ private void createAndStartTransactionProfiler (
181
+ final @ NotNull Context context ,
182
+ final @ NotNull SentryAppStartProfilingOptions profilingOptions ,
183
+ final @ NotNull AppStartMetrics appStartMetrics ) {
184
+ final @ NotNull TracesSamplingDecision appStartSamplingDecision =
185
+ new TracesSamplingDecision (
186
+ profilingOptions .isTraceSampled (),
187
+ profilingOptions .getTraceSampleRate (),
188
+ profilingOptions .isProfileSampled (),
189
+ profilingOptions .getProfileSampleRate ());
190
+ // We store any sampling decision, so we can respect it when the first transaction starts
191
+ appStartMetrics .setAppStartSamplingDecision (appStartSamplingDecision );
192
+
193
+ if (!(appStartSamplingDecision .getProfileSampled () && appStartSamplingDecision .getSampled ())) {
194
+ logger .log (SentryLevel .DEBUG , "App start profiling was not sampled. It will not start." );
195
+ return ;
196
+ }
197
+
198
+ final @ NotNull ITransactionProfiler appStartProfiler =
199
+ new AndroidTransactionProfiler (
200
+ context ,
201
+ buildInfoProvider ,
202
+ new SentryFrameMetricsCollector (context , logger , buildInfoProvider ),
203
+ logger ,
204
+ profilingOptions .getProfilingTracesDirPath (),
205
+ profilingOptions .isProfilingEnabled (),
206
+ profilingOptions .getProfilingTracesHz (),
207
+ new SentryExecutorService ());
208
+ appStartMetrics .setAppStartContinuousProfiler (null );
209
+ appStartMetrics .setAppStartProfiler (appStartProfiler );
210
+ logger .log (SentryLevel .DEBUG , "App start profiling started." );
211
+ appStartProfiler .start ();
212
+ }
213
+
177
214
@ SuppressLint ("NewApi" )
178
215
private void onAppLaunched (
179
216
final @ Nullable Context context , final @ NotNull AppStartMetrics appStartMetrics ) {
0 commit comments