<liclass="toctree-l4"><aclass="reference internal"href="#list-the-top-n-busiest-with-detailed-stack-trace">List the top n busiest with detailed stack trace</a></li>
<liclass="toctree-l4"><aclass="reference internal"href="#list-all-info-when-no-options-provided">List all info when no options provided</a></li>
<liclass="toctree-l4"><aclass="reference internal"href="#thread-thread-id-present-the-specified-thread-profile">thread <thread_id> present the specified thread profile</a></li>
<liclass="toctree-l4"><aclass="reference internal"href="#thread-b-locate-the-blocking-threads">thread -b locate the blocking threads</a></li>
<liclass="toctree-l4"><aclass="reference internal"href="#thread-i-specify-the-collecting-interval">thread -i specify the collecting interval</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>
<tdalign="left">specify the interval to collect data to compute CPU ratios (ms)</td>
</tr>
</tbody>
</table><p>How to get the CPU ratios?</p>
<blockquote>
<div>Within an <em>specified</em> interval, the time cost by the thread compared to the total CPU time.
Take a sample (using <codeclass="docutils literal notranslate"><spanclass="pre">java.lang.management.ThreadMXBean#getThreadCpuTime</span></code>) to get the CPU time cost for all the threads and after a <em>specified</em> interval (default <em>100 ms</em>, which can be specified by <codeclass="docutils literal notranslate"><spanclass="pre">-i</span></code>), take another sample and we have the CPU time cost and the ratios naturally.</div></blockquote>
<blockquote>
<div>Attention: this kind of operation will take time, to decrease the extra cost, you’d better expand the interval to like <codeclass="docutils literal notranslate"><spanclass="pre">5000</span><spanclass="pre">ms</span></code> for less performance overhead.</div></blockquote>
<p>F.Y.I</p>
<p>If you’d like to check the CPU ratios from the very start 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 be a help.</p>
</div>
<divclass="section"id="usage">
<spanid="usage"></span><h2>Usage<aclass="headerlink"href="#usage"title="Permalink to this headline">¶</a></h2>
<spanid="list-the-top-n-busiest-with-detailed-stack-trace"></span><h3>List the top n busiest with detailed stack trace<aclass="headerlink"href="#list-the-top-n-busiest-with-detailed-stack-trace"title="Permalink to this headline">¶</a></h3>
at sun.management.ThreadImpl.dumpThreads0<spanclass="o">(</span>Native Method<spanclass="o">)</span>
at sun.management.ThreadImpl.getThreadInfo<spanclass="o">(</span>ThreadImpl.java:440<spanclass="o">)</span>
at com.taobao.arthas.core.command.monitor200.ThreadCommand<spanclass="nv">$1</span>.action<spanclass="o">(</span>ThreadCommand.java:58<spanclass="o">)</span>
at com.taobao.arthas.core.command.handler.AbstractCommandHandler.execute<spanclass="o">(</span>AbstractCommandHandler.java:238<spanclass="o">)</span>
at com.taobao.arthas.core.command.handler.DefaultCommandHandler.handleCommand<spanclass="o">(</span>DefaultCommandHandler.java:67<spanclass="o">)</span>
at com.taobao.arthas.core.server.ArthasServer<spanclass="nv">$4</span>.run<spanclass="o">(</span>ArthasServer.java:276<spanclass="o">)</span>
at java.util.concurrent.ThreadPoolExecutor.runWorker<spanclass="o">(</span>ThreadPoolExecutor.java:1145<spanclass="o">)</span>
at java.util.concurrent.ThreadPoolExecutor<spanclass="nv">$Worker</span>.run<spanclass="o">(</span>ThreadPoolExecutor.java:615<spanclass="o">)</span>
at java.lang.Thread.run<spanclass="o">(</span>Thread.java:745<spanclass="o">)</span>
Number of locked <spanclass="nv">synchronizers</span><spanclass="o">=</span><spanclass="m">1</span>
at java.lang.Thread.sleep<spanclass="o">(</span>Native Method<spanclass="o">)</span>
at com.taobao.arthas.core.server.DefaultSessionManager<spanclass="nv">$2</span>.run<spanclass="o">(</span>DefaultSessionManager.java:85<spanclass="o">)</span>
<spanclass="s2">"Reference Handler"</span><spanclass="nv">Id</span><spanclass="o">=</span><spanclass="m">2</span><spanclass="nv">cpuUsage</span><spanclass="o">=</span><spanclass="m">0</span>% WAITING on java.lang.ref.Reference<spanclass="nv">$Lock</span>@69ba0f27
at java.lang.Object.wait<spanclass="o">(</span>Native Method<spanclass="o">)</span>
- waiting on java.lang.ref.Reference<spanclass="nv">$Lock</span>@69ba0f27
at java.lang.Object.wait<spanclass="o">(</span>Object.java:503<spanclass="o">)</span>
at java.lang.ref.Reference<spanclass="nv">$ReferenceHandler</span>.run<spanclass="o">(</span>Reference.java:133<spanclass="o">)</span>
<spanid="list-all-info-when-no-options-provided"></span><h3>List all info when no options provided<aclass="headerlink"href="#list-all-info-when-no-options-provided"title="Permalink to this headline">¶</a></h3>
ID NAME GROUP PRIORITY STATE %CPU TIME INTERRUPTE DAEMON
<spanclass="m">30</span> as-command-execute-daemon system <spanclass="m">9</span> RUNNABLE <spanclass="m">72</span><spanclass="m">0</span>:0 <spanclass="nb">false</span><spanclass="nb">true</span>
<spanclass="m">23</span> as-session-expire-daemon system <spanclass="m">9</span> TIMED_WAIT <spanclass="m">27</span><spanclass="m">0</span>:0 <spanclass="nb">false</span><spanclass="nb">true</span>
<spanclass="m">22</span> Attach Listener system <spanclass="m">9</span> RUNNABLE <spanclass="m">0</span><spanclass="m">0</span>:0 <spanclass="nb">false</span><spanclass="nb">true</span>
<spanclass="m">11</span> pool-2-thread-1 main <spanclass="m">5</span> TIMED_WAIT <spanclass="m">0</span><spanclass="m">0</span>:0 <spanclass="nb">false</span><spanclass="nb">false</span>
<spanclass="m">12</span> Thread-2 main <spanclass="m">5</span> RUNNABLE <spanclass="m">0</span><spanclass="m">0</span>:0 <spanclass="nb">false</span><spanclass="nb">true</span>
<spanclass="m">13</span> pool-3-thread-1 main <spanclass="m">5</span> TIMED_WAIT <spanclass="m">0</span><spanclass="m">0</span>:0 <spanclass="nb">false</span><spanclass="nb">false</span>
<spanclass="m">25</span> as-selector-daemon system <spanclass="m">9</span> RUNNABLE <spanclass="m">0</span><spanclass="m">0</span>:0 <spanclass="nb">false</span><spanclass="nb">true</span>
<spanclass="m">14</span> Thread-3 main <spanclass="m">5</span> TIMED_WAIT <spanclass="m">0</span><spanclass="m">0</span>:0 <spanclass="nb">false</span><spanclass="nb">false</span>
<spanclass="m">26</span> pool-5-thread-1 system <spanclass="m">5</span> WAITING <spanclass="m">0</span><spanclass="m">0</span>:0 <spanclass="nb">false</span><spanclass="nb">false</span>
<spanclass="m">15</span> Thread-4 main <spanclass="m">5</span> RUNNABLE <spanclass="m">0</span><spanclass="m">0</span>:0 <spanclass="nb">false</span><spanclass="nb">false</span>
<spanclass="m">1</span> main main <spanclass="m">5</span> WAITING <spanclass="m">0</span><spanclass="m">0</span>:2 <spanclass="nb">false</span><spanclass="nb">false</span>
<spanclass="m">2</span> Reference Handler system <spanclass="m">10</span> WAITING <spanclass="m">0</span><spanclass="m">0</span>:0 <spanclass="nb">false</span><spanclass="nb">true</span>
<spanclass="m">3</span> Finalizer system <spanclass="m">8</span> WAITING <spanclass="m">0</span><spanclass="m">0</span>:0 <spanclass="nb">false</span><spanclass="nb">true</span>
<spanclass="m">4</span> Signal Dispatcher system <spanclass="m">9</span> RUNNABLE <spanclass="m">0</span><spanclass="m">0</span>:0 <spanclass="nb">false</span><spanclass="nb">true</span>
<spanclass="m">20</span> NonBlockingInputStreamThread main <spanclass="m">5</span> WAITING <spanclass="m">0</span><spanclass="m">0</span>:0 <spanclass="nb">false</span><spanclass="nb">true</span>
<spanclass="m">21</span> Thread-8 main <spanclass="m">5</span> RUNNABLE <spanclass="m">0</span><spanclass="m">0</span>:0 <spanclass="nb">false</span><spanclass="nb">true</span>
<spanid="thread-thread-id-present-the-specified-thread-profile"></span><h3>thread <thread_id> present the specified thread profile<aclass="headerlink"href="#thread-thread-id-present-the-specified-thread-profile"title="Permalink to this headline">¶</a></h3>
<spanclass="s2">"main"</span><spanclass="nv">Id</span><spanclass="o">=</span><spanclass="m">1</span> WAITING on java.util.concurrent.CountDownLatch<spanclass="nv">$Sync</span>@29fafb28
at sun.misc.Unsafe.park<spanclass="o">(</span>Native Method<spanclass="o">)</span>
- waiting on java.util.concurrent.CountDownLatch<spanclass="nv">$Sync</span>@29fafb28
at java.util.concurrent.locks.LockSupport.park<spanclass="o">(</span>LockSupport.java:175<spanclass="o">)</span>
at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt<spanclass="o">(</span>AbstractQueuedSynchronizer.java:836<spanclass="o">)</span>
at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedInterruptibly<spanclass="o">(</span>AbstractQueuedSynchronizer.java:997<spanclass="o">)</span>
at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly<spanclass="o">(</span>AbstractQueuedSynchronizer.java:1304<spanclass="o">)</span>
at java.util.concurrent.CountDownLatch.await<spanclass="o">(</span>CountDownLatch.java:231<spanclass="o">)</span>
<spanid="thread-b-locate-the-blocking-threads"></span><h3>thread -b locate the blocking threads<aclass="headerlink"href="#thread-b-locate-the-blocking-threads"title="Permalink to this headline">¶</a></h3>
<p>Using <codeclass="docutils literal notranslate"><spanclass="pre">-b</span></code>, we can effectively locate the threads holding locks blocking other threads resulting in a frozen system.</p>
at java.lang.Thread.sleep<spanclass="o">(</span>Native Method<spanclass="o">)</span>
at test.arthas.TestThreadBlocking.doGet<spanclass="o">(</span>TestThreadBlocking.java:22<spanclass="o">)</span>
- locked java.lang.Object@725be470 <---- but blocks <spanclass="m">4</span> other threads!
at javax.servlet.http.HttpServlet.service<spanclass="o">(</span>HttpServlet.java:624<spanclass="o">)</span>
at javax.servlet.http.HttpServlet.service<spanclass="o">(</span>HttpServlet.java:731<spanclass="o">)</span>
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter<spanclass="o">(</span>ApplicationFilterChain.java:303<spanclass="o">)</span>
at org.apache.catalina.core.ApplicationFilterChain.doFilter<spanclass="o">(</span>ApplicationFilterChain.java:208<spanclass="o">)</span>
at org.apache.tomcat.websocket.server.WsFilter.doFilter<spanclass="o">(</span>WsFilter.java:52<spanclass="o">)</span>
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter<spanclass="o">(</span>ApplicationFilterChain.java:241<spanclass="o">)</span>
at org.apache.catalina.core.ApplicationFilterChain.doFilter<spanclass="o">(</span>ApplicationFilterChain.java:208<spanclass="o">)</span>
at test.filter.TestDurexFilter.doFilter<spanclass="o">(</span>TestDurexFilter.java:46<spanclass="o">)</span>
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter<spanclass="o">(</span>ApplicationFilterChain.java:241<spanclass="o">)</span>
at org.apache.catalina.core.ApplicationFilterChain.doFilter<spanclass="o">(</span>ApplicationFilterChain.java:208<spanclass="o">)</span>
at org.apache.catalina.core.StandardWrapperValve.invoke<spanclass="o">(</span>StandardWrapperValve.java:220<spanclass="o">)</span>
at org.apache.catalina.core.StandardContextValve.invoke<spanclass="o">(</span>StandardContextValve.java:122<spanclass="o">)</span>
at org.apache.catalina.authenticator.AuthenticatorBase.invoke<spanclass="o">(</span>AuthenticatorBase.java:505<spanclass="o">)</span>
at com.taobao.tomcat.valves.ContextLoadFilterValve<spanclass="nv">$FilterChainAdapter</span>.doFilter<spanclass="o">(</span>ContextLoadFilterValve.java:191<spanclass="o">)</span>
at com.taobao.eagleeye.EagleEyeFilter.doFilter<spanclass="o">(</span>EagleEyeFilter.java:81<spanclass="o">)</span>
at com.taobao.tomcat.valves.ContextLoadFilterValve.invoke<spanclass="o">(</span>ContextLoadFilterValve.java:150<spanclass="o">)</span>
at org.apache.catalina.core.StandardHostValve.invoke<spanclass="o">(</span>StandardHostValve.java:170<spanclass="o">)</span>
at org.apache.catalina.valves.ErrorReportValve.invoke<spanclass="o">(</span>ErrorReportValve.java:103<spanclass="o">)</span>
at org.apache.catalina.core.StandardEngineValve.invoke<spanclass="o">(</span>StandardEngineValve.java:116<spanclass="o">)</span>
at org.apache.catalina.connector.CoyoteAdapter.service<spanclass="o">(</span>CoyoteAdapter.java:429<spanclass="o">)</span>
at org.apache.coyote.http11.AbstractHttp11Processor.process<spanclass="o">(</span>AbstractHttp11Processor.java:1085<spanclass="o">)</span>
at org.apache.coyote.AbstractProtocol<spanclass="nv">$AbstractConnectionHandler</span>.process<spanclass="o">(</span>AbstractProtocol.java:625<spanclass="o">)</span>
at org.apache.tomcat.util.net.JIoEndpoint<spanclass="nv">$SocketProcessor</span>.run<spanclass="o">(</span>JIoEndpoint.java:318<spanclass="o">)</span>
at java.util.concurrent.ThreadPoolExecutor.runWorker<spanclass="o">(</span>ThreadPoolExecutor.java:1142<spanclass="o">)</span>
at java.util.concurrent.ThreadPoolExecutor<spanclass="nv">$Worker</span>.run<spanclass="o">(</span>ThreadPoolExecutor.java:617<spanclass="o">)</span>
at org.apache.tomcat.util.threads.TaskThread<spanclass="nv">$WrappingRunnable</span>.run<spanclass="o">(</span>TaskThread.java:61<spanclass="o">)</span>
at java.lang.Thread.run<spanclass="o">(</span>Thread.java:745<spanclass="o">)</span>
Number of locked <spanclass="nv">synchronizers</span><spanclass="o">=</span><spanclass="m">1</span>
<p>Attention: only <codeclass="docutils literal notranslate"><spanclass="pre">synchronized</span></code> blocked threads can be located for now, while <codeclass="docutils literal notranslate"><spanclass="pre">java.util.concurrent.Lock</span></code> not supported yet.</p>
<spanid="thread-i-specify-the-collecting-interval"></span><h3>thread -i specify the collecting interval<aclass="headerlink"href="#thread-i-specify-the-collecting-interval"title="Permalink to this headline">¶</a></h3>
at sun.management.ThreadImpl.dumpThreads0<spanclass="o">(</span>Native Method<spanclass="o">)</span>
at sun.management.ThreadImpl.getThreadInfo<spanclass="o">(</span>ThreadImpl.java:440<spanclass="o">)</span>
at com.taobao.arthas.core.command.monitor200.ThreadCommand.processTopBusyThreads<spanclass="o">(</span>ThreadCommand.java:133<spanclass="o">)</span>
at com.taobao.arthas.core.command.monitor200.ThreadCommand.process<spanclass="o">(</span>ThreadCommand.java:79<spanclass="o">)</span>
at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl.process<spanclass="o">(</span>AnnotatedCommandImpl.java:96<spanclass="o">)</span>
at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl.access<spanclass="nv">$100</span><spanclass="o">(</span>AnnotatedCommandImpl.java:27<spanclass="o">)</span>
at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl<spanclass="nv">$ProcessHandler</span>.handle<spanclass="o">(</span>AnnotatedCommandImpl.java:125<spanclass="o">)</span>
at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl<spanclass="nv">$ProcessHandler</span>.handle<spanclass="o">(</span>AnnotatedCommandImpl.java:122<spanclass="o">)</span>
at com.taobao.arthas.core.shell.system.impl.ProcessImpl<spanclass="nv">$CommandProcessTask</span>.run<spanclass="o">(</span>ProcessImpl.java:332<spanclass="o">)</span>
at java.util.concurrent.ThreadPoolExecutor.runWorker<spanclass="o">(</span>ThreadPoolExecutor.java:1142<spanclass="o">)</span>
at java.util.concurrent.ThreadPoolExecutor<spanclass="nv">$Worker</span>.run<spanclass="o">(</span>ThreadPoolExecutor.java:617<spanclass="o">)</span>
at java.lang.Thread.run<spanclass="o">(</span>Thread.java:756<spanclass="o">)</span>
Number of locked <spanclass="nv">synchronizers</span><spanclass="o">=</span><spanclass="m">1</span>
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>.