You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
arthas/assets/trace.html.272a5864.js

112 lines
52 KiB
JavaScript

import{_ as l,o as i,c as r,a as s,b as n,w as o,e as a,d as t,r as c}from"./app.5024572d.js";const u={},d=s("h1",{id:"trace",tabindex:"-1"},[s("a",{class:"header-anchor",href:"#trace","aria-hidden":"true"},"#"),a(" trace")],-1),m={href:"https://arthas.aliyun.com/doc/arthas-tutorials.html?language=en&id=command-trace",target:"_blank",rel:"noopener noreferrer"},k=s("code",null,"trace",-1),b=a(" online tutorial"),h=t('<div class="custom-container tip"><p class="custom-container-title">TIP</p><p>Trace method calling path, and output the time cost for each node in the path.</p></div><p><code>trace</code> can track the calling path specified by <code>class-pattern</code> / <code>method-pattern</code>, and calculate the time cost on the whole path.</p><h2 id="parameters" tabindex="-1"><a class="header-anchor" href="#parameters" aria-hidden="true">#</a> Parameters</h2><table><thead><tr><th style="text-align:right;">Name</th><th style="text-align:left;">Specification</th></tr></thead><tbody><tr><td style="text-align:right;"><em>class-pattern</em></td><td style="text-align:left;">pattern for the class name</td></tr><tr><td style="text-align:right;"><em>method-pattern</em></td><td style="text-align:left;">pattern for the method name</td></tr><tr><td style="text-align:right;"><em>condition-express</em></td><td style="text-align:left;">condition expression</td></tr><tr><td style="text-align:right;"><code>[E]</code></td><td style="text-align:left;">enable regex match, the default behavior is wildcards match</td></tr><tr><td style="text-align:right;"><code>[n:]</code></td><td style="text-align:left;">execution times, the default value is 100.</td></tr><tr><td style="text-align:right;">#cost</td><td style="text-align:left;">time cost</td></tr><tr><td style="text-align:right;"><code>[m &lt;arg&gt;]</code></td><td style="text-align:left;">Specify the max number of matched Classes, the default value is 50. Long format is <code>[maxMatch &lt;arg&gt;]</code>.</td></tr></tbody></table><p>There&#39;s one thing worthy noting here is <code>condition expression</code>. The <code>condition expression</code> supports OGNL grammar, for example, you can come up a expression like this <code>&quot;params[0]&lt;0&quot;</code>. All OGNL expressions are supported as long as they are legal to the grammar.</p>',5),v=a("Pls. refer to "),g=a("core parameters in expression"),f=a(" for more details."),x=a("Pls. also refer to "),_={href:"https://github.com/alibaba/arthas/issues/71",target:"_blank",rel:"noopener noreferrer"},y=a("https://github.com/alibaba/arthas/issues/71"),C=a(" for more advanced usage"),w=a("OGNL official site: "),M={href:"https://commons.apache.org/dormant/commons-ognl/language-guide.html",target:"_blank",rel:"noopener noreferrer"},L=a("https://commons.apache.org/dormant/commons-ognl/language-guide.html"),G=t('<p>Many times what we are interested is the exact trace result when the method call takes time over one particular period. It is possible to achieve this in Arthas, for example: <code>trace *StringUtils isBlank &#39;#cost&gt;100&#39;</code> means trace result will only be output when the executing time exceeds 100ms.</p><div class="custom-container tip"><p class="custom-container-title">TIP</p><p><code>watch</code>/<code>stack</code>/<code>trace</code>, these three commands all support <code>#cost</code>.</p></div><h2 id="notice" tabindex="-1"><a class="header-anchor" href="#notice" aria-hidden="true">#</a> Notice</h2>',3),T=s("li",null,[s("p",null,[s("code",null,"trace"),a(" is handy to help discovering and locating the performance flaws in your system, but pls. note Arthas can only trace the first level method call each time.")])],-1),A=s("li",null,[s("p",null,"After version 3.3.0, you can use the Dynamic Trace feature to add new matching classes/methods, see the following example.")],-1),j=a("Currently "),I=s("code",null,"trace java.lang.Thread getName",-1),S=a(" is not supported, please refer to issue: "),F={href:"https://github.com/alibaba/arthas/issues/1610",target:"_blank",rel:"noopener noreferrer"},P=a("#1610"),$=a(", considering that it is not very necessary and it is difficult to repair , So it won\u2019t be fixed for now"),E=s("h2",{id:"usage",tabindex:"-1"},[s("a",{class:"header-anchor",href:"#usage","aria-hidden":"true"},"#"),a(" Usage")],-1),B=s("h3",{id:"start-demo",tabindex:"-1"},[s("a",{class:"header-anchor",href:"#start-demo","aria-hidden":"true"},"#"),a(" Start Demo")],-1),q=a("Start "),N=s("code",null,"math-game",-1),Q=a(" in "),D=a("Quick Start"),O=a("."),J=t(`<h3 id="trace-method" tabindex="-1"><a class="header-anchor" href="#trace-method" aria-hidden="true">#</a> Trace method</h3><div class="language-bash ext-sh line-numbers-mode"><pre class="language-bash"><code>$ trace demo.MathGame run
Press Q or Ctrl+C to abort.
Affect<span class="token punctuation">(</span>class-cnt:1 , method-cnt:1<span class="token punctuation">)</span> cost <span class="token keyword">in</span> <span class="token number">28</span> ms.
<span class="token variable"><span class="token variable">\`</span>---ts<span class="token operator">=</span><span class="token number">2019</span>-12-04 00:45:08<span class="token punctuation">;</span><span class="token assign-left variable">thread_name</span><span class="token operator">=</span>main<span class="token punctuation">;</span><span class="token assign-left variable">id</span><span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">;</span><span class="token assign-left variable">is_daemon</span><span class="token operator">=</span>false<span class="token punctuation">;</span><span class="token assign-left variable">priority</span><span class="token operator">=</span><span class="token number">5</span><span class="token punctuation">;</span><span class="token assign-left variable">TCCL</span><span class="token operator">=</span>sun.misc.Launcher$AppClassLoader@3d4eac69
<span class="token variable">\`</span></span>---<span class="token punctuation">[</span><span class="token number">0</span>.617465ms<span class="token punctuation">]</span> demo.MathGame:run<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token variable"><span class="token variable">\`</span>---<span class="token punctuation">[</span><span class="token number">0</span>.078946ms<span class="token punctuation">]</span> demo.MathGame:primeFactors<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">#24 [throws Exception]</span>
<span class="token variable">\`</span></span>---ts<span class="token operator">=</span><span class="token number">2019</span>-12-04 00:45:09<span class="token punctuation">;</span><span class="token assign-left variable">thread_name</span><span class="token operator">=</span>main<span class="token punctuation">;</span><span class="token assign-left variable">id</span><span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">;</span><span class="token assign-left variable">is_daemon</span><span class="token operator">=</span>false<span class="token punctuation">;</span><span class="token assign-left variable">priority</span><span class="token operator">=</span><span class="token number">5</span><span class="token punctuation">;</span><span class="token assign-left variable">TCCL</span><span class="token operator">=</span>sun.misc.Launcher<span class="token variable">$AppClassLoader</span>@3d4eac69
<span class="token variable"><span class="token variable">\`</span>---<span class="token punctuation">[</span><span class="token number">1</span>.276874ms<span class="token punctuation">]</span> demo.MathGame:run<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token variable">\`</span></span>---<span class="token punctuation">[</span><span class="token number">0</span>.03752ms<span class="token punctuation">]</span> demo.MathGame:primeFactors<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">#24 [throws Exception]</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><div class="custom-container tip"><p class="custom-container-title">TIP</p><p>The <code>#24</code> in the result indicates that in the run function, the <code>primeFactors()</code> function was called on line <code>24</code> of the source file.</p></div><h3 id="specify-the-max-number-of-matched-classes" tabindex="-1"><a class="header-anchor" href="#specify-the-max-number-of-matched-classes" aria-hidden="true">#</a> Specify the max number of matched Classes</h3><div class="language-bash ext-sh line-numbers-mode"><pre class="language-bash"><code>$ trace demo.MathGame run <span class="token parameter variable">-m</span> <span class="token number">1</span>
Press Q or Ctrl+C to abort.
Affect<span class="token punctuation">(</span>class count: <span class="token number">1</span> , method count: <span class="token number">1</span><span class="token punctuation">)</span> cost <span class="token keyword">in</span> <span class="token number">412</span> ms, listenerId: <span class="token number">4</span>
<span class="token variable"><span class="token variable">\`</span>---ts<span class="token operator">=</span><span class="token number">2022</span>-12-25 <span class="token number">21</span>:00:00<span class="token punctuation">;</span><span class="token assign-left variable">thread_name</span><span class="token operator">=</span>main<span class="token punctuation">;</span><span class="token assign-left variable">id</span><span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">;</span><span class="token assign-left variable">is_daemon</span><span class="token operator">=</span>false<span class="token punctuation">;</span><span class="token assign-left variable">priority</span><span class="token operator">=</span><span class="token number">5</span><span class="token punctuation">;</span><span class="token assign-left variable">TCCL</span><span class="token operator">=</span>sun.misc.Launcher$AppClassLoader@b4aac2
<span class="token variable">\`</span></span>---<span class="token punctuation">[</span><span class="token number">0</span>.762093ms<span class="token punctuation">]</span> demo.MathGame:run<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token variable"><span class="token variable">\`</span>---<span class="token punctuation">[</span><span class="token number">30.21</span>% <span class="token number">0</span>.230241ms<span class="token punctuation">]</span> demo.MathGame:primeFactors<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">#46 [throws Exception]</span>
<span class="token variable">\`</span></span>---ts<span class="token operator">=</span><span class="token number">2022</span>-12-25 <span class="token number">21</span>:00:10<span class="token punctuation">;</span><span class="token assign-left variable">thread_name</span><span class="token operator">=</span>main<span class="token punctuation">;</span><span class="token assign-left variable">id</span><span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">;</span><span class="token assign-left variable">is_daemon</span><span class="token operator">=</span>false<span class="token punctuation">;</span><span class="token assign-left variable">priority</span><span class="token operator">=</span><span class="token number">5</span><span class="token punctuation">;</span><span class="token assign-left variable">TCCL</span><span class="token operator">=</span>sun.misc.Launcher<span class="token variable">$AppClassLoader</span>@b4aac2
<span class="token variable"><span class="token variable">\`</span>---<span class="token punctuation">[</span><span class="token number">0</span>.315298ms<span class="token punctuation">]</span> demo.MathGame:run<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token variable">\`</span></span>---<span class="token punctuation">[</span><span class="token number">13.95</span>% <span class="token number">0</span>.043995ms<span class="token punctuation">]</span> demo.MathGame:primeFactors<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">#46 [throws Exception]</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="trace-times-limit" tabindex="-1"><a class="header-anchor" href="#trace-times-limit" aria-hidden="true">#</a> Trace times limit</h3><p>If the method invoked many times, use <code>-n</code> options to specify trace times. For example, the command will exit when received a trace result.</p><div class="language-bash ext-sh line-numbers-mode"><pre class="language-bash"><code>$ trace demo.MathGame run <span class="token parameter variable">-n</span> <span class="token number">1</span>
Press Q or Ctrl+C to abort.
Affect<span class="token punctuation">(</span>class-cnt:1 , method-cnt:1<span class="token punctuation">)</span> cost <span class="token keyword">in</span> <span class="token number">20</span> ms.
<span class="token variable"><span class="token variable">\`</span>---ts<span class="token operator">=</span><span class="token number">2019</span>-12-04 00:45:53<span class="token punctuation">;</span><span class="token assign-left variable">thread_name</span><span class="token operator">=</span>main<span class="token punctuation">;</span><span class="token assign-left variable">id</span><span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">;</span><span class="token assign-left variable">is_daemon</span><span class="token operator">=</span>false<span class="token punctuation">;</span><span class="token assign-left variable">priority</span><span class="token operator">=</span><span class="token number">5</span><span class="token punctuation">;</span><span class="token assign-left variable">TCCL</span><span class="token operator">=</span>sun.misc.Launcher$AppClassLoader@3d4eac69
<span class="token variable">\`</span></span>---<span class="token punctuation">[</span><span class="token number">0</span>.549379ms<span class="token punctuation">]</span> demo.MathGame:run<span class="token punctuation">(</span><span class="token punctuation">)</span>
+---<span class="token punctuation">[</span><span class="token number">0</span>.059839ms<span class="token punctuation">]</span> demo.MathGame:primeFactors<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">#24</span>
\`---<span class="token punctuation">[</span><span class="token number">0</span>.232887ms<span class="token punctuation">]</span> demo.MathGame:print<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">#25</span>
Command execution <span class="token builtin class-name">times</span> exceed limit: <span class="token number">1</span>, so <span class="token builtin class-name">command</span> will exit. You can <span class="token builtin class-name">set</span> it with <span class="token parameter variable">-n</span> option.
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="include-jdk-method" tabindex="-1"><a class="header-anchor" href="#include-jdk-method" aria-hidden="true">#</a> Include jdk method</h3><ul><li><code>--skipJDKMethod &lt;value&gt; </code> skip jdk method trace, default value true.</li></ul><div class="language-bash ext-sh line-numbers-mode"><pre class="language-bash"><code>$ trace <span class="token parameter variable">--skipJDKMethod</span> <span class="token boolean">false</span> demo.MathGame run
Press Q or Ctrl+C to abort.
Affect<span class="token punctuation">(</span>class-cnt:1 , method-cnt:1<span class="token punctuation">)</span> cost <span class="token keyword">in</span> <span class="token number">60</span> ms.
<span class="token variable"><span class="token variable">\`</span>---ts<span class="token operator">=</span><span class="token number">2019</span>-12-04 00:44:41<span class="token punctuation">;</span><span class="token assign-left variable">thread_name</span><span class="token operator">=</span>main<span class="token punctuation">;</span><span class="token assign-left variable">id</span><span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">;</span><span class="token assign-left variable">is_daemon</span><span class="token operator">=</span>false<span class="token punctuation">;</span><span class="token assign-left variable">priority</span><span class="token operator">=</span><span class="token number">5</span><span class="token punctuation">;</span><span class="token assign-left variable">TCCL</span><span class="token operator">=</span>sun.misc.Launcher$AppClassLoader@3d4eac69
<span class="token variable">\`</span></span>---<span class="token punctuation">[</span><span class="token number">1</span>.357742ms<span class="token punctuation">]</span> demo.MathGame:run<span class="token punctuation">(</span><span class="token punctuation">)</span>
+---<span class="token punctuation">[</span><span class="token number">0</span>.028624ms<span class="token punctuation">]</span> java.util.Random:nextInt<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">#23</span>
+---<span class="token punctuation">[</span><span class="token number">0</span>.045534ms<span class="token punctuation">]</span> demo.MathGame:primeFactors<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">#24 [throws Exception]</span>
+---<span class="token punctuation">[</span><span class="token number">0</span>.005372ms<span class="token punctuation">]</span> java.lang.StringBuilder:<span class="token operator">&lt;</span>init<span class="token operator">&gt;</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">#28</span>
+---<span class="token punctuation">[</span><span class="token number">0</span>.012257ms<span class="token punctuation">]</span> java.lang.Integer:valueOf<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">#28</span>
+---<span class="token punctuation">[</span><span class="token number">0</span>.234537ms<span class="token punctuation">]</span> java.lang.String:format<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">#28</span>
+---<span class="token punctuation">[</span>min<span class="token operator">=</span><span class="token number">0</span>.004539ms,max<span class="token operator">=</span><span class="token number">0</span>.005778ms,total<span class="token operator">=</span><span class="token number">0</span>.010317ms,count<span class="token operator">=</span><span class="token number">2</span><span class="token punctuation">]</span> java.lang.StringBuilder:append<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">#28</span>
+---<span class="token punctuation">[</span><span class="token number">0</span>.013777ms<span class="token punctuation">]</span> java.lang.Exception:getMessage<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">#28</span>
+---<span class="token punctuation">[</span><span class="token number">0</span>.004935ms<span class="token punctuation">]</span> java.lang.StringBuilder:toString<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">#28</span>
<span class="token variable"><span class="token variable">\`</span>---<span class="token punctuation">[</span><span class="token number">0</span>.06941ms<span class="token punctuation">]</span> java.io.PrintStream:println<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">#28</span>
<span class="token variable">\`</span></span>---ts<span class="token operator">=</span><span class="token number">2019</span>-12-04 00:44:42<span class="token punctuation">;</span><span class="token assign-left variable">thread_name</span><span class="token operator">=</span>main<span class="token punctuation">;</span><span class="token assign-left variable">id</span><span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">;</span><span class="token assign-left variable">is_daemon</span><span class="token operator">=</span>false<span class="token punctuation">;</span><span class="token assign-left variable">priority</span><span class="token operator">=</span><span class="token number">5</span><span class="token punctuation">;</span><span class="token assign-left variable">TCCL</span><span class="token operator">=</span>sun.misc.Launcher<span class="token variable">$AppClassLoader</span>@3d4eac69
<span class="token variable"><span class="token variable">\`</span>---<span class="token punctuation">[</span><span class="token number">3</span>.030432ms<span class="token punctuation">]</span> demo.MathGame:run<span class="token punctuation">(</span><span class="token punctuation">)</span>
+---<span class="token punctuation">[</span><span class="token number">0</span>.010473ms<span class="token punctuation">]</span> java.util.Random:nextInt<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">#23</span>
+---<span class="token punctuation">[</span><span class="token number">0</span>.023715ms<span class="token punctuation">]</span> demo.MathGame:primeFactors<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">#24 [throws Exception]</span>
+---<span class="token punctuation">[</span><span class="token number">0</span>.005198ms<span class="token punctuation">]</span> java.lang.StringBuilder:<span class="token operator">&lt;</span>init<span class="token operator">&gt;</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">#28</span>
+---<span class="token punctuation">[</span><span class="token number">0</span>.006405ms<span class="token punctuation">]</span> java.lang.Integer:valueOf<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">#28</span>
+---<span class="token punctuation">[</span><span class="token number">0</span>.178583ms<span class="token punctuation">]</span> java.lang.String:format<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">#28</span>
+---<span class="token punctuation">[</span>min<span class="token operator">=</span><span class="token number">0</span>.011636ms,max<span class="token operator">=</span><span class="token number">0</span>.838077ms,total<span class="token operator">=</span><span class="token number">0</span>.849713ms,count<span class="token operator">=</span><span class="token number">2</span><span class="token punctuation">]</span> java.lang.StringBuilder:append<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">#28</span>
+---<span class="token punctuation">[</span><span class="token number">0</span>.008747ms<span class="token punctuation">]</span> java.lang.Exception:getMessage<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">#28</span>
+---<span class="token punctuation">[</span><span class="token number">0</span>.019768ms<span class="token punctuation">]</span> java.lang.StringBuilder:toString<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">#28</span>
<span class="token variable">\`</span></span>---<span class="token punctuation">[</span><span class="token number">0</span>.076457ms<span class="token punctuation">]</span> java.io.PrintStream:println<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">#28</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="filtering-by-cost" tabindex="-1"><a class="header-anchor" href="#filtering-by-cost" aria-hidden="true">#</a> Filtering by cost</h3><div class="language-bash ext-sh line-numbers-mode"><pre class="language-bash"><code>$ trace demo.MathGame run <span class="token string">&#39;#cost &gt; 10&#39;</span>
Press Ctrl+C to abort.
Affect<span class="token punctuation">(</span>class-cnt:1 , method-cnt:1<span class="token punctuation">)</span> cost <span class="token keyword">in</span> <span class="token number">41</span> ms.
<span class="token variable"><span class="token variable">\`</span>---ts<span class="token operator">=</span><span class="token number">2018</span>-12-04 01:12:02<span class="token punctuation">;</span><span class="token assign-left variable">thread_name</span><span class="token operator">=</span>main<span class="token punctuation">;</span><span class="token assign-left variable">id</span><span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">;</span><span class="token assign-left variable">is_daemon</span><span class="token operator">=</span>false<span class="token punctuation">;</span><span class="token assign-left variable">priority</span><span class="token operator">=</span><span class="token number">5</span><span class="token punctuation">;</span><span class="token assign-left variable">TCCL</span><span class="token operator">=</span>sun.misc.Launcher$AppClassLoader@3d4eac69
<span class="token variable">\`</span></span>---<span class="token punctuation">[</span><span class="token number">12</span>.033735ms<span class="token punctuation">]</span> demo.MathGame:run<span class="token punctuation">(</span><span class="token punctuation">)</span>
+---<span class="token punctuation">[</span><span class="token number">0</span>.006783ms<span class="token punctuation">]</span> java.util.Random:nextInt<span class="token punctuation">(</span><span class="token punctuation">)</span>
+---<span class="token punctuation">[</span><span class="token number">11</span>.852594ms<span class="token punctuation">]</span> demo.MathGame:primeFactors<span class="token punctuation">(</span><span class="token punctuation">)</span>
\`---<span class="token punctuation">[</span><span class="token number">0</span>.05447ms<span class="token punctuation">]</span> demo.MathGame:print<span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><div class="custom-container tip"><p class="custom-container-title">TIP</p><p>Only the call path which&#39;s time cost is higher than <code>10ms</code> will be shown. This feature is handy to focus on what&#39;s needed to focus when troubleshoot.</p></div><ul><li>Here Arthas provides the similar functionality JProfile and other commercial software provide. Compared to these professional softwares, Arthas doesn&#39;t deduce the time cost <code>trace</code> itself takes, therefore it is not as accurate as these softwares offer. More classes and methods on the calling path, more inaccurate <code>trace</code> output is, but it is still helpful for diagnostics where the bottleneck is.</li><li>&quot;[12.033735ms]&quot; means the method on the node takes <code>12.033735</code> ms.</li><li>&quot;[min=0.005428ms,max=0.094064ms,total=0.105228ms,count=3] demo:call()&quot; means aggregating all same method calls into one single line. The minimum time cost is <code>0.005428</code> ms, the maximum time cost is <code>0.094064</code> ms, and the total time cost for all method calls (<code>3</code> times in total) to &quot;demo:call()&quot; is <code>0.105228ms</code>. If &quot;throws Exception&quot; appears in this line, it means some exceptions have been thrown from this method calls.</li><li>The total time cost may not equal to the sum of the time costs each sub method call takes, this is because Arthas instrumented code takes time too.</li></ul><h3 id="trace-multiple-classes-or-multiple-methods" tabindex="-1"><a class="header-anchor" href="#trace-multiple-classes-or-multiple-methods" aria-hidden="true">#</a> Trace multiple classes or multiple methods</h3><p>The trace command will only trace the subcalls in the method to the trace, and will not trace down multiple layers. Because traces are expensive, multi-layer traces can lead to a lot of classes and methods that ultimately have to be traced.</p><p>You can use the regular expression to match multiple classes and methods on the path to achieve a multi-layer trace effect to some extent.</p><div class="language-bash ext-sh line-numbers-mode"><pre class="language-bash"><code>Trace <span class="token parameter variable">-E</span> com.test.ClassA<span class="token operator">|</span>org.test.ClassB method1<span class="token operator">|</span>method2<span class="token operator">|</span>method3
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><h3 id="exclude-the-specified-class" tabindex="-1"><a class="header-anchor" href="#exclude-the-specified-class" aria-hidden="true">#</a> Exclude the specified class</h3><div class="custom-container tip"><p class="custom-container-title">TIP</p><p>The watch/trace/monitor/stack/tt commands all support the <code>--exclude-class-pattern</code> parameter</p></div><p>Use the <code>--exclude-class-pattern</code> parameter to exclude the specified class, for example:</p><div class="language-bash ext-sh line-numbers-mode"><pre class="language-bash"><code><span class="token function">watch</span> javax.servlet.Filter * --exclude-class-pattern com.demo.TestFilter
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><h3 id="dynamic-trace" tabindex="-1"><a class="header-anchor" href="#dynamic-trace" aria-hidden="true">#</a> Dynamic trace</h3><div class="custom-container tip"><p class="custom-container-title">TIP</p><p>Supported since version 3.3.0.</p></div><p>Open terminal 1, trace the <code>run</code> method in the above demo, and you can see the printout <code>listenerId: 1</code> .</p><div class="language-bash ext-sh line-numbers-mode"><pre class="language-bash"><code><span class="token punctuation">[</span>arthas@59161<span class="token punctuation">]</span>$ trace demo.MathGame run
Press Q or Ctrl+C to abort.
Affect<span class="token punctuation">(</span>class count: <span class="token number">1</span> , method count: <span class="token number">1</span><span class="token punctuation">)</span> cost <span class="token keyword">in</span> <span class="token number">112</span> ms, listenerId: <span class="token number">1</span>
<span class="token variable"><span class="token variable">\`</span>---ts<span class="token operator">=</span><span class="token number">2020</span>-07-09 <span class="token number">16</span>:48:11<span class="token punctuation">;</span><span class="token assign-left variable">thread_name</span><span class="token operator">=</span>main<span class="token punctuation">;</span><span class="token assign-left variable">id</span><span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">;</span><span class="token assign-left variable">is_daemon</span><span class="token operator">=</span>false<span class="token punctuation">;</span><span class="token assign-left variable">priority</span><span class="token operator">=</span><span class="token number">5</span><span class="token punctuation">;</span><span class="token assign-left variable">TCCL</span><span class="token operator">=</span>sun.misc.Launcher$AppClassLoader@3d4eac69
<span class="token variable">\`</span></span>---<span class="token punctuation">[</span><span class="token number">1</span>.389634ms<span class="token punctuation">]</span> demo.MathGame:run<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token variable"><span class="token variable">\`</span>---<span class="token punctuation">[</span><span class="token number">0</span>.123934ms<span class="token punctuation">]</span> demo.MathGame:primeFactors<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">#24 [throws Exception]</span>
<span class="token variable">\`</span></span>---ts<span class="token operator">=</span><span class="token number">2020</span>-07-09 <span class="token number">16</span>:48:12<span class="token punctuation">;</span><span class="token assign-left variable">thread_name</span><span class="token operator">=</span>main<span class="token punctuation">;</span><span class="token assign-left variable">id</span><span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">;</span><span class="token assign-left variable">is_daemon</span><span class="token operator">=</span>false<span class="token punctuation">;</span><span class="token assign-left variable">priority</span><span class="token operator">=</span><span class="token number">5</span><span class="token punctuation">;</span><span class="token assign-left variable">TCCL</span><span class="token operator">=</span>sun.misc.Launcher<span class="token variable">$AppClassLoader</span>@3d4eac69
<span class="token variable"><span class="token variable">\`</span>---<span class="token punctuation">[</span><span class="token number">3</span>.716391ms<span class="token punctuation">]</span> demo.MathGame:run<span class="token punctuation">(</span><span class="token punctuation">)</span>
+---<span class="token punctuation">[</span><span class="token number">3</span>.182813ms<span class="token punctuation">]</span> demo.MathGame:primeFactors<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">#24</span>
<span class="token variable">\`</span></span>---<span class="token punctuation">[</span><span class="token number">0</span>.167786ms<span class="token punctuation">]</span> demo.MathGame:print<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">#25</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>Now to drill down into the sub method <code>primeFactors</code>, you can open a new terminal 2 and use the <code>telnet localhost 3658</code> connects to the arthas, then trace <code>primeFactors</code> with the specify <code>listenerId</code>.</p><div class="language-bash ext-sh line-numbers-mode"><pre class="language-bash"><code><span class="token punctuation">[</span>arthas@59161<span class="token punctuation">]</span>$ trace demo.MathGame primeFactors <span class="token parameter variable">--listenerId</span> <span class="token number">1</span>
Press Q or Ctrl+C to abort.
Affect<span class="token punctuation">(</span>class count: <span class="token number">1</span> , method count: <span class="token number">1</span><span class="token punctuation">)</span> cost <span class="token keyword">in</span> <span class="token number">34</span> ms, listenerId: <span class="token number">1</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>At Terminal 2 prints the results, indicating that a method has been enhanced: <code>Affect(class count: 1 , method count: 1)</code>, but no more results are printed.</p><p>At terminal 1, you can see that the trace result has increased by one layer:</p><div class="language-bash ext-sh line-numbers-mode"><pre class="language-bash"><code><span class="token variable"><span class="token variable">\`</span>---ts<span class="token operator">=</span><span class="token number">2020</span>-07-09 <span class="token number">16</span>:49:29<span class="token punctuation">;</span><span class="token assign-left variable">thread_name</span><span class="token operator">=</span>main<span class="token punctuation">;</span><span class="token assign-left variable">id</span><span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">;</span><span class="token assign-left variable">is_daemon</span><span class="token operator">=</span>false<span class="token punctuation">;</span><span class="token assign-left variable">priority</span><span class="token operator">=</span><span class="token number">5</span><span class="token punctuation">;</span><span class="token assign-left variable">TCCL</span><span class="token operator">=</span>sun.misc.Launcher$AppClassLoader@3d4eac69
<span class="token variable">\`</span></span>---<span class="token punctuation">[</span><span class="token number">0</span>.492551ms<span class="token punctuation">]</span> demo.MathGame:run<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token variable"><span class="token variable">\`</span>---<span class="token punctuation">[</span><span class="token number">0</span>.113929ms<span class="token punctuation">]</span> demo.MathGame:primeFactors<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">#24 [throws Exception]</span>
<span class="token variable">\`</span></span>---<span class="token punctuation">[</span><span class="token number">0</span>.061462ms<span class="token punctuation">]</span> demo.MathGame:primeFactors<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token variable"><span class="token variable">\`</span>---<span class="token punctuation">[</span><span class="token number">0</span>.001018ms<span class="token punctuation">]</span> throw:java.lang.IllegalArgumentException<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">#46</span>
<span class="token variable">\`</span></span>---ts<span class="token operator">=</span><span class="token number">2020</span>-07-09 <span class="token number">16</span>:49:30<span class="token punctuation">;</span><span class="token assign-left variable">thread_name</span><span class="token operator">=</span>main<span class="token punctuation">;</span><span class="token assign-left variable">id</span><span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">;</span><span class="token assign-left variable">is_daemon</span><span class="token operator">=</span>false<span class="token punctuation">;</span><span class="token assign-left variable">priority</span><span class="token operator">=</span><span class="token number">5</span><span class="token punctuation">;</span><span class="token assign-left variable">TCCL</span><span class="token operator">=</span>sun.misc.Launcher<span class="token variable">$AppClassLoader</span>@3d4eac69
<span class="token variable"><span class="token variable">\`</span>---<span class="token punctuation">[</span><span class="token number">0</span>.409446ms<span class="token punctuation">]</span> demo.MathGame:run<span class="token punctuation">(</span><span class="token punctuation">)</span>
+---<span class="token punctuation">[</span><span class="token number">0</span>.232606ms<span class="token punctuation">]</span> demo.MathGame:primeFactors<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">#24</span>
<span class="token operator">|</span> <span class="token variable">\`</span></span>---<span class="token punctuation">[</span><span class="token number">0</span>.1294ms<span class="token punctuation">]</span> demo.MathGame:primeFactors<span class="token punctuation">(</span><span class="token punctuation">)</span>
\`---<span class="token punctuation">[</span><span class="token number">0</span>.084025ms<span class="token punctuation">]</span> demo.MathGame:print<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">#25</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>Dynamic trace by specifying <code>listenerId</code>, you can go deeper and deeper. In addition, commands such as <code>watch</code>/<code>tt</code>/<code>monitor</code> also support similar functionality.</p><h2 id="trace-result-time-inaccuracy-problem" tabindex="-1"><a class="header-anchor" href="#trace-result-time-inaccuracy-problem" aria-hidden="true">#</a> Trace result time inaccuracy problem</h2><p>For example, in the following result: <code>0.705196 &gt; (0.152743 + 0.145825)</code></p><div class="language-bash ext-sh line-numbers-mode"><pre class="language-bash"><code>$ trace demo.MathGame run <span class="token parameter variable">-n</span> <span class="token number">1</span>
Press Q or Ctrl+C to abort.
Affect<span class="token punctuation">(</span>class count: <span class="token number">1</span> , method count: <span class="token number">1</span><span class="token punctuation">)</span> cost <span class="token keyword">in</span> <span class="token number">66</span> ms, listenerId: <span class="token number">1</span>
<span class="token variable"><span class="token variable">\`</span>---ts<span class="token operator">=</span><span class="token number">2021</span>-02-08 <span class="token number">11</span>:27:36<span class="token punctuation">;</span><span class="token assign-left variable">thread_name</span><span class="token operator">=</span>main<span class="token punctuation">;</span><span class="token assign-left variable">id</span><span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">;</span><span class="token assign-left variable">is_daemon</span><span class="token operator">=</span>false<span class="token punctuation">;</span><span class="token assign-left variable">priority</span><span class="token operator">=</span><span class="token number">5</span><span class="token punctuation">;</span><span class="token assign-left variable">TCCL</span><span class="token operator">=</span>sun.misc.Launcher$AppClassLoader@232204a1
<span class="token variable">\`</span></span>--<span class="token punctuation">[</span><span class="token number">0</span>.705196ms<span class="token punctuation">]</span> demo.MathGame:run<span class="token punctuation">(</span><span class="token punctuation">)</span>
+---<span class="token punctuation">[</span><span class="token number">0</span>.152743ms<span class="token punctuation">]</span> demo.MathGame:primeFactors<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">#24</span>
\`--<span class="token punctuation">[</span><span class="token number">0</span>.145825ms<span class="token punctuation">]</span> demo.MathGame:print<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">#25</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>So where is the rest of the time consumed?</p><ol><li><p>Methods that are not traced to. For example, methods under <code>java.*</code> are ignored by default. This can be printed out by adding the <code>-skipJDKMethod false</code> parameter.</p><div class="language-bash ext-sh line-numbers-mode"><pre class="language-bash"><code>$ trace demo.MathGame run <span class="token parameter variable">--skipJDKMethod</span> <span class="token boolean">false</span>
Press Q or Ctrl+C to abort.
Affect<span class="token punctuation">(</span>class count: <span class="token number">1</span> , method count: <span class="token number">1</span><span class="token punctuation">)</span> cost <span class="token keyword">in</span> <span class="token number">35</span> ms, listenerId: <span class="token number">2</span>
<span class="token variable"><span class="token variable">\`</span>---ts<span class="token operator">=</span><span class="token number">2021</span>-02-08 <span class="token number">11</span>:27:48<span class="token punctuation">;</span><span class="token assign-left variable">thread_name</span><span class="token operator">=</span>main<span class="token punctuation">;</span><span class="token assign-left variable">id</span><span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">;</span><span class="token assign-left variable">is_daemon</span><span class="token operator">=</span>false<span class="token punctuation">;</span><span class="token assign-left variable">priority</span><span class="token operator">=</span><span class="token number">5</span><span class="token punctuation">;</span><span class="token assign-left variable">TCCL</span><span class="token operator">=</span>sun.misc.Launcher$AppClassLoader@232204a1
<span class="token variable">\`</span></span>--<span class="token punctuation">[</span><span class="token number">0</span>.810591ms<span class="token punctuation">]</span> demo.MathGame:run<span class="token punctuation">(</span><span class="token punctuation">)</span>
+--<span class="token punctuation">[</span><span class="token number">0</span>.034568ms<span class="token punctuation">]</span> java.util.Random:nextInt<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">#23</span>
+---<span class="token punctuation">[</span><span class="token number">0</span>.119367ms<span class="token punctuation">]</span> demo.MathGame:timeFactors<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">#24 [throws Exception]</span>
+---<span class="token punctuation">[</span><span class="token number">0</span>.017407ms<span class="token punctuation">]</span> java.lang.StringBuilder:<span class="token operator">&lt;</span>init<span class="token operator">&gt;</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">#28</span>
+--<span class="token punctuation">[</span><span class="token number">0</span>.127922ms<span class="token punctuation">]</span> java.lang.String:format<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">#57</span>
+---<span class="token punctuation">[</span>min<span class="token operator">=</span><span class="token number">0</span>.01419ms,max<span class="token operator">=</span><span class="token number">0</span>.020221ms,total<span class="token operator">=</span><span class="token number">0</span>.034411ms,count<span class="token operator">=</span><span class="token number">2</span><span class="token punctuation">]</span> java.lang.StringBuilder:append<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">#57</span>
+--<span class="token punctuation">[</span><span class="token number">0</span>.021911ms<span class="token punctuation">]</span> java.lang.Exception:getMessage<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">#57</span>
+---<span class="token punctuation">[</span><span class="token number">0</span>.015643ms<span class="token punctuation">]</span> java.lang.StringBuilder:toString<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">#57</span>
\`--<span class="token punctuation">[</span><span class="token number">0</span>.086622ms<span class="token punctuation">]</span> java.io.PrintStream:println<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">#57</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div></li><li><p>Instruction consumption. For example, instructions such as <code>i++</code>, <code>getfield</code>, etc.</p></li><li><p>Possible JVM pause during code execution, such as GC, entering synchronization blocks, etc.</p></li></ol><h3 id="use-the-v-parameter-to-print-more-information" tabindex="-1"><a class="header-anchor" href="#use-the-v-parameter-to-print-more-information" aria-hidden="true">#</a> Use the -v parameter to print more information</h3><div class="custom-container tip"><p class="custom-container-title">TIP</p><p>The watch/trace/monitor/stack/tt commands all support the <code>-v</code> parameter.</p></div><p>When the command is executed, there is no output result. There are two possibilities:</p><ol><li>The matched function is not executed</li><li>The result of the conditional expression is false</li></ol><p>But the user cannot tell which situation is.</p><p>Using the <code>-v</code> option, the specific value and execution result of <code>Condition express</code> will be printed for easy confirmation.</p>`,44);function R(U,V){const e=c("ExternalLinkIcon"),p=c("RouterLink");return i(),r("div",null,[d,s("p",null,[s("a",m,[k,b,n(e)])]),h,s("p",null,[v,n(p,{to:"/en/doc/advice-class.html"},{default:o(()=>[g]),_:1}),f]),s("ul",null,[s("li",null,[x,s("a",_,[y,n(e)]),C]),s("li",null,[w,s("a",M,[L,n(e)])])]),G,s("ul",null,[T,A,s("li",null,[s("p",null,[j,I,S,s("a",F,[P,n(e)]),$])])]),E,B,s("p",null,[q,N,Q,n(p,{to:"/en/doc/quick-start.html"},{default:o(()=>[D]),_:1}),O]),J])}const Y=l(u,[["render",R],["__file","trace.html.vue"]]);export{Y as default};