Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,16 @@ Android Profiling is in Preview.

{% img src="real_user_monitoring/android/android-profiling-ttid.png" alt="Android profiling data in a time to initial display vital event." style="width:90%;" /%}

Android profiling captures detailed data about your application's performance during launch, helping you identify slow methods and optimize startup time. Android profiling is built on top of the [ProfilingManager Android API][4] and samples the device's CPU to collect method call stacks from the application's process.
Android profiling helps you identify and optimize slow methods during important moments in user sessions. Android profiling is built on top of the [ProfilingManager Android API][4] and samples the device's CPU to collect method call stacks from the application's process.

{% alert level="warning" %}
Only devices running Android 15 (API level 35) or higher generate profiling data.
{% /alert %}

## Prerequisites

- Your Android application must use the Datadog Android SDK version 3.6.0+.
- Application launch profiling requires Android SDK version 3.6.0+.
- Continuous profiling requires Android SDK version 3.12.0+.
- [RUM without Limits][5] must be enabled in your organization.

## Setup
Expand All @@ -222,59 +223,83 @@ To start collecting data, set up [Mobile RUM for Android][6].

### Step 2 - Configure the profiling sampling rate

1. Initialize the RUM SDK and configure the `applicationLaunchSampleRate`, which determines the percentage of application launches that are profiled (for example, 15% means profiling runs on 15 out of 100 launches).
Initialize the RUM SDK and configure the `setApplicationLaunchSampleRate` and `setContinuousSampleRate` parameters, which are independent of each other:

{% alert level="danger" %}
If no value is specified, the default `applicationLaunchSampleRate` is 15 percent.
{% /alert %}
- `setApplicationLaunchSampleRate` determines how often the time to initial display is profiled (for example, 15 means profiling runs on 15 out of 100 launches).
Comment thread
arti-arutiunov marked this conversation as resolved.
- `setContinuousSampleRate` determines whether the time to full display, application not responding (ANR) errors, long tasks, or [RUM Operations][19] are profiled (for example, 15 means that 15 out of 100 sessions will have their time to full display, ANRs, and long tasks profiled).

```kotlin
class SampleApplication : Application() {
override fun onCreate() {
super.onCreate()
val configuration = Configuration.Builder(
clientToken = "<CLIENT_TOKEN>",
env = "<ENV_NAME>",
variant = "<APP_VARIANT_NAME>"
).build()
Both sample rates are applied on top of the [RUM session sampling rate][17].

Datadog.initialize(this, configuration, trackingConsent)
{% alert level="danger" %}
If no value is specified, the default for both `setApplicationLaunchSampleRate` and `setContinuousSampleRate` is 15%.
{% /alert %}

// Enable RUM (required for Profiling)
val rumConfig = RumConfiguration.Builder(applicationId)
```kotlin
class SampleApplication : Application() {
override fun onCreate() {
super.onCreate()
val configuration = Configuration.Builder(
clientToken = "<CLIENT_TOKEN>",
env = "<ENV_NAME>",
variant = "<APP_VARIANT_NAME>"
).build()

Datadog.initialize(this, configuration, trackingConsent)

// Enable RUM (required for Profiling)
val rumConfig = RumConfiguration.Builder(applicationId)
.build()
Rum.enable(rumConfig)

// Enable Profiling
Profiling.enable(
ProfilingConfiguration.Builder()
.setApplicationLaunchSampleRate(15f)
.setContinuousSampleRate(15f)
.build()
Rum.enable(rumConfig)

// Enable Profiling
val profilingConfig = ProfilingConfiguration.Builder()
.setApplicationLaunchSampleRate(15) // default is 15%
.build()

Profiling.enable(profilingConfig)
}
)
}
```
}
```

{% alert level="warning" %}
The total volume of profiles may not match the percentage configured in `applicationLaunchSampleRate`. This variation results from [rate limitations](https://developer.android.com/topic/performance/tracing/profiling-manager/will-my-profile-always-be-collected#how-rate-limiting-works) within the data collector, including profiling support on older devices and the maximum profiling frequency per device.
{% /alert %}
{% alert level="warning" %}
The total volume of profiles may not match the percentage configured in `applicationLaunchSampleRate` or `continuousSampleRate`. This variation results from [rate limitations][20] within the data collector, including profiling support on older devices and the maximum profiling frequency per device.
{% /alert %}

The [ProfilingManager API][7] also supports disabling rate limiting during debug builds.

## Explore profiling data

Profiling data is captured on vitals and rolls up to views and sessions. Use `@profiling.has_profile` in the Sessions Explorer to filter to profiled events and investigate which code ran and how it affected the user's experience. This is available for sessions, views, and vitals.
You can use the `@profiling.has_profile` attribute in the Sessions Explorer to filter to profiled events and investigate which code ran and how it affected the user's experience. This is available for sessions, views, errors, long tasks, vitals, and operations.

### During the time to initial display
### During the time to initial display and time to full display

Android application launch profiling data is attached to the [time to initial display][8] vital event in a RUM session. You can access the time to initial display from the session side panel, view side panel, or directly from the time to initial display vital side panel.
Android application launch profiling data is attached to the [time to initial display][8] and [time to full display][8] vital events in a RUM session. You can access profiles for the time to initial display and time to full display from the session side panel, view side panel, or directly from the vital side panels.

{% img src="real_user_monitoring/android/android-profiling-session.png" alt="Android profiling data in RUM session." style="width:90%;" /%}
{% img src="real_user_monitoring/android/android-profiling-ttfd.png" alt="Android profiling data for a time to full display event." style="width:90%;" /%}

Use the **flame graph** to identify which methods consume the most CPU time during launch, the **thread timeline** to see parallel execution patterns, and the **call graph** to trace method dependencies. You can also download the profiling data for external analysis or deeper investigation.

{% img src="real_user_monitoring/android/android-profiling-thread-timeline.png" alt="Android profiling data for the time to initial display in a thread timeline." style="width:90%;" /%}

### During application not responding errors

Android profiling data is attached to [application not responding (ANR)][16] errors in a RUM session. You can access profiles for ANR errors from the view side panel or from the error event side panel.

{% img src="real_user_monitoring/android/android-profiling-anr.png" alt="Android profiling data for an application not responding error event." style="width:90%;" /%}

### During long tasks

Android profiling data is attached to long task events in a RUM session. You can access profiles for long tasks from the view side panel or from the long task event side panel.

{% img src="real_user_monitoring/android/android-profiling-long-task.png" alt="Android profiling data for a long task event." style="width:90%;" /%}

### During operations

Android profiling data is attached to operations events in a RUM session. You can access profiles for operations from the view side panel or from the operations event side panel.

< TO BE ADDED>

{% /if %}
<!-- end Android -->

Expand All @@ -287,11 +312,12 @@ iOS Profiling is in Preview.

{% img src="real_user_monitoring/ios/ios-profiling-ttid.png" alt="iOS profiling data in a time to initial display vital event." style="width:90%;" /%}

iOS profiling captures detailed data about your application's performance during launch, helping you identify slow functions and optimize startup time. iOS profiling is built on top of the [mach Kernel API][9] and periodically samples all application threads to collect call stacks.
iOS profiling helps you identify and optimize slow methods during important moments in user sessions. iOS profiling is built on top of the [mach Kernel API][9] and periodically samples all application threads to collect call stacks.

## Prerequisites

- Your iOS application must use the Datadog iOS SDK version 3.6.0+.
- Application launch profiling requires iOS SDK version 3.6.0+.
- Continuous profiling requires iOS SDK version 3.14.0+.
- [RUM without Limits][10] must be enabled in your organization.

## Setup
Expand All @@ -301,10 +327,15 @@ To start collecting data, set up [Mobile RUM for iOS][11].

### Step 2 - Configure the profiling sampling rate

Initialize the RUM SDK and configure the `applicationLaunchSampleRate`, which determines the percentage of application launches that are profiled (for example, 5% means profiling runs on 5 out of 100 launches).
Initialize the RUM SDK and configure the `applicationLaunchSampleRate` and `continuousSampleRate` parameters, which are independent of each other:

- `applicationLaunchSampleRate` determines how often the time to initial display is profiled (for example, 5 means profiling runs on 5 out of 100 launches).
- `continuousSampleRate` determines whether the time to full display, application hangs, long tasks, or [RUM Operations] [21] are profiled (for example, 5 means that 5 out of 100 sessions will have their time to full display, application hangs, and long tasks profiled).

Both sample rates are applied on top of the [RUM session sampling rate][21].

{% alert level="danger" %}
If no value is specified, the default `applicationLaunchSampleRate` is 5 percent.
If no value is specified, the default for both `applicationLaunchSampleRate` and `continuousSampleRate` is 5%.
{% /alert %}

```swift
Expand All @@ -330,23 +361,47 @@ If no value is specified, the default `applicationLaunchSampleRate` is 5 percent
)

// Enable Profiling feature
Profiling.enable() // default is 5%
Profiling.enable(with:
Profiling.Configuration(
applicationLaunchSampleRate: 5.0,
continuousSampleRate: 5.0
)
)
```

## Explore profiling data

Profiling data is captured on vitals and rolls up to views and sessions. Use `@profiling.has_profile` in the Sessions Explorer to filter to profiled events and investigate which code ran and how it affected the user's experience. This is available for sessions, views, and vitals.
You can use the `@profiling.has_profile`attribute in the Sessions Explorer to filter to profiled events and investigate which code ran and how it affected the user's experience. This is available for sessions, views, errors, long tasks, vitals, and operations.

### During the time to initial display
### During the time to initial display and time to full display

iOS application launch profiling data is attached to the [time to initial display][12] vital event in a RUM session. You can access the time to initial display from the session side panel, view side panel, or directly from the time to initial display vital side panel.
iOS application launch profiling data is attached to the [time to initial display][12] and [time to full display][12] vital events in a RUM session. You can access profiles for the time to initial display and time to full display from the session side panel, view side panel, or directly from the vital side panels.

{% img src="real_user_monitoring/ios/ios-profiling-session.png" alt="iOS profiling data in a view event to initial display vital event." style="width:90%;" /%}
{% img src="real_user_monitoring/ios/ios-profiling-ttfd.png" alt="iOS profiling data in a time to full display vital event." style="width:90%;" /%}

Use the **flame graph** to identify which functions consume the most Wall time during launch, the **thread timeline** to see parallel execution patterns, and the **call graph** to trace function dependencies. You can also download the profiling data for external analysis or deeper investigation.

{% img src="real_user_monitoring/ios/ios-profiling-thread-timeline.png" alt="iOS profiling data for the time to initial display in a thread timeline." style="width:90%;" /%}

### During application hangs

iOS profiling data is attached to [application hangs][18] in a RUM session. You can access profiles for application hangs from the view side panel or from the error event side panel.

{% img src="real_user_monitoring/ios/ios-profiling-app-hang.png" alt="iOS profiling data in an application hang event." style="width:90%;" /%}

Comment thread
arti-arutiunov marked this conversation as resolved.
### During long tasks

iOS profiling data is attached to long task events in a RUM session. You can access profiles for long tasks from the view side panel or from the long task event side panel.

{% img src="real_user_monitoring/ios/ios-profiling-long-task.png" alt="iOS profiling data in a long task event." style="width:90%;" /%}

### During operations

iOS profiling data is attached to operations events in a RUM session. You can access profiles for operations from the view side panel or from the operations event side panel.

{% img src="real_user_monitoring/ios/ios-profiling-operation.png" alt="iOS profiling data in an operation event." style="width:90%;" /%}


Comment thread
arti-arutiunov marked this conversation as resolved.
{% /if %}
<!-- end iOS -->

Expand All @@ -365,3 +420,9 @@ Use the **flame graph** to identify which functions consume the most Wall time d
[13]: /real_user_monitoring/guide/proxy-rum-data
[14]: /integrations/content_security_policy_logs
[15]: /real_user_monitoring/#supported-endpoints-for-sdk-domains
[16]: /real_user_monitoring/application_monitoring/android/data_collected#error-attributes
[17]: /real_user_monitoring/application_monitoring/android/setup?tab=kotlin#sample-session-rates-2
[18]: /real_user_monitoring/application_monitoring/ios/data_collected#error-attributes
[19]: /real_user_monitoring/operations_monitoring/?tab=browser
[20]: https://developer.android.com/topic/performance/tracing/profiling-manager/will-my-profile-always-be-collected#how-rate-limiting-works
[21]: /real_user_monitoring/application_monitoring/ios/setup?tab=swift-package-manager--spm
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Comment thread
arti-arutiunov marked this conversation as resolved.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading