JVM GC日志分析之日志参数

  不同的垃圾收集器(参考JVM 垃圾收集器分类),输出的日志格式各不相同,但也有一些相同的特征。熟悉各个常用垃圾收集器的GC日志,是进行JVM调优的必备一步。 解析GC日志,首先需要收集日志(参考https://docs.oracle.com/en/java/javase/17/docs/specs/man/java.html#enable-logging-with-the-jvm-unified-logging-framework),通过-Xlog:help打印日志相关帮助信息如下:

            

            

  从上图看首先日志配置的使用语法是:-Xlog[:[selections][:[output][:[decorators][:output-options]]]]

    'selections' are combinations of tags and levels of the form tag1[+tag2...][*][=level][,...]

  而tag的内容可以是(Available log tags):

    add, age, alloc, annotation, arguments, attach, barrier, biasedlocking, blocks, bot, breakpoint, bytecode, cds, census, class, classhisto, cleanup, codecache, compaction, compilation, condy, constantpool, constraints, container, coops, cpu, cset, data, datacreation, dcmd, decoder, defaultmethods, director, dump, dynamic, ergo, event, exceptions, exit, fingerprint, free, freelist, gc, handshake, hashtables, heap, humongous, ihop, iklass, indy, init, inlining, install, interpreter, itables, jfr, jit, jni, jvmci, jvmti, lambda, library, liveness, load, loader, logging, malloc, map, mark, marking, membername, memops, metadata, metaspace, methodcomparator, methodhandles, mirror, mmu, module, monitorinflation, monitormismatch, nestmates, nmethod, nmt, normalize, numa, objecttagging, obsolete, oldobject, oom, oopmap, oops, oopstorage, os, owner, pagesize, parser, patch, path, perf, periodic, phases, plab, placeholders, preorder, preview, promotion, protectiondomain, ptrqueue, purge, record, redefine, ref, refine, region, reloc, remset, resolve, safepoint, sampling, scavenge, sealed, setting, smr, stackbarrier, stackmap, stacktrace, stackwalk, start, startup, startuptime, state, stats, streaming, stringdedup, stringtable, subclass, survivor, suspend, sweep, symboltable, system, table, task, thread, throttle, time, timer, tlab, tracking, unload, unshareable, update, valuebasedclasses, verification, verify, vmmutex, vmoperation, vmthread, vtables, vtablestubs, workgang

    如果使用all而不是tag的组合会将所有tag组合日志打印出来。

  tag为必需项,仅提供tag即可打印日志了。例如:

            

            

            

            

  level级别可以选择:off, trace, debug, info, warning, error。

  其他选项具体使用参考帮助文档中的说明。常用的有以下JVM参数用来打印输出日志信息:

            

    -Xlog:gc

            

    -Xlog:gc*

            

    -Xlog:gc+heap=debug

            

    -Xlog:gc=debug:file=gc.txt

            

   具体gc日志的灵活使用参考官网https://docs.oracle.com/en/java/javase/17/docs/specs/man/java.html#convert-gc-logging-flags-to-xlog。

  

 

posted on 2024-05-30 15:41  池塘里洗澡的鸭子  阅读(133)  评论(0编辑  收藏  举报