java memory monitoring tools and commands

Keywords: memory monitoring tools and commands

A very good memory monitoring knowledge, shared with those who love to learn.....

jinfo: You can output and modify the opts of the java process at runtime.
jps: Similar to ps on unix, it is used to display the local java process, you can view several java programs running locally, and display their process numbers.
jstat: An extremely powerful tool for monitoring VM memory. Can be used to monitor various heap and non-heap sizes and their memory usage within VM memory.
jmap: Print out all 'objects' in the memory of a java process (using pid) (eg: those objects are generated, and their number).
jconsole: A java GUI monitoring tool that can display various data in graphical form. And can monitor the remote server VM through the remote connection.

jprofiler: It is a very good memory monitoring tool, which can monitor tomcat, eclipse, etc.

Next is a detailed introduction to these tools:

start with the simplest jstat tool: I think many people have used the ps command in the unix system, This command is mainly used to display the process status of the current system, which processes are present, and their ids. The same is true for jps. Its function is to display the current system's java process and its id number. We can use it to see how many java processes we have started (because each java program will have an exclusive instance of a java virtual machine), and their process numbers (in preparation for the following programs), and can be viewed through opt Detailed startup parameters for these processes.
How to use: Hit jps in the current command line (JAVA_HOME is required, if not, go to the directory where you changed the program)

Next is jstat. The reason why I tuned the Liferay portal this time is because, by default, if there are too many concurrent users in Liferay, a perm out of momery exception will occur. Although very open to solve, but found the importance of monitoring VM memory usage. Through google, I quickly discovered the jstat tool.
The jstat tool is particularly powerful, with numerous options to view the usage of various parts of the heap in detail, as well as the number of loaded classes. When using, you need to add the process id of the viewing process and the selected parameters. The meaning of each parameter is described in detail below.
jstat -class pid: Displays information such as the number of loaded classes and the space they occupy.
jstat -compiler pid: Displays information such as the number of VM real-time compilations.
jstat -gc pid: can display gc information, check the number of gc, and time. The last five items are the number of young gc, the time of young gc, the number of full gc, the time of full gc, and the total time of gc.
jstat -gccapacity: can display the usage and occupancy size of the three-generation (young, old, perm) objects in the VM memory, such as: PGCMN displays the minimum perm memory usage, PGCMX displays the perm maximum memory usage, PGC is the current newly generated perm memory usage, PC is the previous perm memory usage. Others can be analogized according to this, OC is the pure occupancy in old.
jstat -gcnew pid: new object information.
jstat -gcnewcapacity pid: information of the new object and its occupancy.
jstat -gcold pid: information about the old object.
jstat -gcoldcapacity pid: information on old objects and their occupancy.
jstat -gcpermcapacity pid: Perm object information and its occupancy.
jstat -util pid: Statistics gc information statistics.
jstat -printcompilation pid: Information about the current VM execution.
In addition to the above parameters, you can also add two numbers at the same time, such as: jstat -printcompilation 3024 250 6 is printed every 250 milliseconds, a total of 6 times, you can also add -h3 to display the title every three lines.

jmap is a tool that can output all objects in memory, and even the heap in the VM can be output as text in binary. Use the method jmap -histo pid. If you use SHELL jmap -histo pid>a.log together, you can save it to the text. After a period of time, you can use the text comparison tool to compare which objects are recovered by the GC. jmap -dump:format=b,file=String 3024 can output the memory heap of the 3024 process to a String file.

The use of jinfo: is relatively simple, that is, it can output and modify the running parameters of the java process at runtime. The usage is jinfo -opt pid such as: to view the MaxPerm size of 2788, you can use jinfo -flag MaxPermSize 2788.

jconsole is a GUI program written in java to monitor VM and remote VM. It is very easy to use and powerful. Since it is a GUI program, it will not be introduced in detail here, and you can refer to the official documents of SUN for the places where it is not possible.
How to use: Play jconsole on the command line, and select the process.

Here are the official SUN instructions for these tools:
jps:http://java.sun.com/j2se/1.5.0/docs/tooldocs/share/jps.html
jstat:http://java.sun.com/j2se/1.5.0/docs/tooldocs/share /jstat.html
jmap:http: //java.sun.com/j2se/1.5.0/docs/tooldocs/share/jmap.html
jconsole:http://java.sun.com/j2se/1.5.0/docs /guide/management/jconsole.htmlAdditional

: windows view the process ID , because the task manager does not display the process ID by default, it can be added by the following method. ctrl+alt+del to open the task manager, select the 'process' tab, click 'view' -> 'select column' -> add 'PID', that's it.


Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326673771&siteId=291194637