import{_ as t,a as o}from"./arthas-output-svg.30f64f53.js";import{_ as r,o as l,c as d,a,b as i,e,d as n,r as c}from"./app.977e81c1.js";const p={},h=a("h1",{id:"profiler",tabindex:"-1"},[a("a",{class:"header-anchor",href:"#profiler","aria-hidden":"true"},"#"),e(" profiler")],-1),u={href:"https://arthas.aliyun.com/doc/arthas-tutorials.html?language=en&id=command-profiler",target:"_blank",rel:"noopener noreferrer"},m=a("code",null,"profiler",-1),f=e(" online tutorial"),v={class:"custom-container tip"},b=a("p",{class:"custom-container-title"},"TIP",-1),g=e("Generate a flame graph using "),_={href:"https://github.com/jvm-profiling-tools/async-profiler",target:"_blank",rel:"noopener noreferrer"},x=e("async-profiler"),y=a("p",null,[e("The "),a("code",null,"profiler"),e(" command supports generating flame graph for application hotspots.")],-1),k=a("p",null,[e("The basic usage of the "),a("code",null,"profiler"),e(" command is "),a("code",null,"profiler action [actionArg]")],-1),w=e("The arguments of "),j=a("code",null,"profiler",-1),T=e(" command basically keeps consistent with upstream project "),S={href:"https://github.com/async-profiler/async-profiler",target:"_blank",rel:"noopener noreferrer"},F=e("async-profiler"),C=e(", you can refer to its README, Github Discussions and other documentations for further information of usage."),B=n(`
Name | Specification |
---|---|
action | Action to execute |
actionArg | Attribute name pattern |
[i:] | sampling interval in ns (default: 10'000'000, i.e. 10 ms) |
[f:] | dump output to specified directory |
[d:] | run profiling for specified seconds |
[e:] | which event to trace (cpu, alloc, lock, cache-misses etc.), default value is cpu |
$ profiler start
Started [cpu] profiling
TIP
By default, the sample event is cpu
. Other valid profiling modes can be specified with the --event
parameter, see relevant contents below.
$ profiler getSamples
23
$ profiler status
[cpu] profiling is running for 4 seconds
Can view which event
and sampling time.
$ profiler meminfo
Call trace storage: 10244 KB
Dictionaries: 72 KB
Code cache: 12890 KB
------------------------------
Total: 23206 KB
$ profiler stop --format flamegraph
profiler output file: /tmp/test/arthas-output/20211207-111550.html
OK
When extension of filename in --file
parameter is html
or jfr
, the output format can be infered. For example, --file /tmp/result.html
will generate flamegraph automatically.
Click to view specific results:
TIP
If using the chrome browser, may need to be refreshed multiple times.
Under different platforms and different OSs, the supported events are different. For example, under macos:
$ profiler list
Basic events:
cpu
alloc
lock
wall
itimer
Under linux
$ 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
You can use check
action to check if a profiling event is available, this action receives the same format options with start
.
You can use the --event
parameter to specify the event to sample, for example, alloc
event means heap memory allocation profiling:
$ profiler start --event alloc
$ profiler resume
Started [cpu] profiling
The difference between start
and resume
is: start
will clean existing result of last profiling before starting, resume
will retain the existing result and add result of this time to it.
You can verify the number of samples by executing profiler getSamples
.
$ profiler dump
OK
The dump
action saves profiling result to default file or specified file, but profiling will continue. That means if you start profiling and dump after 5 seconds, then dump after 2 seconds again, you will get 2 result files, the first one contains profiling result of 0~5 seconds and the second one contains that of 0~7 seconds.
execute
action to execute complex commandsFor example, start sampling:
profiler execute 'start,framebuf=5000000'
Stop sampling and save to the specified file:
profiler execute 'stop,file=/tmp/result.html'
$ profiler actions
Supported Actions: [resume, dumpCollapsed, getSamples, start, list, version, execute, meminfo, stop, load, dumpFlat, dump, actions, dumpTraces, status, check]
$ profiler version
Async-profiler 2.9 built on May 8 2023
Copyright 2016-2021 Andrei Pangin
You can use -j
or --jstackdepth
option to configure maximum Java stack depth. This option will be ignored if value is greater than default 2048. This option is useful when you don't want to see stacks that are too deep. Below is usage example:
profiler start -j 256
You can use -t
or --threads
flag option to profile different threads separately, each stack trace will end with a frame that denotes a single thread.
profiler start -t
If the application is complex and generates a lot of content, and you want to focus on only part of stack traces, you can filter stack traces by --include/--exclude
. --include
defines the name pattern that must be present in the stack traces, while --exclude
is the pattern that must not occur in any of stack traces in the output.A pattern may begin or end with a star *
that denotes any (possibly empty) sequence of characters. such as
profiler stop --include'java/*' --include 'com/demo/*' --exclude'*Unsafe.park*'
Both
--include/--exclude
support being set multiple times, but need to be configured at the end of the command line. You can also use short parameter format-I/-X
. Note that--include/--exclude
only supports configuration atstop
action orstart
action with-d
/--duration
parameter, otherwise it will not take effect.
For example, if you want the profiler to automatically end after 300 seconds, you can specify it with the -d
/--duration
parameter in collect action:
profiler collect --duration 300
Note that jfr only supports configuration at
start
. If it is specified atstop
, it will not take effect.
profiler start --file /tmp/test.jfr
profiler start -o jfr
The file
parameter supports some variables:
--file /tmp/test-%t.jfr
--file /tmp/test-%p.jfr
The generated results can be viewed with tools that support the jfr format. such as:
For example, in command below, -s
use simple name for Java class, -g
show method signatures, -a
will annotate Java methods, -l
will prepend library names for native method, --title
specify a title for flame graph page, --minwidth
will skip frames smaller than 15% in flame graph, --reverse
will generate stack-reversed FlameGraph / Call tree.
profiler stop -s -g -a -l --title <flametitle> --minwidth 15 --reverse
When profiling in locks or allocations event, you can use --lock
or --alloc
to config thresholds, for example:
profiler start -e lock --lock 10ms
profiler start -e alloc --alloc 2m
will profile contended locks longer than 10ms (default unit is ns if no unit is specified), or profile allocations with 2m BYTES interval.
When using JFR as output format, you can use --chunksize
or --chunktime
to config approximate size (in bytes, default value is 100MB) and time limits (default value is 1 hour) for a single JFR chunk. For example:
profiler start -f profile.jfr --chunksize 100m --chunktime 1h
You can use --sched
flag option to group threads in output by Linux-specific scheduling policy: BATCH/IDLE/OTHER, for example:
profiler start --sched
The second line from bottom in flamegraph represent the scheduling policy.
Use --live
flag option to retain allocation samples with live objects only (object that have not been collected by the end of profiling session). Useful for finding Java heap memory leaks.
profiler start --live
Use --cstack MODE
to config how to walk native frames (C stack). Possible modes are fp (Frame Pointer), dwarf (DWARF unwind info), lbr (Last Branch Record, available on Haswell since Linux 4.1), and no (do not collect C stack).
By default, C stack is shown in cpu, itimer, wall-clock and perf-events profiles. Java-level events like alloc and lock collect only Java stack.
profiler --cstack fp
The command above will collection Frame Pointer of C stacks.
Use --begin function
and --end function
to automatically start/stop profiling when the specified native function is executed. Its main purpose is to profile certain JVM phases like GC and Safepoint pauses. You should use native function name defined in a JVM implement, for example SafepointSynchronize::begin
and SafepointSynchronize::end
in HotSpot JVM.
The --ttsp
option is an alias for --begin SafepointSynchronize::begin --end RuntimeService::record_safepoint_synchronized
. It is not a separate event type, but rather a constraint. Whatever event type you choose (e.g. cpu or wall), the profiler will work as usual, except that only events between the safepoint request and the start of the VM operation will be recorded.
profiler start --begin SafepointSynchronize::begin --end RuntimeService::record_safepoint_synchronized
profiler --ttsp
Use --jfrsync CONFIG
to start Java Flight Recording with the given configuration synchronously with the profiler. The output .jfr file will include all regular JFR events, except that execution samples will be obtained from async-profiler. This option implies -o jfr.
For example, command below use "profile" config of JFR:
profiler start -e cpu --jfrsync profile -f combined.jfr
Use --loop TIME
to run profiler in a loop (continuous profiling). The argument is either a clock time (hh:mm:ss) or a loop duration in seconds, minutes, hours, or days. Make sure the filename includes a timestamp pattern, or the output will be overwritten on each iteration. The command below will run profiling endlessly and save records of each hour to a jfr file.
profiler start --loop 1h -f /var/log/profile-%t.jfr
--timeout
optionThis option specifies the time when profiling will automatically stop. The format is the same as in loop: it is either a wall clock time (12:34:56) or a relative time interval (2h).
`,7),Ie=e("Both "),Me=a("code",null,"--loop",-1),Ne=e(" and "),Ve=a("code",null,"--timeout",-1),Ae=e(" are used for "),Ee=a("code",null,"start",-1),Pe=e(" action but not for "),$e=a("code",null,"collect",-1),De=e(" action, for further information refer to "),Le={href:"https://github.com/async-profiler/async-profiler/discussions/789",target:"_blank",rel:"noopener noreferrer"},Oe=e("async-profiler Github Discussions"),Ue=e(".");function Ye(qe,ze){const s=c("ExternalLinkIcon");return l(),d("div",null,[h,a("p",null,[a("a",u,[m,f,i(s)])]),a("div",v,[b,a("p",null,[g,a("a",_,[x,i(s)])])]),y,k,a("p",null,[w,j,T,a("a",S,[F,i(s)]),C]),B,a("p",null,[J,G,R,a("a",I,[M,i(s)]),N,V,A,E,P]),$,a("p",null,[D,a("a",L,[O,i(s)]),U,Y,q]),z,a("p",null,[K,a("a",H,[W,i(s)]),X]),Q,a("p",null,[Z,a("a",ee,[ae,i(s)])]),se,a("p",null,[ie,ne,te,oe,re,le,de,ce,pe,he,ue,me,fe,a("a",ve,[be,i(s)]),ge,a("a",_e,[xe,i(s)]),ye]),ke,a("p",null,[we,je,Te,Se,Fe,Ce,a("a",Be,[Je,i(s)]),Ge]),Re,a("p",null,[Ie,Me,Ne,Ve,Ae,Ee,Pe,$e,De,a("a",Le,[Oe,i(s)]),Ue])])}const We=r(p,[["render",Ye],["__file","profiler.html.vue"]]);export{We as default};