import{_ as l,o as i,c as u,a as s,b as a,w as t,d as e,e as n,r as o}from"./app.391b0e4e.js";const r={},k=e(`

\u5FEB\u901F\u5165\u95E8

1. \u542F\u52A8 math-game

curl -O https://arthas.aliyun.com/math-game.jar
java -jar math-game.jar

math-game\u662F\u4E00\u4E2A\u7B80\u5355\u7684\u7A0B\u5E8F\uFF0C\u6BCF\u9694\u4E00\u79D2\u751F\u6210\u4E00\u4E2A\u968F\u673A\u6570\uFF0C\u518D\u6267\u884C\u8D28\u56E0\u6570\u5206\u89E3\uFF0C\u5E76\u6253\u5370\u51FA\u5206\u89E3\u7ED3\u679C\u3002

`,4),d=s("code",null,"math-game",-1),m=n("\u6E90\u4EE3\u7801\uFF1A"),b={href:"https://github.com/alibaba/arthas/blob/master/math-game/src/main/java/demo/MathGame.java",target:"_blank",rel:"noopener noreferrer"},v=n("\u67E5\u770B"),h=e(`

2. \u542F\u52A8 arthas

\u5728\u547D\u4EE4\u884C\u4E0B\u9762\u6267\u884C\uFF08\u4F7F\u7528\u548C\u76EE\u6807\u8FDB\u7A0B\u4E00\u81F4\u7684\u7528\u6237\u542F\u52A8\uFF0C\u5426\u5219\u53EF\u80FD attach \u5931\u8D25\uFF09\uFF1A

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

\u9009\u62E9\u5E94\u7528 java \u8FDB\u7A0B\uFF1A

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

math-game\u8FDB\u7A0B\u662F\u7B2C 2 \u4E2A\uFF0C\u5219\u8F93\u5165 2\uFF0C\u518D\u8F93\u5165\u56DE\u8F66/enter\u3002Arthas \u4F1A attach \u5230\u76EE\u6807\u8FDB\u7A0B\u4E0A\uFF0C\u5E76\u8F93\u51FA\u65E5\u5FD7\uFF1A

[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. \u67E5\u770B dashboard

`,9),g=n("\u8F93\u5165"),_=n("dashboard"),f=n("\uFF0C\u6309"),y=s("code",null,"\u56DE\u8F66/enter",-1),w=n("\uFF0C\u4F1A\u5C55\u793A\u5F53\u524D\u8FDB\u7A0B\u7684\u4FE1\u606F\uFF0C\u6309"),I=s("code",null,"ctrl+c",-1),j=n("\u53EF\u4EE5\u4E2D\u65AD\u6267\u884C\u3002"),M=e(`
$ 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

4. \u901A\u8FC7 thread \u547D\u4EE4\u6765\u83B7\u53D6\u5230math-game\u8FDB\u7A0B\u7684 Main Class

thread 1\u4F1A\u6253\u5370\u7EBF\u7A0B ID 1 \u7684\u6808\uFF0C\u901A\u5E38\u662F main \u51FD\u6570\u7684\u7EBF\u7A0B\u3002

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

5. \u901A\u8FC7 jad \u6765\u53CD\u7F16\u8BD1 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.

6. watch

`,7),A=n("\u901A\u8FC7"),x=n("watch"),N=n("\u547D\u4EE4\u6765\u67E5\u770B"),L=s("code",null,"demo.MathGame#primeFactors",-1),E=n("\u51FD\u6570\u7684\u8FD4\u56DE\u503C\uFF1A"),R=e(`
$ 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],
]
`,1),C=n("\u66F4\u591A\u7684\u529F\u80FD\u53EF\u4EE5\u67E5\u770B"),G=n("\u8FDB\u9636\u4F7F\u7528"),T=n("\u3002"),S=s("h2",{id:"_7-\u9000\u51FA-arthas",tabindex:"-1"},[s("a",{class:"header-anchor",href:"#_7-\u9000\u51FA-arthas","aria-hidden":"true"},"#"),n(" 7. \u9000\u51FA arthas")],-1),q=s("p",null,[n("\u5982\u679C\u53EA\u662F\u9000\u51FA\u5F53\u524D\u7684\u8FDE\u63A5\uFF0C\u53EF\u4EE5\u7528"),s("code",null,"quit"),n("\u6216\u8005"),s("code",null,"exit"),n("\u547D\u4EE4\u3002Attach \u5230\u76EE\u6807\u8FDB\u7A0B\u4E0A\u7684 arthas \u8FD8\u4F1A\u7EE7\u7EED\u8FD0\u884C\uFF0C\u7AEF\u53E3\u4F1A\u4FDD\u6301\u5F00\u653E\uFF0C\u4E0B\u6B21\u8FDE\u63A5\u65F6\u53EF\u4EE5\u76F4\u63A5\u8FDE\u63A5\u4E0A\u3002")],-1),F=s("p",null,[n("\u5982\u679C\u60F3\u5B8C\u5168\u9000\u51FA arthas\uFF0C\u53EF\u4EE5\u6267\u884C"),s("code",null,"stop"),n("\u547D\u4EE4\u3002")],-1);function O(B,U){const c=o("ExternalLinkIcon"),p=o("RouterLink");return i(),u("div",null,[k,s("p",null,[d,m,s("a",b,[v,a(c)])]),h,s("p",null,[g,a(p,{to:"/doc/dashboard.html"},{default:t(()=>[_]),_:1}),f,y,w,I,j]),M,s("p",null,[A,a(p,{to:"/doc/watch.html"},{default:t(()=>[x]),_:1}),N,L,E]),R,s("p",null,[C,a(p,{to:"/doc/advanced-use.html"},{default:t(()=>[G]),_:1}),T]),S,q,F])}var $=l(r,[["render",O],["__file","quick-start.html.vue"]]);export{$ as default};