mirror of
https://github.com/alibaba/arthas.git
synced 2026-11-21 07:06:18 +00:00
update doc
This commit is contained in:
1 parent
c1dcc8ff9e
commit
f599c74408
133 files changed
+793
-617
No files matched your search
+91
-56
@@ -8,7 +8,7 @@
|
||||
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
|
||||
<title>thread — Arthas 3.4.1 documentation</title>
|
||||
<title>thread — Arthas 3.4.2 documentation</title>
|
||||
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@
|
||||
|
||||
|
||||
<div class="version">
|
||||
3.4.1
|
||||
3.4.2
|
||||
</div>
|
||||
|
||||
|
||||
@@ -108,9 +108,11 @@
|
||||
<li class="toctree-l2"><a class="reference internal" href="dashboard.html">dashboard</a></li>
|
||||
<li class="toctree-l2 current"><a class="current reference internal" href="#">thread</a><ul>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#parameters">Parameters</a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#how-the-cpu-ratios-are-calculated">How the CPU ratios are calculated?</a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#usage">Usage</a><ul>
|
||||
<li class="toctree-l4"><a class="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>
|
||||
<li class="toctree-l4"><a class="reference internal" href="#list-all-threads-info-when-no-options-provided">List all threads’ info when no options provided</a></li>
|
||||
<li class="toctree-l4"><a class="reference internal" href="#list-first-page-threads-info-when-no-options-provided">List first page threads’ info when no options provided</a></li>
|
||||
<li class="toctree-l4"><a class="reference internal" href="#thread-all-show-all-matching-threads">thread –all, show all matching threads</a></li>
|
||||
<li class="toctree-l4"><a class="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>
|
||||
<li class="toctree-l4"><a class="reference internal" href="#thread-b-locate-the-thread-bocking-the-others">thread -b, locate the thread bocking the others</a></li>
|
||||
<li class="toctree-l4"><a class="reference internal" href="#thread-i-specify-the-sampling-interval">thread -i, specify the sampling interval</a></li>
|
||||
@@ -262,12 +264,31 @@
|
||||
<td align="right">[i <code><value></code>]</td>
|
||||
<td align="left">specify the interval to collect data to compute CPU ratios (ms)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">[--all]</td>
|
||||
<td align="left">Show all matching threads</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table><blockquote>
|
||||
<div><p>How the CPU ratios are calculated? <br/><br/>
|
||||
CPU ratio for a given thread is the CPU time it takes divided by the total CPU time within a specified interval period. It is calculated in the following way: sample CPU times for all the thread by calling <code class="docutils literal notranslate"><span class="pre">java.lang.management.ThreadMXBean#getThreadCpuTime</span></code> first, then sleep for a period (the default value is 100ms, which can be specified by <code class="docutils literal notranslate"><span class="pre">-i</span></code>), then sample CPU times again. By this, we can get the time cost for this period for each thread, then come up with the ratio. <br/><br/>
|
||||
Note: this operation consumes CPU time too (<code class="docutils literal notranslate"><span class="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/><br/>
|
||||
If you’d like to check the CPU ratios from the very beginning of the Java process, <a class="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>
|
||||
</table></div>
|
||||
<div class="section" id="how-the-cpu-ratios-are-calculated">
|
||||
<h2>How the CPU ratios are calculated?<a class="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 <code class="docutils literal notranslate"><span class="pre">%CPU</span></code> of the linux command <code class="docutils literal notranslate"><span class="pre">top</span> <span class="pre">-H</span> <span class="pre">-p</span> <span class="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>
|
||||
<ul class="simple">
|
||||
<li><p>Do the first sampling, get the CPU time of all threads ( by calling <code class="docutils literal notranslate"><span class="pre">java.lang.management.ThreadMXBean#getThreadCpuTime()</span></code> and
|
||||
<code class="docutils literal notranslate"><span class="pre">sun.management.HotspotThreadMBean.getInternalThreadCpuTimes()</span></code> )</p></li>
|
||||
<li><p>Sleep and wait for an interval (the default is 200ms, the interval can be specified by <code class="docutils literal notranslate"><span class="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>
|
||||
<li><p><code class="docutils literal notranslate"><span class="pre">Thread</span> <span class="pre">CPU</span> <span class="pre">usage</span> <span class="pre">ratio</span></code> = <code class="docutils literal notranslate"><span class="pre">Thread</span> <span class="pre">increment</span> <span class="pre">CPU</span> <span class="pre">time</span></code> / <code class="docutils literal notranslate"><span class="pre">Sampling</span> <span class="pre">interval</span> <span class="pre">time</span></code> * 100%</p></li>
|
||||
</ul>
|
||||
<blockquote>
|
||||
<div><p>Note: this operation consumes CPU time too (<code class="docutils literal notranslate"><span class="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, <a class="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>
|
||||
</div></blockquote>
|
||||
</div>
|
||||
<div class="section" id="usage">
|
||||
@@ -275,54 +296,66 @@ If you’d like to check the CPU ratios from the very beginning of the Java proc
|
||||
<div class="section" id="list-the-top-n-busiest-threads-with-detailed-stack-trace">
|
||||
<h3>List the top n busiest threads with detailed stack trace<a class="headerlink" href="#list-the-top-n-busiest-threads-with-detailed-stack-trace" title="Permalink to this headline">¶</a></h3>
|
||||
<div class="highlight-shell notranslate"><div class="highlight hljs"><pre class="shell">$ thread -n 3
|
||||
"as-command-execute-daemon" Id=29 cpuUsage=75% RUNNABLE
|
||||
at sun.management.ThreadImpl.dumpThreads0(Native Method)
|
||||
at sun.management.ThreadImpl.getThreadInfo(ThreadImpl.java:440)
|
||||
at com.taobao.arthas.core.command.monitor200.ThreadCommand$1.action(ThreadCommand.java:58)
|
||||
at com.taobao.arthas.core.command.handler.AbstractCommandHandler.execute(AbstractCommandHandler.java:238)
|
||||
at com.taobao.arthas.core.command.handler.DefaultCommandHandler.handleCommand(DefaultCommandHandler.java:67)
|
||||
at com.taobao.arthas.core.server.ArthasServer$4.run(ArthasServer.java:276)
|
||||
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
|
||||
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
|
||||
at java.lang.Thread.run(Thread.java:745)
|
||||
"C1 CompilerThread0" [Internal] cpuUsage=1.63% deltaTime=3ms time=1170ms
|
||||
|
||||
Number of locked synchronizers = 1
|
||||
- java.util.concurrent.ThreadPoolExecutor$Worker@6cd0b6f8
|
||||
"arthas-command-execute" Id=23 cpuUsage=0.11% deltaTime=0ms time=401ms RUNNABLE
|
||||
at java.management@11.0.7/sun.management.ThreadImpl.dumpThreads0(Native Method)
|
||||
at java.management@11.0.7/sun.management.ThreadImpl.getThreadInfo(ThreadImpl.java:466)
|
||||
at com.taobao.arthas.core.command.monitor200.ThreadCommand.processTopBusyThreads(ThreadCommand.java:199)
|
||||
at com.taobao.arthas.core.command.monitor200.ThreadCommand.process(ThreadCommand.java:122)
|
||||
at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl.process(AnnotatedCommandImpl.java:82)
|
||||
at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl.access$100(AnnotatedCommandImpl.java:18)
|
||||
at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl$ProcessHandler.handle(AnnotatedCommandImpl.java:111)
|
||||
at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl$ProcessHandler.handle(AnnotatedCommandImpl.java:108)
|
||||
at com.taobao.arthas.core.shell.system.impl.ProcessImpl$CommandProcessTask.run(ProcessImpl.java:385)
|
||||
at java.base@11.0.7/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
|
||||
at java.base@11.0.7/java.util.concurrent.FutureTask.run(FutureTask.java:264)
|
||||
at java.base@11.0.7/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
|
||||
at java.base@11.0.7/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
|
||||
at java.base@11.0.7/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
|
||||
at java.base@11.0.7/java.lang.Thread.run(Thread.java:834)
|
||||
|
||||
"as-session-expire-daemon" Id=25 cpuUsage=24% TIMED_WAITING
|
||||
at java.lang.Thread.sleep(Native Method)
|
||||
at com.taobao.arthas.core.server.DefaultSessionManager$2.run(DefaultSessionManager.java:85)
|
||||
|
||||
"Reference Handler" Id=2 cpuUsage=0% WAITING on java.lang.ref.Reference$Lock@69ba0f27
|
||||
at java.lang.Object.wait(Native Method)
|
||||
- waiting on java.lang.ref.Reference$Lock@69ba0f27
|
||||
at java.lang.Object.wait(Object.java:503)
|
||||
at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:133)</pre></div>
|
||||
"VM Periodic Task Thread" [Internal] cpuUsage=0.07% deltaTime=0ms time=584ms</pre></div>
|
||||
</div>
|
||||
<ul class="simple">
|
||||
<li><p>Without thread ID, including <code class="docutils literal notranslate"><span class="pre">[Internal]</span></code> means JVM internal thread, refer to the introduction of <a class="reference internal" href="dashboard.html"><span class="doc">dashboard</span></a> command.</p></li>
|
||||
<li><p><code class="docutils literal notranslate"><span class="pre">cpuUsage</span></code> is the CPU usage of the thread during the sampling interval, consistent with the data of the <a class="reference internal" href="dashboard.html"><span class="doc">dashboard</span></a> command.</p></li>
|
||||
<li><p><code class="docutils literal notranslate"><span class="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><code class="docutils literal notranslate"><span class="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>
|
||||
</div>
|
||||
<div class="section" id="list-all-threads-info-when-no-options-provided">
|
||||
<h3>List all threads’ info when no options provided<a class="headerlink" href="#list-all-threads-info-when-no-options-provided" title="Permalink to this headline">¶</a></h3>
|
||||
<div class="section" id="list-first-page-threads-info-when-no-options-provided">
|
||||
<h3>List first page threads’ info when no options provided<a class="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>
|
||||
<div class="highlight-shell notranslate"><div class="highlight hljs"><pre class="shell">$ thread
|
||||
Threads Total: 16, NEW: 0, RUNNABLE: 7, BLOCKED: 0, WAITING: 5, TIMED_WAITING: 4, TERMINATED: 0
|
||||
ID NAME GROUP PRIORITY STATE %CPU TIME INTERRUPTE DAEMON
|
||||
30 as-command-execute-daemon system 9 RUNNABLE 72 0:0 false true
|
||||
23 as-session-expire-daemon system 9 TIMED_WAIT 27 0:0 false true
|
||||
22 Attach Listener system 9 RUNNABLE 0 0:0 false true
|
||||
11 pool-2-thread-1 main 5 TIMED_WAIT 0 0:0 false false
|
||||
12 Thread-2 main 5 RUNNABLE 0 0:0 false true
|
||||
13 pool-3-thread-1 main 5 TIMED_WAIT 0 0:0 false false
|
||||
25 as-selector-daemon system 9 RUNNABLE 0 0:0 false true
|
||||
14 Thread-3 main 5 TIMED_WAIT 0 0:0 false false
|
||||
26 pool-5-thread-1 system 5 WAITING 0 0:0 false false
|
||||
15 Thread-4 main 5 RUNNABLE 0 0:0 false false
|
||||
1 main main 5 WAITING 0 0:2 false false
|
||||
2 Reference Handler system 10 WAITING 0 0:0 false true
|
||||
3 Finalizer system 8 WAITING 0 0:0 false true
|
||||
4 Signal Dispatcher system 9 RUNNABLE 0 0:0 false true
|
||||
20 NonBlockingInputStreamThread main 5 WAITING 0 0:0 false true
|
||||
21 Thread-8 main 5 RUNNABLE 0 0:0 false true</pre></div>
|
||||
Threads Total: 33, NEW: 0, RUNNABLE: 9, BLOCKED: 0, WAITING: 3, TIMED_WAITING: 4, TERMINATED: 0, Internal threads: 17
|
||||
ID NAME GROUP PRIORITY STATE %CPU DELTA_TIME TIME INTERRUPT DAEMON
|
||||
-1 C2 CompilerThread0 - -1 - 5.06 0.010 0:0.973 false true
|
||||
-1 C1 CompilerThread0 - -1 - 0.95 0.001 0:0.603 false true
|
||||
23 arthas-command-execute system 5 RUNNABLE 0.17 0.000 0:0.226 false true
|
||||
-1 VM Periodic Task Thread - -1 - 0.05 0.000 0:0.094 false true
|
||||
-1 Sweeper thread - -1 - 0.04 0.000 0:0.011 false true
|
||||
-1 G1 Young RemSet Sampling - -1 - 0.02 0.000 0:0.025 false true
|
||||
12 Attach Listener system 9 RUNNABLE 0.0 0.000 0:0.022 false true
|
||||
11 Common-Cleaner InnocuousThrea 8 TIMED_WAI 0.0 0.000 0:0.000 false true
|
||||
3 Finalizer system 8 WAITING 0.0 0.000 0:0.000 false true
|
||||
2 Reference Handler system 10 RUNNABLE 0.0 0.000 0:0.000 false true
|
||||
4 Signal Dispatcher system 9 RUNNABLE 0.0 0.000 0:0.000 false true
|
||||
15 arthas-NettyHttpTelnetBootstra system 5 RUNNABLE 0.0 0.000 0:0.029 false true
|
||||
22 arthas-NettyHttpTelnetBootstra system 5 RUNNABLE 0.0 0.000 0:0.196 false true
|
||||
24 arthas-NettyHttpTelnetBootstra system 5 RUNNABLE 0.0 0.000 0:0.038 false true
|
||||
16 arthas-NettyWebsocketTtyBootst system 5 RUNNABLE 0.0 0.000 0:0.001 false true
|
||||
17 arthas-NettyWebsocketTtyBootst system 5 RUNNABLE 0.0 0.000 0:0.001 false true</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="thread-all-show-all-matching-threads">
|
||||
<h3>thread –all, show all matching threads<a class="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>
|
||||
</div>
|
||||
<div class="section" id="thread-id-show-the-running-stack-for-the-target-thread">
|
||||
<h3>thread id, show the running stack for the target thread<a class="headerlink" href="#thread-id-show-the-running-stack-for-the-target-thread" title="Permalink to this headline">¶</a></h3>
|
||||
<div class="highlight-shell notranslate"><div class="highlight hljs"><pre class="shell">$ thread 1
|
||||
@@ -382,6 +415,10 @@ ID NAME GROUP PRIORITY STA
|
||||
</div>
|
||||
<div class="section" id="thread-i-specify-the-sampling-interval">
|
||||
<h3>thread -i, specify the sampling interval<a class="headerlink" href="#thread-i-specify-the-sampling-interval" title="Permalink to this headline">¶</a></h3>
|
||||
<ul class="simple">
|
||||
<li><p><code class="docutils literal notranslate"><span class="pre">thread</span> <span class="pre">-i</span> <span class="pre">1000</span></code>: Count the thread cpu time of the last 1000ms.</p></li>
|
||||
<li><p><code class="docutils literal notranslate"><span class="pre">thread</span> <span class="pre">-n</span> <span class="pre">3</span> <span class="pre">-i</span> <span class="pre">1000</span></code>: List the 3 busiest thread stacks in 1000ms</p></li>
|
||||
</ul>
|
||||
<div class="highlight-bash notranslate"><div class="highlight hljs"><pre class="bash">$ thread -n 3 -i 1000
|
||||
"as-command-execute-daemon" Id=4759 cpuUsage=23% RUNNABLE
|
||||
at sun.management.ThreadImpl.dumpThreads0(Native Method)
|
||||
@@ -405,13 +442,11 @@ ID NAME GROUP PRIORITY STA
|
||||
<div class="section" id="thread-state-view-the-special-state-theads">
|
||||
<h3>thread –state , view the special state theads<a class="headerlink" href="#thread-state-view-the-special-state-theads" title="Permalink to this headline">¶</a></h3>
|
||||
<div class="highlight-bash notranslate"><div class="highlight hljs"><pre class="bash">[arthas@28114]$ thread --state WAITING
|
||||
Threads Total: 15, NEW: 0, RUNNABLE: 7, BLOCKED: 0, WAITING: 5, TIMED_WAITING: 3, TERMINATED: 0
|
||||
ID NAME GROUP PRIORITY STATE %CPU TIME INTERRU DAEMON
|
||||
198 AsyncAppender-Worker-arth system 9 WAITING 0 0:0 false true
|
||||
3 Finalizer system 8 WAITING 0 0:0 false true
|
||||
14 RMI Scheduler(0) system 9 WAITING 0 0:0 false true
|
||||
2 Reference Handler system 10 WAITING 0 0:0 false true
|
||||
204 pool-8-thread-1 system 5 WAITING 0 0:0 false false</pre></div>
|
||||
Threads Total: 16, NEW: 0, RUNNABLE: 9, BLOCKED: 0, WAITING: 3, TIMED_WAITING: 4, TERMINATED: 0
|
||||
ID NAME GROUP PRIORITY STATE %CPU DELTA_TIME TIME INTERRUPTE DAEMON
|
||||
3 Finalizer system 8 WAITING 0.0 0.000 0:0.000 false true
|
||||
20 arthas-UserStat system 9 WAITING 0.0 0.000 0:0.001 false true
|
||||
14 arthas-timer system 9 WAITING 0.0 0.000 0:0.000 false true</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user