-
-
Notifications
You must be signed in to change notification settings - Fork 468
Handle App Start Continuous Profiling v8 (p4) #3730
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
ffc470f
391485f
089f636
b7e889c
540e276
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |
| import android.os.Process; | ||
| import android.os.SystemClock; | ||
| import androidx.annotation.NonNull; | ||
| import io.sentry.IContinuousProfiler; | ||
| import io.sentry.ILogger; | ||
| import io.sentry.ITransactionProfiler; | ||
| import io.sentry.JsonSerializer; | ||
|
|
@@ -98,6 +99,11 @@ public void shutdown() { | |
| if (appStartProfiler != null) { | ||
| appStartProfiler.close(); | ||
| } | ||
| final @Nullable IContinuousProfiler appStartContinuousProfiler = | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as I understood there could be only one profiler at a time (cont. or tx-based), right? Just got an idea we could have a general This way you could only manage one instance of
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you're probably right on this, but in the long term we will deprecate and optionally remove the transaction profiler. |
||
| AppStartMetrics.getInstance().getAppStartContinuousProfiler(); | ||
| if (appStartContinuousProfiler != null) { | ||
| appStartContinuousProfiler.close(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -135,41 +141,18 @@ private void launchAppStartProfiler(final @NotNull AppStartMetrics appStartMetri | |
| return; | ||
| } | ||
|
|
||
| if (profilingOptions.isContinuousProfilingEnabled()) { | ||
| createAndStartContinuousProfiler(context, profilingOptions, appStartMetrics); | ||
| return; | ||
| } | ||
|
|
||
| if (!profilingOptions.isProfilingEnabled()) { | ||
| logger.log( | ||
| SentryLevel.INFO, "Profiling is not enabled. App start profiling will not start."); | ||
| return; | ||
| } | ||
|
|
||
| final @NotNull TracesSamplingDecision appStartSamplingDecision = | ||
| new TracesSamplingDecision( | ||
| profilingOptions.isTraceSampled(), | ||
| profilingOptions.getTraceSampleRate(), | ||
| profilingOptions.isProfileSampled(), | ||
| profilingOptions.getProfileSampleRate()); | ||
| // We store any sampling decision, so we can respect it when the first transaction starts | ||
| appStartMetrics.setAppStartSamplingDecision(appStartSamplingDecision); | ||
|
|
||
| if (!(appStartSamplingDecision.getProfileSampled() | ||
| && appStartSamplingDecision.getSampled())) { | ||
| logger.log(SentryLevel.DEBUG, "App start profiling was not sampled. It will not start."); | ||
| return; | ||
| } | ||
| logger.log(SentryLevel.DEBUG, "App start profiling started."); | ||
|
|
||
| final @NotNull ITransactionProfiler appStartProfiler = | ||
| new AndroidTransactionProfiler( | ||
| context.getApplicationContext(), | ||
| buildInfoProvider, | ||
| new SentryFrameMetricsCollector( | ||
| context.getApplicationContext(), logger, buildInfoProvider), | ||
| logger, | ||
| profilingOptions.getProfilingTracesDirPath(), | ||
| profilingOptions.isProfilingEnabled(), | ||
| profilingOptions.getProfilingTracesHz(), | ||
| new SentryExecutorService()); | ||
| appStartMetrics.setAppStartProfiler(appStartProfiler); | ||
| appStartProfiler.start(); | ||
| createAndStartTransactionProfiler(context, profilingOptions, appStartMetrics); | ||
|
|
||
| } catch (FileNotFoundException e) { | ||
| logger.log(SentryLevel.ERROR, "App start profiling config file not found. ", e); | ||
|
|
@@ -178,6 +161,60 @@ private void launchAppStartProfiler(final @NotNull AppStartMetrics appStartMetri | |
| } | ||
| } | ||
|
|
||
| private void createAndStartContinuousProfiler( | ||
| final @NotNull Context context, | ||
| final @NotNull SentryAppStartProfilingOptions profilingOptions, | ||
| final @NotNull AppStartMetrics appStartMetrics) { | ||
| final @NotNull IContinuousProfiler appStartContinuousProfiler = | ||
| new AndroidContinuousProfiler( | ||
| buildInfoProvider, | ||
| new SentryFrameMetricsCollector( | ||
| context.getApplicationContext(), logger, buildInfoProvider), | ||
| logger, | ||
| profilingOptions.getProfilingTracesDirPath(), | ||
| profilingOptions.getProfilingTracesHz(), | ||
| new SentryExecutorService()); | ||
| appStartMetrics.setAppStartProfiler(null); | ||
| appStartMetrics.setAppStartContinuousProfiler(appStartContinuousProfiler); | ||
| logger.log(SentryLevel.DEBUG, "App start continuous profiling started."); | ||
| appStartContinuousProfiler.start(); | ||
| } | ||
|
|
||
| private void createAndStartTransactionProfiler( | ||
| final @NotNull Context context, | ||
| final @NotNull SentryAppStartProfilingOptions profilingOptions, | ||
| final @NotNull AppStartMetrics appStartMetrics) { | ||
| final @NotNull TracesSamplingDecision appStartSamplingDecision = | ||
| new TracesSamplingDecision( | ||
| profilingOptions.isTraceSampled(), | ||
| profilingOptions.getTraceSampleRate(), | ||
| profilingOptions.isProfileSampled(), | ||
| profilingOptions.getProfileSampleRate()); | ||
| // We store any sampling decision, so we can respect it when the first transaction starts | ||
| appStartMetrics.setAppStartSamplingDecision(appStartSamplingDecision); | ||
|
|
||
| if (!(appStartSamplingDecision.getProfileSampled() && appStartSamplingDecision.getSampled())) { | ||
| logger.log(SentryLevel.DEBUG, "App start profiling was not sampled. It will not start."); | ||
| return; | ||
| } | ||
|
|
||
| final @NotNull ITransactionProfiler appStartProfiler = | ||
| new AndroidTransactionProfiler( | ||
| context.getApplicationContext(), | ||
| buildInfoProvider, | ||
| new SentryFrameMetricsCollector( | ||
| context.getApplicationContext(), logger, buildInfoProvider), | ||
| logger, | ||
| profilingOptions.getProfilingTracesDirPath(), | ||
| profilingOptions.isProfilingEnabled(), | ||
| profilingOptions.getProfilingTracesHz(), | ||
| new SentryExecutorService()); | ||
| appStartMetrics.setAppStartContinuousProfiler(null); | ||
| appStartMetrics.setAppStartProfiler(appStartProfiler); | ||
| logger.log(SentryLevel.DEBUG, "App start profiling started."); | ||
| appStartProfiler.start(); | ||
| } | ||
|
|
||
| @SuppressLint("NewApi") | ||
| private void onAppLaunched( | ||
| final @Nullable Context context, final @NotNull AppStartMetrics appStartMetrics) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.