-
-
Notifications
You must be signed in to change notification settings - Fork 475
feat(profiling): Add Android ProfilingManager (Perfetto) support #5251
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
base: main
Are you sure you want to change the base?
Changes from all commits
9a60ad1
1250aa1
05d73b1
5f894d0
c2a4442
bc2e59d
a53c383
dd2c5a4
6ebea19
5e4bead
443cc45
dcee449
331622b
85e54fc
11331ea
4c48101
35b2bcb
268a1e0
ffd5c6b
a1e703e
0c7f8fd
1a6742c
e387e89
cd26427
d760522
e3a6c2b
8a37dec
bab9781
b4c224a
8c560c6
ac104ed
6e522f6
24bcfed
9c8285a
c53be37
bc39a7d
9648cd5
c787eeb
a49856e
5149ee9
ad4925c
642e7a5
9c9715f
9d3cb80
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 |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
|
|
||
| import static io.sentry.android.core.NdkIntegration.SENTRY_NDK_CLASS_NAME; | ||
|
|
||
| import android.annotation.SuppressLint; | ||
| import android.app.Application; | ||
| import android.content.Context; | ||
| import android.content.pm.PackageInfo; | ||
|
|
@@ -294,6 +295,7 @@ static void initializeIntegrationsAndProcessors( | |
| } | ||
|
|
||
| /** Setup the correct profiler (transaction or continuous) based on the options. */ | ||
| @SuppressLint("NewApi") | ||
| private static void setupProfiler( | ||
| final @NotNull SentryAndroidOptions options, | ||
| final @NotNull Context context, | ||
|
|
@@ -303,6 +305,28 @@ private static void setupProfiler( | |
| final @NotNull CompositePerformanceCollector performanceCollector) { | ||
| if (options.isProfilingEnabled() || options.getProfilesSampleRate() != null) { | ||
| options.setContinuousProfiler(NoOpContinuousProfiler.getInstance()); | ||
| // Transaction-based profiling always relies on the legacy Debug-based profiler, so it is | ||
| // disabled together with legacy profiling. Perfetto profiling only supports continuous | ||
| // profiling. | ||
| if (!options.isEnableLegacyProfiling()) { | ||
| options | ||
| .getLogger() | ||
| .log( | ||
| SentryLevel.WARNING, | ||
| "Transaction-based profiling (profilesSampleRate/profilesSampler) is disabled " | ||
| + "because enableLegacyProfiling is false. Transaction-based profiling always " | ||
| + "uses the legacy profiler and is not supported by Perfetto. No profiling " | ||
| + "data will be collected. Use profileSessionSampleRate for continuous " | ||
| + "profiling instead."); | ||
| options.setTransactionProfiler(NoOpTransactionProfiler.getInstance()); | ||
| if (appStartTransactionProfiler != null) { | ||
| appStartTransactionProfiler.close(); | ||
| } | ||
| if (appStartContinuousProfiler != null) { | ||
| appStartContinuousProfiler.close(true); | ||
| } | ||
| return; | ||
| } | ||
| // This is a safeguard, but it should never happen, as the app start profiler should be the | ||
| // continuous one. | ||
| if (appStartContinuousProfiler != null) { | ||
|
|
@@ -336,16 +360,36 @@ private static void setupProfiler( | |
| performanceCollector.start(chunkId.toString()); | ||
| } | ||
| } else { | ||
| options.setContinuousProfiler( | ||
| new AndroidContinuousProfiler( | ||
| buildInfoProvider, | ||
| Objects.requireNonNull( | ||
| options.getFrameMetricsCollector(), | ||
| "options.getFrameMetricsCollector is required"), | ||
| options.getLogger(), | ||
| options.getProfilingTracesDirPath(), | ||
| options.getProfilingTracesHz(), | ||
| () -> options.getExecutorService())); | ||
| final @NotNull SentryFrameMetricsCollector frameMetricsCollector = | ||
| Objects.requireNonNull( | ||
| options.getFrameMetricsCollector(), "options.getFrameMetricsCollector is required"); | ||
| if (buildInfoProvider.getSdkInfoVersion() >= Build.VERSION_CODES.VANILLA_ICE_CREAM) { | ||
| final @NotNull Context appContext = context.getApplicationContext(); | ||
| options.setContinuousProfiler( | ||
| new PerfettoContinuousProfiler( | ||
| options.getLogger(), | ||
| frameMetricsCollector, | ||
| () -> options.getExecutorService(), | ||
| () -> | ||
| new PerfettoProfiler( | ||
| appContext, options.getLogger(), options.getExecutorService()))); | ||
|
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. Null app context crashes profilingMedium Severity
Reviewed by Cursor Bugbot for commit 9c9715f. Configure here. |
||
| } else if (options.isEnableLegacyProfiling()) { | ||
| options.setContinuousProfiler( | ||
| new AndroidContinuousProfiler( | ||
| buildInfoProvider, | ||
| frameMetricsCollector, | ||
| options.getLogger(), | ||
| options.getProfilingTracesDirPath(), | ||
| options.getProfilingTracesHz(), | ||
| () -> options.getExecutorService())); | ||
| } else { | ||
| options | ||
| .getLogger() | ||
| .log( | ||
| SentryLevel.WARNING, | ||
| "enableLegacyProfiling is disabled and device is below API 35. " | ||
| + "No profiling data will be collected."); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.