Difference between revisions of "Tutorial: Profiling Java Programs"
(→JVisualVM) |
|||
Line 12: | Line 12: | ||
<br /> | <br /> | ||
− | + | =VisualVM= | |
<br /> | <br /> | ||
− | + | * On some system '''Java VisualVM''' is already part of the installed software, so test first if you have it. It is sometimes in the Applications folder under Java VisualVM, or sometimes it starts in the Terminal with the command '''jvisualvm'''. | |
− | |||
* VisualVM can be downloaded from [http://visualvm.java.net/download.html visualvm.java.net]. Once you have downloaded and installed it, you should be ready for running the application. | * VisualVM can be downloaded from [http://visualvm.java.net/download.html visualvm.java.net]. Once you have downloaded and installed it, you should be ready for running the application. | ||
* The documentation for VisualVM is available [http://visualvm.java.net/docindex.html here]. | * The documentation for VisualVM is available [http://visualvm.java.net/docindex.html here]. | ||
Line 23: | Line 22: | ||
=The Packing Application= | =The Packing Application= | ||
− | * The packing application we are going to use for this tutorial is a Processing application. The YouTube movie | + | * The packing application we are going to use for this tutorial is a Processing application. The YouTube movie below illustrates how it proceeds at packing randomly sized rectangles into a larger rectangle. |
* Setup the packing application either as an Eclipse project, or using the Processing IDE. If you are using Eclipse, do not forget to include the '''core.jar''' as an external library in your '''Build Path'''. | * Setup the packing application either as an Eclipse project, or using the Processing IDE. If you are using Eclipse, do not forget to include the '''core.jar''' as an external library in your '''Build Path'''. | ||
+ | * Run the application (or watch the movie) and observe that the application starts quite fast, but slows down significantly. One factor is the fact that the list containing the random rectangles is sorted by decreasing area, and the algorithm picks them largest first, smallest last. So as the algorithm progresses with the packing from left to right, it packs smaller and smaller rectangles and the right frontier advances more slowly than at first. | ||
+ | The second reason is that there is potentially some bottleneck in the program. VisualVM should allow us to look at different aspects of the program. | ||
+ | |||
+ | =Starting Monitoring the Processing/Java Application= | ||
+ | * First start Java Visual VM. | ||
+ | <br /> | ||
+ | <center>[[Image:JavaVisualVM1.jpg|600px]]</center> | ||
+ | <br /> | ||
+ | * Start your packing application. In our case we are starting it from Eclipse. As soon as the applet opens and fills up with purple rectangles, a new entry appears in the Java VisualVM window: | ||
+ | <br /> | ||
+ | <center>[[Image:JavaVisualVM2.jpg|600px]]</center> | ||
+ | <br /> | ||
+ | * Click on the new entry, and in the right panel click on Monitor: | ||
+ | <br /> | ||
+ | <center>[[Image:JavaVisualVM3.jpg|600px]]</center> | ||
+ | <br /> | ||
+ | |||
+ | |||
+ | |||
+ | |||
<br /> | <br /> | ||
<br /> | <br /> |
Revision as of 14:46, 30 September 2013
--D. Thiebaut (talk) 15:01, 30 September 2013 (EDT)
This tutorial is intended to give a brief overview of JVisualVM, the profiler for Java. We use this profiler with Eclipse and use a 2D-packing application as our target application. Our goal is to figure out where the program is spending most of its time. The environment used to create this tutorial is VisualVM 1.3.6 running on OS X 10.7.5, and the hardware is a 2.8 GHz dual quad-core MacPro.
VisualVM
- On some system Java VisualVM is already part of the installed software, so test first if you have it. It is sometimes in the Applications folder under Java VisualVM, or sometimes it starts in the Terminal with the command jvisualvm.
- VisualVM can be downloaded from visualvm.java.net. Once you have downloaded and installed it, you should be ready for running the application.
- The documentation for VisualVM is available here.
The Packing Application
- The packing application we are going to use for this tutorial is a Processing application. The YouTube movie below illustrates how it proceeds at packing randomly sized rectangles into a larger rectangle.
- Setup the packing application either as an Eclipse project, or using the Processing IDE. If you are using Eclipse, do not forget to include the core.jar as an external library in your Build Path.
- Run the application (or watch the movie) and observe that the application starts quite fast, but slows down significantly. One factor is the fact that the list containing the random rectangles is sorted by decreasing area, and the algorithm picks them largest first, smallest last. So as the algorithm progresses with the packing from left to right, it packs smaller and smaller rectangles and the right frontier advances more slowly than at first.
The second reason is that there is potentially some bottleneck in the program. VisualVM should allow us to look at different aspects of the program.
Starting Monitoring the Processing/Java Application
- First start Java Visual VM.
- Start your packing application. In our case we are starting it from Eclipse. As soon as the applet opens and fills up with purple rectangles, a new entry appears in the Java VisualVM window:
- Click on the new entry, and in the right panel click on Monitor: