浅谈JDK9的特性之JVM的xlog
作者:flydean 发布时间:2022-07-20 12:00:45
简介
JVM是java程序运行的基础,JVM中各种事件比如:GC,class loading,JPMS,heap,thread等等其实都可以有日志来记录。通过这些日志,我们可以监控JVM中的事件,并可以依次来对java应用程序进行调优。
在JDK9中引入的Xlog日志服务就是为这个目的而创建的。
通过xlog,JDK将JVM中的各种事件统一起来,以统一的形式对外输出。通过tag参数来区分子系统,通过log level来区分事件的紧急性,通过logging output来配置输出的地址。
xlog的使用
先看一个最简单的xlog的使用例子:
java -Xlog -version
输出结果:
[0.016s][info][os] Use of CLOCK_MONOTONIC is supported
[0.016s][info][os] Use of pthread_condattr_setclock is not supported
[0.016s][info][os] Relative timed-wait using pthread_cond_timedwait is associated with the default clock
[0.017s][info][os] SafePoint Polling address, bad (protected) page:0x0000000108901000, good (unprotected) page:0x0000000108902000
[0.022s][info][biasedlocking] Aligned thread 0x00007f983e008200 to 0x00007f983e008800
[0.023s][info][os,thread ] Thread attached (tid: 10499, pthread id: 123145571979264).
日志非常非常长,这里就不全部列出来了。从输出的日志我们可以看到java -verson命令中JVM执行了诸多的操作。
我们可以看到日志中对每一个操作都列出了操作花费的时间,日志级别和操作所属的分类。
通过这些日志,我们对于JVM的运行可以有更加深入的理解。
使用java -Xlog:help命令我们看一下xlog的基本格式:
-Xlog Usage: -Xlog[:[selections][:[output][:[decorators][:output-options]]]]
where 'selections' are combinations of tags and levels of the form tag1[+tag2...][*][=level][,...]
NOTE: Unless wildcard (*) is specified, only log messages tagged with exactly the tags specified will be matched.
selections
selections表示的是到底需要输出哪些信息。是以tag=level来表示的。
tag表示的是JVM中的事件或者子系统:
Available log tags:
add, age, alloc, annotation, aot, arguments, attach, barrier, biasedlocking, blocks, bot, breakpoint, bytecode, cds, census, class, classhisto, cleanup, codecache, compaction, compilation, 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, init, inlining, install, interpreter, itables, jfr, jit, jni, jvmti, liveness, load, loader, logging, malloc, mark, marking, membername, memops, metadata, metaspace, methodcomparator, mirror, mmu, module, monitorinflation, monitormismatch, nestmates, nmethod, normalize, numa, objecttagging, obsolete, oldobject, oom, oopmap, oops, oopstorage, os, pagesize, parser, patch, path, perf, periodic, phases, plab, preorder, preview, promotion, protectiondomain, ptrqueue, purge, record, redefine, ref, refine, region, reloc, remset, resolve, safepoint, sampling, scavenge, setting, smr, stackmap, stacktrace, stackwalk, start, startuptime, state, stats, streaming, stringdedup, stringtable, subclass, survivor, sweep, symboltable, system, table, task, thread, time, timer, tlab, tracking, unload, unshareable, update, verification, verify, vmmutex, vmoperation, vmthread, vtables, vtablestubs, workgang
Specifying 'all' instead of a tag combination matches all tag combinations
levels表示的是日志的级别:
Available log levels: off, trace, debug, info, warning, error
下面举个例子:
java -Xlog:os,class=info -version
输出结果:
[0.002s][info][os] Use of CLOCK_MONOTONIC is supported
[0.002s][info][os] Use of pthread_condattr_setclock is not supported
[0.002s][info][os] Relative timed-wait using pthread_cond_timedwait is associated with the default clock
[0.003s][info][os] SafePoint Polling address, bad (protected) page:0x0000000109543000, good (unprotected) page:0x0000000109544000
[0.006s][info][os] attempting shared library load of /Library/Java/JavaVirtualMachines/jdk-14.0.1.jdk/Contents/Home/lib/libjava.dylib
[0.007s][info][os] shared library load of /Library/Java/JavaVirtualMachines/jdk-14.0.1.jdk/Contents/Home/lib/libjava.dylib was successful
[0.007s][info][os] attempting shared library load of /Library/Java/JavaVirtualMachines/jdk-14.0.1.jdk/Contents/Home/lib/libzip.dylib
[0.010s][info][os] shared library load of /Library/Java/JavaVirtualMachines/jdk-14.0.1.jdk/Contents/Home/lib/libzip.dylib was successful
output
output表示将日志输出到什么地方。
output的可选项:
stdout/stderr file=<filename>
stdout表示标准输出,stderr表示标准错误。file表示输出到文件里面。
举个例子:
java -Xlog:all=debug:file=debug.log -version
decorators
decorators表示输出哪些内容到日志中。
time (t), utctime (utc), uptime (u), timemillis (tm), uptimemillis (um), timenanos (tn), uptimenanos (un), hostname (hn), pid (p), tid (ti), level (l), tags (tg)
Decorators can also be specified as 'none' for no decoration
看下这个例子:
java -Xlog:gc*=debug:stdout:time,uptimemillis,tid -version
输出结果:
[2020-05-05T16:12:06.871-0800][32ms][9475] Heap region size: 1M
[2020-05-05T16:12:06.871-0800][32ms][9475] Minimum heap 8388608 Initial heap 134217728 Maximum heap 2147483648
[2020-05-05T16:12:06.872-0800][33ms][9475] Heap address: 0x0000000780000000, size: 2048 MB, Compressed Oops mode: Zero based, Oop shift amount: 3
[2020-05-05T16:12:06.872-0800][33ms][9475] ConcGCThreads: 1 offset 8
[2020-05-05T16:12:06.872-0800][33ms][9475] ParallelGCThreads: 4
来源:https://www.cnblogs.com/flydean/p/jdk9-jvm-xlog.html


猜你喜欢
- 目录一、简述二、内容一、简述利用C# TcpClient在局域网内传输文件,可是文件发送到对面的时候却要重新命名文件的。那可不可以连着文件名
- 0.解释器(Interpreter)模式定义 :给定一门语言,定义它的文法的一种表示,并定义一个解释器,该解释器使用该表示来解释语言中句子。
- 一般来说一个 HTML 文档有很多标签,比如“<html>”、“<body>”、“<table>”等,想
- 在工作中经常读写文本文件,在读文件时,需要按开头的两个字节判断文件格式,然后按该格式读文件中的内容。 写文件时,也要按目标文件指定
- 1、maven打包Spring Boot项目的pom.xml文件中默认使用spring-boot-maven-plugin插件进行打包:&l
- 关于为什么需要创建单例?这里不过多介绍,具体百度知。 关于C# 创建单例步骤或条件吧1、声明静态变量;2、私有构造函
- 树的同构备忘!定义:给定两棵树r1、r2,如果r1可以通过若干次的左子树和右子树互换,使之与r2完全相同,这说明两者同构。举例树的构造树可以
- 本文实例为大家分享了C#实现学生档案查询的具体代码,供大家参考,具体内容如下using System;using System.Collec
- 在实际的应用中会经常需要将数据导出成excel,导出的方式除原样导出还有分页导出、分页分sheet导出和大数据量导出。对于excel2003
- 主要为以下实现步骤:1.绑定域名先登录微信公众平台进入“公众号设置”的“功能设置”里填写“JS接口安全域名”。(特别提示不需要加上http或
- 本文实例为大家分享了Android实现简单banner轮播图的具体代码,供大家参考,具体内容如下说明:想玩一个简单的轮播图效果
- 模拟ThreadLocal类实现:线程范围内的共享变量,每个线程只能访问他自己的,不能访问别的线程。package com.ljq.test
- 随着目前微信越来越火,所以研究微信的人也就越来越多,这不前一段时间,我们公司就让我做一个微信公众号中问卷调查发红包功能,经过一段时间的研究,
- 新建类Product:class Product{ public string name; &
- 很多时候我们开发的软件需要向用户提供软件参数设置功能,例如我们常用的QQ,用户可以设置是否允许陌生人添加自己为好友。对于软件配置参数的保存,
- 很多app中在第一次安装登陆时会有引导欢迎界面,第二次打开时就不再显示引导页面。这个功能可以通过使用SharePreferences将用户的
- 一、概述1.目标:要在Tank的move()方法做时间代理及日志代理(可以设想以后还要增加很多代理处理),且代理间的顺序可活更换2.思路:(
- Android开发sdk过程中,很有可能在sdk内部引
- 这篇文章主要介绍了springboot 定时任务@Scheduled实现解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的
- 关于注入数据说明1.不通过配置文件注入数据通过@Value将外部的值动态注入到Bean中,使用的情况有:注入普通字符串注入操作系统属性注入表