Tips & Tricks

Profile Java and Kotlin Code with the IntelliJ Profiler

At JetBrains, we believe that profiling Java and Kotlin code should be simple and accessible to all developers, regardless of their level of expertise. That’s why the IntelliJ Profiler puts ease of use and seamless integration at the forefront of its mission.

In previous releases, we introduced a range of features to support these efforts. These include a single out-of-the-box configuration that spares you tedious setup, as well as the Home tab of the Profiler tool window. This tab makes it easy to attach the profiler to a running process.

We’re continuing on our mission to simplify profiling, and we want to share some of our progress with you.

Start profiling with the IntelliJ Profiler

Fast start

First, you can now attach the profiler and capture a memory dump for a running Java or Kotlin program right from the Run tool window:

Menu in the Run tool window allowing you to attach to a process

Find synchronization issues and bottlenecks

Second, the profiling report has become more informative. The default configuration now also profiles sleeping and waiting threads. This enables you to detect synchronization issues and external bottlenecks like long service calls and other I/O interactions. Together with milliseconds as the new default measurement unit, this makes profiling more intuitive and transparent.

On the screenshot below, you can see a timeline with color-coding for threads’ busy states (green) and waiting states (red):

Timeline showing a thread that performed some activity among other, mostly sleeping threads

In-editor performance hints

Finally, in a particularly exciting update, you no longer need to leave your code to view profiling data. When you open a snapshot, lines of code that took a significant amount of time to execute are labeled with their respective runtimes.

Line profiler label in the gutter indicating the total duration of the line's execution

Hot lines are indicated with a distinctive red fire icon:

Red label in the gutter indicating a hot line

Clicking on a label takes you directly to its declaration, enabling you to examine the method’s implementation in detail and pinpoint slow lines. If this does not give you enough granularity, you can continue to drill down until you find the root cause.

Line profiler hints in the method, to which we navigated by clicking the gutter label near it

While this feature can definitely be used in large-scale projects, we hope that it will be equally useful for novice users and smaller problems like evaluating the performance of a LeetCode submission.

Comparing search algorithm performance with line profiler

If you need more advanced views, like Flame Graph and Call Tree, you can still access them through the Profiler tool window.

If you’re new to profiling and interested in these updates, don’t hesitate to give the new features a try. To learn about more advanced techniques and in-depth profiling with IntelliJ IDEA, we recommend following these tutorials:

More exciting improvements are on their way, so stay tuned!

image description