title | sidebar_title | description | sidebar_order |
---|---|---|---|
Set Up Profiling |
Profiling |
Learn how to enable profiling in your app if it is not already set up. |
5000 |
Android UI Profiling is available starting in SDK version 8.7.0
.
The transaction-based profiler is available on SDK versions 6.16.0
and higher through its options.
UI Profiling supports two modes - manual
and trace
. The two modes are mutually exclusive, and cannot be used at the same time.
In manual
mode, the profiling data collection can be managed via calls to Sentry.profiler.startProfiler
and Sentry.profiler.stopProfiler
. You are entirely in the in control of when the profiler runs.
In trace
mode, the profiler manages its own start and stop calls, which are based on spans: the profiler continues to run while there is at least one active sampled span, and stops when there are no active sampled spans.
Sentry SDK supports an additional profileSessionSampleRate
that will enable or disable profiling for the entire session. This sampling decision is evaluated only once per session.
To enable trace profiling, set the lifecycle to trace
. Trace profiling requires tracing to be enabled.
Check out the tracing setup documentation for more detailed information on how to configure sampling. Setting the sample rate to 1.0 means all transactions will be captured.
By default, some transactions will be created automatically for common operations like loading a view controller/activity and app startup.
<application>
<meta-data android:name="io.sentry.dsn" android:value="___PUBLIC_DSN___" />
<!-- Enable tracing, needed for profiling `trace` mode, adjust in production env -->
<meta-data android:name="io.sentry.traces.sample-rate" android:value="1.0" />
<!-- Enable UI profiling, adjust in production env. This is evaluated only once per session -->
<meta-data android:name="io.sentry.traces.profiling.session-sample-rate" android:value="1.0" />
<meta-data android:name="io.sentry.traces.profiling.lifecycle" android:value="trace" />
<!-- Enable profiling on app start. The app start profile will be stopped automatically when the app start root span finishes -->
<meta-data android:name="io.sentry.traces.profiling.start-on-app-start" android:value="true" />
</application>
import io.sentry.ProfileLifecycle;
import io.sentry.android.core.SentryAndroid;
// App main Application class
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
SentryAndroid.init(
this,
options -> {
options.setDsn("___PUBLIC_DSN___");
// Enable tracing, needed for profiling `trace` mode, adjust in production env
options.setTracesSampleRate(1.0);
// Enable UI profiling, adjust in production env. This is evaluated only once per session
options.setProfileSessionSampleRate(1.0);
options.setProfileLifecycle(ProfileLifecycle.TRACE);
// Enable profiling on app start. The app start profile will be stopped automatically when the app start root span finishes
options.setStartProfilerOnAppStart(true);
});
}
}
import io.sentry.ProfileLifecycle
import io.sentry.android.core.SentryAndroid
// App main Application class
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
SentryAndroid.init(
this,
{ options ->
options.dsn = "___PUBLIC_DSN___"
// Enable tracing, needed for profiling `trace` mode, adjust in production env
options.tracesSampleRate = 1.0
// Enable UI profiling, adjust in production env. This is evaluated only once per session
options.profileSessionSampleRate = 1.0
options.profileLifecycle = ProfileLifecycle.TRACE
// Enable profiling on app start. The app start profile will be stopped automatically when the app start root span finishes
options.isStartProfilerOnAppStart = true
})
}
}
To enable manual profiling, set the lifecycle to manual
. Manual profiling does not require tracing to be enabled.
<application>
<meta-data android:name="io.sentry.dsn" android:value="___PUBLIC_DSN___" />
<!-- Enable UI profiling, adjust in production env. This is evaluated only once per session -->
<meta-data android:name="io.sentry.traces.profiling.session-sample-rate" android:value="1.0" />
<meta-data android:name="io.sentry.traces.profiling.lifecycle" android:value="manual" />
<!-- Enable profiling on app start. The app start profile has to be stopped through Sentry.stopProfiler() -->
<meta-data android:name="io.sentry.traces.profiling.start-on-app-start" android:value="true" />
</application>
import io.sentry.ProfileLifecycle;
import io.sentry.Sentry;
import io.sentry.android.core.SentryAndroid;
// App main Application class
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
SentryAndroid.init(
this,
options -> {
options.setDsn("___PUBLIC_DSN___");
// Enable UI profiling, adjust in production env. This is evaluated only once per session
options.setProfileSessionSampleRate(1.0);
options.setProfileLifecycle(ProfileLifecycle.MANUAL);
// Enable profiling on app start. The app start profile has to be stopped through Sentry.stopProfiler()
options.setStartProfilerOnAppStart(true);
});
// Start profiling, if lifecycle is set to `manual` and startProfilerOnAppStart is set to `true`
Sentry.startProfiler();
// Stop profiling, if lifecycle is set to `manual` and startProfilerOnAppStart is set to `true`.
// This call is optional. If you don't stop the profiler, it will keep profiling your application until the process exits.
Sentry.stopProfiler();
}
}
import io.sentry.ProfileLifecycle
import io.sentry.Sentry
import io.sentry.android.core.SentryAndroid
// App main Application class
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
SentryAndroid.init(
this,
{ options ->
options.dsn = "___PUBLIC_DSN___"
// Enable UI profiling, adjust in production env. This is evaluated only once per session
options.profileSessionSampleRate = 1.0
options.profileLifecycle = ProfileLifecycle.MANUAL
// Enable profiling on app start. The app start profile has to be stopped through Sentry.stopProfiler()
options.isStartProfilerOnAppStart = true
})
// Start profiling, if lifecycle is set to `manual` and startProfilerOnAppStart is set to `true`
Sentry.startProfiler()
// Stop profiling, if lifecycle is set to `manual` and startProfilerOnAppStart is set to `true`.
// This call is optional. If you don't stop the profiler, it will keep profiling your application until the process exits.
Sentry.stopProfiler()
}
}
This mode will eventually be deprecated, and it's recommended to upgrade to UI Profiling. The same behaviour, without the 30 seconds limitation, can be achieved with the Trace Lifecycle UI Profiling. In order to upgrade to UI Profiling, you also need to remove the transaction-based profiling options from your configuration.
Android transaction-based profiling is available starting in SDK version 6.16.0
and is supported on API level 22 and up.
App start profiling is available starting in SDK version 7.3.0
.
The transaction-based profiling only runs in tandem with performance transactions that were started either automatically or manually with Sentry.startTransaction
, and stops automatically after 30 seconds (unless you manually stop it earlier). Naturally, this limitation makes it difficult to get full coverage of your app's execution.
<application>
<meta-data android:name="io.sentry.dsn" android:value="___PUBLIC_DSN___" />
<!-- Enable tracing, needed for legacy profiling, adjust in production env -->
<meta-data android:name="io.sentry.traces.sample-rate" android:value="1.0" />
<!-- Enable transaction-based profiling, adjust in production env. This is relative to traces sample rate -->
<meta-data android:name="io.sentry.traces.profiling.sample-rate" android:value="1.0" />
<!-- Enable profiling on app start -->
<meta-data android:name="io.sentry.traces.profiling.enable-app-start" android:value="true" />
</application>
import io.sentry.ProfileLifecycle;
import io.sentry.Sentry;
import io.sentry.android.core.SentryAndroid;
// App main Application class
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
SentryAndroid.init(
this,
options -> {
options.setDsn("___PUBLIC_DSN___");
// Enable tracing, needed for legacy profiling, adjust in production env
options.setTracesSampleRate(1.0);
// Enable transaction-based profiling, adjust in production env. This is relative to traces sample rate
options.setProfilesSampleRate(1.0);
// Enable profiling on app start
options.setEnableAppStartProfiling(true);
});
}
}
import io.sentry.ProfileLifecycle
import io.sentry.Sentry
import io.sentry.android.core.SentryAndroid
// App main Application class
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
SentryAndroid.init(
this,
{ options ->
options.dsn = "___PUBLIC_DSN___"
// Enable tracing, needed for profiling `trace` mode, adjust in production env
options.tracesSampleRate = 1.0
// Enable transaction-based profiling, adjust in production env. This is relative to traces sample rate
options.profilesSampleRate = 1.0
// Enable profiling on app start
options.isEnableAppStartProfiling = true
})
}
}
The SDK won't run app start profiling the very first time the app runs, as the SDK won't have read the options by the time the profile should run.
The SDK will set the isForNextAppStart
flag in TransactionContext
if app start profiling is enabled.