</code></pre><divclass="line-numbers"aria-hidden="true"><divclass="line-number"></div><divclass="line-number"></div></div></div><divclass="custom-container tip"><pclass="custom-container-title">TIP</p><p>By default, the sample event is <code>cpu</code>. Can be specified with the <code>--event</code> parameter.</p></div><h3id="get-the-number-of-samples-collected"tabindex="-1"><aclass="header-anchor"href="#get-the-number-of-samples-collected"aria-hidden="true">#</a> Get the number of samples collected</h3><divclass="language-text ext-text line-numbers-mode"><preclass="language-text"><code>$ profiler getSamples
23
</code></pre><divclass="line-numbers"aria-hidden="true"><divclass="line-number"></div><divclass="line-number"></div></div></div><h3id="view-profiler-status"tabindex="-1"><aclass="header-anchor"href="#view-profiler-status"aria-hidden="true">#</a> View profiler status</h3><divclass="language-bash ext-sh line-numbers-mode"><preclass="language-bash"><code>$ profiler status
<spanclass="token punctuation">[</span>cpu<spanclass="token punctuation">]</span> profiling is running <spanclass="token keyword">for</span><spanclass="token number">4</span> seconds
</code></pre><divclass="line-numbers"aria-hidden="true"><divclass="line-number"></div><divclass="line-number"></div></div></div><p>Can view which <code>event</code> and sampling time.</p><h3id="stop-profiler"tabindex="-1"><aclass="header-anchor"href="#stop-profiler"aria-hidden="true">#</a> Stop profiler</h3><h4id="generating-html-format-results"tabindex="-1"><aclass="header-anchor"href="#generating-html-format-results"aria-hidden="true">#</a> Generating html format results</h4><p>By default, the result file is <code>html</code> format. You can also specify it with the <code>--format</code> parameter:</p><divclass="language-bash ext-sh line-numbers-mode"><preclass="language-bash"><code>$ profiler stop --format html
</code></pre><divclass="line-numbers"aria-hidden="true"><divclass="line-number"></div><divclass="line-number"></div><divclass="line-number"></div></div></div><p>Or use the file name name format in the <code>--file</code> parameter. For example, <code>--file /tmp/result.html</code>.</p><h3id="view-profiler-results-under-arthas-output-via-browser"tabindex="-1"><aclass="header-anchor"href="#view-profiler-results-under-arthas-output-via-browser"aria-hidden="true">#</a> View profiler results under arthas-output via browser</h3><p>By default, arthas uses port 3658, which can be opened: <ahref="http://localhost:3658/arthas-output/"target="_blank"rel="noopener noreferrer">http://localhost:3658/arthas-output/<span><svgclass="external-link-icon"xmlns="http://www.w3.org/2000/svg"aria-hidden="true"focusable="false"x="0px"y="0px"viewbox="0 0 100 100"width="15"height="15"><pathfill="currentColor"d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygonfill="currentColor"points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><spanclass="external-link-icon-sr-only">open in new window</span></span></a> View the <code>arthas-output</code> directory below Profiler results:</p><p><imgsrc="/images/arthas-output.jpg"alt=""></p><p>Click to view specific results:</p><p><imgsrc="/images/arthas-output-svg.jpg"alt=""></p><divclass="custom-container tip"><pclass="custom-container-title">TIP</p><p>If using the chrome browser, may need to be refreshed multiple times.</p></div><h3id="profiler-supported-events"tabindex="-1"><aclass="header-anchor"href="#profiler-supported-events"aria-hidden="true">#</a> Profiler supported events</h3><p>Under different platforms and different OSs, the supported events are different. For example, under macos:</p><divclass="language-bash ext-sh line-numbers-mode"><preclass="language-bash"><code>$ profiler list
Basic events:
cpu
alloc
lock
wall
itimer
</code></pre><divclass="line-numbers"aria-hidden="true"><divclass="line-number"></div><divclass="line-number"></div><divclass="line-number"></div><divclass="line-number"></div><divclass="line-number"></div><divclass="line-number"></div><divclass="line-number"></div></div></div><p>Under linux</p><divclass="language-bash ext-sh line-numbers-mode"><preclass="language-bash"><code>$ profiler list
Basic events:
cpu
alloc
lock
wall
itimer
Perf events:
page-faults
context-switches
cycles
instructions
cache-references
cache-misses
branches
branch-misses
bus-cycles
L1-dcache-load-misses
LLC-load-misses
dTLB-load-misses
mem:breakpoint
trace:tracepoint
</code></pre><divclass="line-numbers"aria-hidden="true"><divclass="line-number"></div><divclass="line-number"></div><divclass="line-number"></div><divclass="line-number"></div><divclass="line-number"></div><divclass="line-number"></div><divclass="line-number"></div><divclass="line-number"></div><divclass="line-number"></div><divclass="line-number"></div><divclass="line-number"></div><divclass="line-number"></div><divclass="line-number"></div><divclass="line-number"></div><divclass="line-number"></div><divclass="line-number"></div><divclass="line-number"></div><divclass="line-number"></div><divclass="line-number"></div><divclass="line-number"></div><divclass="line-number"></div><divclass="line-number"></div></div></div><p>If you encounter the permissions/configuration issues of the OS itself and then missing some events, you can refer to the <ahref="https://github.com/jvm-profiling-tools/async-profiler"target="_blank"rel="noopener noreferrer">async-profiler<span><svgclass="external-link-icon"xmlns="http://www.w3.org/2000/svg"aria-hidden="true"focusable="false"x="0px"y="0px"viewbox="0 0 100 100"width="15"height="15"><pathfill="currentColor"d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygonfill="currentColor"points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><spanclass="external-link-icon-sr-only">open in new window</span></span></a> documentation.</p><p>You can use the <code>--event</code> parameter to specify the event to sample, such as sampling the <code>alloc</code> event:</p><divclass="language-bash ext-sh line-numbers-mode"><preclass="language-bash"><code>$ profiler start --event alloc
Started <spanclass="token punctuation">[</span>cpu<spanclass="token punctuation">]</span> profiling
</code></pre><divclass="line-numbers"aria-hidden="true"><divclass="line-number"></div><divclass="line-number"></div></div></div><p>The difference between <code>start</code> and <code>resume</code> is: <code>start</code> is the new start sampling, <code>resume</code> will retain the data of the last <code>stop</code>.</p><p>You can verify the number of samples by executing <code>profiler getSamples</code>.</p><h3id="use-execute-action-to-execute-complex-commands"tabindex="-1"><aclass="header-anchor"href="#use-execute-action-to-execute-complex-commands"aria-hidden="true">#</a> Use <code>execute</code> action to execute complex commands</h3><p>For example, start sampling:</p><divclass="language-bash ext-sh line-numbers-mode"><preclass="language-bash"><code>profiler execute <spanclass="token string">'start,framebuf=5000000'</span>
</code></pre><divclass="line-numbers"aria-hidden="true"><divclass="line-number"></div></div></div><p>Stop sampling and save to the specified file:</p><divclass="language-bash ext-sh line-numbers-mode"><preclass="language-bash"><code>profiler execute <spanclass="token string">'stop,file=/tmp/result.html'</span>
</code></pre><divclass="line-numbers"aria-hidden="true"><divclass="line-number"></div></div></div><p>Specific format reference: <ahref="https://github.com/jvm-profiling-tools/async-profiler/blob/v2.5/src/arguments.cpp#L50"target="_blank"rel="noopener noreferrer">arguments.cpp<span><svgclass="external-link-icon"xmlns="http://www.w3.org/2000/svg"aria-hidden="true"focusable="false"x="0px"y="0px"viewbox="0 0 100 100"width="15"height="15"><pathfill="currentColor"d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygonfill="currentColor"points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><spanclass="external-link-icon-sr-only">open in new window</span></span></a></p><h3id="view-all-supported-actions"tabindex="-1"><aclass="header-anchor"href="#view-all-supported-actions"aria-hidden="true">#</a> View all supported actions</h3><divclass="language-bash ext-sh line-numbers-mode"><preclass="language-bash"><code>$ profiler actions
</code></pre><divclass="line-numbers"aria-hidden="true"><divclass="line-number"></div><divclass="line-number"></div></div></div><h3id="view-version"tabindex="-1"><aclass="header-anchor"href="#view-version"aria-hidden="true">#</a> View version</h3><divclass="language-bash ext-sh line-numbers-mode"><preclass="language-bash"><code>$ profiler version
Async-profiler <spanclass="token number">1.6</span> built on Sep <spanclass="token number">9</span><spanclass="token number">2019</span>
Copyright <spanclass="token number">2019</span> Andrei Pangin
</code></pre><divclass="line-numbers"aria-hidden="true"><divclass="line-number"></div><divclass="line-number"></div><divclass="line-number"></div></div></div><h3id="configure-framebuf-option"tabindex="-1"><aclass="header-anchor"href="#configure-framebuf-option"aria-hidden="true">#</a> Configure framebuf option</h3><divclass="custom-container tip"><pclass="custom-container-title">TIP</p><p>you encounter <code>[frame_buffer_overflow]</code> in the generated result, you need to increase the framebuf (the default value is 1'000'000), which can be configured explicitly, such as:</p></div><divclass="language-bash ext-sh line-numbers-mode"><preclass="language-bash"><code>profiler start --framebuf <spanclass="token number">5000000</span>
</code></pre><divclass="line-numbers"aria-hidden="true"><divclass="line-number"></div></div></div><h3id="configure-include-exclude-to-filter-data"tabindex="-1"><aclass="header-anchor"href="#configure-include-exclude-to-filter-data"aria-hidden="true">#</a> Configure include/exclude to filter data</h3><p>If the application is complex and generates a lot of content, and you want to focus on only part of the data, you can filter by include/exclude. such as</p><divclass="language-bash ext-sh line-numbers-mode"><preclass="language-bash"><code>profiler start --include<spanclass="token string">'java/*'</span> --include<spanclass="token string">'demo/*'</span> --exclude<spanclass="token string">'*Unsafe.park*'</span>
</code></pre><divclass="line-numbers"aria-hidden="true"><divclass="line-number"></div></div></div><blockquote><p>Both include/exclude support setting multiple values, but need to be configured at the end of the command line.</p></blockquote><h3id="specify-execution-time"tabindex="-1"><aclass="header-anchor"href="#specify-execution-time"aria-hidden="true">#</a> Specify execution time</h3><p>For example, if you want the profiler to automatically end after 300 seconds, you can specify it with the <code>-d</code>/<code>--duration</code> parameter:</p><divclass="language-bash ext-sh line-numbers-mode"><preclass="language-bash"><code>profiler start --duration <spanclass="token number">300</span>
</code></pre><divclass="line-numbers"aria-hidden="true"><divclass="line-number"></div></div></div><h3id="generate-jfr-format-result"tabindex="-1"><aclass="header-anchor"href="#generate-jfr-format-result"aria-hidden="true">#</a> Generate jfr format result</h3><blockquote><p>Note that jfr only supports configuration at <code>start</code>. If it is specified at <code>stop</code>, it will not take effect.</p></blockquote><divclass="language-text ext-text line-numbers-mode"><preclass="language-text"><code>profiler start --file /tmp/test.jfr
</code></pre><divclass="line-numbers"aria-hidden="true"><divclass="line-number"></div></div></div><p>The <code>file</code> parameter supports some variables:</p><ul><li>Timestamp: <code>--file /tmp/test-%t.jfr</code></li><li>Process ID: <code>--file /tmp/test-%p.jfr</code></li></ul><p>The generated results can be viewed with tools that support the jfr format. such as:</p><ul><li>JDK Mission Control: https://github.com/openjdk/jmc</li><li>JProfiler: https://github.com/alibaba/arthas/issues/1416</li></ul><h3id="the-unknown-in-profiler-result"tabindex="-1"><aclass="header-anchor"href="#the-unknown-in-profiler-result"aria-hidden="true">#</a> The 'unknown' in profiler result</h3><ul><li>https://github.com/jvm-profiling-tools/async-profiler/discussions/409</li></ul></div><!--[--><!--]--></div><footerclass="page-meta right-menu-padding"data-v-e0e60120><divclass="meta-item edit-link"><aclass="external-link meta-item-label"href="https://github.com/alibaba/arthas/edit/master/site/docs/en/doc/profiler.md"rel="noopener noreferrer"target="_blank"aria-label="Edit this page on GitHub"><!--[--><!--]--><span>Edit this page on GitHub</span><span><svgclass="external-link-icon"xmlns="http://www.w3.org/2000/svg"aria-hidden="true"focusable="false"x="0px"y="0px"viewbox="0 0 100 100"width="15"height="15"><pathfill="currentColor"d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygonfill="currentColor"points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><spanclass="external-link-icon-sr-only">open in new window</span></span><!--[--><!--]--></a></div><divclass="meta-item last-updated"><spanclass="meta-item-label">Last Updated: </span><!----></div><divclass="meta-item contributors"><spanclass="meta-item-label">Contributors: </span><spanclass="meta-item-info"><!--[--><!--[--><spanclass="contributor"title="email: hengyunabc@gmail.com">hengyunabc</span><!--[-->, <!--]--><!--]--><!--[--><spanclass="contributor"title="email: hollowman186@vip.qq.com">Hollow Man</span><!----><!--]--><!--]--></span></div></footer><!----><!--[--><!--]--></main><!--]--></div><!----><!--]--></div>