Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion develop-docs/feature/profiling/perfetto.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ by default. Applications can temporarily opt into the legacy `Debug`-based
with the deprecated `enableLegacyProfiling` option (manifest key
`io.sentry.profiling.enable-legacy-profiling`). The legacy profiler can cause Android Runtime
crashes and will be removed in version 10. Only **continuous profiling** is supported on the
Perfetto path — transaction-based and app-start profiling are not.
Perfetto path — transaction-based and app-start profiling are not. When both transaction and
continuous profiling are configured on API 35 and newer, continuous UI Profiling takes precedence
and the transaction profiling options are ignored. Below API 35, transaction profiling keeps its
existing precedence when the legacy profiler is explicitly enabled.

### Capturing chunks

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,25 @@ private static void setupProfiler(
final @Nullable ITransactionProfiler appStartTransactionProfiler,
final @Nullable IContinuousProfiler appStartContinuousProfiler,
final @NotNull CompositePerformanceCollector performanceCollector) {
final boolean isTransactionProfilingRequested =
final boolean isPerfettoAvailable =
buildInfoProvider.getSdkInfoVersion() >= Build.VERSION_CODES.VANILLA_ICE_CREAM;
boolean isTransactionProfilingRequested =
options.isProfilingEnabled() || options.getProfilesSampleRate() != null;
final @Nullable Double profileSessionSampleRate = options.getProfileSessionSampleRate();
if (isPerfettoAvailable
&& profileSessionSampleRate != null
&& profileSessionSampleRate > 0
&& isTransactionProfilingRequested) {
options
.getLogger()
.log(
SentryLevel.WARNING,
"Both transaction and UI profiling are configured. UI profiling takes precedence "
+ "on API 35 and newer. profilesSampleRate and profilesSampler will be ignored.");
options.setProfilesSampleRate(null);
options.setProfilesSampler(null);
isTransactionProfilingRequested = false;
}
if (isTransactionProfilingRequested && options.isEnableLegacyProfiling()) {
options
.getLogger()
Expand Down Expand Up @@ -373,7 +390,7 @@ private static void setupProfiler(
final @NotNull SentryFrameMetricsCollector frameMetricsCollector =
Objects.requireNonNull(
options.getFrameMetricsCollector(), "options.getFrameMetricsCollector is required");
if (buildInfoProvider.getSdkInfoVersion() >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
if (isPerfettoAvailable) {
final @NotNull Context appContext = ContextUtils.getApplicationContext(context);
options.setContinuousProfiler(
new PerfettoContinuousProfiler(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,26 @@ class AndroidOptionsInitializerTest {
assertTrue(fixture.sentryOptions.continuousProfiler is PerfettoContinuousProfiler)
}

@Config(sdk = [35])
@Test
fun `init on API 35+ prefers UI profiling when both profiling modes are configured`() {
fixture.initSut(
configureOptions = {
profilesSampleRate = 1.0
profilesSampler = mock()
profileSessionSampleRate = 1.0
isEnableLegacyProfiling = true
},
)

assertEquals(NoOpTransactionProfiler.getInstance(), fixture.sentryOptions.transactionProfiler)
assertTrue(fixture.sentryOptions.continuousProfiler is PerfettoContinuousProfiler)
assertTrue(fixture.sentryOptions.isContinuousProfilingEnabled)
assertFalse(fixture.sentryOptions.isProfilingEnabled)
assertNull(fixture.sentryOptions.profilesSampleRate)
assertNull(fixture.sentryOptions.profilesSampler)
}

@Config(sdk = [35])
@Test
fun `init on API 35+ reports PerfettoContinuousProfiling integration`() {
Expand Down Expand Up @@ -472,6 +492,23 @@ class AndroidOptionsInitializerTest {
assertTrue(fixture.sentryOptions.continuousProfiler is NoOpContinuousProfiler)
}

@Config(sdk = [33])
@Test
fun `init below API 35 keeps transaction profiling precedence when both modes are configured`() {
fixture.initSut(
configureOptions = {
profilesSampleRate = 1.0
profileSessionSampleRate = 1.0
isEnableLegacyProfiling = true
},
)

assertTrue(fixture.sentryOptions.transactionProfiler is AndroidTransactionProfiler)
assertEquals(NoOpContinuousProfiler.getInstance(), fixture.sentryOptions.continuousProfiler)
assertTrue(fixture.sentryOptions.isProfilingEnabled)
assertFalse(fixture.sentryOptions.isContinuousProfilingEnabled)
}

@Test
fun `init with profilesSampleRate and legacy profiling enabled sets transaction profiler`() {
fixture.initSut(
Expand Down
18 changes: 10 additions & 8 deletions sentry/src/main/java/io/sentry/SentryOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -2332,9 +2332,9 @@ public void setProfilesSampleRate(final @Nullable Double profilesSampleRate) {
}

/**
* Returns the session sample rate. Default is null (disabled). ProfilesSampleRate takes
* precedence over this. To enable continuous profiling, don't set profilesSampleRate or
* profilesSampler, or set them to null.
* Returns the session sample rate. Default is null (disabled). On Android API 35 and newer, a
* positive session sample rate takes precedence over {@code profilesSampleRate} and {@code
* profilesSampler}. On other platforms, transaction profiling takes precedence.
*
* @return the sample rate
*/
Expand All @@ -2343,9 +2343,9 @@ public void setProfilesSampleRate(final @Nullable Double profilesSampleRate) {
}

/**
* Set the session sample rate. Default is null (disabled). ProfilesSampleRate takes precedence
* over this. To enable continuous profiling, don't set profilesSampleRate or profilesSampler, or
* set them to null.
* Set the session sample rate. Default is null (disabled). On Android API 35 and newer, a
* positive session sample rate takes precedence over {@code profilesSampleRate} and {@code
* profilesSampler}. On other platforms, transaction profiling takes precedence.
*/
public void setProfileSessionSampleRate(final @Nullable Double profileSessionSampleRate) {
if (!SampleRateUtils.isValidContinuousProfilesSampleRate(profileSessionSampleRate)) {
Expand Down Expand Up @@ -2398,7 +2398,8 @@ public void setStartProfilerOnAppStart(final boolean startProfilerOnAppStart) {
* used for continuous profiling regardless of this setting) as well as transaction-based
* profiling ({@code profilesSampleRate}/{@code profilesSampler}) on all devices, since
* transaction-based profiling always relies on the legacy profiler and is not supported by
* Perfetto.
* Perfetto. When both profiling modes are configured on API 35 and newer, continuous profiling
* takes precedence.
*
* @return true if legacy profiling is enabled. The default is false.
* @deprecated The legacy profiler can cause Android Runtime crashes and will be removed in
Expand All @@ -2415,7 +2416,8 @@ public boolean isEnableLegacyProfiling() {
* continuous profiling on devices below API 35 as well as transaction-based profiling ({@code
* profilesSampleRate}/{@code profilesSampler}) on all devices. On API 35+ devices, Android's
* {@code ProfilingManager} / Perfetto is always used for continuous profiling and this setting
* has no effect on it.
* has no effect on it. When both profiling modes are configured on API 35 and newer, continuous
* profiling takes precedence.
*
* @param enableLegacyProfiling true to enable legacy profiling.
* @deprecated The legacy profiler can cause Android Runtime crashes and will be removed in
Expand Down
Loading