Java Virtual machine 12: Virtual machine performance monitoring and troubleshooting tools

Source: Internet
Author: User
Tags stack trace unique id jconsole

Objective

When locating system problems, knowledge, experience is the basis, data is the basis, tools are the means of using knowledge to process data. The data mentioned here are: Run log, exception stack, GC log, thread snapshot, heap dump snapshot, and so on. Frequent use of the appropriate tools for virtual machine monitoring and analysis can speed up the analysis of data and pinpoint problem resolution.

JPS: Virtual Machine Process Health tool

First of all, the code that runs is the following paragraph

1 public class Testmain 2 {3 publicly     static void main (string[] args) 4     {5 while         (true) 6         {7              8         } 9     }10}

The names of many of the JDK's gadgets refer to how UNIX commands are named, and the JPS (JVM Process Status) is typical. In addition to the PS command named UNIX, it also functions like the PS command: You can list the running virtual machine processes and display the virtual machine execution main class name and the local virtual machine unique ID for those processes (Identifier,lvmid). While the functionality is relatively single, it uses the highest JDK command-line tool, because most other JDK tools need to enter the Lvmid it queries to determine which virtual machine process to monitor.

JPS command format:

JPS [Options] [HostID]

JPS Tools Main Options

Options Role
-Q Output only Lvmid, omit the name of the main class
-M Parameters passed to the main class main () function when the output virtual machine process starts
-L Output the full name of the main class, if the process is executing a jar package, the output jar package path
-V JVM parameters when the output virtual machine process starts

JPS Execution Example

A virtual machine process executes the main method of the Testmain class, seeing that 10492 is the ID of the virtual machine process

Jstat: Virtual Machine Statistics monitoring tool

The Jstat (JVM Statistics monitoring tool) is used for command-line tools that monitor various health state information for a virtual machine. It can display the local or remote (need to provide RMI support) virtual machine process of the class information, memory, garbage Collection, JIT compilation and other running data, in the absence of a GUI, only provides a plain text console environment on the server, it will be the operating period to locate virtual machine performance issues of the preferred tool.

Jstat command format

jstat [option Vmid [interval [s | ms] [COUNT]]

This vmid, Vmid and Lvmid are consistent for the local virtual machine process. The parameters interval and count respectively represent the query interval and number of times, if you omit these two parameters, the description is queried only once, assuming that you need to query the garbage collection of process 2764 every 250 milliseconds, the total query 20 times, the command should be:

JSTAT-GC 2764 250 20

Jstat Main tool options

Options Role
-class Monitor class load, unload quantity, total space, and time spent on class loading
-gc Monitor Java heap status, including Eden Zone, two survivor zone, old age, permanent band capacity, used space, GC time totals, and more
-gccapacity The monitoring content is basically the same as-GC, but the output focuses on the maximum and minimum space used by each area of the Java heap
-gcutil The monitoring content is basically the same as-GC, but the output focuses on the percentage of space used for the total space
-gccause Same as-gcutil function, but additional output causes the last GC to occur
-gcnew Monitor New generation GC status
-gcnewcapacity The monitoring content is basically the same as-gcnew, but the output focuses on the maximum and minimum space used
-gcold Monitoring the status of GC in the old age
-gcoldcapacity The monitoring content is basically the same as-gcold, but the output focuses on the maximum and minimum space used
-gcpermcapacity Maximum and minimum space used for output permanent generation
-compiler Output JIT compiler compiled methods, time-consuming and other information
-printcompilation How the output has been JIT-compiled

Jstat Execution Example

Jstat monitoring options are numerous, take an example to see how the command looks at the monitoring results

The query results show that the new Generation Eden region (E, which represents Eden) uses 2% of the space, two survivor zones (S0, S1, Survivor0, Survivor1) are empty, the old age (O, the older) and the permanent band (P. Represents permanent) uses 0% and 13.84% of space respectively. The minor GC (YGC, which represents young GC) has occurred 0 times since the program was run, taking a total of 0 seconds, a full GC (FGC, representing the full GC) 3 times, a total GC time of 0 seconds, and a total GC time (GCT, Represents GC time) for 0 seconds.

Jinfo:java Configuration Information tool

The purpose of Jinfo (Configuration Info for Java) is to view and adjust the virtual machine parameters in real time. Use the-V of the JPS command to view the list of parameters that are explicitly specified when the virtual machine starts, but if you want to know the system defaults for parameters that are not explicitly specified, you can query using the jinfo-flag option. Jinfo can also print the contents of the system.getproperties () of the virtual machine process using the-SYSPROPS option.

Jinfo command format

jinfo [option] pid

Jinfo Execution Example

Jinfo This command has a large limitation on the Windows platform and is not available in Linux and Solaris systems, so this is not demonstrated here.

Jmap:java Memory Imaging Tool

The Jmap (Memory Map for Java) command is used to generate a heap dump snapshot. If you do not use the Jmap command, to get a Java heap dump, you can use the "-xx:+heapdumponoutofmemoryerror" parameter, which allows the virtual machine to automatically generate a dump file after the oom exception occurs, and the Linux command can be used to kill- 3 Send process exit signal can also get dump file.

Jmap's role is not just to get the dump file, it can also query the details of the Finalize execution queue, the Java heap, and the permanent generation, such as space usage, which collector is currently in use, and so on. Like Jinfo, Jmap has a number of features that are restricted under the Windows platform, in addition to the-dump options for generating dump files and the-histo options for viewing instances of each class, and the spatial occupancy statistics that are available on all operating systems. The remaining options are only available under Linux and Solaris systems.

JMAP command format

jmap [option] Vmid

Jmap Tools Main Options

Options

Role
-dump Generates a Java heap dump snapshot. The format is-dump:[live,]format=b,file=<filename>, where live arguments indicate whether to dump only the surviving objects
-finalizerinfo Displays the object in F-queue that waits for the finalizer thread to execute the Finalize method. Valid only under Linux and Solaris systems
-heap Displays the Java heap details, such as which collector, parameter configuration, generational status, and so on. Valid only under Linux and Solaris systems
-histo Displays the object statistics in the heap, including the class, number of instances, total capacity
-permstat Displays the permanent memory status with ClassLoader as the statistical aperture. Valid only under Linux and Solaris systems
-F Use this option to force a dump snapshot when the virtual machine does not respond to the-dump option. Valid only under Linux and Solaris systems

Jmap Execution Example

Similarly, this command has a larger limit on the window environment and does not demonstrate it.

Jstack:java Stack Trace Tool

The Jstack (Stack Trace for Java) command is used to generate a thread snapshot of the current moment of the virtual machine. The thread snapshot is the collection of method stacks that each thread in the current virtual machine is executing, and the purpose of generating the thread snapshot is to locate the thread for a long pause, such as a deadlock between threads, a dead loop, a long wait waiting for external resources, and so on, which causes the thread to pause for a long time. When a thread pauses, you can see the call stack of each thread by Jstack, and you know what the unresponsive thread is doing in the background, or what resources are waiting for it.

Jstack command format

jstack [option] Vmid

Jstack Main tool options

Options Role
-F Forces the output thread stack when a normal output request is not responded to
-L Displays additional information about the lock, in addition to the stack
-M If you call to a local method, you can display the C + + stack

Jstack Execution Example

Just intercept the part and see this is the 10492 thread snapshot of the current time of the virtual machine process ID. The thread is in the runnable state, executes to line 7th of the Testmain function, and stays on line 7th.

Other

The above is the use of commands to capture the virtual runtime of the specified process information, in fact, you can also use the visual tools to specify the PID of the virtual runtime information monitoring, here are recommended two:

1, JConsole

In the Java_home/bin directory, there is a Jconsole.exe, double-click to run a bit.

2. Visual VMS

This is the most powerful running monitoring and troubleshooting tool that has been released with the JDK so far, in addition to the most basic operational monitoring, fault handling, and performance analysis capabilities, and is very powerful. The Visual VM also has a large advantage, which has a small impact on the actual performance of the application, making it possible to apply directly to the production environment.

As for the specific how to use, it is not demonstrated, relatively simple. In addition to the above two tools, you can also use Jprofiler, Yourkit and other professional and paid profiling tools.

Reprint: http://www.cnblogs.com/xrq730/p/4842483.html

Java Virtual machine 12: Virtual machine performance monitoring and troubleshooting tools

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.