我要评分
获取效率
正确性
完整性
易理解

Hotspot Analysis Flame Graphs

When a performance bottleneck occurs in a Java program, you can use the command line tool to check the hotspot methods in the JVM and display the hotspot methods in flame graphs.

Command Function

Collects stack information about CPU, CYCLES, LOCK, CACHE_MISSES, and ALLOC events at certain points of time, collects statistics on hotspot methods in the current JVM, and displays the information in a flame graph and an inverted flame graph.

Processes in a container cannot be collected on the container host. To do so, use the command line tool in the container.

Syntax

1
devkit java-perf hotspot [-h] [-p {pid}] [-e {CPU,ALLOC,CYCLES,CACHE_MISSES,LOCK}] [-d <sec> ] [-i <milli>] [-o <path>]

Parameter Description

Table 1 Parameter description

Parameter

Option

Description

-h/--help

-

Obtains help information. This parameter is optional.

-p/--pid

-

PID of the Java process for which hotspot methods are collected. This parameter is optional.

-e/--event

CPU/ALLOC/CYCLES/CACHE_MISSES/LOCK

Sampling event type, which defaults to CPU. This parameter is optional.

  • CPU: collects data of CPU events.
  • ALLOC: collects memory allocation information in the Java heap.
  • CYCLES: collects CPU clock cycles.
  • CACHE_MISSES: collects the number of cache misses.
  • LOCK: collects lock contention information.

-d/--duration

-

Collection duration, which defaults to 20 seconds. The value ranges from 1 to 300 seconds. You can press Ctrl+C to stop the collection and start analysis. This parameter is optional.

-i/--interval

-

Sampling interval, which defaults to 10 ms. The value ranges from 1 ms to 1000 ms. This parameter is optional.

-o/--output

-

Report output directory. By default, reports are generated in the data subdirectory of the tool installation directory. This parameter is optional.

Example

1
devkit java-perf hotspot -p 17329 -e CPU -d 60 -i 10 -o /opt
  • -p: ID of the process whose information is collected.
  • -e CPU: collects data of CPU events.
  • -d 60: The collection duration is 60 seconds.
  • -i 10: The collection interval is 10 ms.
  • -o /opt: The report output directory is /opt.

Command output:

1
2
JAVA HOTSPOT ANALYSIS(Press Ctrl+C to exit and generate the summary report)
The flame graph is generated in /opt/FlameGraph_CPU(31819)_20240612_104433.html.

You can view the generated flame graph HTML file using your browser. Data retrieval and inverted flame graphs are supported.

Figure 1 Flame graph HTML file
Figure 2 Inverted flame graph
  • An inverted flame graph starts from the top of the stack and gradually traces back to the bottom of the stack. It aggregates the call stacks that have the same call method.
  • You can display the flame graph as needed: Click to flip the flame graph up and down. Click to restore the flame graph to its initial state; click to sort the flame graph data by function proportion (which is the default sorting method); click to sort the flame graph data by function name.