Java VisualVM

Java VisualVM是一款强大的工具,提供了一个可视化的界面来查看正在运行的Java应用的详细信息。它允许你查看本地和远程应用的数据,进行性能分析、内存和线程dump,以及使用插件扩展其功能。文章详细介绍了启动VisualVM,应用程序窗口的使用,以及各种功能,如CPU和内存分析,快照和JMX连接。通过这个工具,开发者可以有效地监控和优化Java应用的性能。
摘要由CSDN通过智能技术生成

文章目录

源文档地址:https://docs.oracle.com/javase/8/docs/technotes/guides/visualvm/index.html

1.Java VisualVM简介(Introduction to Java VisualVM)

1.1 Java VisualVM简介(Introduction to Java VisualVM)

Java VisualVM is a tool that provides a visual interface for viewing detailed information about Java technology-based applications (Java applications) while they are running on a Java Virtual Machine (JVM). Java VisualVM organizes JVM data that is retrieved by the Java Development Kit (JDK) tools and presents the information in a way that enables you to quickly view data on multiple Java applications. You can view data on local applications and applications that are running on remote hosts. You can also capture data about the JVM software and save the data to your local system, and view the data later or share the data with others.

In order to benefit from all Java VisualVM’s features, you should run the Java Platform, Standard Edition (Java SE) version 6.

Java VisualVM是一个工具,它提供了一个可视化界面,用于查看基于Java技术的应用程序(Java应用程序)在Java虚拟机(JVM)上运行时的详细信息。Java VisualVM组织由Java Development Kit(JDK)工具检索到JVM数据,并以使您能够在多个Java应用程序上快速查看数据的方式显示信息。您可以查看本地应用程序和运行在远程主机上的应用程序上的数据。您还可以捕获关于JVM软件的数据并将数据保存到本地系统,稍后查看或与他人共享。

为了从Java VisualVM的所有特性中获益,您应该运行Java SE 6

1.2 启动Java VisualVM(Starting Java VisualVM)

Java VisualVM is bundled with JDK version 6 update 7 or greater. Once you have installed an appropriate JDK version, navigate to your JDK software’s bin directory and double-click the Java VisualVM executable. On Windows this directory will be the following:

Java VisualVM与JDK版本6 updated 7以及更高版本捆绑在一起。安装了合适的JDK版本后,导航到JDK软件的bin目录,双击Java VisualVM可执行文件。在Windows下,这个目录如下:

C:\Program Files\Java\jdk1.6.0_*update-number*\bin

Alternatively, navigate to your JDK software’s bin directory and type the following command at the command (shell) prompt:

或者,导航到JDK软件的bin目录,并在命令(shell)提示符下输入一下命令:

jvisualvm

The first time that you launch Java VisualVM you are prompted to accept a license agreement.

第一次启动Java VisualVM时,系统会提示您接受许可协议。

1.2.1 Java VisualVM用户目录(Java VisualVM Userdir)

On Windows, the default location for the Java VisualVM userdir is the following:

在Windows上,Java VisualVM的userdir的默认位置如下:

C:\Documents and Settings\*<USER>*\Application Data\.visualvm\*JDK_update-number*

To find the location of your Java VisualVM userdir, choose Help > About from the main menu and click Details in the About Java VisualVM window.

要找到Java VisualVMuserdir的位置,请从主菜单中选择Help > About,然后单击About Java VisualVM窗口中的Details。

1.3 Java VisualVM 窗口(Java VisualVM Windows)

When you start Java VisualVM, the main Java VisualVM window opens. The main Java VisualVM window is divided into two windows.

当您启动Java VisualVM时,将打开Java VisualVM主窗口。这个Java VisualVM主窗口分为两个窗口。
screenshot of VisualVM window with Start screen

When you first start Java VisualVM, the Applications window is visible in the left side of the window and the Start Page is visible in the right side in the main window. The Start Page contains links to Java VisualVM documentation web pages and additional resources.
Note: The Start Page opens by default each time you start Java VisualVM. You can open the Start Page at any time by choosing Help > Start Page from the main menu. You can also hide the Start page by unchecking the “Show On Startup” check-box.

当您第一次启动Java VisualVM时,应用程序窗口在主窗口的左侧可见,而开始页面在主窗口的右侧可见。开始页面包含指向Java VisualVM文档的web页面和其他资源的连接。

注意: 每次启动Java VisualVM时,默认情况下都会打开开始页面,您可以在任何时候打开开始页面,从主菜单中选择Help > Start Page。您还可以通过取消选中“Show On StartUp”复选框来隐藏开始页面。

1.3.1 应用程序窗口(Applications Window)

The Applications window opens in the left side of the main Java VisualVM window when you launch the application. The Applications window is the main point of entry for exploring the details of running applications. The Applications window uses a tree structure to enable you to quickly view the applications running on the local machine and any connected remote machines. You can also access core dumps (Solaris/Linux) and saved snapshots from the Applications window.

Right-clicking a node in the Applications window opens a popup menu that enables you to perform actions related to that node, including opening application tabs, taking heap and thread dumps and opening snapshots in the main window.

For more details about how to use the Applications window to view and save data, see the following pages:

启动应用程序时,应用程序窗口将在Java VisualVM的主窗口的左侧打开。应用程序窗口是研究正在运行的应用程序的详细信息的主要入口点。应用程序窗口使用树结构,使您能够快速查看在本地机器和任何连接的远程机器上运行的应用程序。您还可以访问core dump(Solaris/Linux)和从应用程序窗口保存的快照。

在应用程序窗口中,右键单击一个节点将打开一个弹出菜单,该菜单允许您执行与该节点相关的操作,包括在主窗口中打开应用程序选项卡,获取堆dump和线程dump以及打开快照。

有关如何使用应用程序窗口查看和保存数据的更多详细信息,请参见如下页面:

1.3.2 主窗口(Main Window)

Detailed information about applications is displayed in the main window. When you view data about an application, each application is represented by a tab in the main window that enables you to easily view and navigate the data. Saved thread dumps and heap dumps are also opened in the main window.

For information about the application data that can be displayed in the main window, see the following pages:

有关应用程序的详细信息显示在主窗口中。当您查看关于应用程序的数据时,每个应用程序都由主窗口中的一个选项卡表示,该选项卡使您能够方便地查看和导航数据。保存的线程dump和堆dump都会在主窗口中打开。

有关可在主窗口中显示的应用程序数据,请参见以下页面

1.4 Java VisualVM插件(Java VisualVM Plugins)

You can add functionality to Java VisualVM by using the Plugins manager to install plugins from the Java VisualVM Plugins Center. You can also extend the functionality of Java VisualVM by developing your own plugins that can then be added to an update center.

For example, installing the Java VisualVM-MBeans plugin adds an MBeans tab to the application tab that enables you to monitor and manage MBeans from within Java VisualVM.

通过使用插件管理器安装来自Java VisualVM插件中心的插件,您可以向Java VisualVM添加功能。您还可以通过开发自己的插件来扩展Java VisualVM的功能,然后可以将这些插件添加到更新中心。

例如,安装Java VisualVM-MBeans插件,可以向应用程序选项卡里添加了一个MBeans选项卡,通过此选项卡,可以在Java VisualVM内监控和管理MBeans

1.4.1 安装Java VisualVM插件(To install a Java VisualVM plugin):

  1. Choose Tools > Plugins from the main menu.

  2. In the Available Plugins tab, select the Install checkbox for the plugin. Click Install.

  3. Step through and complete the plugin installer.

  4. 从主菜单中选择“工具” > “插件”。

  5. 在“可用插件”选项卡中,选中该插件的“安装”复选框。单击“安装”。

  6. 逐步完成插件安装程序。
    screenshot of Plugins window

For more information about creating Java VisualVM plugins, see the following documents:

有关创建Java VisualVM插件的更多信息,请参见以下文档

2 使用应用程序窗口(Using the Applications Window)

When you start Java VisualVM, the Applications window is visible in the left side of the Java VisualVM window. The Applications window uses a tree structure to enable you to quickly view the applications that are running on local and connected remote JVM software instances. The Applications window also displays core dumps and application snapshots.

启动VisualVM后,“应用程序”窗口显示在VisualVM窗口的左侧。“应用程序”窗口使用树形结构,使您快速查看本地和远程JVM上运行的Java应用程序。“应用程序”窗口也能显示核心dumps和应用程序快照

2.1 应用程序窗口节点(Applications Window Nodes)

The Application window has nodes and sub-nodes that you can expand to view running applications and saved files. For most nodes in the Applications window, you can view additional information and perform actions by right-clicking a node and choosing an item from the popup menu. The actions available in the popup menu vary according to the node.

“应用程序”窗口中有节点和子节点,您可以展开它们来查看正在运行的应用程序和保存的文件。对于“应用程序”窗口中的大多数节点,可以通过右键单击一个节点并从弹出菜单中选择一个项来查看其他信息并执行操作。弹出菜单中可用的操作根据节点的不同而不同。
screenshot of VisualVM window
The Applications window has the following primary nodes:

“应用程序”窗口有以下主要节点

2.1.1 本地节点(Local Node)

The Local node displays the name and process IDs (PID) of Java applications that are running on the same system as Java VisualVM. When you launch Java VisualVM and expand the Local node, Java VisualVM automatically displays the currently running Java applications. Java VisualVM is always listed as one of the local applications. When a new local Java application is launched, a node for that application appears under the Local node. The application node disappears when the application terminates.

If you use Java VisualVM to take thread dumps, heap dumps or profiling snapshots of an application, they are displayed as sub-nodes below the node for that application. You can right-click a dump or snapshot sub-node to save it to your local system. You can collect and archive all the information collected about an application and save it as an application snapshot.

For more information about how to view data about local applications, see the following pages:

本地节点显示与VisualVM运行在同一系统上的Java应用程序的名称和进程id(PID)。当启动VisualVM并展开本地节点时,VisualVM将自动显示当前运行的Java应用程序。VisualVM始终被列为本地应用程序之一。当启动新的本地Java应用程序时,该应用程序的节点将显示在本地节点下。当应用程序之中时,该应用程序节点将消失。

如果使用VisualVM获取应用应用程序的线程dumps、堆dumps或分析快照,它们将以子节点形式显示在该应用程序节点下面。您可以右键单击转储或者快照子节点,将其保持到本地文件系统。您可以收集和存档有关应用程序的所有消息,并将其保存为应用程序快照

有关如何查看本地应用程序相关数据的更多详细信息,请参见以下页面:

2.1.2 远程节点(Remote Node)

When Java VisualVM connects to a remote host, the remote host is listed as a node under the Remote node. When connected to a remote host, you can expand the node for the remote host to see the Java applications that are running on that host. When a Java application is launched on the remote host, a node for that application is displayed under the remote host node.

You need to explicitly add the location of remote hosts if you want Java VisualVM to be able to connect to the host. Once a remote host is added, Java VisualVM persists the address of the remote host and will make a connection to the host each time Java VisualVM is started. If you do not want Java VisualVM to connect to the host on startup, you should right-click the remote host node and choose Remove before quitting Java VisualVM.

Note: To retrieve and display information on applications running on the remote host, the jstatd utility needs to be running on the remote host. To start the utility, type jstatd on the command line. The jstatd utility is included as part of Java Development Kit (JDK) version 6.

For more information about how to view data about remote applications, see the following pages:

当VisualVM连接到远程主机时,远程主机将被列为远程节点下的一个节点。当连接远程主机时,可以展开远程主机的节点,以查看在该主机上运行的Java应用程序。当在远程主机上启动Java应用程序时,改应用程序的节点将显示在远程主机节点下。

如果希望VisualVM能够连接到主机,则需要显式地添加远程主机的位置。添加远程主机后,VisualVM将保存远程主机的地址,并在每次启动VisualVM时与主机建立连接。如果不希望VisualVM在启动时连接到主机,则应该右键单击远程主机节点,并在退出VisualVM之前选择“删除”。

注意: 要检索和显示在远程主机上运行的应用程序的信息,需要在远程主机上运行jstatd。要启动jstatd,请在命令行上键入jstatd。在jdk6之后都包含jstatd。

有关如何查看远程应用相关数据的更多详细信息,请参见以下页面:

2.1.3 VM Coredumps

The VM Coredumps node lists open core dump binary files when you open the files in Java VisualVM. A core dump is a binary file that contains information about the runtime status of the machine at the time the core dump was taken. If you have a core dump you can then extract an overview of the system properties, a heap dump and a thread dump.

Note: The Core Dump node is only visible if Java VisualVM is running on Solaris or Linux.

For more information, see the following document:

当您在VisualVM中打开文件时, VM Coredumps节点列出打开的核心转储二进制文件。核心转储是一个二进制文件,其中包含有关在获取核心转储时计算机运行时状态的信息。如果你有一个核心转储,那么您可以提取系统属性的概述、堆dump和线程dump。

注意:只有在Solaris或Linux上运行VisualVM时,Core Dump节点才可见。

有关更多信息,请参见以下页面:

2.1.4 快照(Snapshots)

The Snapshots node lists any application snapshots that are saved in the Java VisualVM userdir until they are explicitly deleted. An application snapshot captures the collected heap dumps, thread dumps and profiler snapshots of an application at the moment the snapshot is taken. You can expand the application snapshot node to see the data collected in the snapshot.

You can right-click an application snapshot node or any of the items listed under the node to open a popup menu enabling you to open, save, delete and rename the selected item.

For more information about taking and saving snapshots, see the following document:

快照节点列出了保存在VisualVM用户目录中的所有应用程序快照,直到显式删除它们为止。应用程序快照在拍摄快照时捕获收集到应用程序的堆dumps,线程dumps和性能分析快照。可以展开应用程序快照节点以查看快照中收集的数据。

您可以右键单击应用程序快照节点或该节点下列出的任何项,以打开弹出菜单,使您能够打开、保存、删除和重命名所选的

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值