profiler online tutorial

Generate a flame graph using async-profiler

The profiler command supports generate flame graph for application hotspots.

The basic usage of the profiler command is profiler action [actionArg]

Supported Options

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

Start profiler

$ profiler start
Started [cpu] profiling

By default, the sample event is cpu. Can be specified with the --event parameter.

Get the number of samples collected

$ profiler getSamples

View profiler status

$ profiler status
[cpu] profiling is running for 4 seconds

Can view which event and sampling time.

Stop profiler

Generating html format results

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

Or use the file name name format in the --file parameter. For example, --file /tmp/result.html.

View profiler results under arthas-output via browser

By default, arthas uses port 3658, which can be opened: http://localhost:3658/arthas-output/ View the arthas-output directory below Profiler results:


Click to view specific results:


If using the chrome browser, may need to be refreshed multiple times.

Profiler supported events

Under different platforms and different OSs, the supported events are different. For example, under macos:

$ profiler list
Basic events:

Under linux

$ profiler list
Basic events:
Perf events:

If you encounter the permissions/configuration issues of the OS itself and then missing some events, you can refer to the async-profiler documentation.

You can use the --event parameter to specify the event to sample, such as sampling the alloc event:

$ profiler start --event alloc

Resume sampling

$ 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.

Use execute action to execute complex commands

For example, start sampling:

profiler execute 'start,framebuf=5000000'

Stop sampling and save to the specified file:

profiler execute 'stop,file=/tmp/result.html'

Specific format reference: arguments.cpp

View all supported actions

$ profiler actions
Supported Actions: [resume, dumpCollapsed, getSamples, start, list, execute, version, stop, load, dumpFlat, actions, dumpTraces, status]

View version

$ profiler version
Async-profiler 1.6 built on Sep  9 2019
Copyright 2019 Andrei Pangin

Configure framebuf option

If 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

Configure include/exclude to filter data

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.

Specify execution time

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

Generate jfr format result

Note that jfr only supports configuration at start. If it is specified at stop, it will not take effect.

profiler start --file /tmp/test.jfr

The file parameter supports some variables:

  • Timestamp: --file /tmp/test-%t.jfr

  • Process ID: --file /tmp/test-%p.jfr

The generated results can be viewed with tools that support the jfr format. such as:

  • JDK Mission Control:

  • JProfiler:

The ‘unknown’ in profiler result