Features Releases

Java Profiling Tools and IntelliJ IDEA

By profiling your Java application, you can discover the methods that execute in your application and for how long. Using these metrics, you can determine ways to improve the performance of your system.

In this blog post, I’ll walk you through the support that IntelliJ IDEA has for profiling Java applications. Let’s get started.

Download IntelliJ IDEA

Run your application with a profiler

There are multiple ways you can start profiling your application. You can click on the start icon in the gutter and select Profile ‘[your app name]’ with IntelliJ Profiler. This option can also be selected from the three-dots menu or by typing Run with Profiler in Search Everywhere (Shift+Shift or ⇧⇧).

Start profiling in IntelliJ IDEA

The output window will then display the Profiler data is ready message, with the option Open to view the profiled data. If you miss the popup that lets you view the profiled data, you can open the Profiler tool window by clicking on the relevant icon.

Profiler data is ready in IntelliJ Profiler

In the Profiler tool window, you will find the following tabs: Flame Graph, Call Tree, Method List, Timeline, and Events.

IntelliJ Profiler tabs

Working with Flame Graph and Call Tree

Flame Graph

Every rectangle in a flame graph represents a function name with native calls and Java calls. The blocks are relative and they represent a snapshot of the total time on the CPU.

Flame graph view in IntelliJ Profiler

A flame graph is not a time series – it doesn’t show the sequence of calling of methods in an application. It shows which methods are calling other methods (this is how the method stacks are represented), for how long, and where they are executed. This graph might suggest where the problems are and where to optimize. A flame graph is another way of stating: “hey, this is what happened when we profiled your application, and we grouped it”.

A flame graph won’t disclose which tasks were performed or called before or after. It lets you find out the total CPU time that is being spent by your application. For example, if it spends 29% of the time on the methodA() method, that doesn’t mean it takes a lot of time to execute. It could also mean that you are calling it many times. So you could either think of reducing the number of calls to this method or optimize it so it executes in less time.

Call Tree

Flame graphs could be represented in a textual form, using Call Trees, showing how methods are called and the percentage of total CPU time used by them.

Call Tree shows the method execution path in your application. You could use them to get a quick overview of application activity, examine the execution path of slowest methods, determine critical execution paths and much more.

Call Tree view in IntelliJ Profiler

Using Search method in a Flame Graph

Application profiling can generate a lot of data. To quickly navigate to the metrics for a method you are looking for, you search it in the Flame Graph view. Transitioning to the Call Tree is easy too. Right-click the method name and select Focus on method in Call Tree.

search method in Call Tree and Flame Graph

Opening Merge/back

You can view Method Merged Callees when you right-click a method name in flame graph or call list.

Method Merge Callees view in IntelliJ Profiler

Method List

As the name suggests, Method Lists shows a list of methods that executed when you profiled your data, with the samples count.

Method List view in IntelliJ Profiler

Events

The Events view enables you to see all data related to JVM events like class loadings, garbage collections, OS events, and many more.

Events view in IntelliJ Profiler

Export and import of profiling results

To export a profiling data click on a Process from the Profiler tools Home window and choose Capture Memory Snapshot.

The profiled data can be stored in a file or snapshot. You can import profiling results created through other utilities or IntelliJ IDEA by clicking on Open Snapshot and selecting the file:

Capture Memory Snapshot in IntelliJ Profiler

With out-of-the-box support for profiling, IntelliJ IDEA makes it easier for you to profile your applications without leaving your IDE.

Happy Profiling with IntelliJ IDEA!

See more:

image description