IntelliJ IDEA 2024.2 Help

Custom profiler configurations

For CPU and allocation profiling, IntelliJ IDEA provides integration with the following profilers:

  • Java Flight Recorder – a standard profiling tool shipped as part of the JDK.

  • Async Profiler – a very accurate profiler that can also collect native call and memory allocation data.

By default, IntelliJ IDEA runs both profilers in parallel to provide the most accurate results. While it is possible to use the supported profilers separately, the combined configuration that you get out of the box is a better choice for most scenarios. This approach leverages the advantages of both profilers and abstracts you from any setup whatsoever unless you have very specific requirements.

The Async Profiler and Java Flight Recorder configurations allow you to run these tools separately and fine-tune them according to specific requirements. This topic describes how to set up these configurations and environment.

Create a separate profiler configuration

  1. Go to Settings | Build, Execution, Deployment | Java Profiler.

  2. Click Add New Configuration and select the profiler.

  3. Modify the profiler options as required.

    For the options' meaning and purpose, refer to the Async Profiler and Java Flight Recorder chapters respectively.

Async Profiler

On Windows and macOS, the profiler works out of the box. If you are on Linux, you have to adjust kernel options before you start profiling.

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'

Configuration options

Option

Description

Agent Options

The options that will be passed to the agent. They can be used, for example, to enable wall-clock profiling, or adjust the sampling interval.

Agent

The agent that will be used for profiling.

Java Flight Recorder

Java Flight Recorder is available on Windows, Linux, and macOS. It is supported natively in the following JDK builds:

  • Oracle JDK 8-10: provided that the UnlockCommercialFeatures VM option is enabled

  • Oracle JDK 11 and later

  • OpenJDK 11 and later

Enable JFR for Oracle JDK 8-11

  1. In the main menu, go to Run | Edit Configurations and from the list on the left, select the run configuration that you want to analyze with JFR.

  2. To the VM options field, add the following line: -XX:+UnlockCommercialFeatures.

  3. Apply the changes and close the dialog.

Enabling JFR

JFR configurations

There are two pre-installed configurations: Default and Profile. The Default configuration has low overhead (about 1%). That's why it works well for continuous profiling. The Profile configuration has overhead about 2% and can be used for more detailed application profiling.

These configurations cover most use cases. You can select the most suitable configuration in Settings | Build, Execution, Deployment | Java Profiler | Java Flight Recorder.

If the pre-defined configurations don't meet your needs, you can create and upload your own settings by means of Java Mission Control.

Create a custom JFR configuration (optional)

  1. Run Java Mission Control that you can find in JAVA_HOME/bin/jmc or download from https://jdk.java.net/jmc/.

  2. From the Java Mission Control main menu, select Window | Flight Recording Template Manager.

  3. Click Import Files on the panel on the right and select one of the pre-installed configurations in the .jfc format:

    • For Java 10 and earlier: JAVA_HOME/jre/lib/jfr/

    • For Java 11 and later: JAVA_HOME/Contents/Home/lib/jfr/

  4. Select Edit | Advanced, change the necessary settings, and click OK.

  5. In the Flight Recording Template Manager dialog, click Export File.

  6. Specify another name for the new settings file and change its location if necessary. Click Save.

For more information about configuring custom settings, refer to Controlling Recording Data by Using Templates.

Load the custom configuration to the IDE (optional)

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

  2. Select the Java Flight Recorder profiling configuration to which you want to load your custom settings or create a new configuration by clicking the Add button.

  3. In the Profiling Settings area, select the Custom settings file option and click the Browse button.

  4. Specify the path to the custom settings file and click Open.

  5. Apply the changes and close the dialog.

Last modified: 17 June 2024