choose java vm_使用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.

27cf39b4a73ace16c3ac0f2d5deb7987.png

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/eclip

se-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.

abf6b011e0ea6b3cfa0c555a16a93da4.png

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

bdd4ddf6274bbeb484fc2fa7e3689e03.png

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

e7bf3568da2ea1a6ea7beed49f31963d.png

finish the installation.

1a499d1640ba18d4ddb6edb1f3848649.png

(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:

e70dd25a08a0ca01b756c2a84b7def52.png

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.

8a212397195135daa1d474c37b43c510.png

(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:

bc93e19c2ea7c68682d96d72d469ccb0.png

Current status: profiling inactive. Click CPU button:

e675fb9ee3ac72d7fee1994e3aa4765e.png

Now profiling is activated:

30bc176f27b94b3902e0127ba77d014a.png

(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.

8465f0c5d25b35fb7439569d3f14734b.png

The result is displayed as below:

62cbcc5d4ecb131e76ffdd20f3987bcb.png

要获取更多Jerry的原创文章,请关注公众号"汪子熙":

ec8443d4647c1d4c770d55e0e21868d0.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值