---
title: "Profiling"
description: "Learn how to enable profiling in your app if it is not already set up."
url: https://docs.sentry.io/platforms/android/profiling/
---

# Set Up Android Profiling | Sentry for Android

With [profiling](https://docs.sentry.io/product/profiling.md), Sentry tracks your software's performance by sampling your program's call stack in a variety of environments. This feature collects function-level information about your code and enables you to fine-tune your program's performance. [Sentry's profiler](https://sentry.io/for/profiling/) captures function calls and their exact locations, aggregates them, and shows you the most common code paths of your program. This highlights areas you could optimize to help increase both the performance of your code and increase user satisfaction, as well as drive down costs.

Starting with SDK version `8.51.0`, Sentry's Android UI Profiling is built on top of the Android [ProfilingManager APIs](https://developer.android.com/reference/android/os/ProfilingManager), available on Android 15 (API level 35), which capture stack samples as [Perfetto](https://perfetto.dev/) traces. This is the recommended way to profile your Android app.

##### Looking for the old profiler?

On devices running below Android 15, the SDK automatically falls back to the legacy profiler, which samples threads using the Android runtime's `tracer`. That implementation, along with the transaction-based profiler, is now considered legacy. See [Legacy Profiling](https://docs.sentry.io/platforms/android/profiling/legacy.md) for details, including how to disable it.

## [Prerequisites](https://docs.sentry.io/platforms/android/profiling.md#prerequisites)

UI Profiling is available starting in SDK version `8.7.0`. On **Android 15 (API level 35) or higher**, it uses the ProfilingManager (Perfetto) backend, available starting in SDK version `8.51.0`.

On devices running below Android 15, the SDK automatically falls back to the [legacy profiler](https://docs.sentry.io/platforms/android/profiling/legacy.md). You can turn this fallback off, and disable profiling on those devices entirely, with the [`enableLegacyProfiling`](https://docs.sentry.io/platforms/android/configuration/options.md#enableLegacyProfiling) option.

## [Enabling UI Profiling](https://docs.sentry.io/platforms/android/profiling.md#enabling-ui-profiling)

To enable UI Profiling, set a `profileSessionSampleRate` and choose a profile lifecycle. The SDK automatically uses the ProfilingManager (Perfetto) backend on Android 15 (API level 35) and higher, and the legacy profiler on older devices.

UI Profiling supports two modes: `manual` and `trace`. These 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 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.

The Sentry SDK supports an additional `profileSessionSampleRate` that will enable or disable profiling for the entire [session](https://docs.sentry.io/platforms/android/configuration/releases.md#sessions). This sampling decision is evaluated only once per session.

### [Enabling Trace Lifecycle UI Profiling](https://docs.sentry.io/platforms/android/profiling.md#enabling-trace-lifecycle-ui-profiling)

To enable trace profiling, set the lifecycle to `trace`. Trace profiling requires tracing to be enabled.

Check out the [tracing setup documentation](https://docs.sentry.io/platforms/android/tracing.md) 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 an activity and app startup.

```xml
<application>
  <meta-data
    android:name="io.sentry.dsn"
    android:value="https://<key>@o<orgId>.ingest.sentry.io/<projectId>"
  />
  <!-- 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"
  />
</application>
```

*Other available variations of the above snippet: java, kotlin*

### [Enabling Manual Lifecycle UI Profiling](https://docs.sentry.io/platforms/android/profiling.md#enabling-manual-lifecycle-ui-profiling)

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

```xml
<application>
  <meta-data
    android:name="io.sentry.dsn"
    android:value="https://<key>@o<orgId>.ingest.sentry.io/<projectId>"
  />
  <!-- 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"
  />
</application>
```

*Other available variations of the above snippet: java, kotlin*

## [Limitations](https://docs.sentry.io/platforms/android/profiling.md#limitations)

On Android 15 (API level 35) and higher, UI Profiling relies on the Android ProfilingManager, so the following limitations apply:

* **Older devices use the legacy profiler.** On devices below Android 15, the SDK automatically falls back to [Legacy Profiling](https://docs.sentry.io/platforms/android/profiling/legacy.md), which has different characteristics. You can disable this fallback with the [`enableLegacyProfiling`](https://docs.sentry.io/platforms/android/configuration/options.md#enableLegacyProfiling) option.
* **App start profiling is not supported.** The `startProfilerOnAppStart` option has no effect with the ProfilingManager (Perfetto) backend. App start profiling is only supported by the legacy profiler used on devices below Android 15. To learn more, see [Legacy Profiling](https://docs.sentry.io/platforms/android/profiling/legacy.md).
* **Profiling requests are rate limited and not guaranteed to be fulfilled.** Apart from the SDK sampling rate, the Android Framework also restricts profiling, so not every request results in a profile. These limits are outside the SDK's control. To learn more, see the Android [ProfilingManager](https://developer.android.com/reference/android/os/ProfilingManager) documentation.

##### Disabling Rate Limiting for Local Testing

When testing locally, you can disable the Android Framework restrictions with the following shell command:

```bash
adb shell device_config put profiling_testing rate_limiter.disabled true
```

## Pages in this section

- [Legacy Profiling](https://docs.sentry.io/platforms/android/profiling/legacy.md)
- [Troubleshooting](https://docs.sentry.io/platforms/android/profiling/troubleshooting.md)
