JVM Performance Monitoring Tool (i)-JDK command-line tools

Source: Internet
Author: User
Tags garbage collection memory usage stack trace
Overview

When the system bugs need to locate the problem, knowledge, experience is the key foundation, the data is the basis, the tool is the use of knowledge processing data means. The data mentioned here include: Run log, exception stack, GC log, thread snapshot (threaddump/javacore file), heap dump Snapshot (heapdump/hprof file), etc. Using the appropriate virtual machine monitoring and analysis tools can accelerate our ability to analyze data and locate problems. command-line tools for JDK

The JDK itself provides a lot of handy JVM performance monitoring tools, in addition to the integrated VISUALVM and Jconsole, there are JPS, Jstack, Jmap, Jhat, Jstat and other small tools. They are under the bin directory of the JDK:


1.jps Description

The JPS (JVM process status Tool) is used to view the specific state of all processes within the JVM, including the process ID, path initiated by the process, and so on. command Format

> JPS [Options] [HostID]

JPS commonly used options are the following table:

Options function
-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, the output jar path
-V JVM parameters when the output virtual machine process starts
Example
> jps-l
2.jstat Description

The Jstat (JVM Statistics monitoring tool) is a command-line utility for monitoring the various operational state information of a virtual machine. It can display class loading, memory, garbage Collection, JIT compilation, and other running data in a local or remote virtual machine. command Format

> jstat [Option Vmid [interval Count]]
parameter DescriptionThe option– option, which represents the virtual machine information that the user wants to query, is divided into 3 categories: class load, garbage collection, run-time compilation state. VMID–VM process number, that is, the current running Java process number interval– interval, in seconds or milliseconds count– print times, if the default print countless times

Jstat commonly used option is the following table:

Options effect
-class Monitor class load, unload quantity, total space, and time spent loading classes
-gc monitor Java heap status, including E Den area, two survivor area, old generation, permanent generation, etc. capacity, used space, GC time total, etc.
-gccapacity monitoring content is basically the same as-GC, but the output focuses on the Java heap Maximum, minimum space used by the zone
-gcutil monitoring content is basically the same as-GC, but the output is primarily concerned about the percentage of space used for total space
-gccause is the same as the-gcutil function, but the additional output causes the last GC to occur
-gcnew monitor Cenozoic GC status
-gcnewcapacity monitoring content is basically the same as-gcnew, output focuses on the maximum, minimum space used
-gcold Monitoring the status of GC in the old age
-gcoldcapacity monitoring content is basically the same as-gcold, output focuses on the maximum, minimum space used
-gcpermcapacity output The maximum, minimum space used by the permanent generation
-compiler output JIT Compiler-compiled methods, time-consuming information
-printcompilation output methods that have been compiled by the JIT compiler


The output content has the following meanings:
Percentage of space used in Survivor space zone 0 on S0–heap

Percentage of space used in Survivor space Zone 1 on S1–heap

Percentage of space used in Eden space on E–heap

The percentage of space used in the old area on the O–heap

Percentage of space already used in the P–perm space area

ygc– number of young GC occurrences from application boot to sample

ygct– the time (in seconds) used by the young GC when booting from the application to sampling

fgc– the number of full GC occurrences from application startup to sampling

fgct– time (in seconds) for full GC from application boot to sampling

gct– total time (in seconds) for garbage collection from application startup to sampling


Example

The parameters interval and count represent the query interval and number of times, and if these two parameters are omitted, the description is queried only once. As follows:

[Root@localhost bin]# Jstat-gcutil 25444

Every 500 milliseconds to query the process 25444 garbage collection status, a total of 10 times, as follows:

[Root@localhost bin]# jstat-gcutil 25444 500 10

Jstat-class PID: Displays the number of loaded classes, and the amount of space that is occupied.

Jstat-compiler PID: Displays information such as the number of real-time VMS compiled.

3.jinfo Description

Jinfo (configuration info for Java) observes the running environment parameters of a running Java program: parameters include the Java system property and JVM command-line arguments, or the configuration information for the crashed Java application from within the core file. command Format

> jinfo [option] pid
Example 4.jmap Description

The Jmap (Memory Map for Java) command is used to generate a heap dump snapshot (commonly known as a heapdump or dump file). command Format

jmap [option] Vmid

The option options are shown in the following table:

Options function
-heap Show JVM Heap Details
-histo Displays object statistics in the JVM heap, including classes, number of instances, total capacity
-dump Generates a Java heap dump snapshot. The format is:-dump:[live],format=b,file=filename, where the live sub-argument indicates whether to dump only the surviving objects
Example

Observed memory usage of Java heap

[Root@localhost bin]# Jmap-heap 2083

Observe the situation of all objects in the heap, including the number of objects and the amount of space occupied

[Root@localhost bin]# jmap-histo:live 2083

Dump out all object files can be used for further analysis

Dump out the surviving object file can be used for further analysis

[Root@localhost bin]# Jmap-dump:live,format=b,file=heap.bin 2083
5.jstack Description

The Jstack (Stack Trace for Java) command is used to generate a thread snapshot of the current moment of the virtual machine (commonly known as threaddump). A thread snapshot is a collection of the method stacks that each thread in the current virtual machine is executing, and the primary purpose of generating the thread snapshot is to locate the cause of the thread's long pauses, such as deadlocks between threads, dead loops, long waits caused by requests for external resources, and so on, which causes the thread to pause for a long time. command Format

> jstack [option] Vmid

The option options are shown in the following table:

Options function
-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 the local method, you can display the C + + stack

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.