Arthas(阿尔萨斯)--(二)

目录

一、Arthas学习

1、JVM相关命令一

1、dashboard

2、thread

3、jvm

4、sysprop


一、Arthas学习

Arthas(阿尔萨斯)--(一)

Arthas代码开源地址

1、JVM相关命令一

1、dashboard

dashboard:显示当前系统的实时数据面板,按q或ctrl+c退出

ID: Java 级别的线程 ID,注意这个 ID 不能跟 jstack 中的 nativeID 一一对应。
NAME: 线程名
GROUP: 线程组名
PRIORITY: 线程优先级, 1~10 之间的数字,越大表示优先级越高
STATE: 线程的状态
CPU%: 线程的 cpu 使用率。比如采样间隔 1000ms,某个线程的增量 cpu 时间为 100ms,则 cpu 使用率=100/1000=10%
DELTA_TIME: 上次采样之后线程运行增量 CPU 时间,数据格式为秒
TIME: 线程运行总 CPU 时间,数据格式为分:秒
INTERRUPTED: 线程当前的中断位状态
DAEMON: 是否是 daemon 线程

2、thread

thread:查看当前JVM的线程堆栈信息

参数:数字:线程id
     [n:]:指定最忙的前N个线程并打印堆栈

[arthas@14156]$ thread -n 3
"main" Id=1 cpuUsage=0.0% deltaTime=0ms time=218ms TIMED_WAITINGat java.base@21.0.1/java.lang.Thread.sleep0(Native Method)at java.base@21.0.1/java.lang.Thread.sleep(Thread.java:558)at java.base@21.0.1/java.util.concurrent.TimeUnit.sleep(TimeUnit.java:446)at app//demo.MathGame.main(MathGame.java:17)"Reference Handler" Id=9 cpuUsage=0.0% deltaTime=0ms time=0ms RUNNABLEat java.base@21.0.1/java.lang.ref.Reference.waitForReferencePendingList(Native Method)at java.base@21.0.1/java.lang.ref.Reference.processPendingReferences(Reference.java:246)at java.base@21.0.1/java.lang.ref.Reference$ReferenceHandler.run(Reference.java:208)"Finalizer" Id=10 cpuUsage=0.0% deltaTime=0ms time=0ms WAITING on java.lang.ref.NativeReferenceQueue$Lock@2b55402bat java.base@21.0.1/java.lang.Object.wait0(Native Method)-  waiting on java.lang.ref.NativeReferenceQueue$Lock@2b55402bat java.base@21.0.1/java.lang.Object.wait(Object.java:366)at java.base@21.0.1/java.lang.Object.wait(Object.java:339)at java.base@21.0.1/java.lang.ref.NativeReferenceQueue.await(NativeReferenceQueue.java:48)at java.base@21.0.1/java.lang.ref.ReferenceQueue.remove0(ReferenceQueue.java:158)at java.base@21.0.1/java.lang.ref.NativeReferenceQueue.remove(NativeReferenceQueue.java:89)at java.base@21.0.1/java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:173)[arthas@14156]$

     [b]:找出当前阻塞其他线程的线程

有时候我们发现应用卡住了, 通常是由于某个线程拿住了某个锁, 并且其他线程都在等待这把锁造成的。 为了排查这类问题, arthas 提供了thread -b

运行一个死锁程序

public class DeadLock {static Object a = new Object();static Object b = new Object();public static void main(String[] args) {new Thread(() -> {synchronized (a) {System.out.println(Thread.currentThread().getName() + "持有锁a,试图获取锁b");synchronized (b) {System.out.println(Thread.currentThread().getName() + "持有锁b");}}}, "t1").start();new Thread(() -> {synchronized (b) {System.out.println(Thread.currentThread().getName() + "持有锁b,试图获取锁a");synchronized (a) {System.out.println(Thread.currentThread().getName() + "持有锁a");}}}, "t2").start();}}

运行arthas,粘附到这个死锁程序中

[arthas@11400]$ thread -b
"t2" Id=34 BLOCKED on java.lang.Object@1e8eb080 owned by "t1" Id=33at app//com.lwz.xxx.DeadLock.lambda$main$1(DeadLock.java:21)-  blocked on java.lang.Object@1e8eb080-  locked java.lang.Object@6fe0e9fb <---- but blocks 1 other threads!at app//com.lwz.controller.DeadLock$$Lambda/0x0000020111003418.run(Unknown Source)at java.base@21.0.1/java.lang.Thread.runWith(Thread.java:1596)at java.base@21.0.1/java.lang.Thread.run(Thread.java:1583)[arthas@11400]$

     [i <value>]:指定cpu占比统计的采样间隔,单位为毫秒

thread -i 1000 : 统计最近 1000ms 内的线程 CPU 时间。thread -n 3 -i 1000 : 列出 1000ms 内最忙的 3 个线程栈
[arthas@14156]$ thread -i 1000
Threads Total: 16, NEW: 0, RUNNABLE: 9, BLOCKED: 0, WAITING: 3, TIMED_WAITING: 4, TERMINATED: 0
ID   NAME                          GROUP          PRIORITY  STATE    %CPU      DELTA_TIM TIME      INTERRUPT DAEMON
1    main                          main           5         TIMED_WA 0.0       0.000     0:0.234   false     false
9    Reference Handler             system         10        RUNNABLE 0.0       0.000     0:0.000   false     true
10   Finalizer                     system         8         WAITING  0.0       0.000     0:0.000   false     true
11   Signal Dispatcher             system         9         RUNNABLE 0.0       0.000     0:0.000   false     true
12   Attach Listener               system         5         RUNNABLE 0.0       0.000     0:0.046   false     true
30   Notification Thread           system         9         RUNNABLE 0.0       0.000     0:0.000   false     true
31   Common-Cleaner                InnocuousThrea 8         TIMED_WA 0.0       0.000     0:0.000   false     true
33   arthas-timer                  system         5         WAITING  0.0       0.000     0:0.000   false     true
59   arthas-NettyHttpTelnetBootstr system         5         RUNNABLE 0.0       0.000     0:0.046   false     true
60   arthas-NettyWebsocketTtyBoots system         5         RUNNABLE 0.0       0.000     0:0.000   false     true
61   arthas-NettyWebsocketTtyBoots system         5         RUNNABLE 0.0       0.000     0:0.000   false     true
62   arthas-shell-server           system         5         TIMED_WA 0.0       0.000     0:0.000   false     true
63   arthas-session-manager        system         5         TIMED_WA 0.0       0.000     0:0.000   false     true
64   arthas-UserStat               system         5         WAITING  0.0       0.000     0:0.000   false     true
66   arthas-NettyHttpTelnetBootstr system         5         RUNNABLE 0.0       0.000     0:0.140   false     true
67   arthas-command-execute        system         5         RUNNABLE 0.0       0.000     0:0.046   false     true[arthas@14156]$ thread -n 3 -i 1000
"main" Id=1 cpuUsage=0.0% deltaTime=0ms time=234ms TIMED_WAITINGat java.base@21.0.1/java.lang.Thread.sleep0(Native Method)at java.base@21.0.1/java.lang.Thread.sleep(Thread.java:558)at java.base@21.0.1/java.util.concurrent.TimeUnit.sleep(TimeUnit.java:446)at app//demo.MathGame.main(MathGame.java:17)"Reference Handler" Id=9 cpuUsage=0.0% deltaTime=0ms time=0ms RUNNABLEat java.base@21.0.1/java.lang.ref.Reference.waitForReferencePendingList(Native Method)at java.base@21.0.1/java.lang.ref.Reference.processPendingReferences(Reference.java:246)at java.base@21.0.1/java.lang.ref.Reference$ReferenceHandler.run(Reference.java:208)"Finalizer" Id=10 cpuUsage=0.0% deltaTime=0ms time=0ms WAITING on java.lang.ref.NativeReferenceQueue$Lock@2b55402bat java.base@21.0.1/java.lang.Object.wait0(Native Method)-  waiting on java.lang.ref.NativeReferenceQueue$Lock@2b55402bat java.base@21.0.1/java.lang.Object.wait(Object.java:366)at java.base@21.0.1/java.lang.Object.wait(Object.java:339)at java.base@21.0.1/java.lang.ref.NativeReferenceQueue.await(NativeReferenceQueue.java:48)at java.base@21.0.1/java.lang.ref.ReferenceQueue.remove0(ReferenceQueue.java:158)at java.base@21.0.1/java.lang.ref.NativeReferenceQueue.remove(NativeReferenceQueue.java:89)at java.base@21.0.1/java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:173)

例:
thread --state WAITING :查看线程中处于等待状态的线程

3、jvm

与JVM相关的信息

[arthas@14156]$ jvmRUNTIME
-----------------------------------------------------------------------------------------------------------------------MACHINE-NAME                      14156@lwzoozycJVM-START-TIME                    2023-11-13 23:10:24MANAGEMENT-SPEC-VERSION           4.0SPEC-NAME                         Java Virtual Machine SpecificationSPEC-VENDOR                       Oracle CorporationSPEC-VERSION                      21VM-NAME                           Java HotSpot(TM) 64-Bit Server VMVM-VENDOR                         Oracle CorporationVM-VERSION                        21.0.1+12-LTS-29INPUT-ARGUMENTS                   []CLASS-PATH                        math-game.jarBOOT-CLASS-PATHLIBRARY-PATH                      C:\Program Files\Java\jdk-21\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;"C:\Program Files\Java\jdk-21\bin;C:\Program Files\Java\jdk-21\jre\bin;";C:\Program Files\Go\bin;C:\Program Files\Go\bin;C:\Program Files\PuTTY\;C:\Program Files\Git\cmd;C:\Program Files\TortoiseGit\bin;C:\Program Files\Microsoft VSCode\bin;C:\Program Files\Java\jdk-21\bin;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;C:\Users\Administrator\go\bin;C:\Program Files\JetBrains\GoLand 2023.2\bin;;C:\Program Files\JetBrains\IntelliJ IDEA 2023.2.3\bin;;.-----------------------------------------------------------------------------------------------------------------------CLASS-LOADING
-----------------------------------------------------------------------------------------------------------------------LOADED-CLASS-COUNT                4623TOTAL-LOADED-CLASS-COUNT          4623UNLOADED-CLASS-COUNT              0IS-VERBOSE                        false-----------------------------------------------------------------------------------------------------------------------COMPILATION
-----------------------------------------------------------------------------------------------------------------------NAME                              HotSpot 64-Bit Tiered CompilersTOTAL-COMPILE-TIME                3011[time (ms)]-----------------------------------------------------------------------------------------------------------------------GARBAGE-COLLECTORS
-----------------------------------------------------------------------------------------------------------------------G1 Young Generation               name : G1 Young Generation[count/time (ms)]                 collectionCount : 1collectionTime : 11G1 Concurrent GC                  name : G1 Concurrent GC[count/time (ms)]                 collectionCount : 0collectionTime : 0G1 Old Generation                 name : G1 Old Generation[count/time (ms)]                 collectionCount : 0collectionTime : 0-----------------------------------------------------------------------------------------------------------------------MEMORY-MANAGERS
-----------------------------------------------------------------------------------------------------------------------CodeCacheManager                  CodeHeap 'non-nmethods'CodeHeap 'profiled nmethods'CodeHeap 'non-profiled nmethods'Metaspace Manager                 MetaspaceCompressed Class SpaceG1 Young Generation               G1 Eden SpaceG1 Survivor SpaceG1 Old GenG1 Concurrent GC                  G1 Old GenG1 Old Generation                 G1 Eden SpaceG1 Survivor SpaceG1 Old Gen-----------------------------------------------------------------------------------------------------------------------MEMORY
-----------------------------------------------------------------------------------------------------------------------HEAP-MEMORY-USAGE                 init : 1073741824(1.0 GiB)[memory in bytes]                 used : 27318272(26.1 MiB)committed : 1073741824(1.0 GiB)max : 17146314752(16.0 GiB)NO-HEAP-MEMORY-USAGE              init : 7667712(7.3 MiB)[memory in bytes]                 used : 31832208(30.4 MiB)committed : 36438016(34.8 MiB)max : -1(-1 B)PENDING-FINALIZE-COUNT            0-----------------------------------------------------------------------------------------------------------------------OPERATING-SYSTEM
-----------------------------------------------------------------------------------------------------------------------OS                                Windows 10ARCH                              amd64PROCESSORS-COUNT                  36LOAD-AVERAGE                      -1.0VERSION                           10.0-----------------------------------------------------------------------------------------------------------------------THREAD
-----------------------------------------------------------------------------------------------------------------------COUNT                             16DAEMON-COUNT                      15PEAK-COUNT                        16STARTED-COUNT                     19DEADLOCK-COUNT                    0-----------------------------------------------------------------------------------------------------------------------FILE-DESCRIPTOR
-----------------------------------------------------------------------------------------------------------------------MAX-FILE-DESCRIPTOR-COUNT         -1OPEN-FILE-DESCRIPTOR-COUNT        -1

4、sysprop

sysprop:查看和修改JVM的系统属性

[arthas@14156]$ syspropKEY                     VALUE
-----------------------------------------------------------------------------------------------------------------------java.specification.ver  21sionsun.cpu.isalist         amd64sun.jnu.encoding        GBKjava.class.path         math-game.jarjava.vm.vendor          Oracle Corporationsun.arch.data.model     64user.variantjava.vendor.url         https://java.oracle.com/user.timezone           Asia/Shanghaijava.vm.specification.  21versionos.name                 Windows 10sun.java.launcher       SUN_STANDARDuser.country            CNsun.boot.library.path   C:\Program Files\Java\jdk-21\binsun.java.command        math-game.jarjdk.debug               releasesun.cpu.endian          littleuser.home               C:\Users\Administratoruser.language           zhjava.specification.ven  Oracle Corporationdorjava.version.date       2023-10-17java.home               C:\Program Files\Java\jdk-21file.separator          \java.vm.compressedOops  Zero basedModejava.vm.specification.  Oracle Corporationvendorjava.specification.nam  Java Platform API Specificationeuser.scriptsun.management.compile  HotSpot 64-Bit Tiered Compilersrjava.runtime.version    21.0.1+12-LTS-29user.name               Administratorstdout.encoding         ms936path.separator          ;os.version              10.0java.runtime.name       Java(TM) SE Runtime Environmentfile.encoding           UTF-8java.vm.name            Java HotSpot(TM) 64-Bit Server VMjava.vendor.url.bug     https://bugreport.java.com/bugreport/java.io.tmpdir          C:\Users\ADMINI~1\AppData\Local\Temp\java.version            21.0.1user.dir                C:\Users\Administrator\.arthas\lib\3.7.1\arthasos.arch                 amd64java.vm.specification.  Java Virtual Machine Specificationnamesun.os.patch.levelnative.encoding         GBKjava.library.path       C:\Program Files\Java\jdk-21\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;"C:\Program Files\Java\jdk-21\bin;C:\Program Files\Java\jdk-21\jre\bin;";C:\Program Files\Go\bin;C:\Program Files\Go\bin;C:\Program Files\PuTTY\;C:\Program Files\Git\cmd;C:\Program Files\TortoiseGit\bin;C:\Program Files\Microsoft VS Code\bin;C:\Program Files\Java\jdk-21\bin;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;C:\Users\Administrator\go\bin;C:\Program Files\JetBrains\GoLand 2023.2\bin;;C:\Program Files\JetBrains\IntelliJ IDEA 2023.2.3\bin;;.java.vm.info            mixed mode, sharingstderr.encoding         ms936java.vendor             Oracle Corporationjava.vm.version         21.0.1+12-LTS-29sun.io.unicode.encodin  UnicodeLittlegjava.class.version      65.0
[arthas@14156]$
查看单个属性
[arthas@14156]$ sysprop java.versionKEY                     VALUE
------------------------------------------------------------------------------------------java.version            21.0.1
[arthas@14156]$
修改单个属性
[arthas@14156]$ sysprop user.countryKEY                     VALUE
------------------------------------------------------------------------------------------user.country            CN
[arthas@14156]$ sysprop user.country US
Successfully changed the system property.KEY                     VALUE
------------------------------------------------------------------------------------------user.country            US
[arthas@14156]$ sysprop user.country CN
Successfully changed the system property.KEY                     VALUE
------------------------------------------------------------------------------------------user.country            CN
[arthas@14156]$

2、JVM相关命令二

1、sysenv

2、vmoption

3、getstatic

4、ognl

一个程序员最重要的能力是:写出高质量的代码!!
有道无术,术尚可求也,有术无道,止于术。
无论你是年轻还是年长,所有程序员都需要记住:时刻努力学习新技术,否则就会被时代抛弃!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/171208.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Docker - 容器数据卷

Docker - 容器数据卷 什么是容器数据卷 等同于挂载&#xff0c;将容器内的目录地址指向于宿主机文件系统中 直接使用命令来挂载 -v docker run -it -v 主机目录:容器内目录# 测试 docker run -it -v /root:/home centos /bin/bash [rootiZ2zeg7mctvft5renx1qvbZ ~]# docker …

vscode 快速打印console.log

第一步 输入这些 {// Print Selected Variabl 为自定义快捷键中需要使用的name&#xff0c;可以自行修改"Print Selected Variable": {"body": ["\nconsole.log("," %c $CLIPBOARD: ,"," background-color: #3756d4; padding:…

Linux---(六)自动化构建工具 make/Makefile

文章目录 一、make/Makefile二、快速查看&#xff08;1&#xff09;建立Makefile文件&#xff08;2&#xff09;编辑Makefile文件&#xff08;3&#xff09;解释&#xff08;4&#xff09;效果展示 三、背后的基本知识、原理&#xff08;1&#xff09;如何清理对应的临时文件呢…

Js 语句

JavaScript 语句向浏览器发出的命令&#xff0c;语句的作用是告诉浏览器该做什么&#xff1b;分号用于分隔 JavaScript 语句&#xff0c;通常我们在每条可执行的语句结尾添加分号&#xff1b;使用分号的另一用处是在一行中编写多条语句。 JavaScript 语句通常以一个 语句标识符…

postgreSQL中的高速缓存

1. 高速缓存简介 ​如下图所示&#xff0c;当一个postgreSQL进程读取一个元组时&#xff0c;需要获取表的基本信息&#xff08;例如&#xff1a;表的oid、索引信息和统计信息等&#xff09;及元组的模式信息&#xff0c;这些信息被分别记录在多个系统表中。通常一个表的模式信…

2023年数维杯国际大学生数学建模挑战赛A题

当大家面临着复杂的数学建模问题时&#xff0c;你是否曾经感到茫然无措&#xff1f;作为2022年美国大学生数学建模比赛的O奖得主&#xff0c;我为大家提供了一套优秀的解题思路&#xff0c;让你轻松应对各种难题。 cs数模团队在数维杯前为大家提供了许多资料的内容呀&#xff0…

ios 对话框UIAlertController放 tableview

//强弱引用 #define kWeakSelf(type)__weak typeof(type)weak##type type; -(void) showUIAlertTable {kWeakSelf(self)UIAlertController *alert [UIAlertController alertControllerWithTitle:NSLocalizedString("select_stu", nil) message:nil prefer…

基于php+thinkphp的网上书店购物商城系统

运行环境 开发语言&#xff1a;PHP 数据库:MYSQL数据库 应用服务:apache服务器 使用框架:ThinkPHPvue 开发工具:VScode/Dreamweaver/PhpStorm等均可 项目简介 系统主要分为管理员和用户二部分&#xff0c;管理员主要功能包括&#xff1a;首页、个人中心、用户管理、图书分类…

P6入门:项目初始化5-项目支出计划Spending Plan

前言 使用项目详细信息查看和编辑有关所选项目的详细信息&#xff0c;在项目创建完成后&#xff0c;初始化项目是一项非常重要的工作&#xff0c;涉及需要设置的内容包括项目名&#xff0c;ID,责任人&#xff0c;日历&#xff0c;预算&#xff0c;资金&#xff0c;分类码等等&…

Spark3.0中的AOE、DPP和Hint增强

1 Spark3.0 AQE Spark 在 3.0 版本推出了 AQE&#xff08;Adaptive Query Execution&#xff09;&#xff0c;即自适应查询执行。AQE 是 Spark SQL 的一种动态优化机制&#xff0c;在运行时&#xff0c;每当 Shuffle Map 阶段执行完毕&#xff0c;AQE 都会结合这个阶段的统计信…

什么是状态机?

什么是状态机&#xff1f; 定义 我们先来给出状态机的基本定义。一句话&#xff1a; 状态机是有限状态自动机的简称&#xff0c;是现实事物运行规则抽象而成的一个数学模型。 先来解释什么是“状态”&#xff08; State &#xff09;。现实事物是有不同状态的&#xff0c;例…

上门洗衣洗鞋app小程序

上门洗衣洗鞋app小程序作为专业的帮助用户洗衣服务的软件,许多朋友都使用过。在这里,小编就帮助大家收集一些非常不错的洗衣洗鞋软件。 不知道大家是否还在为洗衣而烦恼,而怕麻烦,现在大家都在用网上的洗衣洗鞋小程序来洗衣服,用户只需要打开手机软件,发起订单,门店即可收到订单…