java9中gc log参数迁移
程序员文章站
2022-03-10 10:52:49
序
本文主要研究一下java9 gc log参数的迁移。
统一jvm及gc的logging
java9引进了一个统一的日志框架,把gc相关的log输出及配置也...
序
本文主要研究一下java9 gc log参数的迁移。
统一jvm及gc的logging
java9引进了一个统一的日志框架,把gc相关的log输出及配置也给纳入进来了。
相关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及level
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文件数为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相关参数迁移
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. |
旧版运行时参数迁移
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. |
小结
java9把gc log的选型及输出也给统一到了xlog中,可以按照官方给出的迁移表进行迁移。