---
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/explore/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.

##### Important

Profiling uses the Android runtime's `tracer` under the hood to sample threads. There are known issues that this `tracer` can cause crashes in certain circumstances. See this [troubleshooting](https://docs.sentry.io/platforms/android/profiling/troubleshooting.md#i-see-elevated-number-of-crashes-in-the-android-runtime-when-profiling-is-activated) entry for more information.

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

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](https://docs.sentry.io/platforms/android/configuration/options.md#transaction-based-profiling-options).

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

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 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](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 a view controller/activity and app startup.

`AndroidManifest.xml`

```xml
<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>
```

### [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.

`AndroidManifest.xml`

```xml
<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>
```

### [Enabling Transaction-Based Profiling](https://docs.sentry.io/platforms/android/profiling.md#enabling-transaction-based-profiling)

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](https://docs.sentry.io/platforms/android/profiling.md#enabling-trace-lifecycle-ui-profiling). In order to upgrade to UI Profiling, you also need to remove the [transaction-based profiling options](https://docs.sentry.io/platforms/android/configuration/options.md#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.

`AndroidManifest.xml`

```xml
<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>
```

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.

## Pages in this section

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