{"id":1685,"date":"2023-03-25T22:39:50","date_gmt":"2023-03-25T14:39:50","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1685"},"modified":"2023-04-23T21:47:09","modified_gmt":"2023-04-23T13:47:09","slug":"arthas-basic-tutorial","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/25\/arthas-basic-tutorial\/","title":{"rendered":"Arthas \u57fa\u7840\u6559\u7a0b"},"content":{"rendered":"<h2>Arthas\u7b80\u4ecb<\/h2>\n<p>Arthas \u662fAlibaba\u5f00\u6e90\u7684Java\u8bca\u65ad\u5de5\u5177\uff0c\u6df1\u53d7\u5f00\u53d1\u8005\u559c\u7231\u3002\u5728\u7ebf\u6392\u67e5\u95ee\u9898\uff0c\u65e0\u9700\u91cd\u542f\uff1b\u52a8\u6001\u8ddf\u8e2aJava\u4ee3\u7801\uff1b\u5b9e\u65f6\u76d1\u63a7JVM\u72b6\u6001\u3002<\/p>\n<p>Arthas \u652f\u6301JDK 6+\uff0c\u652f\u6301Linux\/Mac\/Windows\uff0c\u91c7\u7528\u547d\u4ee4\u884c\u4ea4\u4e92\u6a21\u5f0f\uff0c\u540c\u65f6\u63d0\u4f9b\u4e30\u5bcc\u7684 Tab \u81ea\u52a8\u8865\u5168\u529f\u80fd\uff0c\u8fdb\u4e00\u6b65\u65b9\u4fbf\u8fdb\u884c\u95ee\u9898\u7684\u5b9a\u4f4d\u548c\u8bca\u65ad\u3002<\/p>\n<p><!-- more --><\/p>\n<p>Github: <a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/github.com\/alibaba\/arthas\">https:\/\/github.com\/alibaba\/arthas<\/a><br \/>\n\u6587\u6863: <a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/arthas.aliyun.com\/doc\/\">https:\/\/arthas.aliyun.com\/doc\/<\/a><br \/>\n\u53c2\u8003\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/alibaba.github.io\/arthas\/quick-start.html\">https:\/\/alibaba.github.io\/arthas\/quick-start.html<\/a><br \/>\n\u6f14\u793a\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/arthas.aliyun.com\/doc\/arthas-tutorials.html?language=cn\">https:\/\/arthas.aliyun.com\/doc\/arthas-tutorials.html?language=cn<\/a><\/p>\n<h2>Arthas\u4f7f\u7528<\/h2>\n<h3>\u542f\u52a8arthas-demo<\/h3>\n<p>\u4e0b\u8f7d<code>arthas-demo.jar<\/code>\uff0c\u518d\u7528<code>java -jar<\/code>\u547d\u4ee4\u542f\u52a8\uff1a<\/p>\n<pre><code>wget https:\/\/arthas.aliyun.com\/arthas-demo.jar\njava -jar arthas-demo.jar<\/code><\/pre>\n<p><code>arthas-demo<\/code>\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\u5982\u679c\u751f\u6210\u7684\u968f\u673a\u6570\u662f\u8d1f\u6570\uff0c\u5219\u4f1a\u6253\u5370\u63d0\u793a\u4fe1\u606f\u3002<\/p>\n<h3>\u542f\u52a8arthas-boot<\/h3>\n<p>\u5728\u65b0\u7684<code>Terminal<\/code>\u91cc\uff0c\u4e0b\u8f7d<code>arthas-boot.jar<\/code>\uff0c\u518d\u7528<code>java -jar<\/code>\u547d\u4ee4\u542f\u52a8\uff08\u4f7f\u7528\u548c\u76ee\u6807\u8fdb\u7a0b\u4e00\u81f4\u7684\u7528\u6237\u542f\u52a8\uff0c\u5426\u5219\u53ef\u80fdattach\u5931\u8d25\uff09\uff1a<\/p>\n<pre><code>wget https:\/\/arthas.aliyun.com\/arthas-boot.jar\njava -jar arthas-boot.jar<\/code><\/pre>\n<ul>\n<li>\u6267\u884c\u8be5\u7a0b\u5e8f\u7684\u7528\u6237\u9700\u8981\u548c\u76ee\u6807\u8fdb\u7a0b\u5177\u6709\u76f8\u540c\u7684\u6743\u9650\u3002\u6bd4\u5982\u4ee5admin\u7528\u6237\u6765\u6267\u884c\uff1a<code>sudo su admin &amp;&amp; java -jar arthas-boot.jar<\/code>\u6216<code>sudo -u admin -EH java -jar arthas-boot.jar<\/code><\/li>\n<li>\u5982\u679c<code>attach<\/code>\u4e0d\u4e0a\u76ee\u6807\u8fdb\u7a0b\uff0c\u53ef\u4ee5\u67e5\u770b<code>~\/logs\/arthas\/<\/code>\u76ee\u5f55\u4e0b\u7684\u65e5\u5fd7<\/li>\n<li>\u5982\u679c\u4e0b\u8f7d\u901f\u5ea6\u6bd4\u8f83\u6162\uff0c\u53ef\u4ee5\u4f7f\u7528aliyun\u7684\u955c\u50cf\uff1a<code>java -jar arthas-boot.jar --repo-mirror aliyun --use-http<\/code><\/li>\n<li><code>java -jar arthas-boot.jar -h<\/code>\u6253\u5370\u66f4\u591a\u53c2\u6570\u4fe1\u606f<\/li>\n<\/ul>\n<p><code>arthas-boot<\/code>\u662f<code>Arthas<\/code>\u7684\u542f\u52a8\u7a0b\u5e8f\uff0c\u5b83\u542f\u52a8\u540e\uff0c\u4f1a\u5217\u51fa\u6240\u6709\u7684Java\u8fdb\u7a0b\uff0c\u7528\u6237\u53ef\u4ee5\u9009\u62e9\u9700\u8981\u8bca\u65ad\u7684\u76ee\u6807\u8fdb\u7a0b\uff1a<\/p>\n<pre><code>$ $ java -jar arthas-boot.jar\n* [1]: 35512\n  [2]: 71560 arthas-demo.jar<\/code><\/pre>\n<p>Demo\u8fdb\u7a0b\u662f\u7b2c2\u4e2a\uff0c\u5219\u8f93\u5165<code>2<\/code>\uff0c\u518d\u8f93\u5165\u56de\u8f66<code>\/Enter<\/code>\u3002Arthas\u4f1aattach\u5230\u76ee\u6807\u8fdb\u7a0b\u4e0a\uff0c\u5e76\u8f93\u51fa\u65e5\u5fd7\uff1a<\/p>\n<p><code>Attach<\/code>\u6210\u529f\u4e4b\u540e\uff0c\u4f1a\u6253\u5370<code>Arthas LOGO<\/code>\u3002\u8f93\u5165<code>help<\/code>\u53ef\u4ee5\u83b7\u53d6\u5230\u66f4\u591a\u7684\u5e2e\u52a9\u4fe1\u606f\u3002<\/p>\n<pre><code>[INFO] Try to attach process 71560\n[INFO] Attach process 71560 success.\n[INFO] arthas-client connect 127.0.0.1 3658\n  ,---.  ,------. ,--------.,--.  ,--.  ,---.   ,---.\n \/  O  \\ |  .--. &#039;&#039;--.  .--&#039;|  &#039;--&#039;  | \/  O  \\ &#039;   .-&#039;\n|  .-.  ||  &#039;--&#039;.&#039;   |  |   |  .--.  ||  .-.  |`.  `-.\n|  | |  ||  |\\  \\    |  |   |  |  |  ||  | |  |.-&#039;    |\n`--&#039; `--&#039;`--&#039; &#039;--&#039;   `--&#039;   `--&#039;  `--&#039;`--&#039; `--&#039;`-----&#039;\n\nwiki: https:\/\/arthas.aliyun.com\/doc\nversion: 3.0.5.20181127201536\npid: 71560\ntime: 2018-11-28 19:16:24\n\n$<\/code><\/pre>\n<h3>\u67e5\u770bDashboard<\/h3>\n<p><code>dashboard<\/code>\u547d\u4ee4\u53ef\u4ee5\u67e5\u770b\u5f53\u524d\u7cfb\u7edf\u7684\u5b9e\u65f6\u6570\u636e\u9762\u677f\u3002<\/p>\n<p>\u8f93\u5165<code>Q<\/code>\u6216\u8005<code>Ctrl+C<\/code>\u53ef\u4ee5\u9000\u51fa<code>dashboard<\/code>\u547d\u4ee4\u3002<\/p>\n<pre><code>$ dashboard\nID     NAME                   GROUP          PRIORI STATE  %CPU    TIME   INTERRU DAEMON\n17     pool-2-thread-1        system         5      WAITIN 67      0:0    false   false\n27     Timer-for-arthas-dashb system         10     RUNNAB 32      0:0    false   true\n11     AsyncAppender-Worker-a system         9      WAITIN 0       0:0    false   true\n9      Attach Listener        system         9      RUNNAB 0       0:0    false   true\n3      Finalizer              system         8      WAITIN 0       0:0    false   true\n2      Reference Handler      system         10     WAITIN 0       0:0    false   true\n4      Signal Dispatcher      system         9      RUNNAB 0       0:0    false   true\n26     as-command-execute-dae system         10     TIMED_ 0       0:0    false   true\n13     job-timeout            system         9      TIMED_ 0       0:0    false   true\n1      main                   main           5      TIMED_ 0       0:0    false   false\n14     nioEventLoopGroup-2-1  system         10     RUNNAB 0       0:0    false   false\n18     nioEventLoopGroup-2-2  system         10     RUNNAB 0       0:0    false   false\n23     nioEventLoopGroup-2-3  system         10     RUNNAB 0       0:0    false   false\n15     nioEventLoopGroup-3-1  system         10     RUNNAB 0       0:0    false   false\nMemory             used   total max    usage GC\nheap               32M    155M  1820M  1.77% gc.ps_scavenge.count  4\nps_eden_space      14M    65M   672M   2.21% gc.ps_scavenge.time(m 166\nps_survivor_space  4M     5M    5M           s)\nps_old_gen         12M    85M   1365M  0.91% gc.ps_marksweep.count 0\nnonheap            20M    23M   -1           gc.ps_marksweep.time( 0\ncode_cache         3M     5M    240M   1.32% ms)\nRuntime\nos.name                Mac OS X\nos.version             10.13.4\njava.version           1.8.0_162\njava.home              \/Library\/Java\/JavaVirtualMachines\/jdk1.8.0_162.jdk\/Contents\/Home\/jre<\/code><\/pre>\n<h3>Thread<\/h3>\n<p>\u901a\u8fc7<code>thread<\/code>\u547d\u4ee4\u6765\u83b7\u53d6\u5230<code>arthas-demo<\/code>\u8fdb\u7a0b\u7684<code>Main Class<\/code>\u3002<code>thread 1<\/code>\u547d\u4ee4\u4f1a\u6253\u5370\u7ebf\u7a0bID 1\u7684\u6808\uff0c\u901a\u5e38\u662fmain\u51fd\u6570\u7684\u7ebf\u7a0b\u3002<\/p>\n<p><code>Arthas<\/code>\u652f\u6301\u7ba1\u9053\uff0c\u53ef\u4ee5\u7528<code>thread 1 | grep &#039;main(&#039;<\/code>\u67e5\u627e\u5230<code>main class<\/code>\u3002<\/p>\n<p>\u53ef\u4ee5\u770b\u5230<code>main class<\/code>\u662f<code>demo.MathGame<\/code>\uff1a<\/p>\n<pre><code>$ thread 1 | grep &#039;main(&#039;\n    at demo.MathGame.main(MathGame.java:17)<\/code><\/pre>\n<h3>Sc<\/h3>\n<p>\u53ef\u4ee5\u901a\u8fc7<code>sc<\/code>\u547d\u4ee4\u6765\u67e5\u627eJVM\u91cc\u5df2\u52a0\u8f7d\u7684\u7c7b\uff1a<\/p>\n<pre><code>sc -d *MathGame<\/code><\/pre>\n<h3>Jad<\/h3>\n<p>\u53ef\u4ee5\u901a\u8fc7<code>jad<\/code>\u547d\u4ee4\u6765\u53cd\u7f16\u8bd1\u4ee3\u7801\uff1a<\/p>\n<pre><code>jad demo.MathGame<\/code><\/pre>\n<h3>Watch<\/h3>\n<p>\u901a\u8fc7<code>watch<\/code>\u547d\u4ee4\u53ef\u4ee5\u67e5\u770b\u51fd\u6570\u7684\u53c2\u6570\/\u8fd4\u56de\u503c\/\u5f02\u5e38\u4fe1\u606f\u3002<\/p>\n<pre><code>watch demo.MathGame primeFactors returnObj<\/code><\/pre>\n<p>\u8f93\u5165<code>Q<\/code>\u6216\u8005<code>Ctrl+C<\/code>\u9000\u51fa<code>watch<\/code>\u547d\u4ee4\u3002<\/p>\n<pre><code>$ watch demo.MathGame primeFactors returnObj\nPress Ctrl+C to abort.\nAffect(class-cnt:1 , method-cnt:1) cost in 107 ms.\nts=2018-11-28 19:22:30; [cost=1.715367ms] result=null\nts=2018-11-28 19:22:31; [cost=0.185203ms] result=null\nts=2018-11-28 19:22:32; [cost=19.012416ms] result=@ArrayList[\n    @Integer[5],\n    @Integer[47],\n    @Integer[2675531],\n]\nts=2018-11-28 19:22:33; [cost=0.311395ms] result=@ArrayList[\n    @Integer[2],\n    @Integer[5],\n    @Integer[317],\n    @Integer[503],\n    @Integer[887],\n]\nts=2018-11-28 19:22:34; [cost=10.136007ms] result=@ArrayList[\n    @Integer[2],\n    @Integer[2],\n    @Integer[3],\n    @Integer[3],\n    @Integer[31],\n    @Integer[717593],\n]\nts=2018-11-28 19:22:35; [cost=29.969732ms] result=@ArrayList[\n    @Integer[5],\n    @Integer[29],\n    @Integer[7651739],\n]<\/code><\/pre>\n<h3>Exit\/Stop<\/h3>\n<h4>\u9000\u51faArthas<\/h4>\n<p>\u7528<code>exit<\/code>\u6216\u8005<code>quit<\/code>\u547d\u4ee4\u53ef\u4ee5\u9000\u51fa<code>Arthas<\/code>\u3002<\/p>\n<p>\u9000\u51fa<code>Arthas<\/code>\u4e4b\u540e\uff0c\u8fd8\u53ef\u4ee5\u518d\u6b21\u7528<code>java -jar arthas-boot.jar<\/code>\u6765\u8fde\u63a5\u3002<\/p>\n<h4>\u5f7b\u5e95\u9000\u51faArthas<\/h4>\n<p><code>exit\/quit<\/code>\u547d\u4ee4\u53ea\u662f\u9000\u51fa\u5f53\u524d<code>session<\/code>\uff0c<code>arthas server<\/code>\u8fd8\u5728\u76ee\u6807\u8fdb\u7a0b\u4e2d\u8fd0\u884c\u3002<\/p>\n<p>\u60f3\u5b8c\u5168\u9000\u51fa<code>Arthas<\/code>\uff0c\u53ef\u4ee5\u6267\u884c<code>stop<\/code>\u547d\u4ee4\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Arthas\u7b80\u4ecb Arthas \u662fAlibaba\u5f00\u6e90\u7684Java\u8bca\u65ad\u5de5\u5177\uff0c\u6df1\u53d7\u5f00\u53d1\u8005\u559c\u7231\u3002\u5728\u7ebf\u6392\u67e5\u95ee\u9898\uff0c\u65e0\u9700\u91cd\u542f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[419],"tags":[420],"class_list":["post-1685","post","type-post","status-publish","format-standard","hentry","category-jvm","tag-arthas"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1685","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1685"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1685\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1685"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1685"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1685"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}