序
本文主要研究一下java9 gc log參數(shù)的遷移逮诲。
統(tǒng)一JVM及GC的Logging
java9引進了一個統(tǒng)一的日志框架瓢喉,對gc log的輸出進行了統(tǒng)一的配置。
相關(guān)JEP(JDK Enhancement Proposal
)
Xlog語法
-Xlog[:option]
option := [<what>][:[<output>][:[<decorators>][:<output-options>]]]
'help'
'disable'
what := <selector>[,...]
selector := <tag-set>[*][=<level>]
tag-set := <tag>[+...]
'all'
tag := name of tag
level := trace
debug
info
warning
error
output := 'stderr'
'stdout'
[file=]<filename>
decorators := <decorator>[,...]
'none'
decorator := time
uptime
timemillis
uptimemillis
timenanos
uptimenanos
pid
tid
level
tags
output-options := <output_option>[,...]
output-option := filecount=<file count>
filesize=<file size in kb>
parameter=value
what
主要是配置tag及l(fā)evel
tag
其中all代表所有的tag皂冰,其他的如下:
add贿讹,age吠裆,alloc伐谈,annotation,aot试疙,arguments诵棵,attach,barrier祝旷,biasedlocking履澳,blocks,bot缓屠,breakpoint,bytecode护侮,census敌完,class,classhisto羊初,cleanup滨溉,compaction,comparator长赞,constraints晦攒,constantpool,coops得哆,cpu脯颜,cset,data贩据,defaultmethods栋操,dump,ergo饱亮,event矾芙,exceptions,exit近上,fingerprint剔宪,freelist,gc,hashtables葱绒,heap感帅,humongous,ihop哈街,iklass留瞳,init,itables骚秦,jfr她倘,jni,jvmti作箍,liveness硬梁,load,loader胞得,logging荧止,mark,marking阶剑,metadata跃巡,metaspace,method牧愁,mmu素邪,modules,monitorinflation猪半,monitormismatch兔朦,nmethod,normalize磨确,objecttagging沽甥,obsolete,oopmap乏奥,os摆舟,pagesize,parser邓了,patch盏檐,path,phases驶悟,plab胡野,preorder,promotion痕鳍,protectiondomain硫豆,purge龙巨,redefine,ref熊响,refine旨别,region,remset汗茄,resolve秸弛,safepoint,scavenge洪碳,scrub递览,setting,stackmap瞳腌,stacktrace绞铃,stackwalk,start嫂侍,startuptime儿捧,state,stats挑宠,stringdedup菲盾,stringtable,subclass各淀,survivor懒鉴,sweep,system揪阿,task疗我,thread咆畏,time南捂,timer,tlab旧找,unload溺健,update,verification钮蛛,verify鞭缭,vmoperation,vtables魏颓,workgang
level
主要分off岭辣,trace,debug甸饱,info沦童,warning仑濒,error
output
- stdout(`Sends output to stdout`)
- stderr(`Sends output to stderr`)
- file=filename(`Sends output to text file(s)`)
有如上三種,其中指定file的話偷遗,可以使用%p變量表示當前jvm的pid墩瞳,用%t表示jvm的啟動時間戳。比如
-Xlog:gc:demoapp-gc-%p-%t.log
輸出的文件名如下:
demoapp-gc-1678-2018-03-01_21-44-18.log
decorators
- time -- Current time and date in ISO-8601 format
- uptime -- Time since the start of the JVM in seconds and milliseconds (e.g., 6.567s)
- timemillis -- The same value as generated by System.currentTimeMillis()
- uptimemillis -- Milliseconds since the JVM started
- timenanos -- The same value as generated by System.nanoTime()
- uptimenanos -- Nanoseconds since the JVM started
- pid -- The process identifier
- tid -- The thread identifier
- level -- The level associated with the log message
- tags -- The tag-set associated with the log message
不指定的話氏豌,默認是uptime, level, and tags這三個喉酌。比如
[3.080s][info][gc,cpu ] GC(5) User=0.03s Sys=0.00s Real=0.01s
實例
-Xlog:gc=trace:file=gctrace.txt:uptimemillis,pid:filecount=5,filesize=1024
tag為gc,levle為trace泵喘,rotate文件數(shù)為5泪电,每個文件1M,文件名為gctrace.txt涣旨,decrotators為uptimemillis和pid
輸出實例
[1110ms][1867] GC(2) Pause Remark 17M->17M(256M) 2.024ms
[1110ms][1867] GC(2) Finalize Live Data 0.000ms
[1110ms][1867] GC(2) Pause Cleanup 17M->17M(256M) 0.177ms
[1112ms][1867] GC(2) Concurrent Cycle 7.470ms
[2951ms][1867] GC(3) Pause Initial Mark (Metadata GC Threshold) 149M->30M(256M) 27.175ms
[2951ms][1867] GC(4) Concurrent Cycle
[2972ms][1867] GC(4) Pause Remark 32M->32M(256M) 5.132ms
[2974ms][1867] GC(4) Finalize Live Data 0.000ms
[2974ms][1867] GC(4) Pause Cleanup 32M->32M(256M) 0.214ms
[2976ms][1867] GC(4) Concurrent Cycle 25.422ms
遷移
舊版GC相關(guān)參數(shù)遷移
Legacy Garbage Collection (GC) Flag | Xlog Configuration | Comment |
---|---|---|
G1PrintHeapRegions | -Xlog:gc+region=trace | Not Applicable |
GCLogFileSize | No configuration available | Log rotation is handled by the framework. |
NumberOfGCLogFiles | Not Applicable | Log rotation is handled by the framework. |
PrintAdaptiveSizePolicy | -Xlog:ergo*=level | Use a level of debug for most of the information, or a level of trace for all of what was logged for PrintAdaptiveSizePolicy. |
PrintGC | -Xlog:gc | Not Applicable |
PrintGCApplicationConcurrentTime | -Xlog:safepoint | Note that PrintGCApplicationConcurrentTime and PrintGCApplicationStoppedTime are logged on the same tag and aren’t separated in the new logging. |
PrintGCApplicationStoppedTime | -Xlog:safepoint | Note that PrintGCApplicationConcurrentTime and PrintGCApplicationStoppedTime are logged on the same tag and not separated in the new logging. |
PrintGCCause | Not Applicable | GC cause is now always logged. |
PrintGCDateStamps | Not Applicable | Date stamps are logged by the framework. |
PrintGCDetails | -Xlog:gc* | Not Applicable |
PrintGCID | Not Applicable | GC ID is now always logged. |
PrintGCTaskTimeStamps | -Xlog:task*=debug | Not Applicable |
PrintGCTimeStamps | Not Applicable | Time stamps are logged by the framework. |
PrintHeapAtGC | -Xlog:gc+heap=trace | Not Applicable |
PrintReferenceGC | -Xlog:ref*=debug | Note that in the old logging, PrintReferenceGC had an effect only if PrintGCDetails was also enabled. |
PrintStringDeduplicationStatistics | -Xlog:stringdedup*=debug | Not Applicable |
PrintTenuringDistribution | -Xlog:age*=level | Use a level of debug for the most relevant information, or a level of trace for all of what was logged for PrintTenuringDistribution. |
UseGCLogFileRotation | Not Applicable | What was logged for PrintTenuringDistribution. |
舊版運行時參數(shù)遷移
Legacy Runtime Flag | Xlog Configuration | Comment |
---|---|---|
TraceExceptions | -Xlog:exceptions=info | Not Applicable |
TraceClassLoading | -Xlog:class+load=level | Use level=info for regular information, or level=debug for additional information. In Unified Logging syntax, -verbose:class equals -Xlog:class+load=info,class+unload=info. |
TraceClassLoadingPreorder | -Xlog:class+preorder=debug | Not Applicable |
TraceClassUnloading | -Xlog:class+unload=level | Use level=info for regular information, or level=trace for additional information. In Unified Logging syntax, -verbose:class equals -Xlog:class+load=info,class+unload=info. |
VerboseVerification | -Xlog:verification=info | Not Applicable |
TraceClassPaths | -Xlog:class+path=info | Not Applicable |
TraceClassResolution | -Xlog:class+resolve=debug | Not Applicable |
TraceClassInitialization | -Xlog:class+init=info | Not Applicable |
TraceLoaderConstraints | -Xlog:class+loader+constraints=info | Not Applicable |
TraceClassLoaderData | -Xlog:class+loader+data=level | Use level=debug for regular information or level=trace for additional information. |
TraceSafepointCleanupTime | -Xlog:safepoint+cleanup=info | Not Applicable |
TraceSafepoint | -Xlog:safepoint=debug | Not Applicable |
TraceMonitorInflation | -Xlog:monitorinflation=debug | Not Applicable |
TraceBiasedLocking | -Xlog:biasedlocking=level | Use level=info for regular information, or level=trace for additional information. |
TraceRedefineClasses | -Xlog:redefine+class*=level | level=info, =debug, and =trace provide increasing amounts of information. |
小結(jié)
java9把gc log的配置統(tǒng)一到了Xlog中歪架,可以按照官方給出的新舊參數(shù)映射表進行遷移。