专栏首页Jerry的SAP技术分享使用VisualVM进行Java应用的性能测量

使用VisualVM进行Java应用的性能测量

Recently I am trying to find a handy tool to measure the performance of my Java application and finally I think the VisualVM provided by JDK is the ideal one. This blog is written based on JDK1.7 + Eclipse 4.3.2.

What is VisualVM

It is a tool automatically available after JDK is installed. The executable file could be found on your /bin as displayed below.

In order to measure the performance of your application, it is necessary for the application to be recognized by VisualVM first. There is a plugin named “VisualVM launcher for Eclipse” which can help us about it.

Install and configure VisualVM launcher

(1) download the zip from http://visualvm.java.net/eclipse-launcher.html. Unzip the file and put it to the plugin folder of your Eclipse installation folder. In my laptop it looks like below. There should be a site.xml inside the unzipped folder.

(2) In Eclipse, choose menu “Help->Install New Software”, click “Local”, add locate the folder to the one you finish in step1.

Then the local downloaded plugin is successfully parsed and ready for install.

finish the installation.

(3) Restart Eclipse, then you can find a new option via the path below. Configure two paths accordingly.

For “JDK Home”, if you configure the JRE path by mistake, later when you try to measure your application, the VisualVM will fail to load with the following error message:

Now the plugin is ready to use.

Do performance measurement

(1) Select your Java project, choose context menu “Run as”->”Run configuration”, create a new Application configuration by specifying VisualVM launcher as its launcher, instead of the default Eclipse JDT launcher.

(2) For example I have a Java application which sorts an array by QuickSort algorithm written by myself and I would like to get its performance data, then I set a breakpoint on line 57, before my main logic is executed. Then launch the application in debugging mode with the application configuration created in previous step. Afterwards VisualVM will automatically be launched and successfully recognize the execution of my application. Click Profiler tab:

Current status: profiling inactive. Click CPU button:

Now profiling is activated:

(3) Go back to Eclipse and click F8 to finish execution. Once finished, VisualVM will immediately capture this event and notify you. Just click Yes to get performance result.

The result is displayed as below:

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • 如何把ABAP视图添加到SAPGUI的收藏夹里

    Suppose I need to add the maintenance view COMV_PARTNER_FCT to my favorite list....

    Jerry Wang
  • 如何把一个ABAP视图添加到SAP GUI的收藏夹里

    The idea comes from Sougata Chatterjee’s anwser in this thread:

    Jerry Wang
  • SAP UI5应用里类型为Edm.DateTime的日期控件设计原理

    Recently I was struggled with a customer incident and finally I realized that I ...

    Jerry Wang
  • linux到3.0了

    Yay! Let the bikeshed painting discussions about version numbering begin (or at...

    用户3765803
  • Hack the box: Bastion

    In conclusion, Bastion is not a medium box. But it would be easier to solve this...

    madneal
  • Control is important! model predictive control mpc.pytorch lib

    Optimal control is a widespread field that involve finding an optimal sequence o...

    用户1908973
  • 如何把一个ABAP视图添加到SAP GUI的收藏夹里

    The idea comes from Sougata Chatterjee’s anwser in this thread:

    Jerry Wang
  • 如何把ABAP视图添加到SAPGUI的收藏夹里

    Suppose I need to add the maintenance view COMV_PARTNER_FCT to my favorite list....

    Jerry Wang
  • SAP UI5应用里类型为Edm.DateTime的日期控件设计原理

    Recently I was struggled with a customer incident and finally I realized that I ...

    Jerry Wang
  • GPIOs and Go

    Recently, I decided that I needed a small heads up display for import things I k...

    李海彬

扫码关注云+社区

领取腾讯云代金券