Friday, April 11, 2014

Looking for a Java Profiler. No IntelliJ IDEA profiler? What to do?

I have previously written about NetBeans 8 vs. IntelliJ IDEA 13. One thing I am missing in IntelliJ is a profiler. The advantages in having a profiler integrated into the IDE compared to having the profiler running on the side are multiple: the profiler is integrated into the IDE's start application functionality and so is the ability to go directly to the (slow) profiled code to name a few.

However, IDEA does not ship with a profiler. I know that it integrates very nicely with JProfiler but that is a rather expensive tool. This led me to look for other options. I have previously used VisualVM but Mission Control caught my eye as it has a cool feature called Flight Recorder (a low overhead profiler that you can use in production). It requires you have a recent JVM that bundles Mission Control (a recent Java 7 or 8 will do) + for running your app with the extra options that I'll show below.

Run options

From within IDEA: 

To address the first problem, profiling a unit test or app from with IDEA, here is what I do. When you start you app or unit test from with in IDEA add this to the run configuration's VM options:

-XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:StartFlightRecording=duration=120m,filename=recording.jfr

It starts the flight recorder immediately and runs it for up to 120 minutes. It puts the results in a file called recording.jfr in the root project folder. When done or after 120 minutes you can then open the file using Mission Control and view for instance the Code tab's Hot Methods tab.

Of course you can also just connect Mission Control to the running process that is execution you code directly. You do this by having Mission Control open and select the the Flight Recorder item in the JVM Browser of the process. But it is nice to know that you can make it start along side the actual application start using the above configuration.

Options intermezzo:

When you want to do more experimentation you can add an extra settings argument to the XX:StartFlightRecording (see Maven example below). The argument must equal a file name in the JRE_HOME/lib/jfr folder. The files contain information on for instance sampling rate, what will be recorded (for instance what JVM and OS metrics) etc. You can edit it in Mission Control in the Flight Recording Template Manager.

From the console using Maven:

If you prefer the console, here are some nifty Maven commands:

To run tests that match Profile* and profile them (note that if you use Surefire and already have an argLine in the pom.xml file, then you can't override it from the console):

mvn -Dtest=Profile* test -DargLine="-XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:StartFlightRecording=filename=result.jfr,duration=120m,settings=MyWicketSettings.jfc"

Run app with profiling enabled (here a Spring boot app):

MAVEN_OPTS="-XX:+UnlockCommercialFeatures -XX:+FlightRecorder" mvn spring-boot:run

With that command you have enabled Flight Recorder. You can then open Mission Control when you want to look at the apps performance etc.


  1. The effectiveness of IEEE Project Domains depends very much on the situation in which they are applied. In order to further improve IEEE Final Year Project Domains practices we need to explicitly describe and utilise our knowledge about software domains of software engineering Final Year Project Domains for CSE technologies. This paper suggests a modelling formalism for supporting systematic reuse of software engineering technologies during planning of software projects and improvement programmes in Final Year Project Centers in Chennai.

    Spring Framework has already made serious inroads as an integrated technology stack for building user-facing applications. Spring Framework Corporate TRaining the authors explore the idea of using Java in Big Data platforms.
    Specifically, Spring Framework provides various tasks are geared around preparing data for further analysis and visualization. Spring Training in Chennai

  2. Great post, and great website. Thanks for the information! Kopar at Newton Kampong Java Road

  3. It is the key strength of Python. Instead of curly braces, indentation helps in easy readability and understandability of the program. Well-indented code delimits the blocks of code in a program. It is very important for writing or understanding a code. unindent does not match any outer indentation level python

  4. Pretty nice post. I just stumbled upon your weblog and wanted to say that I have really enjoyed browsing your blog posts. After all I’ll be subscribing to your feed and I hope you write again soon! Europa-Road targonca szállítás Debrecen