Profile your applications with Java VisualVM
July 13, 2010 by Baptiste Wicht 11 Comments
When you need to discover what part of an application consume the more CPU or Memory, you must use a profiler to do that.
One profiler, packed by default with the Sun JDK is Java VisualVM. This profiler is really simple to use and really powerful.
VisualVM start logo
In this post, we’ll see how to install it and use it to profile an application.
Normally, to install it, you have nothing to do, because, it’s installed with the JDK. But in several Unix system, like Ubuntu, this is not the case. If you want to install it, just use apt-get (or aptitude) :
sudo apt-get install visualvm
To launch it just launch jvisualvm (jvisualvm.exe in the bin directory of the jdk for Windows)【(jdk安装之后bin中有一个 jvisualvm.exe)】.
That will open the following window :
VisualVM Main Frame
There is not a lot of interesting things to see here. To profile a application, you just have to launch it and VisualVM will detect it as launched :
After that, you just have to double click to view information about your running application. You’ve four tabs available for your applications (Overview, Monitor, Threads, Profiler). We’ll see all that 4 tabs. First of all, the default tab, the overview :
VisualVM Overview tab
This tab contains the main informations about the launched application. You can see the main class, the arguments of the command line, the JVM arguments. You can also see what kind of JVM is running your program and where the JVM is located. And you can see all the properties set in the program.
A more interesting tab is the “Monitor”【监视】 tab :
VisualVM Monitor tab
This tab follow the CPU and Memory usages of your applications. You have 4 graphs in this view. The first one, from left to right, up to down, display the CPU usage and the Garbage Collector CPU usage. The second graph display the usage of the heap space and the PermGen space. The next graph display the total number of classes loaded in the application and the last one displays the number of threads currently running. With these graphs, you can see if your application take too CPU or if there is too memory used by the application.
The third tab provide some details about Threads :
VisualVM Threads tab
In this view, you can see how the different threads of the application are changing state and how they evolve. You can also see the time each time pass in each state and you can have details about the threads you want.
And now, I think the most interesting tab, is the Profiler one :
VisualVM Profiler tab
When you open this tab first, it contains no information at all. You must start one kind of profiling before seeing informations. We’ll start with CPU profiling. Just click on the CPU button the instrumentation will start. During the instrumentation, the application will be blocked. After the instrumentation, you can access the application again and you will see the results of the profiling be displayed in the table. Of course the profiling has an overhead on your application. Normally it’s not visible, but for certain applications, you can loose a lot of fluidity. Here are the results I have obtained with my simple application :
VisualVM CPU profiling
In my example, we can see that the waitForTimeout method takes 81.6% of the CPU time. We can also see that the notifyDecision and getSensor methods are the two next most CPU consuming methods, perhaps, it will be interesting to optimize them. You can also look at the number of invocations of each, perhaps, you’ll find a method that is invoked too much time.
The next profiling we can do is the Memory profiling. Here again, you have to start the profiling and the instrumentation will start and during this, the application will be frozen. Here are the results for my application :
VisualVM Memory profiling
Here we can see that this application store some big double[] and float[] arrays and that EllipseIterator and BasicStroke classes take also a lot of memory spaces.
In both the memory and CPU profiling, you can save the results to a file to see it later. By example, you can let an application working the all night, save the results the morning and examine them or make three profiling and compare the three.
To conclude, I have to say that this profiler is really simple but also really powerful to use. We’ve the main features we want for a profiler and the results are really good. That kind of tools can really help you to improve an application to use less CPU and memory. Of course that kind of tool doesn’t do everything, it just help showing what part of the application must be improved, the improvement part is the task of the developer and it’s not the easiest one. But having that kind of tool is a good start.
原文地址:http://www.baptiste-wicht.com/2010/07/profile-applications-java-visualvm/
- 大小: 94 KB
- 大小: 20 KB
- 大小: 36.1 KB
- 大小: 47.3 KB
- 大小: 56.8 KB
- 大小: 47 KB
- 大小: 30 KB
- 大小: 70.8 KB
- 大小: 39.1 KB
分享到:
相关推荐
Java VisualVM是一款强大的Java应用程序性能分析工具,由Oracle公司提供,它是JDK的一部分。这款工具集成了多种功能,包括内存分析、线程分析、CPU剖析、JVM配置信息查看等,其中GC(Garbage Collection)插件是其...
### Java内存监控工具Java VisualVM #### 一、概述 Java VisualVM是一款强大的Java应用程序性能分析和诊断工具,主要用于监控和分析Java应用的运行时行为,包括但不限于内存使用情况、线程状态、CPU使用率等关键...
VisualVM是一个功能强大的Java虚拟机(JVM)监控、分析和故障排查工具,它提供了广泛的监控和分析功能,可帮助开发人员诊断和解决Java应用程序的性能问题。 主要功能: 1.CPU监控:显示Java进程的CPU使用率、线程...
VisualVM是一款强大的Java诊断工具,它提供了丰富的功能来帮助开发者理解和优化JVM上的应用程序。VisualVM_20可能是该工具的一个更新版本,提供了更多改进和新特性。 VisualVM主要包含以下几方面的功能: 1. **...
Java VisualVM是一款强大的Java应用程序性能分析工具,它包含了许多功能,如内存分析、线程分析、JMX连接、采样器等。而TAD(Thread Analysis and Dump)是VisualVM的一个插件,专为了解析和分析Java应用程序的线程...
VisualVM是一款强大的Java应用程序性能分析工具,由Oracle公司开发并提供。它集成了多种功能,使得开发者能够深入了解JVM(Java虚拟机)的行为,优化应用性能,定位内存泄漏,并进行线程和内存分析。这款工具的中文...
Java VisualVM是一个多线程的监控分析工具,VisualVM 是一款免费的\集成了多个 JDK 命令行工具的可视化工具,它能为您提供强大的分析能力,对 Java 应用程序做性能分析和调优。功能包括内存分析、快照功能、转储功能...
VisualVM是一款强大的Java虚拟机(JVM)监控和分析工具,由Oracle公司开发并提供,是Java开发者进行性能调优的得力助手。它集成了多种功能,包括内存分析、线程检查、CPU使用率监控、类加载和垃圾回收查看等,能够...
net-java-btrace-visualvm.nbm java visualvm btrace 插件
VisualVM 是一个工具,它提供了一个可视界面,用于查看 Java 虚拟机 (Java Virtual Machine, JVM) 上运行的基于 Java 技术的应用程序(Java 应用程序)的详细信息。VisualVM 对 Java Development Kit (JDK) 工具所...
VisualVM 提供在 Java 虚拟机 (Java Virutal Machine, JVM) 上运行的 Java 应用程序的详细信息。在 VisualVM 的图形用户界面中,您可以方便、快捷地查看多个 Java 应用程序的相关信息。
VisualVM是一款强大的Java性能分析工具,由Oracle公司开发并维护,它是Java开发者的重要辅助工具,尤其在优化应用程序的性能方面。VisualVM集成了多种监视和诊断功能,包括JVM(Java虚拟机)性能监控、线程分析、...
VisualVM是一个集成多个JDK命令行工具的可视化工具。可以作为Java应用程序性能分析和运行监控的工具。开发人员可以利用它来监控、分析线程信息,浏览内存堆数据。系统管理员可以利用它来监测、控制Java应用程序横跨...
VisualVM是一款强大的Java应用程序性能分析工具,由Oracle公司开发并维护。它提供了丰富的功能,包括内存分析、线程检查、CPU使用率监控、JVM配置信息查看以及各种JVM垃圾收集器(GC)的详细信息展示。在"visualVM...
Java 8 VisualVM 插件是一组用于增强VisualVM工具的功能扩展,VisualVM是Oracle公司提供的一个强大的Java应用程序性能分析工具。它允许开发者对JVM(Java虚拟机)进行深入的监控和诊断,包括内存使用、线程分析、CPU...
VisualVM for mac 2.0.7 安装包,亲测可用.. 网上找了好久都没有,上传到csdn也算是备份了..
NULL 博文链接:https://zizhu2012.iteye.com/blog/1612522
Java VisualVM插件--Visual GC-附件资源
### 2.5 通过 Java VisualVM 连接到服务器监控 Java 程序 在客户端,我们可以使用VisualVM连接到服务器监控Java程序。首先,需要添加远程主机,输入服务器的IP地址和端口号,然后点击连接按钮,即可监控服务器上的...
VisualVM 2.1.5 是一款强大的Java应用程序性能分析工具,它集合了多种JDK命令行工具的功能,并提供了一个直观的图形用户界面。这款工具是开发者和运维人员的得力助手,尤其在优化和调试Java应用时,能提供丰富的信息...