Jump to content
We've recently updated our Privacy Statement, available here ×
  • Using Visual VM with JasperReports Server to view call traces


    gdmoreno
    • Product: JasperReports® Server

    Introduction

    Viewing call traces is an important debugging activity, which allows the developer to see exactly what methods the applications is calling, in what order, and how much time it takes to execute. This is useful for looking analyzing bottlenecks, and for verifying that classes that you expected to run actually did.

    While there are many tools out in the market that do this, Visual VM stands out because it's part of the JDK itself; no extra expense, and no extra downloads are necessary.

    Enable JMX in the Tomcat startup script

    To be able to run Visual VM, you'll need to modify the Tomcat startup scripts, and activate JMX. To activate JMX, open up the setenv.bat or setenv.sh file in the [TOMCAT_HOME]/bin directory and add the lines below. I did this on a Windows machine; you'll have to substitute REM for # in a Unix-based system.

    REM For enabling JMX (for using with Visual VM)
    set CATALINA_OPTS=-Dcom.sun.management.jmxremote
    set CATALINA_OPTS=%CATALINA_OPTS% -Dcom.sun.management.jmxremote.port=8999
    set CATALINA_OPTS=%CATALINA_OPTS% -Dcom.sun.management.jmxremote.ssl=false
    set CATALINA_OPTS=%CATALINA_OPTS% -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=localhost
    

    The "8999" could be any open port you want; that value is just an example. When you are done testing with Visual VM, I suggest you add a "REM" (the Windows command for commenting out a line) at the start of each line. That way you can come back later, remove the REM's, and test again.

    Use the Visual VM tool in the JDK

    Browse to where you've installed the JDK, and in the bin directory, you should the VisualVM executable. It's a graphical desktop application. On Windows environments, it appears at "jvisualvm.exe"; in Unix-based systems, it appears simply as "jvisualvm." Go ahead and double-click on it.

    Make sure to add the "VisualVM-Sampler" plugin

    This plugin will record the application call trace, so you've got to install it if it's not already there. To check the installed plug-ins, choose "Tools -> Plugins" from the menu, and a new pop-up will appear. Check the VisualVM-Sample choice, and click "Install." This will take through the installation process, eventually asking you to re-start the application. Once you restart, you'll see that the "VisualVM-Sampler" plugin now appears under the "Installed" tab.

    Running Visual VM

    Now that you have the plugin installed, it's time to connect Visual VM with Tomcat. At this point, you should have already restarted Tomcat with the updated setenv file.

    Choose "File -> Add JMX Connection", and fill in Connection details. If you're running this test locally, you'll put something like "localhost:8999", where the "8999" is the port you defined in the setenv script earlier.

    After you click "OK", your connection will appear in the "Applications" bar on the left, like below:

    Visualvm1.png.f15c421f8aca2dce7f2030360e95ba91.png

    Double-click on the entry, and you'll get a new set of options:

    Visualvm2.png.1730380f8f06d1fa0235837d0639e3b1.png

    Click on the "Sampler" tab, if you haven't done so already, and now you're ready to record the application call traces.

    Click on the CPU button, and you should now see call activity, like below:

    Visualvm3.png.40a3d230b5068c12c42d0f8dfb3f6344.png

    At this point, go ahead and do the application activity you were interested in, whether it's executing reports, running ad hoc, or some area of the application. This will generate the call trace you were interested in testing, which will result in something like what you see below:

    Visualvm4.png.94b95563fd96d9ff880913b268aff3a2.png

    When you're done, hit the "Stop" button. Then click the "Snapshot" button, which will create a new tab, like what you see below:

    Visualvm5.png.cb899f6c50b374a8004c1c2473157c1b.png

    This will give you a complete call trace, starting at the individual thread level, which you investigate by drilling down into. Or, if you want to check a particular class, you can search for it by doing a Ctrl-F and filling in the name of the class. The result will be the location in the call tree where that class gets executed.


    User Feedback

    Recommended Comments

    There are no comments to display.



    Guest
    This is now closed for further comments

×
×
  • Create New...