<liclass="toctree-l4"><aclass="reference internal"href="#list-the-top-n-busiest-threads-with-detailed-stack-trace">List the top n busiest threads with detailed stack trace</a></li>
<liclass="toctree-l4"><aclass="reference internal"href="#list-first-page-threads-info-when-no-options-provided">List first page threads’ info when no options provided</a></li>
<liclass="toctree-l4"><aclass="reference internal"href="#thread-all-show-all-matching-threads">thread –all, show all matching threads</a></li>
<liclass="toctree-l4"><aclass="reference internal"href="#thread-id-show-the-running-stack-for-the-target-thread">thread id, show the running stack for the target thread</a></li>
<liclass="toctree-l4"><aclass="reference internal"href="#thread-b-locate-the-thread-bocking-the-others">thread -b, locate the thread bocking the others</a></li>
<liclass="toctree-l4"><aclass="reference internal"href="#thread-i-specify-the-sampling-interval">thread -i, specify the sampling interval</a></li>
<liclass="toctree-l4"><aclass="reference internal"href="#thread-state-view-the-special-state-theads">thread –state , view the special state theads</a></li>
<liclass="toctree-l1"><aclass="reference external"href="https://github.com/alibaba/arthas/issues?q=label%3Aquestion-answered">Questions and answers</a></li>
<liclass="toctree-l1"><aclass="reference external"href="https://github.com/alibaba/arthas">Fork me at GitHub</a></li>
<liclass="toctree-l1"><aclass="reference external"href="https://github.com/alibaba/arthas/blob/master/CONTRIBUTING.md#">Compile and debug/CONTRIBUTING</a></li>
<h2>How the CPU ratios are calculated?<aclass="headerlink"href="#how-the-cpu-ratios-are-calculated"title="Permalink to this headline">¶</a></h2>
<p>The cpu ratios here is similar to the thread <codeclass="docutils literal notranslate"><spanclass="pre">%CPU</span></code> of the linux command <codeclass="docutils literal notranslate"><spanclass="pre">top</span><spanclass="pre">-H</span><spanclass="pre">-p</span><spanclass="pre"><pid></span></code>. During a sampling interval,
the ratio of the incremental cpu time of each thread in the current JVM to the sampling interval time.</p>
<blockquote>
<div><p>Working principle description:</p>
</div></blockquote>
<ulclass="simple">
<li><p>Do the first sampling, get the CPU time of all threads ( by calling <codeclass="docutils literal notranslate"><spanclass="pre">java.lang.management.ThreadMXBean#getThreadCpuTime()</span></code> and
<li><p>Sleep and wait for an interval (the default is 200ms, the interval can be specified by <codeclass="docutils literal notranslate"><spanclass="pre">-i</span></code>)</p></li>
<li><p>Do the second sampling, get the CPU time of all threads, compare the two sampling data, and calculate the incremental CPU time of each thread</p></li>
<div><p>Note: this operation consumes CPU time too (<codeclass="docutils literal notranslate"><spanclass="pre">getThreadCpuTime</span></code> is time-consuming), therefore it is possible to observe Arthas’s thread appears in the list. To avoid this, try to increase sample interval, for example: 5000 ms.<br/></p>
</div></blockquote>
<blockquote>
<div><p>Another way to view the thread cpu usage of the Java process, <aclass="reference external"href="https://github.com/oldratlee/useful-scripts/blob/master/docs/java.md#-show-busy-java-threads">show-busy-java-threads</a> can come to help.</p>
<h3>List the top n busiest threads with detailed stack trace<aclass="headerlink"href="#list-the-top-n-busiest-threads-with-detailed-stack-trace"title="Permalink to this headline">¶</a></h3>
<li><p>Without thread ID, including <codeclass="docutils literal notranslate"><spanclass="pre">[Internal]</span></code> means JVM internal thread, refer to the introduction of <aclass="reference internal"href="dashboard.html"><spanclass="doc">dashboard</span></a> command.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">cpuUsage</span></code> is the CPU usage of the thread during the sampling interval, consistent with the data of the <aclass="reference internal"href="dashboard.html"><spanclass="doc">dashboard</span></a> command.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">deltaTime</span></code> is the incremental CPU time of the thread during the sampling interval. If it is less than 1ms, it will be rounded and displayed as 0ms.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">time</span></code> The total CPU time of thread.</p></li>
</ul>
<p><strong>Note:</strong> The thread stack is acquired at the end of the second sampling, which does not indicate that the thread is
processing the same task during the sampling interval. It is recommended that the interval time should not be too long.
The larger the interval time, the more inaccurate.</p>
<p>You can try to specify different intervals according to the specific situation and observe the output results.</p>
<h3>List first page threads’ info when no options provided<aclass="headerlink"href="#list-first-page-threads-info-when-no-options-provided"title="Permalink to this headline">¶</a></h3>
<p>By default, they are arranged in descending order of CPU increment time, and only the first page of data is displayed.</p>
<h3>thread –all, show all matching threads<aclass="headerlink"href="#thread-all-show-all-matching-threads"title="Permalink to this headline">¶</a></h3>
<p>Display all matching threads. Sometimes it is necessary to obtain all the thread data of the JVM for analysis.</p>
<h3>thread id, show the running stack for the target thread<aclass="headerlink"href="#thread-id-show-the-running-stack-for-the-target-thread"title="Permalink to this headline">¶</a></h3>
<h3>thread -b, locate the thread bocking the others<aclass="headerlink"href="#thread-b-locate-the-thread-bocking-the-others"title="Permalink to this headline">¶</a></h3>
<p>In some occasions, we experience the whole application is stuck because there’s one particular thread hold one lock that other threads are relying on. To diagnose such an issue, Arthas provides <codeclass="docutils literal notranslate"><spanclass="pre">thread</span><spanclass="pre">-b</span></code> to find the problematic thread in one single command.</p>
<div><p>Note: By now Arthas only supports to locate the thread blocked by <codeclass="docutils literal notranslate"><spanclass="pre">synchronzied</span></code>, while <codeclass="docutils literal notranslate"><spanclass="pre">java.util.concurrent.Lock</span></code> is not supported yet.</p>
<h3>thread -i, specify the sampling interval<aclass="headerlink"href="#thread-i-specify-the-sampling-interval"title="Permalink to this headline">¶</a></h3>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">thread</span><spanclass="pre">-i</span><spanclass="pre">1000</span></code>: Count the thread cpu time of the last 1000ms.</p></li>
<li><p><codeclass="docutils literal notranslate"><spanclass="pre">thread</span><spanclass="pre">-n</span><spanclass="pre">3</span><spanclass="pre">-i</span><spanclass="pre">1000</span></code>: List the 3 busiest thread stacks in 1000ms</p></li>
<h3>thread –state , view the special state theads<aclass="headerlink"href="#thread-state-view-the-special-state-theads"title="Permalink to this headline">¶</a></h3>
Built with <ahref="http://sphinx-doc.org/">Sphinx</a> using a <ahref="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <ahref="https://readthedocs.org">Read the Docs</a>.