`
RednaxelaFX
  • 浏览: 3023168 次
  • 性别: Icon_minigender_1
  • 来自: 海外
社区版块
存档分类
最新评论

通过jstat工具来查看jvmstat monitor的值

    博客分类:
  • Java
阅读更多
接上之前发的几帖(1)  (2)  (3),再回过头来看看如果不是用Java API,有没有什么工具能直接看到某个Java进程的jvmstat的各个monitor的值。

Sun JDK自带的jstat工具其实就可以看到HotSpot支持的所有jvmstat信息,只不过官方文档上没把相关的隐藏参数写出来而已。

下面还是用例子来说明。这次的目标是查看一个跑在Windows XP SP3, Sun JDK 6 update 17上的Eclipse的状况。

首先用jps工具查出Eclipse进程的vmid:
D:\>jps
1028 Jps
1996 org.eclipse.equinox.launcher_1.0.201.R35x_v20090715.jar


好,目标就是ID为1996的进程。然后使用jstat,加上一个文档上没记录的-snap参数:
D:\>jstat -snap 1996
java.ci.totalTime=11274276735
java.cls.loadedClasses=15981
java.cls.sharedLoadedClasses=0
java.cls.sharedUnloadedClasses=0
java.cls.unloadedClasses=53
java.property.java.class.path="D:\editor\eclipse_jee\plugins/org.eclipse.equinox.launcher_1.0.201.R35x_v20090715.jar;lombok.jar"
java.property.java.endorsed.dirs="C:\sdk\Java\jdk1.6.0_17\jre\lib\endorsed"
java.property.java.ext.dirs="C:\sdk\Java\jdk1.6.0_17\jre\lib\ext;C:\WINDOWS\Sun\Java\lib\ext"
java.property.java.home="C:\sdk\Java\jdk1.6.0_17\jre"
java.property.java.library.path="C:\sdk\Java\jdk1.6.0_20\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Perl\site\bin;C:\Perl\bin;D:\sdk\Python31\;D:\sdk\Ruby\bin;;C:\WINDOWS\System32\Wbem;C:\Program Files\ATI Technologies\ATI.ACE\Core-Static;C:\sdk\SlikSvn\bin\;C:\sdk\TortoiseSVN\bin;C:\sdk\TortoiseHg;C:\sdk\Git\cmd;D:\sdk\ChezScheme7.4d\bin\i3nt;C:\sdk\Graphviz2.26.3\bin;D:\sdk\GnuWin32\bin;C:\Program Files\Haskell\bin;D:\sdk\ghc-6.10.4\bin;D:\sdk\apache-maven-2.2.1\bin;D:\sdk\Python31\Scripts;D:\script;D:\sdk\apache-ant-1.7.1\bin"
java.property.java.version="1.6.0_17"
java.property.java.vm.info="mixed mode"
java.property.java.vm.name="Java HotSpot(TM) Client VM"
java.property.java.vm.specification.name="Java Virtual Machine Specification"
java.property.java.vm.specification.vendor="Sun Microsystems Inc."
java.property.java.vm.specification.version="1.0"
java.property.java.vm.vendor="Sun Microsystems Inc."
java.property.java.vm.version="14.3-b01"
java.rt.vmArgs="-Dosgi.requiredJavaVersion=1.5 -Xms40m -Xmx512m -javaagent:lombok.jar -Xbootclasspath/a:lombok.jar -XX:MaxPermSize=256m"
java.rt.vmFlags=""
java.threads.daemon=18
java.threads.live=23
java.threads.livePeak=33
java.threads.started=3743

这里已经可以看到很多信息,像是HotSpot的动态编译器用了多少时间,整个VM加载了多少个类卸载了多少个类,启动路径、参数,VM的版本等。不过前面一帖的列表里明明有更多的monitor,它们跑哪儿去了呢?

于是再多加一个-J-Djstat.showUnsupported=true参数来跑jstat:
D:\>jstat -J-Djstat.showUnsupported=true -snap 1996
java.ci.totalTime=11274276735
java.cls.loadedClasses=15981
java.cls.sharedLoadedClasses=0
java.cls.sharedUnloadedClasses=0
java.cls.unloadedClasses=53
java.property.java.class.path="D:\editor\eclipse_jee\plugins/org.eclipse.equinox.launcher_1.0.201.R35x_v20090715.jar;lombok.jar"
java.property.java.endorsed.dirs="C:\sdk\Java\jdk1.6.0_17\jre\lib\endorsed"
java.property.java.ext.dirs="C:\sdk\Java\jdk1.6.0_17\jre\lib\ext;C:\WINDOWS\Sun\Java\lib\ext"
java.property.java.home="C:\sdk\Java\jdk1.6.0_17\jre"
java.property.java.library.path="C:\sdk\Java\jdk1.6.0_20\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Perl\site\bin;C:\Perl\bin;D:\sdk\Python31\;D:\sdk\Ruby\bin;;C:\WINDOWS\System32\Wbem;C:\Program Files\ATI Technologies\ATI.ACE\Core-Static;C:\sdk\SlikSvn\bin\;C:\sdk\TortoiseSVN\bin;C:\sdk\TortoiseHg;C:\sdk\Git\cmd;D:\sdk\ChezScheme7.4d\bin\i3nt;C:\sdk\Graphviz2.26.3\bin;D:\sdk\GnuWin32\bin;C:\Program Files\Haskell\bin;D:\sdk\ghc-6.10.4\bin;D:\sdk\apache-maven-2.2.1\bin;D:\sdk\Python31\Scripts;D:\script;D:\sdk\apache-ant-1.7.1\bin"
java.property.java.version="1.6.0_17"
java.property.java.vm.info="mixed mode"
java.property.java.vm.name="Java HotSpot(TM) Client VM"
java.property.java.vm.specification.name="Java Virtual Machine Specification"
java.property.java.vm.specification.vendor="Sun Microsystems Inc."
java.property.java.vm.specification.version="1.0"
java.property.java.vm.vendor="Sun Microsystems Inc."
java.property.java.vm.version="14.3-b01"
java.rt.vmArgs="-Dosgi.requiredJavaVersion=1.5 -Xms40m -Xmx512m -javaagent:lombok.jar -Xbootclasspath/a:lombok.jar -XX:MaxPermSize=256m"
java.rt.vmFlags=""
java.threads.daemon=18
java.threads.live=23
java.threads.livePeak=33
java.threads.started=3744
sun.ci.compilerThread.0.compiles=6302
sun.ci.compilerThread.0.method=""
sun.ci.compilerThread.0.time=4923396
sun.ci.compilerThread.0.type=1
sun.ci.lastFailedMethod="org/eclipse/jdt/internal/core/CompilationUnitStructureRequestor createTypeInfo"
sun.ci.lastFailedType=1
sun.ci.lastInvalidatedMethod=""
sun.ci.lastInvalidatedType=0
sun.ci.lastMethod="org/eclipse/ui/internal/layout/TrimArea computeWrappedTrim"
sun.ci.lastSize=577
sun.ci.lastType=1
sun.ci.nmethodCodeSize=5622944
sun.ci.nmethodSize=13224788
sun.ci.osrBytes=16202
sun.ci.osrCompiles=29
sun.ci.osrTime=159843303
sun.ci.standardBytes=1206710
sun.ci.standardCompiles=6267
sun.ci.standardTime=11114433432
sun.ci.threads=1
sun.ci.totalBailouts=6
sun.ci.totalCompiles=6296
sun.ci.totalInvalidates=0
sun.cls.classInitTime=57799894653
sun.cls.classLinkedTime=79687099728
sun.cls.classVerifyTime=192186673173
sun.cls.initializedClasses=11406
sun.cls.isUnsyncloadClassSet=0
sun.cls.jniDefineClassNoLockCalls=1
sun.cls.jvmDefineClassNoLockCalls=106
sun.cls.jvmFindLoadedClassNoLockCalls=0
sun.cls.linkedClasses=13248
sun.cls.loadInstanceClassFailRate=0
sun.cls.loadedBytes=20912352
sun.cls.methodBytes=13457952
sun.cls.nonSystemLoaderLockContentionRate=62
sun.cls.sharedLoadedBytes=0
sun.cls.sharedUnloadedBytes=0
sun.cls.systemLoaderLockContentionRate=0
sun.cls.time=96533747082
sun.cls.unloadedBytes=47848
sun.cls.unsafeDefineClassCalls=106
sun.gc.cause="No GC"
sun.gc.collector.0.invocations=1035
sun.gc.collector.0.lastEntryTime=340630839536481
sun.gc.collector.0.lastExitTime=340630849279881
sun.gc.collector.0.name="Copy"
sun.gc.collector.0.time=9872748234
sun.gc.collector.1.invocations=2950
sun.gc.collector.1.lastEntryTime=530223797079243
sun.gc.collector.1.lastExitTime=530224765895475
sun.gc.collector.1.name="MSC"
sun.gc.collector.1.time=2813934945510
sun.gc.generation.0.agetable.bytes.00=0
sun.gc.generation.0.agetable.bytes.01=343736
sun.gc.generation.0.agetable.bytes.02=0
sun.gc.generation.0.agetable.bytes.03=0
sun.gc.generation.0.agetable.bytes.04=0
sun.gc.generation.0.agetable.bytes.05=0
sun.gc.generation.0.agetable.bytes.06=0
sun.gc.generation.0.agetable.bytes.07=0
sun.gc.generation.0.agetable.bytes.08=0
sun.gc.generation.0.agetable.bytes.09=0
sun.gc.generation.0.agetable.bytes.10=0
sun.gc.generation.0.agetable.bytes.11=0
sun.gc.generation.0.agetable.bytes.12=0
sun.gc.generation.0.agetable.bytes.13=0
sun.gc.generation.0.agetable.bytes.14=0
sun.gc.generation.0.agetable.bytes.15=0
sun.gc.generation.0.agetable.size=16
sun.gc.generation.0.capacity=7864320
sun.gc.generation.0.maxCapacity=41287680
sun.gc.generation.0.minCapacity=3211264
sun.gc.generation.0.name="new"
sun.gc.generation.0.space.0.capacity=6291456
sun.gc.generation.0.space.0.initCapacity=0
sun.gc.generation.0.space.0.maxCapacity=33030144
sun.gc.generation.0.space.0.name="eden"
sun.gc.generation.0.space.0.used=742104
sun.gc.generation.0.space.1.capacity=786432
sun.gc.generation.0.space.1.initCapacity=0
sun.gc.generation.0.space.1.maxCapacity=4128768
sun.gc.generation.0.space.1.name="s0"
sun.gc.generation.0.space.1.used=0
sun.gc.generation.0.space.2.capacity=786432
sun.gc.generation.0.space.2.initCapacity=0
sun.gc.generation.0.space.2.maxCapacity=4128768
sun.gc.generation.0.space.2.name="s1"
sun.gc.generation.0.space.2.used=0
sun.gc.generation.0.spaces=3
sun.gc.generation.1.capacity=93532160
sun.gc.generation.1.maxCapacity=495583232
sun.gc.generation.1.minCapacity=38731776
sun.gc.generation.1.name="old"
sun.gc.generation.1.space.0.capacity=93532160
sun.gc.generation.1.space.0.initCapacity=38731776
sun.gc.generation.1.space.0.maxCapacity=495583232
sun.gc.generation.1.space.0.name="old"
sun.gc.generation.1.space.0.used=51151056
sun.gc.generation.1.spaces=1
sun.gc.generation.2.capacity=86245376
sun.gc.generation.2.maxCapacity=268435456
sun.gc.generation.2.minCapacity=12582912
sun.gc.generation.2.name="perm"
sun.gc.generation.2.space.0.capacity=86245376
sun.gc.generation.2.space.0.initCapacity=12582912
sun.gc.generation.2.space.0.maxCapacity=268435456
sun.gc.generation.2.space.0.name="perm"
sun.gc.generation.2.space.0.used=86128864
sun.gc.generation.2.spaces=1
sun.gc.lastCause="System.gc()"
sun.gc.policy.collectors=2
sun.gc.policy.desiredSurvivorSize=393216
sun.gc.policy.generations=3
sun.gc.policy.maxTenuringThreshold=15
sun.gc.policy.name="Copy:MSC"
sun.gc.policy.tenuringThreshold=15
sun.gc.tlab.alloc=40188
sun.gc.tlab.allocThreads=7
sun.gc.tlab.fastWaste=0
sun.gc.tlab.fills=7
sun.gc.tlab.gcWaste=36050
sun.gc.tlab.maxFastWaste=0
sun.gc.tlab.maxFills=1
sun.gc.tlab.maxGcWaste=18546
sun.gc.tlab.maxSlowAlloc=0
sun.gc.tlab.maxSlowWaste=0
sun.gc.tlab.slowAlloc=0
sun.gc.tlab.slowWaste=0
sun.os.hrt.frequency=2992520000
sun.os.hrt.ticks=530286231578049
sun.perfdata.majorVersion=2
sun.perfdata.minorVersion=0
sun.perfdata.overflow=0
sun.perfdata.size=65536
sun.perfdata.timestamp=2374418412
sun.perfdata.used=14496
sun.property.sun.boot.class.path="C:\sdk\Java\jdk1.6.0_17\jre\lib\resources.jar;C:\sdk\Java\jdk1.6.0_17\jre\lib\rt.jar;C:\sdk\Java\jdk1.6.0_17\jre\lib\sunrsasign.jar;C:\sdk\Java\jdk1.6.0_17\jre\lib\jsse.jar;C:\sdk\Java\jdk1.6.0_17\jre\lib\jce.jar;C:\sdk\Java\jdk1.6.0_17\jre\lib\charsets.jar;C:\sdk\Java\jdk1.6.0_17\jre\classes;lombok.jar"
sun.property.sun.boot.library.path="C:\sdk\Java\jdk1.6.0_17\jre\bin"
sun.rt._sync_ContendedLockAttempts=111725
sun.rt._sync_Deflations=25166
sun.rt._sync_EmptyNotifications=0
sun.rt._sync_FailedSpins=0
sun.rt._sync_FutileWakeups=3979
sun.rt._sync_Inflations=25184
sun.rt._sync_MonExtant=14336
sun.rt._sync_MonInCirculation=0
sun.rt._sync_MonScavenged=0
sun.rt._sync_Notifications=101533
sun.rt._sync_Parks=125094
sun.rt._sync_PrivateA=0
sun.rt._sync_PrivateB=0
sun.rt._sync_SlowEnter=0
sun.rt._sync_SlowExit=0
sun.rt._sync_SlowNotify=0
sun.rt._sync_SlowNotifyAll=0
sun.rt._sync_SuccessfulSpins=0
sun.rt.applicationTime=527384947891815
sun.rt.createVmBeginTime=1288056340317
sun.rt.createVmEndTime=1288056341110
sun.rt.internalVersion="Java HotSpot(TM) Client VM (14.3-b01) for windows-x86 JRE (1.6.0_17-b04), built on Oct 11 2009 00:52:06 by "java_re" with MS VC++ 7.1"
sun.rt.interruptedBeforeIO=0
sun.rt.interruptedDuringIO=0
sun.rt.javaCommand="D:\editor\eclipse_jee\plugins/org.eclipse.equinox.launcher_1.0.201.R35x_v20090715.jar -os win32 -ws win32 -arch x86 -showsplash -launcher D:\editor\eclipse_jee\eclipse.exe -name Eclipse --launcher.library D:\editor\eclipse_jee\plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.0.200.v20090519\eclipse_1206.dll -startup D:\editor\eclipse_jee\plugins/org.eclipse.equinox.launcher_1.0.201.R35x_v20090715.jar -exitdata a0c_44 -product org.eclipse.epp.package.jee.product -vm C:/sdk/Java/jdk1.6.0_17/bin/javaw.exe -vmargs -Dosgi.requiredJavaVersion=1.5 -Xms40m -Xmx512m -javaagent:lombok.jar -Xbootclasspath/a:lombok.jar -XX:MaxPermSize=256m -jar D:\editor\eclipse_jee\plugins/org.eclipse.equinox.launcher_1.0.201.R35x_v20090715.jar"
sun.rt.jvmCapabilities="1000000000000000000000000000000000000000000000000000000000000000"
sun.rt.jvmVersion=235077633
sun.rt.safepointSyncTime=971909442
sun.rt.safepointTime=2837457553374
sun.rt.safepoints=8467
sun.rt.threadInterruptSignaled=0
sun.rt.vmInitDoneTime=1288056340674
sun.threads.vmOperationTime=2824580448243

嗯现在信息就全了不是?

HotSpot并不是没记录内部信息,只是还没什么特别好的工具把它们整理、显示出来而已。这点上JRockit Mission Control/Flight Recorder就强悍多了。

===========================================================

P.S. 有人问为什么VisualVM的VisualGC插件里的histogram面板有时候会显示不出东西。其实很简单:只是这功能不支持ParallelGC而已。
VisualGC需要通过jvmstat API来读取名为"sun.gc.generation.0.agetable.size"的PerfData计数器的值,在visualgc.jar里的com.sun.jvmstat.tools.visualgc.MonitoredVmModel.initialize_common()。
这个计数器是在全局的ageTable初始化时创建的。HotSpot VM里DefNew/ParNew/G1等涉及young GC的实现都用到了全局的ageTable,但ParallelScavange则没有。于是在使用UseParallelGC/UseParallelOldGC时,这个计数器就不存在,VisualGC就会认为目标JVM不支持显示histogram的功能。

(注:Windows 7上的话JDK7里的VisualVM的VisualGC插件的内容可以在%User%/AppData/Roaming/.visualvm/7/modules/com-sun-tools-visualvm-modules-visualgc.jar 以及 %User%/AppData/Roaming/.visualvm/7/modules/ext/visualgc.jar 找到。
VisualGC插件自身没开源,所以就不能指望从visualvm.java.net那边找到它的源码了)
分享到:
评论
2 楼 expone 2014-04-14  
兄弟 jstat 提供的rmi接口,还知道怎么调用啊
1 楼 bingyingao 2013-01-18  
好文章, 标记一下

相关推荐

Global site tag (gtag.js) - Google Analytics