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.

Profiling depends on Sentry’s performance monitoring product being enabled beforehand. To enable performance monitoring in the SDK:

Copied
import Sentry

SentrySDK.start { options in
    options.dsn = "https://examplePublicKey@o0.ingest.sentry.io/0"
    options.tracesSampleRate = 1.0
}

Check out the performance 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.

iOS profiling is available starting in SDK version 8.12.0.

Copied
import Sentry

SentrySDK.start { options in
    options.dsn = "https://examplePublicKey@o0.ingest.sentry.io/0"
    options.tracesSampleRate = 1.0 // tracing must be enabled for profiling
    options.profilesSampleRate = 1.0 // see also `profilesSampler` if you need custom sampling logic
    options.enableAppLaunchProfiling = true // experimental new feature to start profiling in the pre-main launch phase
}

The profilesSampleRate setting is relative to the tracesSampleRate setting.

This feature is experimental and may have bugs.

(New in version 8.21.0)

Normally, a profile can only be taken during a trace span after the SDK has been initialized. Now, you can configure the SDK to automatically profile certain app launches.

To set up launch profiling, use the enableAppLaunchProfiling option and configure the sample rates for traces and profiles with SentrySDK.startWithOptions to determine if the subsequent app launch should be automatically profiled. This allows you to gather information on what is going on in your app even before main is called, making it easier to diagnose issues with slow app launches.

If you use SentryOptions.tracesSampler or SentryOptions.profilesSampler, it will be invoked after you call SentrySDK.startWithOptions, with SentryTransactionContext.forNextAppLaunch set to true indicating that it's evaluating a launch profile sampling decision. If instead you simply set SentryOptions.tracesSampleRate and SentryOptions.profilesSampleRate, those numerical rates will be used directly.

Currently, launch profiles are attached to a special performance transaction operation called app.launch and displayed in the product simply as launch.

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").