IntelliJ IDEA 2020.2 Help

Async Profiler

Async Profiler monitors JVM-level parameters of your application to provide a better understanding of how your application is executed and how exactly memory and CPU resources are allocated. This data can help you find and resolve performance problems and bottlenecks.

Async Profiler does not require threads to be at safe points to be able to sample stacks, which means that it avoids the safepoint bias problem. On top of that, the profiler features Flame Graph support that allows it to visualize stack traces.

Async Profiler

Adjust kernel options before you start using the profiler on Linux. On macOS, the profiler works out of the box.

Adjust kernel options on Linux

  1. Adjust perf_event_paranoid. This option controls the use of the performance events data by non-root users.

    Set the value to be less than 2 to let the profiler collect performance information without root privileges:

    sudo sh -c 'echo 1 >/proc/sys/kernel/perf_event_paranoid'
  2. Adjust kptr_restrict. This option sets restrictions on exposing kernel addresses.

    To have kernel symbols properly resolved, disable the protection offered by kptr_restrict by setting its value to 0:

    sudo sh -c 'echo 0 >/proc/sys/kernel/kptr_restrict'

By default, these changes affect your current OS session only. To keep the settings across system reboots, run:

sudo sh -c 'echo kernel.perf_event_paranoid=1 >> /etc/sysctl.d/99-perf.conf' sudo sh -c 'echo kernel.kptr_restrict=0 >> /etc/sysctl.d/99-perf.conf' sudo sh -c 'sysctl --system'

Profiler configurations

IntelliJ IDEA features two pre-defined Async Profiler configurations: the CPU profiler and the memory allocation profiler that you can find in Settings/Preferences | Build, Execution, Deployment | Java Profiler.

Configuring CPU profiler configuration

These configurations are adjusted to provide the most accurate results, that is why they don't require any modifications. However, you can still change the values in the settings.

Modify a profiling configuration

  1. In the Settings/Preferences dialog Ctrl+Alt+S, select Build, Execution, Deployment | Java Profiler.

  2. Select one of the pre-defined CPU or memory profiling configuration or copy the template configuration by clicking the Add button.

  3. Change the values in the Agent options field and apply the changes. For more information, refer to Async Profiler on GitHub.

Profile your application with Async Profiler

You can run the profiler for projects built with Gradle and with the native IntelliJ IDEA build tool. If you use Maven, you can run the application with the native IntelliJ IDEA runner to get the profiling data.

Use any of the following options to analyze your application:

  • Click Profiler on the toolbar (or click the the Run button icon in the gutter) and select Run 'run configuration name' with 'profiler configuration name':

    run with profiler

  • From the main menu, select Run | Run with Profiler and then select the necessary configuration (Run 'run configuration name' with 'configuration name').

    (Only for Linux) Upon the first launch of the profiler, IntelliJ IDEA checks whether kernel variables are already set up and suggests the necessary changes:

    adjust linux kernel variables for the profiler

When the profiling data is ready, you will see a confirmation popup together with the Profiler tool window bar. Click this bar to open the Profiler tool window or go to View | Tool Windows | Profiler if you don't use tool window bars.

Profiler popup informing that the data is ready

When the analysis is finished, you can review and analyze the reports.

Last modified: 19 August 2020