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

What is the visual performance monitoring tool visual vm in java jdk

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

Today, I will talk to you about the visual performance monitoring tool visual vm in java jdk, which may not be well understood by many people. in order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

Visual vm is a powerful visual tool for multi-in-one fault diagnosis and performance monitoring. Visual vm can be used instead of jstat, jmap, jhat, jstack and so on. Nevertheless, considering that the vast majority of production projects are published on linux servers and do not support gui interface, it is impossible to use visual vm directly, so jstat, jmap, jhat, jstack and other tools are mostly used in production.

1. Installation

Jdk7 and jdk8 versions, you can use the jvisualvm command to start visual vm. Starting with jdk 9, visual VM is no longer integrated into Oracle JDK and needs to be downloaded, installed and downloaded separately. After the installation is complete, you need to configure the environment variables so that you can start from the command line.

Visual vm supports plug-in installation. Open the plug-in installation interface through the menu bar Tools-> Plugins:

It is recommended to install visual gc, so you can easily see the memory space occupation and recycling in eden area, suvivor area, old age, meatspace area and so on.

two。 Connect the application

Visual vm can connect to either local java applications or remote java applications.

2.1 Local connection

When visual vm is enabled, all java threads on the machine will be listed under the local node on the left panel. Double-click the corresponding node to connect.

2.2 remote connection

Visaul vm also supports remote jmx connections, and java applications can open jmx ports with the following parameters:

-Djava.rmi.server.hostname=127.0.0.1\-Dcom.sun.management.jmxremote\-Dcom.sun.management.jmxremote.port=8888\-Dcom.sun.management.jmxremote.ssl=false\-Dcom.sun.management.jmxremote.authenticate=false "example: remote connection to admin.jar project

Start the project

Java-jar-Djava.rmi.server.hostname=192.168.0.104\-Dcom.sun.management.jmxremote\-Dcom.sun.management.jmxremote.port=8888\-Dcom.sun.management.jmxremote.ssl=false\-Dcom.sun.management.jmxremote.authenticate=false\ admin.jar

-Djava.rmi.server.hostname corresponds to the server ip to be accessed remotely. If your remote server ip is 10.1.23.4, then the corresponding value for-Djava.rmi.server.hostname is 10.1.23.4.

-Dcom.sun.management.jmxremote.port specifies the open port of the remote server jmx.

Use visualvm to connect to the menu bar of visualvm, through File-> Add JMX Connection... Open the jmx connections panel

The 192.168.0.104 Connection 8888 in the column corresponds to the values of-Djava.rmi.server.hostname and-Dcom.sun.management.jmxremote.port in the startup parameters.

The interface for a successful connection is as follows:

Another example of a local direct connection:

Compared with the local direct connection, the remote jmx connection lacks several functions such as Minitor, threads, Sampler, Profiler, and so on. In addition, Visual GC cannot be used when connecting remotely:

3. Monitor application overview

Through visual vm, you can view the basic overview of the program, such as process id, Main Class, startup parameters, and so on.

Click the monitoring page on the Tab page to monitor the overall state of the application's cpu, heap, permanent zone, class loading, and threads. You can also manually perform FullGC and generate heap snapshots through the perform garbage collection and heap dump buttons on the page.

4. Thread Dump and analysis

The thread page of visual vm can provide detailed thread information. Click the "thread dump" button in the upper right corner to export the stack information for all current threads (equivalent to the jstack command).

5. Performance analysis.

Visual vm has two samplers, and two performance samplers, cpu and memory, are displayed on the sample page to monitor application information in real time. The cpu sampler can locate the cpu elapsed time to the method, and the memory sampler can view the heap information of the current program.

Through the sampling function of visual vm, you can find the method that takes up the longest cpu time in the program, as shown in the figure.

Function call statistics for jdk's built-in objects, such as classes in the java.* package, are not included in visual vm's default statistics. If you need to count the method calls in the jdk, you need to click the "Settings" option in the upper right corner to configure it manually.

Through the memory sampler, you can view the distribution of instances in the system in real time:

6. Memory snapshot analysis

Using the heap dump in the right-click menu, you can immediately get a memory snapshot of the current application, as shown in the figure:

The memory snapshot is shown in the figure. In the drop-down box at the top, four basic function pages are prompted: profile, object, thread, and OQL console.

The summary page shows the overall information of the current memory, including memory size, total number of instances, total number of classes, and so on.

The object page, indexed by classes, shows the number of instances and occupied space for each class.

On the thread page, it shows the thread stack when dump is currently applied.

The OQL console provides more powerful object query capabilities.

After reading the above, do you have any further understanding of the visual performance monitoring tool visual vm in java jdk? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

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

Development

Wechat

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

12
Report