import{_ as n,a as r}from"./arthas-output-svg.39442da8.js";import{_ as l,o,c as d,a as e,b as t,e as s,d as i,r as c}from"./app.6c27e557.js";const u={},p=e("h1",{id:"profiler",tabindex:"-1"},[e("a",{class:"header-anchor",href:"#profiler","aria-hidden":"true"},"#"),s(" profiler")],-1),h={href:"https://arthas.aliyun.com/doc/arthas-tutorials.html?language=en&id=command-profiler",target:"_blank",rel:"noopener noreferrer"},m=e("code",null,"profiler",-1),f=s(" online tutorial"),v={class:"custom-container tip"},b=e("p",{class:"custom-container-title"},"TIP",-1),g=s("Generate a flame graph using "),x={href:"https://github.com/jvm-profiling-tools/async-profiler",target:"_blank",rel:"noopener noreferrer"},_=s("async-profiler"),y=i(`
The profiler
command supports generate flame graph for application hotspots.
The basic usage of the profiler
command is profiler action [actionArg]
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
. Can be specified with the --event
parameter.
$ profiler getSamples
23
$ profiler status
[cpu] profiling is running for 4 seconds
Can view which event
and sampling time.
By default, the result file is html
format. You can also specify it with the --format
parameter:
$ profiler stop --format html
profiler output file: /tmp/test/arthas-output/20211207-111550.html
OK
Or use the file name name format in the --file
parameter. For example, --file /tmp/result.html
.
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
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
You can use the --event
parameter to specify the event to sample, such as sampling the alloc
event:
$ profiler start --event alloc
$ profiler resume
Started [cpu] profiling
The difference between start
and resume
is: start
is the new start sampling, resume
will retain the data of the last stop
.
You can verify the number of samples by executing profiler getSamples
.
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, execute, version, stop, load, dumpFlat, actions, dumpTraces, status]
$ profiler version
Async-profiler 1.6 built on Sep 9 2019
Copyright 2019 Andrei Pangin
TIP
you encounter [frame_buffer_overflow]
in the generated result, you need to increase the framebuf (the default value is 1'000'000), which can be configured explicitly, such as:
profiler start --framebuf 5000000
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
profiler start --include'java/*' --include'demo/*' --exclude'*Unsafe.park*'
Both include/exclude support setting multiple values, but need to be configured at the end of the command line.
For example, if you want the profiler to automatically end after 300 seconds, you can specify it with the -d
/--duration
parameter:
profiler start --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
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: