@ -33,13 +33,16 @@ Many times what we are interested is the exact trace result when the method call
`trace` 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.
After version 3.3.0, you can use the Dynamic Trace feature to add new matching classes/methods, see the following example.
### Usage
#### Start Demo
Start `arthas-demo` in [Quick Start](quick-start.md).
* 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.
#### trace multiple classes or multiple methods
#### Trace multiple classes or multiple methods
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.
@ -134,3 +137,52 @@ You can use the regular expression to match multiple classes and methods on the
Now to drill down into the sub method `primeFactors`, you can open a new terminal 2 and use the `telnet localhost 3658` connects to the arthas, then trace `primeFactors` with the specify `listenerId`.
At Terminal 2 prints the results, indicating that a method has been enhanced: `Affect(class count: 1 , method count: 1)`, but no more results are printed.
At terminal 1, you can see that the trace result has increased by one layer:
Dynamic trace by specifying `listenerId`, you can go deeper and deeper. In addition, commands such as `watch`/`tt`/`monitor` also support similar functionality.
<h2>as.sh and arthas-boot tips<aclass="headerlink"href="#as-sh-and-arthas-boot-tips"title="Permalink to this headline">¶</a></h2>
<ulclass="simple">
<li><p>Select the process to be attached via the <codeclass="docutils literal notranslate"><spanclass="pre">select</span></code> option.</p></li>
</ul>
<p>Normally, <codeclass="docutils literal notranslate"><spanclass="pre">as.sh</span></code>/<codeclass="docutils literal notranslate"><spanclass="pre">arthas-boot.jar</span></code> needs to a pid, bacause the pid will change.</p>
<p>For example, with <codeclass="docutils literal notranslate"><spanclass="pre">arthas-demo.jar</span></code> already started, use the <codeclass="docutils literal notranslate"><spanclass="pre">jps</span></code> command to see.</p>
<p>The <codeclass="docutils literal notranslate"><spanclass="pre">select</span></code> option allows you to specify a process name, which is very convenient.</p>
<h2>Notice<aclass="headerlink"href="#notice"title="Permalink to this headline">¶</a></h2>
<p><codeclass="docutils literal notranslate"><spanclass="pre">trace</span></code> 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.</p>
<p>After version 3.3.0, you can use the Dynamic Trace feature to add new matching classes/methods, see the following example.</p>
</div>
<divclass="section"id="usage">
<h2>Usage<aclass="headerlink"href="#usage"title="Permalink to this headline">¶</a></h2>
@ -286,7 +288,7 @@
<p>Start <codeclass="docutils literal notranslate"><spanclass="pre">arthas-demo</span></code> in <aclass="reference internal"href="quick-start.html"><spanclass="doc">Quick Start</span></a>.</p>
</div>
<divclass="section"id="trace-method">
<h3>trace method<aclass="headerlink"href="#trace-method"title="Permalink to this headline">¶</a></h3>
<h3>Trace method<aclass="headerlink"href="#trace-method"title="Permalink to this headline">¶</a></h3>
<divclass="highlight-bash notranslate"><divclass="highlight hljs"><preclass="bash">$ trace demo.MathGame run
<h3>trace times limit<aclass="headerlink"href="#trace-times-limit"title="Permalink to this headline">¶</a></h3>
<h3>Trace times limit<aclass="headerlink"href="#trace-times-limit"title="Permalink to this headline">¶</a></h3>
<p>If the method invoked many times, use <codeclass="docutils literal notranslate"><spanclass="pre">-n</span></code> options to specify trace times. For example, the command will exit when received a trace result.</p>
<divclass="highlight-bash notranslate"><divclass="highlight hljs"><preclass="bash">$ trace demo.MathGame run -n 1
<h3>trace multiple classes or multiple methods<aclass="headerlink"href="#trace-multiple-classes-or-multiple-methods"title="Permalink to this headline">¶</a></h3>
<h3>Trace multiple classes or multiple methods<aclass="headerlink"href="#trace-multiple-classes-or-multiple-methods"title="Permalink to this headline">¶</a></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>
<h3>Dynamic trace<aclass="headerlink"href="#dynamic-trace"title="Permalink to this headline">¶</a></h3>
<blockquote>
<div><p>Supported since version 3.3.0.</p>
</div></blockquote>
<p>Open terminal 1, trace the <codeclass="docutils literal notranslate"><spanclass="pre">run</span></code> method, and you can see the printout <codeclass="docutils literal notranslate"><spanclass="pre">listenerId:</span><spanclass="pre">1</span></code> .</p>
<divclass="highlight-bash notranslate"><divclass="highlight hljs"><preclass="bash">[arthas@59161]$ trace demo.MathGame run
<p>Now to drill down into the sub method <codeclass="docutils literal notranslate"><spanclass="pre">primeFactors</span></code>, you can open a new terminal 2 and use the <codeclass="docutils literal notranslate"><spanclass="pre">telnet</span><spanclass="pre">localhost</span><spanclass="pre">3658</span></code> connects to the arthas, then trace <codeclass="docutils literal notranslate"><spanclass="pre">primeFactors</span></code> with the specify <codeclass="docutils literal notranslate"><spanclass="pre">listenerId</span></code>.</p>
<p>At Terminal 2 prints the results, indicating that a method has been enhanced: <codeclass="docutils literal notranslate"><spanclass="pre">Affect(class</span><spanclass="pre">count:</span><spanclass="pre">1</span><spanclass="pre">,</span><spanclass="pre">method</span><spanclass="pre">count:</span><spanclass="pre">1)</span></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>
<p>Dynamic trace by specifying <codeclass="docutils literal notranslate"><spanclass="pre">listenerId</span></code>, you can go deeper and deeper. In addition, commands such as <codeclass="docutils literal notranslate"><spanclass="pre">watch</span></code>/<codeclass="docutils literal notranslate"><spanclass="pre">tt</span></code>/<codeclass="docutils literal notranslate"><spanclass="pre">monitor</span></code> also support similar functionality.</p>