arthas的监控java性能

news2025/7/8 11:45:38

目录

  • 1 arthas简介
  • 2 arthas下载
  • 3 arthas的使用
    • 3.1 arthas启动
    • 3.2 常用命令
      • 3.2.1 dashboard
      • 3.2.2 thread
      • 3.2.3 jad
      • 3.2.4 watch
      • 3.2.5 getstatic
      • 3.2.6 heapdump
        • 3.2.6.1 dump到指定的文件
        • 3.2.6.2 dump live 对象
        • 3.2.6.3 dump 到临时文件
      • 3.2.7 jvm
      • 3.2.8 logger
      • 3.2.9 mbean
        • 3.2.9.1 列出所有 Mbean 的名称
        • 3.2.9.2 查看 Mbean 的元信息
        • 3.2.9.3 查看 mbean 属性信息
        • 3.2.9.4 mbean 的 name 支持通配符匹配
        • 3.2.9.5 通配符匹配特定的属性字段:
        • 3.2.9.6 使用-E命令切换为正则匹配:
        • 3.2.9.7 使用-i命令实时监控
      • 3.2.10 memory
      • 3.2.11 ognl
        • 3.2.11.1 通过 hashcode 指定 ClassLoader
        • 3.2.11.2 执行多行表达式
      • 3.2.12 perfcounter
      • 3.2.13 sysenv
      • 3.2.14 vmoption
      • 3.2.15 vmtool
      • 3.2.16 classloader
      • 3.2.17 dump
      • 3.2.18 mc
      • 3.2.19 redefine
      • 3.2.20 retransform
      • 3.2.21 sc
      • 3.2.22 sm
      • 3.2.23 monitor
      • 3.2.24 stack
      • 3.2.25 trace
      • 3.2.26 tt
      • 3.2.27 auth
      • 3.2.28 options
      • 3.2.29 base64
      • 3.2.30 cat
      • 3.2.31 cls
      • 3.2.32 echo
      • 3.2.33 grep
      • 3.2.34 help
      • 3.2.35 history
        • 3.2.35.1 查看最近执行的3条指令
        • 3.2.35.2 清空指令
      • 3.2.36 keymap
      • 3.2.37 pwd
      • 3.2.38 tee
      • 3.2.39 profile
      • 3.2.40 session
      • 3.2.41 version
      • 3.2.42 quit
      • 3.2.43 reset
        • 3.2.43.1 还原指定类
        • 3.2.43.2 还原所有类
      • 3.2.44 stop

1 arthas简介

Arthas 是一款线上监控诊断产品,通过全局视角实时查看应用load、内存、gc、线程的状态信息,并能在不修改应用代码的情况下,对业务问题进行诊断,包括查看方法调用的出入参、异常,监测方法执行耗时,类加载信息等,大大提升线上问题排查效率。

参考地址:

https://arthas.aliyun.com/

2 arthas下载

curl -O https://arthas.aliyun.com/arthas-boot.jar

3 arthas的使用

3.1 arthas启动

$ $ java -jar arthas-boot.jar
* [1]: 71560 math-game.jar
  [2]: 35542 

进程是第 1 个,则输入 1,再输入回车/enter。Arthas 会 attach 到目标进程上,并输出日志:

[INFO] Try to attach process 71560
[INFO] Attach process 71560 success.
[INFO] arthas-client connect 127.0.0.1 3658
  ,---.  ,------. ,--------.,--.  ,--.  ,---.   ,---.
 /  O  \ |  .--. ''--.  .--'|  '--'  | /  O  \ '   .-'
|  .-.  ||  '--'.'   |  |   |  .--.  ||  .-.  |`.  `-.
|  | |  ||  |\  \    |  |   |  |  |  ||  | |  |.-'    |
`--' `--'`--' '--'   `--'   `--'  `--'`--' `--'`-----'


wiki: https://arthas.aliyun.com/doc
version: 3.0.5.20181127201536
pid: 71560
time: 2018-11-28 19:16:24

$

3.2 常用命令

3.2.1 dashboard

$ dashboard
ID     NAME                   GROUP          PRIORI STATE  %CPU    TIME   INTERRU DAEMON
17     pool-2-thread-1        system         5      WAITIN 67      0:0    false   false
27     Timer-for-arthas-dashb system         10     RUNNAB 32      0:0    false   true
11     AsyncAppender-Worker-a system         9      WAITIN 0       0:0    false   true
9      Attach Listener        system         9      RUNNAB 0       0:0    false   true
3      Finalizer              system         8      WAITIN 0       0:0    false   true
2      Reference Handler      system         10     WAITIN 0       0:0    false   true
4      Signal Dispatcher      system         9      RUNNAB 0       0:0    false   true
26     as-command-execute-dae system         10     TIMED_ 0       0:0    false   true
13     job-timeout            system         9      TIMED_ 0       0:0    false   true
1      main                   main           5      TIMED_ 0       0:0    false   false
14     nioEventLoopGroup-2-1  system         10     RUNNAB 0       0:0    false   false
18     nioEventLoopGroup-2-2  system         10     RUNNAB 0       0:0    false   false
23     nioEventLoopGroup-2-3  system         10     RUNNAB 0       0:0    false   false
15     nioEventLoopGroup-3-1  system         10     RUNNAB 0       0:0    false   false
Memory             used   total max    usage GC
heap               32M    155M  1820M  1.77% gc.ps_scavenge.count  4
ps_eden_space      14M    65M   672M   2.21% gc.ps_scavenge.time(m 166
ps_survivor_space  4M     5M    5M           s)
ps_old_gen         12M    85M   1365M  0.91% gc.ps_marksweep.count 0
nonheap            20M    23M   -1           gc.ps_marksweep.time( 0
code_cache         3M     5M    240M   1.32% ms)
Runtime
os.name                Mac OS X
os.version             10.13.4
java.version           1.8.0_162
java.home              /Library/Java/JavaVir
                       tualMachines/jdk1.8.0
                       _162.jdk/Contents/Hom
                       e/jre

3.2.2 thread

thread 1会打印线程 ID 1 的栈,通常是 main 函数的线程

$ thread 1 | grep 'main('
    at demo.MathGame.main(MathGame.java:17)

3.2.3 jad

反编译 Main Class

$ jad demo.MathGame

ClassLoader:
+-sun.misc.Launcher$AppClassLoader@3d4eac69
  +-sun.misc.Launcher$ExtClassLoader@66350f69

Location:
/tmp/math-game.jar

/*
 * Decompiled with CFR 0_132.
 */
package demo;

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import java.util.concurrent.TimeUnit;

public class MathGame {
    private static Random random = new Random();
    private int illegalArgumentCount = 0;

    public static void main(String[] args) throws InterruptedException {
        MathGame game = new MathGame();
        do {
            game.run();
            TimeUnit.SECONDS.sleep(1L);
        } while (true);
    }

    public void run() throws InterruptedException {
        try {
            int number = random.nextInt();
            List<Integer> primeFactors = this.primeFactors(number);
            MathGame.print(number, primeFactors);
        }
        catch (Exception e) {
            System.out.println(String.format("illegalArgumentCount:%3d, ", this.illegalArgumentCount) + e.getMessage());
        }
    }

    public static void print(int number, List<Integer> primeFactors) {
        StringBuffer sb = new StringBuffer("" + number + "=");
        Iterator<Integer> iterator = primeFactors.iterator();
        while (iterator.hasNext()) {
            int factor = iterator.next();
            sb.append(factor).append('*');
        }
        if (sb.charAt(sb.length() - 1) == '*') {
            sb.deleteCharAt(sb.length() - 1);
        }
        System.out.println(sb);
    }

    public List<Integer> primeFactors(int number) {
        if (number < 2) {
            ++this.illegalArgumentCount;
            throw new IllegalArgumentException("number is: " + number + ", need >= 2");
        }
        ArrayList<Integer> result = new ArrayList<Integer>();
        int i = 2;
        while (i <= number) {
            if (number % i == 0) {
                result.add(i);
                number /= i;
                i = 2;
                continue;
            }
            ++i;
        }
        return result;
    }
}

Affect(row-cnt:1) cost in 970 ms.

3.2.4 watch

查看demo.MathGame#primeFactors函数的返回值

$ watch demo.MathGame primeFactors returnObj
Press Ctrl+C to abort.
Affect(class-cnt:1 , method-cnt:1) cost in 107 ms.
ts=2018-11-28 19:22:30; [cost=1.715367ms] result=null
ts=2018-11-28 19:22:31; [cost=0.185203ms] result=null
ts=2018-11-28 19:22:32; [cost=19.012416ms] result=@ArrayList[
    @Integer[5],
    @Integer[47],
    @Integer[2675531],
]
ts=2018-11-28 19:22:33; [cost=0.311395ms] result=@ArrayList[
    @Integer[2],
    @Integer[5],
    @Integer[317],
    @Integer[503],
    @Integer[887],
]
ts=2018-11-28 19:22:34; [cost=10.136007ms] result=@ArrayList[
    @Integer[2],
    @Integer[2],
    @Integer[3],
    @Integer[3],
    @Integer[31],
    @Integer[717593],
]
ts=2018-11-28 19:22:35; [cost=29.969732ms] result=@ArrayList[
    @Integer[5],
    @Integer[29],
    @Integer[7651739],
]

3.2.5 getstatic

通过 getstatic 命令可以方便的查看类的静态属性。使用方法为getstatic class_name field_name

$ getstatic demo.MathGame random
field: random
@Random[
    serialVersionUID=@Long[3905348978240129619],
    seed=@AtomicLong[120955813885284],
    multiplier=@Long[25214903917],
    addend=@Long[11],
    mask=@Long[281474976710655],
    DOUBLE_UNIT=@Double[1.1102230246251565E-16],
    BadBound=@String[bound must be positive],
    BadRange=@String[bound must be greater than origin],
    BadSize=@String[size must be non-negative],
    seedUniquifier=@AtomicLong[-3282039941672302964],
    nextNextGaussian=@Double[0.0],
    haveNextNextGaussian=@Boolean[false],
    serialPersistentFields=@ObjectStreamField[][isEmpty=false;size=3],
    unsafe=@Unsafe[sun.misc.Unsafe@2eaa1027],
    seedOffset=@Long[24],
]

3.2.6 heapdump

3.2.6.1 dump到指定的文件

[arthas@58205]$ heapdump /tmp/dump.hprof
Dumping heap to /tmp/dump.hprof...
Heap dump file created

3.2.6.2 dump live 对象

[arthas@58205]$ heapdump --live /tmp/dump.hprof
Dumping heap to /tmp/dump.hprof...
Heap dump file created

3.2.6.3 dump 到临时文件

[arthas@58205]$ heapdump
Dumping heap to /var/folders/my/wy7c9w9j5732xbkcyt1mb4g40000gp/T/heapdump2019-09-03-16-385121018449645518991.hprof...
Heap dump file created

3.2.7 jvm

$ jvm
RUNTIME
--------------------------------------------------------------------------------------------------------------
 MACHINE-NAME                   37@ff267334bb65
 JVM-START-TIME                 2020-07-23 07:50:36
 MANAGEMENT-SPEC-VERSION        1.2
 SPEC-NAME                      Java Virtual Machine Specification
 SPEC-VENDOR                    Oracle Corporation
 SPEC-VERSION                   1.8
 VM-NAME                        Java HotSpot(TM) 64-Bit Server VM
 VM-VENDOR                      Oracle Corporation
 VM-VERSION                     25.201-b09
 INPUT-ARGUMENTS                []
 CLASS-PATH                     demo-arthas-spring-boot.jar
 BOOT-CLASS-PATH                /usr/lib/jvm/java-8-oracle/jre/lib/resources.jar:/usr/lib/jvm/java-8-oracle/j
                                re/lib/rt.jar:/usr/lib/jvm/java-8-oracle/jre/lib/sunrsasign.jar:/usr/lib/jvm/
                                java-8-oracle/jre/lib/jsse.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jce.jar:/us
                                r/lib/jvm/java-8-oracle/jre/lib/charsets.jar:/usr/lib/jvm/java-8-oracle/jre/l
                                ib/jfr.jar:/usr/lib/jvm/java-8-oracle/jre/classes
 LIBRARY-PATH                   /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib

--------------------------------------------------------------------------------------------------------------
 CLASS-LOADING
--------------------------------------------------------------------------------------------------------------
 LOADED-CLASS-COUNT             7529
 TOTAL-LOADED-CLASS-COUNT       7529
 UNLOADED-CLASS-COUNT           0
 IS-VERBOSE                     false

--------------------------------------------------------------------------------------------------------------
 COMPILATION
--------------------------------------------------------------------------------------------------------------
 NAME                           HotSpot 64-Bit Tiered Compilers
 TOTAL-COMPILE-TIME             14921(ms)

--------------------------------------------------------------------------------------------------------------
 GARBAGE-COLLECTORS
--------------------------------------------------------------------------------------------------------------
 PS Scavenge                            name : PS Scavenge
 [count/time (ms)]                      collectionCount : 7
                                        collectionTime : 68

 PS MarkSweep                           name : PS MarkSweep
 [count/time (ms)]                      collectionCount : 1
                                        collectionTime : 47

--------------------------------------------------------------------------------------------------------------
 MEMORY-MANAGERS
--------------------------------------------------------------------------------------------------------------
 CodeCacheManager               Code Cache

 Metaspace Manager              Metaspace
                                Compressed Class Space

 Copy                           Eden Space
                                Survivor Space

 MarkSweepCompact               Eden Space
                                Survivor Space
                                Tenured Gen


--------------------------------------------------------------------------------------------------------------
 MEMORY
--------------------------------------------------------------------------------------------------------------
 HEAP-MEMORY-USAGE                      init : 268435456(256.0 MiB)
 [memory in bytes]                      used : 18039504(17.2 MiB)
                                        committed : 181403648(173.0 MiB)
                                        max : 3817865216(3.6 GiB)

 NO-HEAP-MEMORY-USAGE                   init : 2555904(2.4 MiB)
 [memory in bytes]                      used : 33926216(32.4 MiB)
                                        committed : 35176448(33.5 MiB)
                                        max : -1(-1 B)

--------------------------------------------------------------------------------------------------------------
 OPERATING-SYSTEM
--------------------------------------------------------------------------------------------------------------
 OS                             Linux
 ARCH                           amd64
 PROCESSORS-COUNT               3
 LOAD-AVERAGE                   29.53
 VERSION                        4.15.0-52-generic

--------------------------------------------------------------------------------------------------------------
 THREAD
--------------------------------------------------------------------------------------------------------------
 COUNT                          30
 DAEMON-COUNT                   24
 PEAK-COUNT                     31
 STARTED-COUNT                  36
 DEADLOCK-COUNT                 0

--------------------------------------------------------------------------------------------------------------
 FILE-DESCRIPTOR
--------------------------------------------------------------------------------------------------------------
 MAX-FILE-DESCRIPTOR-COUNT      1048576
 OPEN-FILE-DESCRIPTOR-COUNT     100
Affect(row-cnt:0) cost in 88 ms.

3.2.8 logger

[arthas@2062]$ logger
 name                                   ROOT
 class                                  ch.qos.logback.classic.Logger
 classLoader                            sun.misc.Launcher$AppClassLoader@2a139a55
 classLoaderHash                        2a139a55
 level                                  INFO
 effectiveLevel                         INFO
 additivity                             true
 codeSource                             file:/Users/hengyunabc/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar
 appenders                              name            CONSOLE
                                        class           ch.qos.logback.core.ConsoleAppender
                                        classLoader     sun.misc.Launcher$AppClassLoader@2a139a55
                                        classLoaderHash 2a139a55
                                        target          System.out
                                        name            APPLICATION
                                        class           ch.qos.logback.core.rolling.RollingFileAppender
                                        classLoader     sun.misc.Launcher$AppClassLoader@2a139a55
                                        classLoaderHash 2a139a55
                                        file            app.log
                                        name            ASYNC
                                        class           ch.qos.logback.classic.AsyncAppender
                                        classLoader     sun.misc.Launcher$AppClassLoader@2a139a55
                                        classLoaderHash 2a139a55
                                        appenderRef     [APPLICATION]

3.2.9 mbean

查看或监控 Mbean 的属性信息。

参数名称参数说明
name-pattern名称表达式匹配
attribute-pattern属性名表达式匹配
[m]查看元信息
[i:]刷新属性值的时间间隔 (ms)
[n:]刷新属性值的次数
[E]开启正则表达式匹配,默认为通配符匹配。仅对属性名有效

3.2.9.1 列出所有 Mbean 的名称

mbean

3.2.9.2 查看 Mbean 的元信息

mbean -m java.lang:type=Threading

3.2.9.3 查看 mbean 属性信息

mbean java.lang:type=Threading

3.2.9.4 mbean 的 name 支持通配符匹配

mbean java.lang:type=Th*

3.2.9.5 通配符匹配特定的属性字段:

mbean java.lang:type=Threading *Count

3.2.9.6 使用-E命令切换为正则匹配:

mbean -E java.lang:type=Threading PeakThreadCount|ThreadCount|DaemonThreadCount

3.2.9.7 使用-i命令实时监控

mbean -i 1000 java.lang:type=Threading *Count

3.2.10 memory

$ memory
Memory                           used      total      max        usage
heap                             32M       256M       4096M      0.79%
g1_eden_space                    11M       68M        -1         16.18%
g1_old_gen                       17M       184M       4096M      0.43%
g1_survivor_space                4M        4M         -1         100.00%
nonheap                          35M       39M        -1         89.55%
codeheap_'non-nmethods'          1M        2M         5M         20.53%
metaspace                        26M       27M        -1         96.88%
codeheap_'profiled_nmethods'     4M        4M         117M       3.57%
compressed_class_space           2M        3M         1024M      0.29%
codeheap_'non-profiled_nmethods' 685K      2496K      120032K    0.57%
mapped                           0K        0K         -          0.00%
direct                           48M       48M        -          100.00%

3.2.11 ognl

参数名称参数说明
express执行的表达式
[c:]执行表达式的 ClassLoader 的 hashcode,默认值是 SystemClassLoader
[classLoaderClass:]指定执行表达式的 ClassLoader 的 class name
[x]结果对象的展开层次,默认值 1

3.2.11.1 通过 hashcode 指定 ClassLoader

$ classloader -t
+-BootstrapClassLoader
+-jdk.internal.loader.ClassLoaders$PlatformClassLoader@301ec38b
  +-com.taobao.arthas.agent.ArthasClassloader@472067c7
  +-jdk.internal.loader.ClassLoaders$AppClassLoader@4b85612c
    +-org.springframework.boot.loader.LaunchedURLClassLoader@7f9a81e8

$ ognl -c 7f9a81e8 @org.springframework.boot.SpringApplication@logger
@Slf4jLocationAwareLog[
    FQCN=@String[org.apache.commons.logging.LogAdapter$Slf4jLocationAwareLog],
    name=@String[org.springframework.boot.SpringApplication],
    logger=@Logger[Logger[org.springframework.boot.SpringApplication]],
]
$

注意 hashcode 是变化的,需要先查看当前的 ClassLoader 信息,提取对应 ClassLoader 的 hashcode。

对于只有唯一实例的 ClassLoader 可以通过 class name 指定,使用起来更加方便:

$ ognl --classLoaderClass org.springframework.boot.loader.LaunchedURLClassLoader  @org.springframework.boot.SpringApplication@logger
@Slf4jLocationAwareLog[
    FQCN=@String[org.apache.commons.logging.LogAdapter$Slf4jLocationAwareLog],
    name=@String[org.springframework.boot.SpringApplication],
    logger=@Logger[Logger[org.springframework.boot.SpringApplication]],
]

3.2.11.2 执行多行表达式

赋值给临时变量,返回一个 List:

$ ognl '#value1=@System@getProperty("java.home"), #value2=@System@getProperty("java.runtime.name"), {#value1, #value2}'
@ArrayList[
    @String[/opt/java/8.0.181-zulu/jre],
    @String[OpenJDK Runtime Environment],
]

3.2.12 perfcounter

$ perfcounter
 java.ci.totalTime                            2325637411
 java.cls.loadedClasses                       3403
 java.cls.sharedLoadedClasses                 0
 java.cls.sharedUnloadedClasses               0
 java.cls.unloadedClasses                     0
 java.property.java.version                   11.0.4
 java.property.java.vm.info                   mixed mode
 java.property.java.vm.name                   OpenJDK 64-Bit Server VM
...

3.2.13 sysenv

$ sysenv
 KEY                      VALUE
----------------------------------------------------------------------------------------------------------------------------
 PATH                     /Users/admin/.sdkman/candidates/visualvm/current/bin:/Users/admin/.sdkman/candidates/ja
                          va/current/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Wireshark.app/Contents/
                          MacOS
 SDKMAN_VERSION           5.7.3+337
 JAVA_HOME                /Users/admin/.sdkman/candidates/java/current
 JAVA_MAIN_CLASS_65244    demo.MathGame
 TERM                     xterm-256color
 LANG                     zh_CN.UTF-8
 AUTOJUMP_SOURCED         1
 COLORTERM                truecolor
 LOGNAME                  admin
 XPC_SERVICE_NAME         0
 PWD                      /Users/admin/code/ali/arthas/demo
 TERM_PROGRAM_VERSION     3.2.5
 _                        /Users/admin/.sdkman/candidates/java/current/bin/java
 SHELL                    /bin/bash
 TERM_PROGRAM             iTerm.app
 SDKMAN_PLATFORM          Darwin
 USER                     admin
 ITERM_PROFILE            Default
 TMPDIR                   /var/folders/0r/k561bkk917gg972stqclbz9h0000gn/T/
 XPC_FLAGS                0x0
 TERM_SESSION_ID          w0t4p0:60BC264D-9649-42AC-A7E4-AF85B69F93F8
 __CF_USER_TEXT_ENCODING  0x1F5:0x19:0x34
 Apple_PubSub_Socket_Ren  /private/tmp/com.apple.launchd.DwmmjSQsll/Render
 der
 COLORFGBG                7;0
 HOME                     /Users/admin
 SHLVL                    1
 AUTOJUMP_ERROR_PATH      /Users/admin/Library/autojump/errors.log

3.2.14 vmoption

[arthas@56963]$ vmoption
 KEY                    VALUE                   ORIGIN                 WRITEABLE
---------------------------------------------------------------------------------------------
 HeapDumpBeforeFullGC   false                   DEFAULT                true
 HeapDumpAfterFullGC    false                   DEFAULT                true
 HeapDumpOnOutOfMemory  false                   DEFAULT                true
 Error
 HeapDumpPath                                   DEFAULT                true
 CMSAbortablePrecleanW  100                     DEFAULT                true
 aitMillis
 CMSWaitDuration        2000                    DEFAULT                true
 CMSTriggerInterval     -1                      DEFAULT                true
 PrintGC                false                   DEFAULT                true
 PrintGCDetails         true                    MANAGEMENT             true
 PrintGCDateStamps      false                   DEFAULT                true
 PrintGCTimeStamps      false                   DEFAULT                true
 PrintGCID              false                   DEFAULT                true
 PrintClassHistogramBe  false                   DEFAULT                true
 foreFullGC
 PrintClassHistogramAf  false                   DEFAULT                true
 terFullGC
 PrintClassHistogram    false                   DEFAULT                true
 MinHeapFreeRatio       0                       DEFAULT                true
 MaxHeapFreeRatio       100                     DEFAULT                true
 PrintConcurrentLocks   false                   DEFAULT                true

3.2.15 vmtool

$ vmtool --action getInstances --className java.lang.String --limit 10
@String[][
    @String[com/taobao/arthas/core/shell/session/Session],
    @String[com.taobao.arthas.core.shell.session.Session],
    @String[com/taobao/arthas/core/shell/session/Session],
    @String[com/taobao/arthas/core/shell/session/Session],
    @String[com/taobao/arthas/core/shell/session/Session.class],
    @String[com/taobao/arthas/core/shell/session/Session.class],
    @String[com/taobao/arthas/core/shell/session/Session.class],
    @String[com/],
    @String[java/util/concurrent/ConcurrentHashMap$ValueIterator],
    @String[java/util/concurrent/locks/LockSupport],
]

3.2.16 classloader

参数名称Value
[l]按类加载实例进行统计
[t]打印所有 ClassLoader 的继承树
[a]列出所有 ClassLoader 加载的类,请谨慎使用
[c:]ClassLoader 的 hashcode
[classLoaderClass:]指定执行表达式的 ClassLoader 的 class name
[c: r:]用 ClassLoader 去查找 resource
[c: load:]用 ClassLoader 去加载指定的类

3.2.17 dump

参数名称参数说明
class-pattern类名表达式匹配
[c:]类所属 ClassLoader 的 hashcode
[classLoaderClass:]指定执行表达式的 ClassLoader 的 class name
[d:]设置类文件的目标目录
[E]开启正则表达式匹配,默认为通配符匹配

3.2.18 mc

Memory Compiler/内存编译器,编译.java文件生成.class。

mc /tmp/Test.java

3.2.19 redefine

参数名称参数说明
[c:]ClassLoader 的 hashcode
[classLoaderClass:]指定执行表达式的 ClassLoader 的 class name

3.2.20 retransform

加载外部的.class文件,retransform jvm 已加载的类

   retransform /tmp/Test.class
   retransform -l
   retransform -d 1                    # delete retransform entry
   retransform --deleteAll             # delete all retransform entries
   retransform --classPattern demo.*   # triger retransform classes
   retransform -c 327a647b /tmp/Test.class /tmp/Test\$Inner.class
   retransform --classLoaderClass 'sun.misc.Launcher$AppClassLoader' /tmp/Test.class

3.2.21 sc

查看 JVM 已加载的类信息

参数名称参数说明
class-pattern类名表达式匹配
method-pattern方法名表达式匹配
[d]输出当前类的详细信息,包括这个类所加载的原始文件来源、类的声明、加载的 ClassLoader 等详细信息。
如果一个类被多个 ClassLoader 所加载,则会出现多次
[E]开启正则表达式匹配,默认为通配符匹配
[f]输出当前类的成员变量信息(需要配合参数-d 一起使用)
[x:]指定输出静态变量时属性的遍历深度,默认为 0,即直接使用 toString 输出
[c:]指定 class 的 ClassLoader 的 hashcode
[classLoaderClass:]指定执行表达式的 ClassLoader 的 class name
[n:]具有详细信息的匹配类的最大数量(默认为 100)

3.2.22 sm

参数名称参数说明
class-pattern类名表达式匹配
method-pattern方法名表达式匹配
[d]展示每个方法的详细信息
[E]开启正则表达式匹配,默认为通配符匹配
[c:]指定 class 的 ClassLoader 的 hashcode
[classLoaderClass:]指定执行表达式的 ClassLoader 的 class name
[n:]具有详细信息的匹配类的最大数量(默认为 100)

3.2.23 monitor

参数名称参数说明
class-pattern类名表达式匹配
method-pattern方法名表达式匹配
condition-express条件表达式
[E]开启正则表达式匹配,默认为通配符匹配
[c:]统计周期,默认值为 120 秒
[b]在方法调用之前计算 condition-express

3.2.24 stack

参数名称参数说明
class-pattern类名表达式匹配
method-pattern方法名表达式匹配
condition-express条件表达式
[E]开启正则表达式匹配,默认为通配符匹配
[n:]执行次数限制

3.2.25 trace

参数名称参数说明
class-pattern类名表达式匹配
method-pattern方法名表达式匹配
condition-express条件表达式
[E]开启正则表达式匹配,默认为通配符匹配
[n:]命令执行次数
#cost方法执行耗时

3.2.26 tt

$ tt -t demo.MathGame primeFactors
Press Ctrl+C to abort.
Affect(class-cnt:1 , method-cnt:1) cost in 66 ms.
 INDEX   TIMESTAMP            COST(ms)  IS-RET  IS-EXP   OBJECT         CLASS                          METHOD
-------------------------------------------------------------------------------------------------------------------------------------
 1000    2018-12-04 11:15:38  1.096236  false   true     0x4b67cf4d     MathGame                       primeFactors
 1001    2018-12-04 11:15:39  0.191848  false   true     0x4b67cf4d     MathGame                       primeFactors
 1002    2018-12-04 11:15:40  0.069523  false   true     0x4b67cf4d     MathGame                       primeFactors
 1003    2018-12-04 11:15:41  0.186073  false   true     0x4b67cf4d     MathGame                       primeFactors
 1004    2018-12-04 11:15:42  17.76437  true    false    0x4b67cf4d     MathGame      

3.2.27 auth

[arthas@37430]$ auth ppp
Authentication result: true

3.2.28 options

$ options
 LEVEL  TYPE    NAME          VALUE   SUMMARY               DESCRIPTION
-------------------------------------------------------------------------------------------------------
 0      boolea  unsafe        false   Option to support sy  This option enables to proxy functionality
        n                             stem-level class       of JVM classes. Due to serious security r
                                                            isk a JVM crash is possibly be introduced.
                                                             Do not activate it unless you are able to
                                                             manage.
 1      boolea  dump          false   Option to dump the e  This option enables the enhanced classes t
        n                             nhanced classes       o be dumped to external file for further d
                                                            e-compilation and analysis.
 1      boolea  batch-re-tra  true    Option to support ba  This options enables to reTransform classe
        n       nsform                tch reTransform Clas  s with batch mode.
                                      s
 2      boolea  json-format   false   Option to support JS  This option enables to format object outpu
        n                             ON format of object   t with JSON when -x option selected.
                                      output
 1      boolea  disable-sub-  false   Option to control in  This option disable to include sub class w
        n       class                 clude sub class when  hen matching class.
                                       class matching
 1      boolea  support-defa  true    Option to control in  This option disable to include default met
        n       ult-method            clude default method  hod in interface when matching class.
                                       in interface when c
                                      lass matching
 1      boolea  save-result   false   Option to print comm  This option enables to save each command's
        n                             and's result to log    result to log file, which path is ${user.
                                      file                  home}/logs/arthas-cache/result.log.
 2      String  job-timeout   1d      Option to job timeou  This option setting job timeout,The unit c
                                      t                     an be d, h, m, s for day, hour, minute, se
                                                            cond. 1d is one day in default
 1      boolea  print-parent  true    Option to print all   This option enables print files in parent
        n       -fields               fileds in parent cla  class, default value true.
                                      ss
 1      boolea  verbose       false   Option to print verb  This option enables print verbose informat
        n                             ose information       ion, default value false.
 1      boolea  strict        true    Option to strict mod  By default, strict mode is true, not allow
        n                             e                     ed to set object properties. Want to set o
                                                            bject properties, execute `options strict
                                                            false`

3.2.29 base64

[arthas@70070]$ echo 'abc' > /tmp/test.txt
[arthas@70070]$ cat /tmp/test.txt
abc

[arthas@70070]$ base64 /tmp/test.txt
YWJjCg==

3.2.30 cat

$ cat /tmp/a.txt

3.2.31 cls

清空当前屏幕区域

3.2.32 echo

打印参数,和 linux 里的 echo 命令类似。

3.2.33 grep

类似传统的grep命令。

3.2.34 help

[help 指令]的等同于[指令 -help],都是查看具体指令的使用说明。

3.2.35 history

3.2.35.1 查看最近执行的3条指令

$ history 3
  269  thread
  270  cls
  271  history 3

3.2.35.2 清空指令

 $ history -c
 $ history 3
  1  history 3

3.2.36 keymap

keymap命令输出当前的快捷键映射表

3.2.37 pwd

返回当前的工作目录,和 linux 命令类似

3.2.38 tee

tee 指令会从标准输入设备读取数据,将其内容输出到标准输出设备,同时保存成文件。

3.2.39 profile

[arthas@25575]$ profiler start
Profiling started
[arthas@25575]$ profiler getSamples
291
[arthas@25575]$ profiler status
Profiling is running for 39 seconds
[arthas@25575]$ profiler stop
OK
profiler output file: /data/src/flume/teflume-prod/apache-flume-1.9.0-bin/arthas-output/20220621-161810.html

在这里插入图片描述

3.2.40 session

如果配置了 tunnel server,会追加打印 代理 id、tunnel 服务器的 url 以及连接状态。使用了 staturl 做统计,会追加显示 statUrl 地址。

$ session
  Name        Value
--------------------------------------------------
 JAVA_PID    14584
 SESSION_ID  c2073d3b-443a-4a9b-9249-0c5d24a5756c

3.2.41 version

输出当前目标 Java 进程所加载的 Arthas 版本号。

$ version
 3.5.1

3.2.42 quit

退出当前 Arthas 客户端,其他 Arthas 客户端不受影响。等同于exit、logout、q三个指令。

3.2.43 reset

重置增强类,将被 Arthas 增强过的类全部还原,Arthas 服务端stop时会重置所有增强过的类。

3.2.43.1 还原指定类

$ trace Test test
Press Ctrl+C to abort.
Affect(class-cnt:1 , method-cnt:1) cost in 57 ms.
`---ts=2017-10-26 17:10:33;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@14dad5dc
    `---[0.590102ms] Test:test()

`---ts=2017-10-26 17:10:34;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@14dad5dc
    `---[0.068692ms] Test:test()

$ reset Test
Affect(class-cnt:1 , method-cnt:0) cost in 11 ms.

3.2.43.2 还原所有类

$ trace Test test
Press Ctrl+C to abort.
Affect(class-cnt:1 , method-cnt:1) cost in 15 ms.
`---ts=2017-10-26 17:12:06;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@14dad5dc
    `---[0.128518ms] Test:test()

$ reset
Affect(class-cnt:1 , method-cnt:0) cost in 9 ms

3.2.44 stop

如果只是退出当前的连接,可以用quit或者exit命令。Attach 到目标进程上的 arthas 还会继续运行,端口会保持开放,下次连接时可以直接连接上。如果想完全退出 arthas,可以执行stop命令。

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Baklib|我的企业是不是需要一个维基页面呢?

你很可能已经听说过维基百科。事实上&#xff0c;我们大多数人几乎每天都在使用维基百科来获取有关历史事件、名人或世界各地的有用信息。但是你知道公司也可以创建和维护他们自己的wiki页面吗? 随着时间的推移&#xff0c;公司会积累大量的信息。如果没有一个好的方法来存储…

Java:为什么要更新Java应用程序?

27年来&#xff0c;Java一直是企业软件开发中最流行的编程语言之一。世界上无数的系统都是使用这种广为人知的语言构建的。 传统的Java应用程序是独一无二的。它们的包中包含了运行应用程序所需的一切&#xff0c;但整体性使得开发人员在进行更改时很难保持敏捷。开发人员必须从…

项目实战——实现注册与登录模块(结尾)

目录 一、整体框架 二、前端页面授权 三、实现注册页面 四、实现登录状态的持久化 一、整体框架 二、前端页面授权 当我们登录网站的时候&#xff0c;如果没有登录&#xff0c;强制让用户重定向到 登录界面 在 router 目录下的 index.js 文件下实现。 router -> index.js…

DIVFusion:首个耦合互促低光增强图像融合的框架

DIVFusion:首个耦合互促低光增强&图像融合的框架DIVFusion:首个耦合互促低光增强&图像融合的框架写在前面问题引入Motivation主要贡献网络架构实验验证融合性能目标检测性能消融实验结论写在最后DIVFusion:首个耦合互促低光增强&图像融合的框架 论文&#xff1a;h…

攻防世界Running

Running 题目描述&#xff1a;无 题目环境&#xff1a;https://download.csdn.net/download/m0_59188912/87016663 一个可执行文件&#xff0c;执行后显示error&#xff0c;尝试binwalk文件分离。 命令&#xff1a;binwalk -e run.exe浏览分离出来的文件。 末尾发现一个run.ex…

mannose-CHO|甘露糖-醛基|甘露糖-聚乙二醇-醛基|醛基-PEG-甘露糖

mannose-CHO|甘露糖-醛基|甘露糖-聚乙二醇-醛基|醛基-PEG-甘露糖 羰基中的一个共价键跟氢原子相连而组成的一价原子团&#xff0c;叫做醛基&#xff0c;醛基结构简式是-CHO&#xff0c;醛基是亲水基团&#xff0c;因此有醛基的有机物&#xff08;如乙醛等&#xff09;有一定的…

APS高级排产软件在快消品行业的应用

快消行业是指消费频率高、使用时限短、拥有广泛的消费群体、对于消费的便利性要求很高的商品销售行业。快消行业的销售渠道种类多而复杂&#xff0c;传统业态和新兴业态等多种渠道并存。快消行业集中度逐步上升&#xff0c;竞争度加大。 随着快速消费品市场的复苏&#xff0c;经…

CNN学习笔记

目录 如何理解卷积层和池化层&#xff1f; 机器视角&#xff1a;长文揭秘图像处理和卷积神经网络架构 卷积神经网络 - 基础知识 激活函数的作用是什么&#xff1f; 激活函数&#xff08;加入非线性因素&#xff09; 提高模型鲁棒性&#xff08;抗干扰能力&#xff09;&#…

时间复杂度和空间复杂度详解

文章目录 引入 一、时间复杂度的详解及例题 1、时间复杂度的概念 2、时间复杂度的例题训练 2.1 实题训练1 2.2 实题训练2 2.3 实题训练3 2.4 实题训练4 2.5 大O符号&#xff08;Big O notation)的函数绘图 二、空间复杂度的详解及例题 1、空间复杂的的概念 2、空间复杂度…

Java注解与原理分析

使用的太多&#xff0c;被忽略的理所当然&#xff1b; 一、注解基础 注解即标注与解析&#xff0c;在Java的代码工程中&#xff0c;注解的使用几乎是无处不在&#xff0c;甚至多到被忽视&#xff1b; 无论是在JDK源码或者框架组件&#xff0c;都在使用注解能力完成各种识别和…

【Vue】url拼接参数获取解析

前言&#xff1a; 前端在开发的时候有很多情况下需要提供不带参数的链接或者带参数的链接给自己使用或者给第三方系统&#xff0c;如果提供给第三方系统使用的话一般是第三方需要通过iframe/window.open/a标签打开链接进入对应的页面。 情况一&#xff1a;获取当前浏览器地址栏…

【React二】ref与事件处理与生命周期钩子函数

关于react基础及组件化编程的可以参考本篇笔记 文章目录一、 React中的事件处理1-1 例子&#xff1a; 不要过度使用ref1-2 受控组件与非受控组件1-2-1 受控组件1-2-2 非受控组件1-3 高阶函数1-3-1 函数的柯里化1-3-2 不用柯里化的写法二、生命周期2-1 引出生命周期2-2 组件生命…

TiDB 数据库架构概述

TiDB 数据库架构概述 TiDB体系架构 水平扩容或者缩容金融级高可用实时HTAP云原生的分布式数据兼容MYSQL5.7 Region&#xff1a;存储单位&#xff0c;96~144MB之间,分布式存储在TiKV中 TiKV&#xff1a;默认三副本&#xff0c;将分布式数据存储&#xff0c;并进行存储副本。…

【ARM微型电脑/IoT设备/嵌入式】树莓派安装失败sysstat,成功后还是无法使用sar,并报错:-bash:sar:command not found

1. 安装sysstat报错 安装&#xff1a; sudo apt-get install sysstat错误如下&#xff1a; dpkg: error processing package sysstat (–configure): installed sysstat package post-installation script subprocess returned error exit status 10 Errors were encountered…

1737C - Ela and Crickets

原题链接&#xff1a; Problem - 1737C - Codeforces 题目描述&#xff1a; The problem, which involves a non-standard chess pieces type that is described below, reads: given 33 white crickets on a n⋅nn⋅n board, arranged in an "L" shape next to ea…

详细讲解磁盘及文件系统管理(图例解析)

磁盘及文件系统管理详解 目前市场上主流的磁盘是机械式硬盘 u盘&#xff0c;光盘&#xff0c;软盘&#xff0c;硬盘&#xff0c;磁带 机械式硬盘 【硬盘内部由一个个同心圆组成】如下图&#xff1a; 硬盘内部所有盘片都固定在一根“轴”上&#xff0c;所以&#xff1a;所有…

Vant的List组件列表 滑动后不触底也发送请求的Bug

&#x1f4c3;目录跳转&#x1f4da;简介&#xff1a;&#x1f389;页面效果&#xff1a;&#x1f4ad;使用Float:&#x1f9d0; 问题&#xff1a;&#x1f52d;div 转为行内块 &#xff08;解决&#xff09;&#x1f3c6;总结&#xff1a;&#x1f4da;简介&#xff1a; Vant的…

docke入门基础知识

一、Docker 架构 Docker 包括三个基本概念: 镜像&#xff08;Image&#xff09;&#xff1a;Docker 镜像&#xff08;Image&#xff09;&#xff0c;就相当于是一个 root 文件系统。比如官方镜像 ubuntu:16.04 就包含了完整的一套 Ubuntu16.04 最小系统的 root 文件系统。 容…

html前端跨域问题的解决方案

前言&#xff1a; 在前端发出Ajax请求的时候&#xff0c;有时候会产生跨域问题&#xff0c;报错如下: Access to XMLHttpRequest at ‘http://127.0.0.1/api/post’ from origin ‘null’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is pre…

WINSOFT ComPort轻松连接到各种串行端口和连接设备

WINSOFT ComPort轻松连接到各种串行端口和连接设备 WINSOFT ComPort是一个Delphi库和CBuilder&#xff0c;通过USB端口连接到输入设备。该库提供CP210x、CP2130、CDC、FTDI、PL2303和CH34x设备。这些标准包括广泛的设备和电气从设备。例如&#xff0c;除了标准输入设备之外&…