Introduction to Java's own performance monitoring tool usage--jstack, Jconsole, Jinfo, Jmap, Jdb, Jsta, JVISUALVM

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



JDK built-in tools use



I. Javah command (C Header and Stub File Generator)



Ii. JPS Command (Java Virtual machine Process Status Tool)



Iii. jstack Command (Java Stack Trace)



Iv. jstat Command (Java Virtual machine Statistics monitoring Tool)



V. Jmap command (Java Memory Map)



Vi. jinfo Command (Java Configuration Info)



Vii. jconsole Command (Java monitoring and Management Console)



Viii. JVISUALVM Command (Java Virtual machine monitoring, troubleshooting, and Profiling Tool)



Ix. jhat Command (Java Heap analyse Tool)



X. JDB command (the Java Debugger)


1. Introduction


Jstack is used to print out the Java stack information for a given Java process ID or core file or remote debugging service, and if it is on a 64-bit machine, the option "-J-D64" needs to be specified, and the Jstack usage of Windows only supports the following way:



Jstack [-l] PID



If a Java program crashes generating a core file, the Jstack tool can be used to obtain information about the core file's Java stack and the native stack, making it easy to know how the Java program crashes and where the problem occurs in the program. In addition, the Jstack tool can be attached to a running Java program to see the Java stack and the native stack of the Java program that was running, and jstack is useful if the Java program that is running now renders hung state.



2. Command format
jstack [option] pid
jstack [option] executable core
jstack [option] [[Email Protected]]remote-hostname-or-ip


3. Common parameter description


1), Options:



Executable Java executable from which, the core dump was produced.



(Probably the Java executable that generated the core dump)



Core dump file that will be printed with the information



Remote-hostname-or-ip the host name or IP of the Remote Debug service



Server-id Unique ID, if multiple Remote debug services on a single host



2), Basic parameters:



-F when ' jstack [-l] PID ' does not have a corresponding time to force the printing stack information



-L long list. Prints additional information about the lock, such as the ownable synchronizers list belonging to Java.util.concurrent.



-M prints all of the stack information for Java and Native/C + + frameworks.



-H | -help Printing Help information



The PID requires the Java process ID of the configuration information to be printed and can be queried with JPS.


4. Examples of Use




First, JSTATD
Start the JVM monitoring service. It is an RMI-based application that provides information about native JVM applications to remote machines. Default Port 1099.
Example: Jstatd-j-djava.security.policy=my.policy

The My.policy file needs to be built itself, as in the following:

Grant CodeBase "file:${java.home}/. /lib/tools.jar " {   permission java.security.AllPermission;  }; 

This is a security policy file because the JDK does a Jaas security check on the JVM, so we have to set some policies so that JSTATD is allowed to operate on the network

Second, JPS
List all instances of the JVM
Instance:
JPs
List all JVM instances on this machine

JPS 192.168.0.77
List all JVM instances of the remote server 192.168.0.77 machine, using RMI protocol, the default connection port is 1099
(If the remote server provides JSTATD service)

The output reads as follows:
[Email protected]:~/data/ebook/java/j2se/jdk_gc$ JPS
6286 Jps
6174 Jstat

For details, see Connection: http://www.blogjava.net/aoxj/archive/2007/12/29/171447.html

Third, Jconsole

usage: jconsole [-interval=n] [-notile] [-pluginpath] [-version] [connection ...]

-interval set the update interval to n seconds (the default is 4 seconds)
-notile initially uneven display window (for two or more connections)
-PLUGINPATH Specifies the path Jconsole uses to find the plug-in
-version Output Program version

Connection = PID | | Host:port | | JMX URL (service:jmx:://...)

Process ID of the PID target process
Host remote hostname or IP address
Port port number used for remote connection

-j specifying input parameters for a Java virtual machine that is running Jconsole

Enter command in CMD: jconsole 3980[java process number] Popup



Fourth. Jinfo
Usage:
jinfo [option] pid
jinfo [option] executable core
jinfo [option] [[Email Protected]]remote-hostname-or-ip

Parameters:

PID Process Number
Executable Java executable that produces core dump
Core Core file
REMOTE-HOSTNAME-OR-IP Host name or IP
Server-id Unique ID of the debug server on the remote host

Options:
No option to print command line parameters and System Properties
-flags Print command line arguments
-sysprops Printing System Properties
-H Help

Observe the running environment parameters for Java programs in operation: Parameters include Java System Properties and JVM command-line arguments
Instance:
Jinfo 2083
Where 2083 is the Java process ID number, you can use JPS to get this ID number. I tried to enter this command on Windows, but it didn't work, so I typed the following command:
Jinfo-flag MaxPermSize 3980
Shown below:
-xx:maxpermsize=67108864

Fifth, Jstack
How should the command be used? First need to use the Jstack command to generate the Java process dump file, and then analyze the data in the dump file, the following connection is an article on how to analyze the Jstack generated dump file data, write very good:
Http://www.blogjava.net/jzone/articles/303979.html

Sixth, JMAP (Linux-specific, is also a very common command)
Observe the physical memory usage of the JVM in operation.
The parameters are as follows:
-heap: Printing JVM Heap
-histo: Prints the histogram of the JVM heap. Its output information includes the class name, the number of objects, and the size of the object.
-histo:live: Same as above, but only promise to survive
-permstat: Print permanent generation heap condition

command to use:
Jmap-heap 2083
You can observe the memory usage of the new Generation (Eden space,from space,to Space), tenured generation,perm Generation

Jmap-histo 2083 | jmap-histo:live 2083
You can observe the condition of all objects in the heap (in the case of all surviving objects in the heap). Includes the number of objects and the amount of space occupied.

Jmap-histo Java Process ID
You can view the number of instances and instances in a Java process, and you can use it to query whether a singleton object actually generates only one instance.

In the console, enter the command "Jmap-histo 7329 > Histo_dump" to get the following results:

Java code
  1. Num #instances #bytes class name
  2. ---------------------------------------------
  3. 1: 605348 68849960 [C
  4. 2: 1609734 51511488 java.util.concurrent.concurrenthashmap$segment
  5. 3: 1610022 38640528 java.util.concurrent.locks.reentrantlock$nonfairsync
  6. 4: 70784 31478168 [I
  7. 5: 218224 27628072 <constMethodKlass>
  8. 6: 1609734 26423552 [Ljava.util.concurrent.concurrenthashmap$hashentry;
  9. 7: 40379 24430792 [B
  10. 8: 218224 19211544 <methodKlass>
  11. 9: 602848 14468352 java.lang.String
  12. Ten: 19374 11640184 <constantPoolKlass>
  13. One : 236950 11451216 <symbolKlass>
  14. : 283746 11349840 java.util.concurrent.concurrenthashmap$valueiterator
  15. £ 19374 8826272 <instanceKlassKlass>
  16. : 100613 8048728 [ljava.util.concurrent.concurrenthashmap$segment;
  17. : 85036 7332664 [Ljava.lang.Object;
  18. : 15559 6614824 <constantPoolCacheKlass>
  19. : 78919 6313520 java.lang.reflect.Method
  20. : 103377 4962096 com.sun.tools.javac.zip.ZipFileIndexEntry
  21. : 51998 4324096 [Ljava.util.hashmap$entry;
  22. : 100613 4024520 java.util.concurrent.ConcurrentHashMap
  23. £ º 157136 3771264 java.util.concurrent.concurrenthashmap$hashentry
  24. A : 35932 3736928 com.asiainfo.dbm.core.bean.monitor.FlowService
  25. At : 35932 3736928 com.asiainfo.dbm.core.bean.monitor.FlowService




Seventh, Jstat
In the end, we will focus on this command, which is a more important and useful command in the JDK command, which can be used to observe the CLASSLOADER,COMPILER,GC related information.
The specific parameters are as follows:
-class: Statistics class loader behavior information
-compile: Statistical compilation Behavior Information
-GC: Statistics on JDK GC time heap information
-gccapacity: Statistics of different generations (do not know how to translate well, including the new district, old age area, Permanent district) corresponding heap capacity situation
-gccause: Statistical GC case, (same as-gcutil) and event that caused GC
-gcnew: When statistics GC, the Cenozoic situation
-gcnewcapacity: When statistics GC, the Cenozoic heap capacity
-gcold: Statistics GC, the situation of the elderly area
-gcoldcapacity: When statistics GC, the old area heap capacity
-gcpermcapacity: When statistics GC, permanent area heap capacity
-gcutil: When statistics GC, heap condition
-printcompilation: Don't know what to do, has been useless.

Some of the commonly used parameters are:


Java code
    1. Jstat-class 27629 //monitor every 1 seconds for 10 times



The output content has the following meanings:


Loaded Bytes Unloaded Bytes Time
49955 49701.5 35528 32456.1 34.71
49955 49701.5 35528 32456.1 34.71
49955 49701.5 35528 32456.1 34.71
49955 49701.5 35528 32456.1 34.71
49963 49708.8 35528 32456.1 34.71
49963 49708.8 35528 32456.1 34.71
49963 49708.8 35528 32456.1 34.71
49971 49716.1 35528 32456.1 34.71
49971 49716.1 35528 32456.1 34.71
49971 49716.1 35528 32456.1 34.71




JSTAT-GC 2083 2000 20 (monitored every 2 seconds, total 10)
The output content has the following meanings:


s0c current survivor (live) space 0 capacity (KB).
EC current Eden Space Capacity (KB).
EU Eden Space Utilization (KB).
OC Current old space Capacity (KB).
OU Old space Utilization (KB).
PC Current permanent space capacity (KB).
PU Permanent Space Utilization (KB).
YGC number of young generation GC Events.
ygct Young Generation garbage collection time.
FGC number of full GC events.
fgct full garbage collection time.
GCT Total garbage collection time.




Monitoring memory usage parameters (viewing memory overflow is relatively useful)
Jstat-gccause 2083 5000 (monitored every 5 seconds)
The output content has the following meanings:


S0 Survivor Space 0 Utilization as a percentage of the space ' s current capacity.
S1 Survivor Space 1 Utilization as a percentage of the space ' s current capacity.
E Eden space utilization As a percentage of the space ' s current capacity.
O Old space utilization as a percentage of the space's current capacity.
P Permanent space utilization As a percentage of the space ' s current capacity.
Ygc Number of young generation GC events.
Ygct Young generation garbage collection time.
FGC Number of full GC events.
Fgct Full garbage collection time.
GCT Total garbage collection time.
lgcc Cause of last garbage Collection.
Gcc Cause of current garbage Collection.




Eighth, JVISUALVM&NBSP;
Java VISUALVM is a release version of VISUALVM for Java VMS. For more information about VISUALVM you can access the VISUALVM.JAVA.NET.JVISUALVM tool from JDK 6 Update7 (Apple's Java is from Mac OS X 10.5 update 4) and the JDK tool already exists by default.  
Java VISUALVM is a stable tool that has been tested with each JDK release version. The latest JDK is available for download on the Oracle (Sun) Company's website. The

JVISUALVM features and UI are more powerful than jconsole. Let's look at the usage of JVISUALVM first. He is a GUI (graphical interface) tool, so getting started should be quick.  .

Official website about JVISUALVM usage Introduction http://docs.oracle.com/javase/6/docs/technotes/tools/share/jvisualvm.html  

Simply put, we don't need to pass any parameters to start JVISUALVM.  

We can put JVISUALVM into the path of the JDK and add it to the path of the environment. This is when we run   in Windows or cmd, and
JVISUALVM can start the tool. Or we can directly double click on the software  
Enter the command in cmd: JVISUALVM pop-up  


For specific usage, refer to the following link: http://www.iteye.com/topic/516447 &NBSP

Below we explain how to use VISUALVM to monitor the remote host  
First, we can be anywhere in the user directory (for example: the user root directory, or the JDK root directory) create a new file named Jstatd.all.policy, with the following file contents:  



Grant CodeBase "file:${java.home}/. /lib/tools.jar " {       permission java.security.AllPermission;     }; 


After the new file is created, we give the file the Execute permission, with the following command:





We then start the JSTATD service (the default port for the JSTATD service is 1099) when we run the following command:



Jstatd-j-djava.security.policy=/sw/bes/jstatd.all.policy  


Remember that the Jstatd.all.policy file must be an absolute path to prevent java.security.AccessControlException:access denied ( Java.util.PropertyPermission java.rmi.server.ignoreSubClasses Write) error.

Finally, we can use the JPS command to see if it started successfully:



Jps-l  


The following results are obtained:


      • 9481 Com.bes.enterprise.ee.nodeagent.NodeAgentMain
      • 7329 Com.bes.enterprise.server.Entry
      • 18968 Com.bes.enterprise.server.Entry
      • 15802 SUN.TOOLS.JSTATD.JSTATD
      • 16075 Sun.tools.jps.Jps
      • 9328 Com.bes.enterprise.server.Entry







Introduction to Java's own performance monitoring tool usage--jstack, Jconsole, Jinfo, Jmap, Jdb, Jsta, JVISUALVM


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.