<

Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x

Profiling Java 8 with Java Flight Recorder and Java Mission Control in Eclipse

Published on
6,222 Points
3,022 Views
2 Endorsements
Last Modified:
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collection framework built into the Oracle JDK. It allows Java administrators and developers to gather detailed low level information about how the Java Virtual Machine (JVM) and the Java application are behaving. Java Mission Control is an advanced set of tools that enables efficient and detailed analysis of the extensive of data collected by Java Flight Recorder. The tool chain enables developers and administrators to collect and analyze data from Java applications running locally or deployed in production environments.

The Java Flight Recorder does not trace every function call that gets executed. Instead, it "samples" the application at regular intervals, collecting stack trace information about each thread being executed. So if you're looking for how many times a certain function is being called, or how much total time is spent executing a certain method, you're not going to find that kind of information. However, by analyzing the samples taken, you can still determine where your application is spending most of its time.

We'll assume, at this point, that Java 8 and Eclipse are already installed. If they are not, they can be found at the following locations:
Additionally, a couple of eclipse plugins, that contain the Java Flight Recorder and Java Mission Control tools, will need to be installed. This can be done within Eclipse by going to:
To make things simpler, we'll also install the Flight Recorder Launch Configuration Tab tool:

Once that's complete, create a simple java application that could use some optimization:
   public static void main(String[] args)
   {
      // These values may need to change depending upon the speed of your machine.
      // You want this app to run for approximately 60 seconds to get usable results
      final int outerIterations = 1000;
      final int innerIterations = 10000;

      for (int outer = 0; outer < outerIterations; outer++)
      {
         StringBuilder message = new StringBuilder();

         for (int inner = 0; inner < innerIterations; inner++)
         {
            message.append(inner);
         }

         System.out.println(message);
      }
   }

Open in new window


Create a Run Configuration for the java application:
  • Run -> Run Configurations...
    • Java Application -> New
Within the Run configuration, select the Flight Recorder tab.
Make sure the following two options are checked:
  • Enable - This will create a flight recording of the running application
  • Open recording - This will automatically open the flight recording when the application completes

Now run the application using the Run configuration. Once the application is finished, and the flight recording is open, we can see a lot of information about the running application.
  • Select the Code tab on the left.
    • From here we can see the packages and classes in which the application is spending its time.
  • Select the "Hot Methods" tab on the bottom (still within the Code tab on the left)
    • Here we can see the methods in which the application is spending its time
  • Select the "Call Tree" tab on the bottom
    • Here we can see the stack traces in which the application is spending most of its time
With the information collected in these places, we can see that this sample application is spending most of its time converting the ints to chars when appending them to the StringBuilder.
  • Select the Memory tab on the left
  • Select the Garbage Collections tab on the bottom (still within the Memory tab on the left)
Here we can see in the graph the memory that gets used as we append to the StringBuilder. We can also see when the garbage collector releases the memory, after each iteration of the inner loop, when the StringBuilder no longer has a reference.
2
Comment
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
0 Comments

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Join & Write a Comment

Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month