Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Java Multi-function Profiling tool JVisual VM

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

In this issue, the editor will bring you about how to use the Java multi-function Profiling tool JVisual VM. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

Friends who develop Java must have encountered different kinds of problems in applications, sometimes using Bug analysis, sometimes application performance tuning, application Profiling,GC analysis, and so on.

At this time, there are many tools to choose from, commercial and open source for use in different scenarios. Our multi-functional Profile tool, which is still included with JDK, can be used for application monitoring and analysis in a variety of scenarios.

This tool is JVisual VM, the full name is Java VisualVM. Is a visual Java VM application analysis tool.

After startup, it looks like this:

Divided into local and remote, the current JVM processes are listed. Remote processes connect through JMX, and some local Profile features are not supported.

Let's take the local process as an example to introduce the common features of Visual VM.

Double-click the JVM process you want to analyze, select the function in the open Tab, and the overview, monitoring, thread, sampler, and Profiler items are displayed by default.

Because the Visual VM implementation is consistent with NetBeans, a lot of functionality can be added through plug-ins.

On the tools menu, select plug-ins, open the following figure, and then select the plug-ins to install, or download the plug-ins locally and then install them. The format is a file with a nbm extension.

Like Visual GC and BTrace, which we will introduce later, the corresponding functions are added through plug-in installation.

Overview

In the overview of this Tab, you will have some basic information about the current JVM process, including JVM parameters, system properties, Main-class, and so on. Similar to the following figure:

Please note the red box above, which is a JVM option generally configured at startup, which can generate a heap dump when the OOM is generated for post-mortem analysis. If it is not configured at startup, it is off by default. It is also shown here to be disabled.

With Visual VM, you can change this option in real time. Right-click the corresponding JVM process, and select [generate Heap Dump when OOME appears] from the pop-up menu.

Once selected, the corresponding overview becomes enabled.

Monitor

The Tab displays CPU, heap usage, loaded classes, thread activity, and so on. The point is that there are two buttons [perform garbage collection] and [heap Dump].

Garbage collection will do a Full GC, and the heap Dump will generate a current dump file for analysis.

Thread

Thread Tab will open all threads of the current process in the form of a timeline. It can be viewed according to the state of different threads. It is also possible to perform thread Dump, which is consistent with jstack function, to generate a running call diagram for all threads. (jstack, you can check the previous article for more information. Java 7 weapon Series overlord Gun-Thread State Analysis jstack)

Sampler

You can sample by CPU and memory, similar to Profiler, which we'll see later.

Profiler

Among the many functions, this function can be used for the Profiling of the application, analyzing the time occupied by the application method, the number and size of objects of each class in memory and so on.

The figure below is CPU profiling, the execution time of the analysis method.

This picture shows the profiling of memory, showing the number and size of objects in memory.

Through these two kinds of profiling, when a large amount of memory is occupied in the application, we can observe which objects are occupied and whether there are always a large number of useless objects generated in some code.

These two functions are similar to several of the functions of the tool MAT.

Visual GC

Note: the Tab needs to be installed with the plug-in before it can be displayed.

All along, Java's GC for us can only be displayed on the command line, or to view some execution from gc log, Visual VM's Visual GC plug-in, which allows us to more intuitively observe the heap occupancy, the execution of GC, etc., is a visual GC viewing tool.

Through this tool, you can observe the size and occupancy of each area of the heap. For example, in the configuration of Xms, PermSize, or some xxxRation and so on, the specific size of each generation is, in addition to calculation, you can check it intuitively here.

At the same time, next to each Gen, there is a display of the number and time of GC execution.

BTrace

The previous article wrote that using BTrace analysis is always, at that time, introduced the way through the command line. In the plug-in for Visual VM, there is also a plug-in for BTrace. After installation, you can right-click on the local JVM process and select [Trace application], which will open the Tab, then compile the Trace script directly in the window, and the execution result will be displayed in the window.

Note that there is a Unsafe switch, you can use more operations of BTrace, by selecting checkbox can not be opened. You need to add content after the @ BTrace annotation. The format is as follows:

@ BTrace (unsafe=true)

This is fine, and checkbox is automatically selected.

Heap Dump

After generating the heap dump, it is equivalent to making a mirror of the current heap, based on which you can analyze some problems in the application.

In the whole dump, in addition to the summary, there are also classes, the number of instances and so on are consistent with the real-time content in Profiler. In addition, the stackTrace of the thread is included.

Double-clicking any one you want to follow in a class will open the instance count view and display the data of each instance corresponding to that class.

In the OQL console, you can view the object's information by hosting the OQL, similar to the one described in the previous SA. (Java Seven weapons Series Eternal Sword-- microscope Serviceability Agent of Java Virtual Machine)

Found no, in fact, JDK provides these tools, there are many functions are the same, through a unified interface, in different applications to provide the corresponding data, a water supply for the world.

The above is the editor for you to share the Java multi-functional Profiling tool JVisual VM how to use, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report