背景
很久之前的事情了,在很久很久……
一般在做性能測試的時候為最小限度影響性能,基本會不開gc日志,但出現問題,有要檢視相關資訊,麻勒個煩啊
有沒有兩全其美的辦法?
有
廢話略過,往下看
jinfo
jinfo(Java Configuration Information),主要用于檢視正在運作的Java程序(或核心檔案、遠端調試伺服器)的Java配置資訊
用法
[[email protected] config]# jinfo
Usage:
jinfo [option] <pid>
(to connect to running process)
jinfo [option] <executable <core>
(to connect to a core file)
jinfo [option] [server_id@]<remote server IP or hostname>
(to connect to remote debug server)
where <option> is one of:
-flag <name> to print the value of the named VM flag
-flag [+|-]<name> to enable or disable the named VM flag
-flag <name>=<value> to set the named VM flag to the given value
-flags to print VM flags
-sysprops to print Java system properties
<no option> to print both of the above
-h | -help to print this help message
重點看-flag選項(圈起來要考試~)
在使用-flag選項時,jinfo實用程式可以動态調整特定Java程序的特定Java VM标志的值。這類選項的清單是有限的,但在一些場合仍然有用。JVM上的這些标志的完整清單可以通過以下指令進行檢查
[root@localhost config]# java -XX:+PrintFlagsFinal -version|grep manageable
intx CMSAbortablePrecleanWaitMillis = {manageable}
intx CMSTriggerInterval = - {manageable}
intx CMSWaitDuration = {manageable}
bool HeapDumpAfterFullGC = false {manageable}
bool HeapDumpBeforeFullGC = false {manageable}
bool HeapDumpOnOutOfMemoryError = false {manageable}
ccstr HeapDumpPath = {manageable}
uintx MaxHeapFreeRatio = {manageable}
uintx MinHeapFreeRatio = {manageable}
bool PrintClassHistogram = false {manageable}
bool PrintClassHistogramAfterFullGC = false {manageable}
bool PrintClassHistogramBeforeFullGC = false {manageable}
bool PrintConcurrentLocks = false {manageable}
bool PrintGC = false {manageable}
bool PrintGCDateStamps = false {manageable}
bool PrintGCDetails = false {manageable}
bool PrintGCID = false {manageable}
bool PrintGCTimeStamps = false {manageable}
-XX:+PrintFlagsFinal列出了所有的JVM選項,其中的 “manageable” 選項目前是有興趣的。通過JDK管理界面可以動态的寫(com.sun.management.HotSpotDiagnosticMXBean API)。
應用
-flag [+|-]<name> to enable or disable the named VM flag
從參數的解釋來看很直白,啟用(+)或者關閉(-)vm辨別
一個未開啟gclog的java應用,不停機打開gclog,然後再關閉gclog
[root@localhost config]# jps
main
Jps
[root@localhost config]#
使用jinfo檢視啟動資訊
[root@localhost bin]#jinfo 31519
……
VM Flags:
Non-default VM flags: -XX:CICompilerCount= -XX:CMSInitiatingOccupancyFraction= -XX:+CMSParallelRemarkEnabled -XX:+DisableExplicitGC -XX:InitialHeapSize= -XX:LargePageSizeInBytes= -XX:MaxHeapSize= -XX:MaxNewSize= -XX:MaxTenuringThreshold= -XX:MinHeapDeltaBytes= -XX:NewSize= -XX:OldPLABSize= -XX:OldSize= -XX:+PrintGC -XX:+PrintGCTimeStamps -XX:ThreadStackSize= -XX:+UseCMSCompactAtFullCollection -XX:+UseCMSInitiatingOccupancyOnly -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseConcMarkSweepGC -XX:+UseFastAccessorMethods -XX:+UseFastUnorderedTimeStamps -XX:+UseParNewGC
Command line: -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -Xmx2g -Xms2g -Xmn256m -XX:PermSize=m -Xss256k -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -Xloggc:/root/gc.log -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=
[root@localhost config]# jinfo -flag +PrintGCDetails -flag +PrintGC 31519
[root@localhost config]# jinfo -flag +PrintGC 31519
[root@localhost config]#
新啟視窗檢視日志
[[email protected] bin]#tail -f ~/gc.log
: [GC (Allocation Failure) : [ParNew: K->K(K), secs] K->K(K), secs] [Times: user= sys=, real= secs]
: [GC (Allocation Failure) : [ParNew: K->K(K), secs] K->K(K), secs] [Times: user= sys=, real= secs]
: [GC (Allocation Failure) : [ParNew: K->K(K), secs] K->K(K), secs] [Times: user= sys=, real= secs]
: [GC (Allocation Failure) : [ParNew: K->K(K), secs] K->K(K), secs] [Times: user= sys=, real= secs]
: [GC (Allocation Failure) : [ParNew: K->K(K), secs] K->K(K), secs] [Times: user= sys=, real= secs]
: [GC (Allocation Failure) : [ParNew: K->K(K), secs] K->K(K), secs] [Times: user= sys=, real= secs]
: [GC (Allocation Failure) : [ParNew: K->K(K), secs] K->K(K), secs] [Times: user= sys=, real= secs]
執行指令
[root@localhost ~]# jinfo -flag +PrintGCTimeStamps 31519
[root@localhost ~]# jinfo -flag +PrintGCDateStamps 31519
繼續檢視日志
……
: [GC (Allocation Failure) : [ParNew: K->K(K), secs] K->K(K), secs] [Times: user= sys=, real= secs]
: [GC (Allocation Failure) : [ParNew: K->K(K), secs] K->K(K), secs] [Times: user= sys=, real= secs]
--T17::+: : [GC (Allocation Failure) --T17::+: : [ParNew: K->K(K), secs] K->K(K), secs] [Times: user= sys=, real= secs]
--T17::+: : [GC (Allocation Failure) --T17::+: : [ParNew: K->K(K), secs] K->K(K), secs] [Times: user= sys=, real= secs]
--T17::+: : [GC (Allocation Failure) --T17::+: : [ParNew: K->K(K), secs] K->K(K), secs] [Times: user= sys=, real= secs]
--T17::+: : [GC (Allocation Failure) --T17::+: : [ParNew: K->K(K), secs] K->K(K), secs] [Times: user= sys=, real= secs]
再依次執行指令(每條命名間隔一會)
[root@localhost ~]# jinfo -flag -PrintGCDateStamps 31519
[root@localhost ~]# jinfo -flag -PrintGCTimeStamps 31519
[root@localhost ~]# jinfo -flag -PrintGCDetails 31519
[root@localhost ~]# jinfo -flag -PrintGC 31519
繼續檢視日志檔案
--T17::+: : [GC (Allocation Failure) --T17::+: : [ParNew: K->K(K), secs] K->K(K), secs] [Times: user= sys=, real= secs]
: [GC (Allocation Failure) : [ParNew: K->K(K), secs] K->K(K), secs] [Times: user= sys=, real= secs]
: [GC (Allocation Failure) : [ParNew: K->K(K), secs] K->K(K), secs] [Times: user= sys=, real= secs]
[GC (Allocation Failure) [ParNew: K->K(K), secs] K->K(K), secs] [Times: user= sys=, real= secs]
[GC (Allocation Failure) [ParNew: K->K(K), secs] K->K(K), secs] [Times: user= sys=, real= secs]
[GC (Allocation Failure) [ParNew: K->K(K), secs] K->K(K), secs] [Times: user= sys=, real= secs]
[GC (Allocation Failure) [ParNew: K->K(K), secs] K->K(K), secs] [Times: user= sys=, real= secs]
[GC (Allocation Failure) [ParNew: K->K(K), secs] K->K(K), secs] [Times: user= sys=, real= secs]
[GC (Allocation Failure) K->K(K), secs]
[GC (Allocation Failure) K->K(K), secs]
[GC (Allocation Failure) K->K(K), secs]
不再輸出日志 no more
管不管用自己動手搞一下就知道了~~
原文連接配接 http://blog.csdn.net/yue530tomtom/article/details/78217688