[zz]JDK自带VM分析工具jps,jstat,jmap,jconsole
zz from http://jiajun.javaeye.com/blog/443196
一、概述
SUN 的JDK中的几个工具,非常好用。秉承着有免费,不用商用的原则。以下简单介绍一下这几种工具。(注:本文章下的所有工具都存在JDK5.0以上版本的工具集里,同javac一样,不须特意安装) 。
我一共找到以下四个工具:重点看看jconsole和jmap。
- jps
- :与unix上的ps类似,用来显示本地的java进程,可以查看本地运行着几个java程序,并显示他们的进程号。
- jstat
- :一个极强的监视VM内存工具。可以用来监视VM内存内的各种堆和非堆的大小及其内存使用量。
- jmap
- :打印出某个java进程(使用pid)内存内的,所有‘对象’的情况(如:产生那些对象,及其数量)。
- jconsole
- :一个java GUI监视工具,可以以图表化的形式显示各种数据。并可通过远程连接监视远程的服务器VM。
二、 使用介绍:
1、jstat :我想很多人都是用过unix系统里的ps命令,这个命令主要是用来显示当前系统的进程情况,有哪些进程,及其 id。 jps 也是一样,它的作用是显示当前系统的java进程情况,及其id号。我们可以通过它来查看我们到底启动了几个java进程(因为每一个java程序都会独占一个java虚拟机实例),和他们的进程号(为下面几个程序做准备),并可通过opt来查看这些进程的详细启动参数。
使用方法:在当前命令行下打 jps(需要JAVA_HOME,没有的话,到改程序的目录下打) 。
可惜没有linux下的ps好用,名称不好用。但是在第四个工具jconsole的界面里面会有具体JAR包的名称。
2、jstat :对VM内存使用量进行监控。
jstat工具特别强大,有众多的可选项,详细查看堆内各个部分的使用量,以及加载类的数量。使用时,需加上查看进程的进程id,和所选参数。以下详细介绍各个参数的意义。
jstat -class pid:显示加载class的数量,及所占空间等信息。
jstat -compiler pid:显示VM实时编译的数量等信息。
jstat -gc pid:可以显示gc的信息,查看gc的次数,及时间。其中最后五项,分别是young gc的次数,young gc的时间,full gc的次数,full gc的时间,gc的总时间。
jstat -gccapacity:可以显示,VM内存中三代(young,old,perm)对象的使用和占用大小,如:PGCMN显示的是最小perm的内存使用量,PGCMX显示的是perm的内存最大使用量,PGC是当前新生成的perm内存占用量,PC是但前perm内存占用量。其他的可以根据这个类推, OC是old内纯的占用量。
jstat -gcnew pid:new对象的信息。
jstat -gcnewcapacity pid:new对象的信息及其占用量。
jstat -gcold pid:old对象的信息。
jstat -gcoldcapacity pid:old对象的信息及其占用量。
jstat -gcpermcapacity pid: perm对象的信息及其占用量。
jstat -util pid:统计gc信息统计。
jstat -printcompilation pid:当前VM执行的信息。
除了以上一个参数外,还可以同时加上 两个数字,如:jstat -printcompilation 3024 250 6是每250毫秒打印一次,一共打印6次,还可以加上-h3每三行显示一下标题。
3、jmap 是一个可以输出所有内存中对象的工具,甚至可以将VM 中的heap,以二进制输出成文本。使用方法 jmap -histo pid。如果连用 SHELL jmap -histo pid>a.log可以将其保存到文本中去(windows下也可以使用),在一段时间后,使用文本对比工具,可以对比出GC回收了哪些对象。jmap -dump:format=b,file=f1 3024可以将3024进程的内存heap输出出来到f1文件里。
4、jconsole 是一个用java写的GUI程序,用来监控VM,并可监控远程的VM,非常易用,而且功能非常强。由于是GUI程序,这里就不详细介绍了,不会的地方可以参考SUN的官方文档。
使用方法:命令行里打 jconsole,选则进程就可以了。
友好提示:windows查看进程号,由于任务管理器默认的情况下是不显示进程id号的,所以可以通过如下方法加上。ctrl+alt+del打开任务管理器,选择‘进程’选项卡,点‘查看’->''选择列''->加上''PID'',就可以了。当然还有其他很好的选项。
三、参考资料:
article:http://elf8848.javaeye.com/blog/442806
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.html
Wed, 07 Sep 2022 17:37:01 +0800
Hi are using WordPress for your blog platform? I’m new to the blog world but I’m trying to get started and set up my own. Do you need any coding knowledge to make your own blog? Any help would be greatly appreciated! is god real
Wed, 07 Sep 2022 17:37:59 +0800
I precisely desired to say thanks once again. I’m not certain the things that I might have used in the absence of the entire opinions revealed by you regarding that question. It had become a real difficult concern in my position, nevertheless spending time with your specialised avenue you resolved the issue made me to jump over joy. I’m just grateful for this advice and even wish you comprehend what a great job that you’re carrying out instructing most people all through your webpage. I know that you have never got to know any of us. Sacramento window tinting
Wed, 07 Sep 2022 17:38:51 +0800
Excellent beat ! I wish to apprentice while you amend your web site, how can i subscribe for a blog site? The account helped me a acceptable deal. I had been a little bit acquainted of this your broadcast provided bright clear idea seattle flower delivery
Wed, 07 Sep 2022 21:43:34 +0800
Excellent website! I adore how it is easy on my eyes it is. I am questioning how I might be notified whenever a new post has been made. Looking for more new updates. Have a great day! Excellent team
Fri, 30 Sep 2022 01:08:27 +0800
Every student of Assam Government and Private school class 10th standard student can download SEBA Question Paper for EVS by expert reference to guessing important questions for all chapters of EVS to all mediums of Hindi, English, Assamese, Bengali, Bodo, Manipuri, Garo, Nepali Medium general, SEBA 10th Social Question Paper curriculum and vocational course students to the academic year of 2023.very student of Assam Government and Private school class 10th standard student can download SEBA Question Paper for EVS by expert reference to guessing important questions for all chapters of EVS to all mediums
Tue, 06 Dec 2022 01:43:27 +0800
Gran post y sitio. Bueno que AOL en la lista por lo que he podido llegar hasta aquí. Este sitio va a ir no en Mis marcadores a partir de ahora. 二手Macbook
================
Great site. Plenty of useful information here. I’m sending it to a few friends ans also sharing in delicious. And certainly, thanks for your sweat! 메이저사이트
Thu, 12 Jan 2023 23:17:15 +0800
I the efforts you have put in this, appreciate it for all the great posts . 온라인카지노
Thu, 19 Jan 2023 17:48:32 +0800
This is really interesting, You’re a remarkably professional article writer. I have enrolled with your feed and furthermore , count on enjoying the really great write-ups. And additionally, I’ve got shared your webpage throughout our myspace. SAP Finance
Mon, 23 Jan 2023 21:32:25 +0800
plumbing supplies should always come from reputable suppliers so always check their backgrounds., Apple iPad Pro 12.9 (5th generation) Review
Tue, 24 Jan 2023 15:14:07 +0800
I’m a blog crazed person and i love to read cool blog like yours…;*: cryptocurrency
Sun, 19 Feb 2023 17:16:41 +0800
Fantastic goods from you, man. I have understand your stuff previous to and you are just extremely fantastic. I really like what you’ve acquired here, certainly like what you are stating and the way in which you say it. You make it enjoyable and you still care for to keep it smart. I can’t wait to read much more from you. This is really a terrific website. 슈어맨
Sun, 18 Jun 2023 23:06:43 +0800
Hi” best wishes to you and your very nice blog” 花藝課程
Wed, 28 Jun 2023 19:00:31 +0800
Awesome. Thanks for a great article page. I’ll be coming and reading for more and read your other articles. If you’d like me to refer this to others, please let me know as I have a lot of people who might be interested in what this site has to share. fragrances
========================
Whats up very cool web site!! Man .. Beautiful .. Superb .. I will bookmark your web site and take the feeds additionally…I am happy to find a lot of useful information here in the put up, we want develop extra techniques on this regard, thank you for sharing. skincare
========================
Sometimes, blogging is a bit tiresome specially if you need to update more topics.”:’:’ beauty
========================
Thank you a bunch for sharing this with all folks you actually realize what you’re speaking approximately! Bookmarked. Kindly additionally seek advice from my site =). We could have a link trade contract between us! fashion
=========================
whoah this weblog is great i like studying your articles. Keep up the great paintings! You already know, a lot of people are searching around for this info, you could help them greatly. cosmetics
==========================
Hi there, It’s posts like this that keep me coming back and checking this weblog regularly, thanks for the info! skincare
==========================
very good post, i certainly love this site, keep on it makeup
==========================
cheers, I thoroughly enjoyed scaning your post. I really appreciate your wonderful know-how and the time you put into educating the rest of us. accessories
==========================
I just couldn’t go away your website before suggesting that I actually loved the standard info a person supply on your guests? Is going to be again frequently to investigate cross-check new posts. cosmetics
=========================
great put up, very informative. I wonder why the opposite experts of this sector do not understand this. You must continue your writing. I’m sure, you’ve a huge readers’ base already! Rent a car kosova makeup
Wed, 23 Aug 2023 02:07:08 +0800
Nice post. I discover something harder on different blogs everyday. It will always be stimulating to learn to read content from other writers and rehearse a little at their store. I’d would rather apply certain with all the content in my small blog regardless of whether you don’t mind. Natually I’ll supply you with a link on the web blog. Many thanks sharing. 插花技巧
Sun, 28 Jan 2024 00:27:41 +0800 I think this website holds very great pent written content blog posts. FM카지노먹튀
Thu, 04 Jul 2024 01:27:50 +0800
Shocking dispatch! I'm totally more by then undeniably expecting to over this information, is genuinely extraordinary my amigo. In like manner overpowering site here among a wide store of the crazy data you get. Hold up the beast cycle you are doing here. DIGIHUMAN virtual anatomy and physiology labs anatomy interactive
Thu, 04 Jul 2024 01:28:04 +0800
Benefit by enterprisingly premium substances - you will see that person for: youibot autonomous mobile robots amr amr robot