Profiling the Java application

  1. Run jvisualvm from the <JDK_HOME>/bin folder:
Figure 11.1: Java VisualVM profiler

VisualVM lists all the Java processes that can be profiled by it on the local machine under the Local node. You can see VisualVM itself listed along with Eclipse.

  1. Once you run the CourseManagement application, the process should also show up under Local:
Figure 11.2: The CourseManagement application available for profiling
  1. Double-click on the process (or right-click and select Open). Then, go to the Profile tab and click on the CPU button:
Figure 11.3: VisualVM Profiler tab

You should see the status set as profiling running.

  1. After starting CPU profiling, if you get an error such as Redefinition failed with error 62, try running the application with the -XVerify:none parameter. In Eclipse, select the Run | Run Configurations menu and then select the CourseManagement application under the Java Application group. Go to the Arguments tab and add -Xverify:none to VM arguments. Run the application again.
  2. In the VisualVM Profiler page, click on the Settings checkbox to see the packages included for profiling. Note that VisualVM selects these packages automatically:
Figure 11.4: VisualVM Profiler settings
  1. You must stop CPU profiling to edit the settings. However, we will retain the default settings. Uncheck the Settings box to hide the settings.
  2. Click on the Monitor table for the overview of profiling activities:
Figure 11.5: Overview of profiling activities
  1. Now, let's execute the getCourse method in our application. Go to the console view of Eclipse in which our application is running, type a character (other than q), and hit Enter. Go to the Profiler tab of VisualVM to view the profiled data:
Figure 11.6: CPU profiling of CourseManagement

Observe the Self time column. This indicates the CPU time or the elapsed time to execute the corresponding method, excluding the time taken to execute other methods called from this method. In our case, CourseDAO.getCourses took the maximum time, so it is at the top of the list. This report could help you identify the bottlenecks in your application.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.135.36