Legacy Profiling

Learn about the legacy profilers and how to use them on devices running Android versions earlier than Android 15.

There are two legacy profiling implementations:

  • Legacy UI Profiling, which samples threads using the Android runtime's tracer. It supports the same manual and trace lifecycle modes as the current UI Profiling, but uses the tracer backend instead of the ProfilingManager.
  • Transaction-based profiling, the oldest implementation, which runs only alongside performance transactions and is limited to 30 seconds.

Legacy UI Profiling is available starting with SDK version 8.7.0 and is supported on API level 21 and up.

The SDK uses the legacy profiler automatically on devices below Android 15 (API level 35); on Android 15 and higher it uses the ProfilingManager (Perfetto) backend instead. Configure UI Profiling exactly as described in the UI Profiling documentation — the same profileSessionSampleRate and profileLifecycle options apply. To disable the legacy profiler, and turn off profiling on older devices entirely, set enableLegacyProfiling to false.

UI Profiling supports two modes: manual and trace. These modes are mutually exclusive and cannot be used at the same time.

In manual mode, profiling data collection is managed via calls to Sentry.startProfiler and Sentry.stopProfiler. You are entirely 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 runs while there is at least one active sampled span and stops when there are no active sampled spans.

Unlike the ProfilingManager backend, the legacy profiler supports profiling the app start process through the startProfilerOnAppStart option.

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.

AndroidManifest.xml
Copied
<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>

To enable manual profiling, set the lifecycle to manual. Manual profiling does not require tracing to be enabled.

AndroidManifest.xml
Copied
<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>

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.

AndroidManifest.xml
Copied
<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>
Was this helpful?
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").