mirror of https://github.com/alibaba/arthas.git
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.
219 lines
5.7 KiB
Markdown
219 lines
5.7 KiB
Markdown
3 years ago
|
# profiler
|
||
5 years ago
|
|
||
5 years ago
|
[`profiler` online tutorial](https://arthas.aliyun.com/doc/arthas-tutorials.html?language=en&id=command-profiler)
|
||
|
|
||
3 years ago
|
::: tip
|
||
|
Generate a flame graph using [async-profiler](https://github.com/jvm-profiling-tools/async-profiler)
|
||
|
:::
|
||
5 years ago
|
|
||
|
The `profiler` command supports generate flame graph for application hotspots.
|
||
|
|
||
|
The basic usage of the `profiler` command is `profiler action [actionArg]`
|
||
|
|
||
5 years ago
|
### Supported Options
|
||
|
|
||
3 years ago
|
| 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 |
|
||
5 years ago
|
|
||
5 years ago
|
### Start profiler
|
||
|
|
||
|
```
|
||
|
$ profiler start
|
||
|
Started [cpu] profiling
|
||
|
```
|
||
|
|
||
3 years ago
|
::: tip
|
||
|
By default, the sample event is `cpu`. Can be specified with the `--event` parameter.
|
||
|
:::
|
||
5 years ago
|
|
||
|
### Get the number of samples collected
|
||
|
|
||
|
```
|
||
|
$ profiler getSamples
|
||
|
23
|
||
|
```
|
||
|
|
||
|
### View profiler status
|
||
|
|
||
|
```bash
|
||
|
$ profiler status
|
||
|
[cpu] profiling is running for 4 seconds
|
||
|
```
|
||
|
|
||
|
Can view which `event` and sampling time.
|
||
|
|
||
|
### Stop profiler
|
||
|
|
||
|
#### Generating html format results
|
||
|
|
||
3 years ago
|
By default, the result file is `html` format. You can also specify it with the `--format` parameter:
|
||
5 years ago
|
|
||
|
```bash
|
||
|
$ profiler stop --format html
|
||
3 years ago
|
profiler output file: /tmp/test/arthas-output/20211207-111550.html
|
||
5 years ago
|
OK
|
||
|
```
|
||
|
|
||
|
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/](http://localhost:3658/arthas-output/) View the `arthas-output` directory below Profiler results:
|
||
|
|
||
3 years ago
|

|
||
5 years ago
|
|
||
|
Click to view specific results:
|
||
|
|
||
3 years ago
|

|
||
5 years ago
|
|
||
3 years ago
|
::: tip
|
||
|
If using the chrome browser, may need to be refreshed multiple times.
|
||
|
:::
|
||
5 years ago
|
|
||
|
### Profiler supported events
|
||
|
|
||
|
Under different platforms and different OSs, the supported events are different. For example, under macos:
|
||
|
|
||
|
```bash
|
||
|
$ profiler list
|
||
|
Basic events:
|
||
|
cpu
|
||
|
alloc
|
||
|
lock
|
||
|
wall
|
||
|
itimer
|
||
|
```
|
||
|
|
||
|
Under linux
|
||
|
|
||
|
```bash
|
||
|
$ 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
|
||
|
```
|
||
|
|
||
|
If you encounter the permissions/configuration issues of the OS itself and then missing some events, you can refer to the [async-profiler](https://github.com/jvm-profiling-tools/async-profiler) documentation.
|
||
|
|
||
|
You can use the `--event` parameter to specify the event to sample, such as sampling the `alloc` event:
|
||
|
|
||
|
```bash
|
||
|
$ profiler start --event alloc
|
||
|
```
|
||
|
|
||
|
### Resume sampling
|
||
|
|
||
|
```bash
|
||
|
$ 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
|
||
|
|
||
3 years ago
|
For example, start sampling:
|
||
5 years ago
|
|
||
|
```bash
|
||
5 years ago
|
profiler execute 'start,framebuf=5000000'
|
||
5 years ago
|
```
|
||
|
|
||
|
Stop sampling and save to the specified file:
|
||
|
|
||
|
```bash
|
||
3 years ago
|
profiler execute 'stop,file=/tmp/result.html'
|
||
5 years ago
|
```
|
||
|
|
||
3 years ago
|
Specific format reference: [arguments.cpp](https://github.com/jvm-profiling-tools/async-profiler/blob/v2.5/src/arguments.cpp#L50)
|
||
5 years ago
|
|
||
|
### View all supported actions
|
||
|
|
||
|
```bash
|
||
|
$ profiler actions
|
||
|
Supported Actions: [resume, dumpCollapsed, getSamples, start, list, execute, version, stop, load, dumpFlat, actions, dumpTraces, status]
|
||
|
```
|
||
|
|
||
|
### View version
|
||
|
|
||
|
```bash
|
||
|
$ profiler version
|
||
|
Async-profiler 1.6 built on Sep 9 2019
|
||
|
Copyright 2019 Andrei Pangin
|
||
|
```
|
||
5 years ago
|
|
||
|
### Configure framebuf option
|
||
|
|
||
3 years ago
|
::: 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:
|
||
|
:::
|
||
5 years ago
|
|
||
|
```bash
|
||
|
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
|
||
|
|
||
|
```bash
|
||
|
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:
|
||
|
|
||
|
```bash
|
||
|
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:
|
||
|
|
||
3 years ago
|
- Timestamp: `--file /tmp/test-%t.jfr`
|
||
|
- Process ID: `--file /tmp/test-%p.jfr`
|
||
5 years ago
|
|
||
|
The generated results can be viewed with tools that support the jfr format. such as:
|
||
|
|
||
3 years ago
|
- JDK Mission Control: https://github.com/openjdk/jmc
|
||
|
- JProfiler: https://github.com/alibaba/arthas/issues/1416
|
||
4 years ago
|
|
||
|
### The 'unknown' in profiler result
|
||
|
|
||
3 years ago
|
- https://github.com/jvm-profiling-tools/async-profiler/discussions/409
|