Set Up Profiling

Learn how to enable profiling in your app if it is not already set up.

With profiling, 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 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.

Android profiling is available starting in SDK version 8.7.0. The legacy profiler is available on SDK versions 6.16.0 and higher through its options.

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.

AndroidManifest.xml
Copied
<application>
  <meta-data
    android:name="io.sentry.dsn"
    android:value="https://examplePublicKey@o0.ingest.sentry.io/0"
  />
  <!-- 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 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="https://examplePublicKey@o0.ingest.sentry.io/0"
  />
  <!-- Enable 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>

The legacy 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="https://examplePublicKey@o0.ingest.sentry.io/0"
  />
  <!-- Enable tracing, needed for legacy profiling, adjust in production env -->
  <meta-data
    android:name="io.sentry.traces.sample-rate"
    android:value="1.0"
  />
  <!-- Enable legacy 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").