You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
arthas/doc/profiler.html

121 lines
102 KiB
HTML

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
3 years ago
<meta name="generator" content="VuePress 2.0.0-beta.51">
<style>
:root {
--c-bg: #fff;
}
html.dark {
--c-bg: #22272e;
}
html, body {
background-color: var(--c-bg);
}
</style>
<script>
const userMode = localStorage.getItem('vuepress-color-scheme');
const systemDarkMode = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
if (userMode === 'dark' || (userMode !== 'light' && systemDarkMode)) {
document.documentElement.classList.toggle('dark', true);
}
</script>
3 years ago
<link rel="icon" href="/images/favicon.ico"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta property="og:title" content="Arthas"><meta property="og:image:alt" content="Alibaba Java Diagnostic Tool Arthas/Alibaba Java诊断利器Arthas - alibaba/arthas: Alibaba Java Diagnostic Tool Arthas/Alibaba Java诊断利器Arthas"><meta property="og:image" content="/images/arthas_mate_image.png"><meta property="og:description" content="Alibaba Java Diagnostic Tool Arthas/Alibaba Java诊断利器Arthas - alibaba/arthas: Alibaba Java Diagnostic Tool Arthas/Alibaba Java诊断利器Arthas"><meta property="og:image:width" content="1200"><meta property="og:image:height" content="600"><meta property="twitter:image:src" content="/images/arthas_mate_image.png"><meta property="twitter:image:alt" content="Alibaba Java Diagnostic Tool Arthas/Alibaba Java诊断利器Arthas - alibaba/arthas: Alibaba Java Diagnostic Tool Arthas/Alibaba Java诊断利器Arthas"><meta itemprop="name" content="Arthas"><meta itemprop="image" content="/images/arthas_mate_image.png"><meta itemprop="description" content="Alibaba Java Diagnostic Tool Arthas/Alibaba Java诊断利器Arthas - alibaba/arthas: Alibaba Java Diagnostic Tool Arthas/Alibaba Java诊断利器Arthas"><script>
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?d5c5e25b100f0eb51a4c35c8a86ea9b4";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
2 years ago
</script><meta name="aes-config" content="pid=xux-opensource&user_type=101&uid=&username=&dim10=arthas"><script src="//g.alicdn.com/alilog/mlog/aplus_v2.js" id="beacon-aplus" exparams="clog=o&aplus&sidx=aplusSidx&ckx=aplusCkx"></script><script src="//g.alicdn.com/aes/??tracker/1.0.34/index.js,tracker-plugin-pv/2.4.5/index.js,tracker-plugin-event/1.2.5/index.js,tracker-plugin-jserror/1.0.13/index.js,tracker-plugin-api/1.1.14/index.js,tracker-plugin-perf/1.1.8/index.js,tracker-plugin-eventTiming/1.0.4/index.js"></script><title>profiler | arthas</title><meta name="description" content="arthas 使用文档">
<link rel="modulepreload" href="/assets/app.977e81c1.js"><link rel="modulepreload" href="/assets/profiler.html.cfdf06fc.js"><link rel="modulepreload" href="/assets/arthas-output-svg.30f64f53.js"><link rel="modulepreload" href="/assets/profiler.html.0af96094.js"><link rel="prefetch" href="/assets/index.html.9412a900.js"><link rel="prefetch" href="/assets/index.html.3c03373d.js"><link rel="prefetch" href="/assets/index.html.31581b5f.js"><link rel="prefetch" href="/assets/advanced-use.html.3876077d.js"><link rel="prefetch" href="/assets/advice-class.html.e0d4601b.js"><link rel="prefetch" href="/assets/agent.html.ea7c22e0.js"><link rel="prefetch" href="/assets/arthas-properties.html.4eb539b4.js"><link rel="prefetch" href="/assets/arthas3.html.bee7bffc.js"><link rel="prefetch" href="/assets/async.html.473d320c.js"><link rel="prefetch" href="/assets/auth.html.ac4b67f2.js"><link rel="prefetch" href="/assets/base64.html.4b181e89.js"><link rel="prefetch" href="/assets/batch-support.html.a26e2295.js"><link rel="prefetch" href="/assets/cat.html.c8fbb1c5.js"><link rel="prefetch" href="/assets/classloader.html.04ede152.js"><link rel="prefetch" href="/assets/cls.html.315127c2.js"><link rel="prefetch" href="/assets/commands.html.205fab1f.js"><link rel="prefetch" href="/assets/contact-us.html.259f35c3.js"><link rel="prefetch" href="/assets/dashboard.html.72692286.js"><link rel="prefetch" href="/assets/docker.html.37a9000f.js"><link rel="prefetch" href="/assets/download.html.e9e19894.js"><link rel="prefetch" href="/assets/dump.html.aac38ab5.js"><link rel="prefetch" href="/assets/echo.html.7dac4c37.js"><link rel="prefetch" href="/assets/faq.html.0788d4da.js"><link rel="prefetch" href="/assets/getstatic.html.2a0b4f73.js"><link rel="prefetch" href="/assets/grep.html.09b9f3d8.js"><link rel="prefetch" href="/assets/groovy.html.5effbaba.js"><link rel="prefetch" href="/assets/heapdump.html.a85cf9a1.js"><link rel="prefetch" href="/assets/help.html.e5f40d88.js"><link rel="prefetch" href="/assets/history.html.9c7d2f2e.js"><link rel="prefetch" href="/assets/http-api.html.693537fc.js"><link rel="prefetch" href="/assets/idea-plugin.html.0e7ca126.js"><link rel="prefetch" href="/assets/install-detail.html.2265e71c.js"><link rel="prefetch" href="/assets/jad.html.6682b060.js"><link rel="prefetch" href="/assets/jfr.html.4a6ffa9b.js"><link rel="prefetch" href="/assets/jvm.html.bf9d7353.js"><link rel="prefetch" href="/assets/keymap.html.4a935f93.js"><link rel="prefetch" href="/assets/logger.html.1626eaca.js"><link rel="prefetch" href="/assets/manual-install.html.7d61ca70.js"><link rel="prefetch" href="/assets/mbean.html.30acbef7.js"><link rel="prefetch" href="/assets/mc.html.2ccc704e.js"><link rel="prefetch" href="/assets/memory.html.354446c2.js"><link rel="prefetch" href="/assets/monitor.html.c7c0dac3.js"><link rel="prefetch" href="/assets/ognl.html.56febc20.js"><link rel="prefetch" href="/assets/options.html.f2203677.js"><link rel="prefetch" href="/assets/perfcounter.html.4783a666.js"><link rel="prefetch" href="/assets/pwd.html.bb923193.js"><link rel="prefetch" href="/assets/quick-start.html.3b81c79e.js"><link rel="prefetch" href="/assets/quit.html.bc71e5cc.js"><link rel="prefetch" href="/assets/redefine.html.c762575e.js"><link rel="prefetch" href="/assets/release-notes.html.fef92c13.js"><link rel="prefetch" href="/assets/reset.html.05dc82b5.js"><link rel="prefetch" href="/assets/retransform.html.21fa57be.js"><link rel="prefetch" href="/assets/save-log.html.8b792c19.js"><link rel="prefetch" href="/assets/sc.html.9e910d92.js"><link rel="prefetch" href="/assets/session.html.620f0ab0.js"><link rel="prefetch" href="/assets/sm.html.00c3d56b.js"><link rel="prefetch" href="/assets/spring-boot-starter.html.07a5bd45.js"><link rel="prefetch" href="/assets/stack.html.17704cc3.js"><link rel="prefetch" href="/assets/start-arthas.html.f299d09e.js"><link rel="prefetch" href="/assets/stop.html.75db3522.js"><link rel="prefetch" href="/assets/sysenv.html.fcd3f33c.js"><link rel="prefetch" href="/assets/sysprop.html.f64847c1.js"><link rel="prefetch" href="/assets/tee.ht
2 years ago
<link rel="stylesheet" href="/assets/style.cf0d4c26.css">
</head>
<body>
<div id="app"><!--[--><div class="theme-container"><!--[--><header class="navbar"><div class="toggle-sidebar-button" title="切换侧边栏" aria-expanded="false" role="button" tabindex="0"><div class="icon" aria-hidden="true"><span></span><span></span><span></span></div></div><span><a href="/" class="" data-v-a8869d06><!----><span class="site-name can-hide" data-v-a8869d06>arthas</span><span class="navbar-version" data-v-a8869d06>v3.7.2</span></a></span><div class="navbar-items-wrapper" style=""><!--[--><!--]--><nav class="navbar-items can-hide"><!--[--><div class="navbar-item"><a href="/" class="" aria-label="首页"><!--[--><!--]--> 首页 <!--[--><!--]--></a></div><div class="navbar-item"><a class="external-link" href="/doc/arthas-tutorials.html?language=cn&amp;id=arthas-basics" rel="noopener noreferrer" target="_blank" aria-label="在线教程"><!--[--><!--]--><span>在线教程</span><span><svg class="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"><path fill="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><polygon fill="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><span class="external-link-icon-sr-only">在新窗口打开</span></span><!--[--><!--]--></a></div><div class="navbar-item"><a href="/doc/" class="router-link-active" aria-label="文档"><!--[--><!--]--> 文档 <!--[--><!--]--></a></div><div class="navbar-item"><a href="/doc/commands.md" class="" aria-label="命令列表"><!--[--><!--]--> 命令列表 <!--[--><!--]--></a></div><div class="navbar-item"><a href="/doc/download.md" class="" aria-label="下载"><!--[--><!--]--> 下载 <!--[--><!--]--></a></div><div class="navbar-item"><a href="/doc/expert/intro.md" class="" aria-label="专家答疑"><!--[--><!--]--> 专家答疑 <!--[--><!--]--></a></div><div class="navbar-item"><div class="navbar-dropdown-wrapper"><button class="navbar-dropdown-title" type="button" aria-label="Select language"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="1em" height="1em" style="height:1.25rem;width:1.25rem;vertical-align:bottom;" viewbox="0 0 24 24"><path fill="currentColor" d="M13.35 22q-.6 0-.862-.387q-.263-.388-.063-.963l3.65-9.675q.15-.4.563-.688Q17.05 10 17.5 10q.425 0 .85.287q.425.288.575.688l3.65 9.675q.2.575-.062.963q-.263.387-.888.387q-.275 0-.5-.175q-.225-.175-.325-.425l-.85-2.45H15.1l-.875 2.45q-.1.25-.35.425q-.25.175-.525.175Zm2.35-4.8h3.6l-1.75-4.95h-.1ZM7.15 8.55q.4.725.85 1.337q.45.613 1.05 1.263q1.1-1.2 1.825-2.462Q11.6 7.425 12.1 6H2q-.425 0-.712-.287Q1 5.425 1 5t.288-.713Q1.575 4 2 4h6V3q0-.425.288-.713Q8.575 2 9 2t.713.287Q10 2.575 10 3v1h6q.425 0 .712.287Q17 4.575 17 5t-.288.713Q16.425 6 16 6h-1.9q-.525 1.775-1.425 3.45q-.9 1.675-2.225 3.15l2.4 2.45l-.75 2.05L9 14l-4.3 4.3q-.275.275-.7.275q-.425 0-.7-.275q-.275-.275-.275-.7q0-.425.275-.7l4.35-4.35q-.675-.775-1.25-1.563q-.575-.787-1.025-1.662Q5.1 8.8 5.35 8.4t.875-.4q.25 0 .525.162q.275.163.4.388Z"></path></svg><span class="arrow down"></span></button><button class="navbar-dropdown-title-mobile" type="button" aria-label="Select language"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="1em" height="1em" style="height:1.25rem;width:1.25rem;vertical-align:bottom;" viewbox="0 0 24 24"><path fill="currentColor" d="M13.35 22q-.6 0-.862-.387q-.263-.388-.063-.963l3.65-9.675q.15-.4.563-.688Q17.05 10 17.5 10q.425 0 .85.287q.425.288.575.688l3.65 9.675q.2.575-.062.963q-.263.387-.888.387q-.275 0-.5-.175q-.225-.175-.325-.425l-.85-2.45H15.1l-.875 2.45q-.1.25-.35.425q-.25.175-.525.175Zm2.35-4.8h3.6l-1.75-4.95h-.1ZM7.15 8.55q.4.725.85 1.337q.45.613 1.05 1.263q1.1-1.2 1.825-2.462Q11.6 7.425 12.1 6H2q-.425 0-.712-.287Q1 5.425 1 5t.288-.713Q1.575 4 2 4h6V3q0-.425.288-.713Q8.575 2 9 2t.713.287Q10 2.575 10 3v1h6q.425 0 .712.287Q17 4.575 17 5t-.288.713Q16.425
Started [cpu] profiling
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div></div></div><div class="custom-container tip"><p class="custom-container-title">提示</p><p>默认情况下,生成的是 cpu 的火焰图,即 event 为<code>cpu</code>。可以用<code>--event</code>参数指定其他性能分析模式,见下文。</p></div><h2 id="获取已采集的-sample-的数量" tabindex="-1"><a class="header-anchor" href="#获取已采集的-sample-的数量" aria-hidden="true">#</a> 获取已采集的 sample 的数量</h2><div class="language-text ext-text line-numbers-mode"><pre class="language-text"><code>$ profiler getSamples
23
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="查看-profiling-状态" tabindex="-1"><a class="header-anchor" href="#查看-profiling-状态" aria-hidden="true">#</a> 查看 profiling 状态</h2><div class="language-bash ext-sh line-numbers-mode"><pre class="language-bash"><code>$ profiler status
<span class="token punctuation">[</span>cpu<span class="token punctuation">]</span> profiling is running <span class="token keyword">for</span> <span class="token number">4</span> seconds
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div></div></div><p>可以查看当前 profiler 在采样哪种<code>event</code>和采样时间。</p><h2 id="查看-profiler-自身的内存占用" tabindex="-1"><a class="header-anchor" href="#查看-profiler-自身的内存占用" aria-hidden="true">#</a> 查看 profiler 自身的内存占用</h2><div class="language-text ext-text line-numbers-mode"><pre class="language-text"><code>$ profiler meminfo
Call trace storage: 10244 KB
Dictionaries: 72 KB
Code cache: 12890 KB
------------------------------
Total: 23206 KB
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="停止-profiler" tabindex="-1"><a class="header-anchor" href="#停止-profiler" aria-hidden="true">#</a> 停止 profiler</h2><h3 id="生成火焰图格式结果" tabindex="-1"><a class="header-anchor" href="#生成火焰图格式结果" aria-hidden="true">#</a> 生成火焰图格式结果</h3><p>默认情况下,结果是 <a href="https://github.com/BrendanGregg/FlameGraph" target="_blank" rel="noopener noreferrer">Flame Graph<span><svg class="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"><path fill="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><polygon fill="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><span class="external-link-icon-sr-only">在新窗口打开</span></span></a> 格式的 <code>html</code> 文件,也可以用 <code>-o</code><code>--format</code> 参数指定其他内容格式,包括 flat、traces、collapsed、flamegraph、tree、jfr。</p><div class="language-bash ext-sh line-numbers-mode"><pre class="language-bash"><code>$ profiler stop <span class="token parameter variable">--format</span> flamegraph
profiler output file: /tmp/test/arthas-output/20211207-111550.html
OK
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p><code>--file</code>参数指定的文件名后缀为 <code>html</code><code>jfr</code> 时,文件格式可以被推断出来。比如<code>--file /tmp/result.html</code> 将自动生成火焰图。</p><h2 id="通过浏览器查看-arthas-output-下面的-profiler-结果" tabindex="-1"><a class="header-anchor" href="#通过浏览器查看-arthas-output-下面的-profiler-结果" aria-hidden="true">#</a> 通过浏览器查看 arthas-output 下面的 profiler 结果</h2><p>默认情况下arthas 使用 3658 端口,则可以打开: <a href="http://localhost:3658/arthas-output/" target="_blank" rel="noopener noreferrer">http://localhost:3658/arthas-output/<span><svg class="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"><path fill="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><polygon fill="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><span class="external-link-icon-sr-only">在新窗口打开</span></span></a> 查看到<code>arthas-output</code>目录下面的 profiler 结果:</p><p><img src="/images/arthas-output.jpg" alt=""></p><p>点击可以查看具体的结果:</p><p><img src="/images/arthas-output-svg.jpg" alt=""></p><div class="custom-container tip"><p class="custom-container-title">提示</p><p>如果是 chrome 浏览器,可能需要多次刷新。</p></div><h2 id="profiler-支持的-events" tabindex="-1"><a class="header-anchor" href="#profiler-支持的-events" aria-hidden="true">#</a> profiler 支持的 events</h2><p>在不同的平台,不同的 OS 下面,支持的 events 各有不同。比如在 macos 下面:</p><div class="language-bash ext-sh line-numbers-mode"><pre class="language-bash"><code>$ profiler list
Basic events:
cpu
alloc
lock
wall
itimer
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>在 linux 下面</p><div class="language-bash ext-sh line-numbers-mode"><pre class="language-bash"><code>$ profiler list
Basic events:
cpu
alloc
lock
wall
itimer
Java method calls:
ClassName.methodName
Perf events:
page-faults
context-switches
cycles
instructions
cache-references
cache-misses
branch-instructions
branch-misses
bus-cycles
L1-dcache-load-misses
LLC-load-misses
dTLB-load-misses
rNNN
pmu/event-descriptor/
mem:breakpoint
trace:tracepoint
kprobe:func
uprobe:path
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>如果遇到 OS 本身的权限/配置问题,然后缺少部分 event可以参考 <a href="https://github.com/jvm-profiling-tools/async-profiler" target="_blank" rel="noopener noreferrer">async-profiler 的文档<span><svg class="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"><path fill="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><polygon fill="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><span class="external-link-icon-sr-only">在新窗口打开</span></span></a></p><p>可以使用 <code>check</code> action 测试某个 event 是否可用,此 action 的参数格式与 start 一致。</p><p>可以用<code>--event</code>参数指定要采样的事件,比如 <code>alloc</code> 表示分析内存分配情况:</p><div class="language-bash ext-sh line-numbers-mode"><pre class="language-bash"><code>$ profiler start <span class="token parameter variable">--event</span> alloc
3 years ago
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><h2 id="恢复采样" tabindex="-1"><a class="header-anchor" href="#恢复采样" aria-hidden="true">#</a> 恢复采样</h2><div class="language-bash ext-sh line-numbers-mode"><pre class="language-bash"><code>$ profiler resume
Started <span class="token punctuation">[</span>cpu<span class="token punctuation">]</span> profiling
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div></div></div><p><code>start</code><code>resume</code>的区别是:<code>start</code>会清除已有的分析结果重新开始,<code>resume</code>则会保留已有的结果,将新的分析结果附加到已有结果中。</p><p>通过执行<code>profiler getSamples</code>可以查看 samples 的数量来验证。</p><h2 id="dump-分析结果" tabindex="-1"><a class="header-anchor" href="#dump-分析结果" aria-hidden="true">#</a> Dump 分析结果</h2><div class="language-bash ext-sh line-numbers-mode"><pre class="language-bash"><code>$ profiler dump
OK
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div></div></div><p><code>dump</code> action 将性能分析的结果保存到默认文件或指定的文件中,但 profiling 过程不会停止。例如,如果使用 <code>start</code> action 启动 profiling5 秒后执行 <code>dump</code> action2 秒后再次执行 <code>dump</code> action将会得到 2 个结果文件,第一个文件包括 0~5 秒的分析结果,第二个文件包括 0~7 秒的分析结果。</p><h2 id="使用execute来执行复杂的命令" tabindex="-1"><a class="header-anchor" href="#使用execute来执行复杂的命令" aria-hidden="true">#</a> 使用<code>execute</code>来执行复杂的命令</h2><p>比如开始采样:</p><div class="language-bash ext-sh line-numbers-mode"><pre class="language-bash"><code>profiler execute <span class="token string">&#39;start,framebuf=5000000&#39;</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>停止采样,并保存到指定文件里:</p><div class="language-bash ext-sh line-numbers-mode"><pre class="language-bash"><code>profiler execute <span class="token string">&#39;stop,file=/tmp/result.html&#39;</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>具体的格式参考: <a href="https://github.com/async-profiler/async-profiler/blob/v2.9/src/arguments.cpp#L52" target="_blank" rel="noopener noreferrer">arguments.cpp<span><svg class="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"><path fill="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><polygon fill="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><span class="external-link-icon-sr-only">在新窗口打开</span></span></a></p><h2 id="查看所有支持的-action" tabindex="-1"><a class="header-anchor" href="#查看所有支持的-action" aria-hidden="true">#</a> 查看所有支持的 action</h2><div class="language-bash ext-sh line-numbers-mode"><pre class="language-bash"><code>$ profiler actions
Supported Actions: <span class="token punctuation">[</span>resume, dumpCollapsed, getSamples, start, list, version, execute, meminfo, stop, load, dumpFlat, dump, actions, dumpTraces, status, check<span class="token punctuation">]</span>
3 years ago
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="查看版本" tabindex="-1"><a class="header-anchor" href="#查看版本" aria-hidden="true">#</a> 查看版本</h2><div class="language-bash ext-sh line-numbers-mode"><pre class="language-bash"><code>$ profiler version
Async-profiler <span class="token number">2.9</span> built on May <span class="token number">8</span> <span class="token number">2023</span>
Copyright <span class="token number">2016</span>-2021 Andrei Pangin
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="配置-java-栈深度" tabindex="-1"><a class="header-anchor" href="#配置-java-栈深度" aria-hidden="true">#</a> 配置 Java 栈深度</h2><p>可以使用 <code>-j</code><code>--jstackdepth</code> 选项指定最大 Java 栈深度。如果指定值大于默认值 2048该选项会被忽略。当你不希望看到特别深的栈轨迹的时候这个选项会很有用以下是一个使用样例</p><div class="language-bash ext-sh line-numbers-mode"><pre class="language-bash"><code>profiler start <span class="token parameter variable">-j</span> <span class="token number">256</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><h2 id="各线程分别进行-profiling" tabindex="-1"><a class="header-anchor" href="#各线程分别进行-profiling" aria-hidden="true">#</a> 各线程分别进行 profiling</h2><p>可以使用 <code>-t</code><code>--threads</code> 标志选项令 profiling 对各线程分别进行,每个栈轨迹都会以指示单个线程的帧结束。</p><div class="language-bash ext-sh line-numbers-mode"><pre class="language-bash"><code>profiler start <span class="token parameter variable">-t</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><h2 id="配置-include-exclude-来过滤数据" tabindex="-1"><a class="header-anchor" href="#配置-include-exclude-来过滤数据" aria-hidden="true">#</a> 配置 include/exclude 来过滤数据</h2><p>如果应用比较复杂,生成的内容很多,想只关注部分 stack traces可以通过 <code>--include/--exclude</code> 过滤 stack traces<code>--include</code> 表示定义的匹配表达式必须出现在 stack traces相反 <code>--exclude</code> 表示定义的匹配表达式一定不会出现在 stack traces。 匹配表达式可以以<code>*</code>开始或者结束,<code>*</code> 表示任何(可能为空)字符序列。 比如</p><div class="language-bash ext-sh line-numbers-mode"><pre class="language-bash"><code>profiler stop <span class="token parameter variable">--include</span> <span class="token string">&#39;java/*&#39;</span> <span class="token parameter variable">--include</span> <span class="token string">&#39;com/demo/*&#39;</span> <span class="token parameter variable">--exclude</span> <span class="token string">&#39;*Unsafe.park*&#39;</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><blockquote><p><code>--include/--exclude</code> 都支持多次设置,但是需要配置在命令行的最后。也可使用短参数格式 <code>-I/-X</code>。 注意<code>--include/--exclude</code>只支持在<code>stop</code>action或者带有<code>-d</code>/<code>--duration</code>参数的<code>start</code>action中指定否则不生效。</p></blockquote><h2 id="指定执行时间" tabindex="-1"><a class="header-anchor" href="#指定执行时间" aria-hidden="true">#</a> 指定执行时间</h2><p>比如,希望 profiler 执行 300 秒自动结束,可以用 <code>-d</code>/<code>--duration</code> 参数为 collect action 指定时间:</p><div class="language-bash ext-sh line-numbers-mode"><pre class="language-bash"><code>profiler collect <span class="token parameter variable">--duration</span> <span class="token number">300</span>
3 years ago
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><h2 id="生成-jfr-格式结果" tabindex="-1"><a class="header-anchor" href="#生成-jfr-格式结果" aria-hidden="true">#</a> 生成 jfr 格式结果</h2><blockquote><p>注意jfr 只支持在 <code>start</code>时配置。如果是在<code>stop</code>时指定,则不会生效。</p></blockquote><div class="language-text ext-text line-numbers-mode"><pre class="language-text"><code>profiler start --file /tmp/test.jfr
profiler start -o jfr
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div></div></div><p><code>file</code>参数支持一些变量:</p><ul><li>时间戳: <code>--file /tmp/test-%t.jfr</code></li><li>进程 ID <code>--file /tmp/test-%p.jfr</code></li></ul><p>生成的结果可以用支持 jfr 格式的工具来查看。比如:</p><ul><li>JDK Mission Control https://github.com/openjdk/jmc</li><li>JProfiler https://github.com/alibaba/arthas/issues/1416</li></ul><h2 id="控制分析结果的格式" tabindex="-1"><a class="header-anchor" href="#控制分析结果的格式" aria-hidden="true">#</a> 控制分析结果的格式</h2><p>使用 <code>-s</code> 选项将结果中的 Fully qualified name 替换为简单名称,如 <code>demo.MathGame.main</code> 替换为 <code>MathGame.main</code>。使用 <code>-g</code> 选项指定输出方法签名,如 <code>demo.MathGame.main</code> 替换为 <code>demo.MathGame.main([Ljava/lang/String;)V</code>。此外还有许多可调整分析结果格式的选项,可参考 <a href="https://github.com/async-profiler/async-profiler#readme" target="_blank" rel="noopener noreferrer">async-profiler 的 README 文档<span><svg class="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"><path fill="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><polygon fill="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><span class="external-link-icon-sr-only">在新窗口打开</span></span></a> 以及 <a href="https://github.com/async-profiler/async-profiler/discussions" target="_blank" rel="noopener noreferrer">async-profiler 的 Github Discussions<span><svg class="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"><path fill="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><polygon fill="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><span class="external-link-icon-sr-only">在新窗口打开</span></span></a> 等材料。</p><p>例如,以下命令中,<code>-s</code> 将输出中的类名称指定为简短格式,<code>-g</code> 显示方法的完整签名,<code>-a</code> 标注出 Java 方法,<code>-l</code> 为原生方法增加库名称,<code>--title</code> 为生成火焰图页面指定标题,<code>--minwidth</code> 将过滤火焰图中宽度为 15% 以下的帧,<code>--reverse</code> 将火焰图倒置。</p><div class="language-text ext-text line-numbers-mode"><pre class="language-text"><code>profiler stop -s -g -a -l --title &lt;flametitle&gt; --minwidth 15 --reverse
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><h2 id="生成的火焰图里的-unknown" tabindex="-1"><a class="header-anchor" href="#生成的火焰图里的-unknown" aria-hidden="true">#</a> 生成的火焰图里的 unknown</h2><ul><li>https://github.com/jvm-profiling-tools/async-profiler/discussions/409</li></ul><h2 id="配置-locks-allocations-模式的阈值" tabindex="-1"><a class="header-anchor" href="#配置-locks-allocations-模式的阈值" aria-hidden="true">#</a> 配置 locks/allocations 模式的阈值</h2><p>当使用 lock 或 alloc event 进行 profiling 时,可以使用 <code>--lock</code><code>--alloc</code> 配置阈值,比如下列命令:</p><div class="language-bash ext-sh line-numbers-mode"><pre class="language-bash"><code>profiler start <span class="token parameter variable">-e</span> lock <span class="token parameter variable">--lock</span> 10ms
profiler start <span class="token parameter variable">-e</span> alloc <span class="token parameter variable">--alloc</span> 2m
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div></div></div><p>会记录竞争时间超过 10ms 的锁(如果不指定时间单位,则使用 ns 为单位),或者以 2MB 的单位记录对内存的分配。</p><h2 id="配置-jfr-块" tabindex="-1"><a class="header-anchor" href="#配置-jfr-块" aria-hidden="true">#</a> 配置 JFR 块</h2><p>当使用 JFR 作为输出格式时,可以使用 <code>--chunksize</code><code>--chunktime</code> 配置单个 JFR 块的大致容量(以 byte 为单位,默认 100 MB和时间限制默认值为 1 小时),比如:</p><div class="language-bash ext-sh line-numbers-mode"><pre class="language-bash"><code>profiler start <span class="token parameter variable">-f</span> profile.jfr <span class="token parameter variable">--chunksize</span> 100m <span class="token parameter variable">--chunktime</span> 1h
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><h2 id="将线程按照调度策略分组" tabindex="-1"><a class="header-anchor" href="#将线程按照调度策略分组" aria-hidden="true">#</a> 将线程按照调度策略分组</h2><p>可以使用 <code>--sched</code> 标志选项将输出结果按照 Linux 线程调度策略分组,策略包括 BATCH/IDLE/OTHER。例如</p><div class="language-bash ext-sh line-numbers-mode"><pre class="language-bash"><code>profiler start <span class="token parameter variable">--sched</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>火焰图的倒数第二行会标记不同的调度策略。</p><h2 id="仅用未销毁对象构建内存分析结果" tabindex="-1"><a class="header-anchor" href="#仅用未销毁对象构建内存分析结果" aria-hidden="true">#</a> 仅用未销毁对象构建内存分析结果</h2><p>使用 <code>--live</code> 标志选项在内存分析结果中仅保留那些在分析过程结束时仍未被 JVM 回收的对象。该选项在排查 Java 堆内存泄露问题时比较有用。</p><div class="language-bash ext-sh line-numbers-mode"><pre class="language-bash"><code>profiler start <span class="token parameter variable">--live</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><h2 id="配置收集-c-栈帧的方法" tabindex="-1"><a class="header-anchor" href="#配置收集-c-栈帧的方法" aria-hidden="true">#</a> 配置收集 C 栈帧的方法</h2><p>使用 <code>--cstack MODE</code> 配置收集 native 帧的方法。候选模式有 fp (Frame Pointer), dwarf (DWARF unwind info), lbr (Last Branch Record, 从 Linux 4.1 在 Haswell 可用), and no (不收集 native 栈帧).</p><p>默认情况下C 栈帧会出现在 cpu、itimer、wall-clock、perf-events 模式中,而 Java 级别的 event 比如 alloc 和 lock 只收集 Java stack。</p><div class="language-bash ext-sh line-numbers-mode"><pre class="language-bash"><code>profiler <span class="token parameter variable">--cstack</span> fp
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>此命令将收集 native 栈帧的 Frame Pointer 信息。</p><h2 id="当指定-native-函数执行时开始-停止-profiling" tabindex="-1"><a class="header-anchor" href="#当指定-native-函数执行时开始-停止-profiling" aria-hidden="true">#</a> 当指定 native 函数执行时开始/停止 profiling</h2><p>使用 <code>--begin function</code><code>--end function</code> 选项在指定 native 函数被执行时让 profiling 过程启动或终止。主要用途是分析特定的 JVM 阶段,比如 GC 和安全点。需要使用特定 JVM 实现中的 native 函数名,比如 HotSpot JVM 中的 <code>SafepointSynchronize::begin</code><code>SafepointSynchronize::end</code></p><h3 id="time-to-safepoint-profiling" tabindex="-1"><a class="header-anchor" href="#time-to-safepoint-profiling" aria-hidden="true">#</a> Time-to-safepoint profiling</h3><p>选项 <code>--ttsp</code> 实际上是 <code>--begin SafepointSynchronize::begin --end RuntimeService::record_safepoint_synchronized</code> 的一个别名。它是一种约束而不是独立的 event 类型。无论选择哪种 eventprofiler 都可以正常工作,但只有 VM 操作和 safepoint request 之间的事件会被记录下来。</p><div class="language-bash ext-sh line-numbers-mode"><pre class="language-bash"><code>profiler start <span class="token parameter variable">--begin</span> SafepointSynchronize::begin <span class="token parameter variable">--end</span> RuntimeService::record_safepoint_synchronized
profiler <span class="token parameter variable">--ttsp</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="使用-profiler-记录的-event-生成-jfr-文件" tabindex="-1"><a class="header-anchor" href="#使用-profiler-记录的-event-生成-jfr-文件" aria-hidden="true">#</a> 使用 profiler 记录的 event 生成 JFR 文件</h2><p><code>--jfrsync CONFIG</code> 选项可以指定配置启动 Java Flight Recording输出的 jfr 文件会包含所有常规的 JFR event但采样的来源是由 profiler 提供的。</p><p><code>CONFIG</code> 选项可以是 <code>profile</code>,表示使用在 <code>$JAVA_HOME/lib/jfr</code> 目录下预置的“profile”配置也可以是自定义的 JFR 配置文件(.jfc此选项的值采用与 <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/jcmd.html" target="_blank" rel="noopener noreferrer">JFR.start 命令的 settings 选项<span><svg class="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"><path fill="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><polygon fill="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><span class="external-link-icon-sr-only">在新窗口打开</span></span></a> 相同的格式。</p><p>比如以下命令使用“profile”配置启动 JFR</p><div class="language-bash ext-sh line-numbers-mode"><pre class="language-bash"><code>profiler start <span class="token parameter variable">-e</span> cpu <span class="token parameter variable">--jfrsync</span> profile <span class="token parameter variable">-f</span> combined.jfr
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><h2 id="周期性保存结果" tabindex="-1"><a class="header-anchor" href="#周期性保存结果" aria-hidden="true">#</a> 周期性保存结果</h2><p>使用 <code>--loop TIME</code> 可以持续运行 profiler 并周期性保存结果。选项格式可以是具体时间 hh:mm:ss 或以秒、分钟、小时或天计算的时间间隔。需要确保指定的输出文件名中包含时间戳,否则每次输出的结果都会覆盖上次保存的结果。以下命令持续执行 profiling 并将每个小时内的记录保存到一个 jfr 文件中。</p><div class="language-bash ext-sh line-numbers-mode"><pre class="language-bash"><code>profiler start <span class="token parameter variable">--loop</span> 1h <span class="token parameter variable">-f</span> /var/log/profile-%t.jfr
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><h2 id="timeout-选项" tabindex="-1"><a class="header-anchor" href="#timeout-选项" aria-hidden="true">#</a> <code>--timeout</code> 选项</h2><p>这个选项指定 profiling 自动在多久后停止。该选项和 <code>--loop</code> 选项的格式一致,可以是时间点,也可以是一个时间间隔。这两个选项都是用于 <code>start</code> action 而不是 <code>collect</code> action 的。可参考 <a href="https://github.com/async-profiler/async-profiler/discussions/789" target="_blank" rel="noopener noreferrer">async-profiler Github Discussions<span><svg class="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"><path fill="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><polygon fill="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><span class="external-link-icon-sr-only">在新窗口打开</span></span></a> 了解更多信息。</p></div><!--[--><!--]--></div><footer class="page-meta right-menu-padding" data-v-fdd717e0><div class="meta-item edit-link"><a class="external-link meta-item-label" href="https://github.com/alibaba/arthas/edit/master/site/docs/doc/profiler.md" rel="noopener noreferrer" target="_blank" aria-label="在 GitHub 上编辑此页"><!--[--><!--]--><span>在 GitHub 上编辑此页</span><span><svg class="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"><path fill="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><polygon fill="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><span class="external-link-icon-sr-only">在新窗口打开</span></span><!--[--><!--]--></a></div><div class="meta-item last-updated"><span class="meta-item-label">Last Updated: </span><!----></div><div class="meta-item contributors"><span class="meta-item-label">贡献者: </span><span class="meta-item-info"><!--[--><!--[--><span class="contributor" title="email: wenchenghuang@mail.bnu.edu.cn">Winson Huang</span><!--[-->, <!--]--><!--]--><!--[--><span class="contributor" title="email: hengyunabc@gmail.com">hengyunabc</span><!--[-->, <!--]--><!--]--><!--[--><span class="contributor" title="email: hengyunabc@users.noreply.github.com">hengyunabc</span><!--[-->, <!--]--><!--]--><!--[--><span class="contributor" title="email: 68638598+Allan-QLB@users.noreply.github.com">Allan-QLB</span><!--[-->, <!--]--><!--]--><!--[--><span class="contributor" title="email: i@fatpandac.com">Fatpandac</span><!--[-->, <!--]--><!--]--><!--[--><span class="contributor" title="email: 983433479@qq.com">汪吉</span><!--[-->, <!--]--><!--]--><!--[--><span class="contributor" title="email: hollowman186@vip.qq.com">Hollow Man</span><!----><!--]--><!--]--></span></div></footer><nav class="page-nav right-menu-padding" data-v-fdd717e0><p class="inner"><span class="prev"><a href="/doc/perfcounter.html" class="" aria-label="perfcounter"><!--[--><!--]--> perfcounter <!--[--><!--]--></a></span><span class="next"><a href="/doc/pwd.html" class="" aria-label="pwd"><!--[--><!--]--> pwd <!--[--><!--]--></a></span></p></nav><!--[--><!--]--></main><!--]--></div><!----><!--]--></div>
<script type="module" src="/assets/app.977e81c1.js" defer></script>
</body>
</html>