Preparations

Updated at:

This topic describes the preparations required for analysis.

Step 1: Generate a data source

The Application Diagnostics and Analysis Platform (ATP) is a diagnostic analysis tool. You must prepare a data source before you can perform an analysis.

1. What is a data source?

The data source that you need depends on the application issue that you want to analyze.

Q: Is the garbage collection (GC) frequency too high? Is GC efficiency low? Does the application have issues such as OutOfMemoryError?

A: Generate a Java heap dump file.

Q: Is the CPU load too high? Does the application freeze? Are there too many threads?

A: Generate a Java stack file.

Q: Do you need to evaluate GC performance? Does the application experience long periods of stuttering?

A: Obtain the Java GC log file.

2. Generate a data source

2.1 Generate a Java dump file

A Java dump file is a heap dump file. You can generate it using one of the following methods.

Description

Command

Save the entire Java heap using the jmap command (Recommended)

jmap -dump:format=b,file=heap.bin <pid>

Save only the live objects in the Java heap using the jmap command

jmap -dump:live,format=b,file=heap.bin <pid>

Save the entire Java heap using the jcmd command

jcmd <pid> GC.heap_dump filename=heap.bin

Automatically generate when an OutOfMemoryError occurs (Recommended)

-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp/heap.bin

Automatically generate before or after a Full GC

-XX:+HeapDumpBeforeFullGC or -XX:+HeapDumpAfterFullGC

Generate programmatically

Use the HotSpotDiagnosticMXBean.dumpHeap() method

Generate using the official ATP client

https://github.com/aliyun/aliyun-atp-sdk

The -XX:+HeapDumpBeforeFullGC and -XX:+HeapDumpAfterFullGC parameters cause the JVM to automatically generate a Java heap dump file before and after a Full Garbage Collection (Full GC). This process can be time-consuming, so you should enable these parameters only when necessary:

jinfo -flag +HeapDumpBeforeFullGC <pid> # Enable HeapDumpBeforeFullGC
jinfo -flag -HeapDumpAfterFullGC <pid> # Disable HeapDumpAfterFullGC

2.2 Generate a Java stack file

You can generate a Java stack file using one of the following methods:

Description

Command

Generate using jstack (Recommended)

jstack <pid> > jstack.log

Generate using jcmd

jcmd 7662 Thread.print > jstack.log

Generate using the official ATP client

https://github.com/aliyun/aliyun-atp-sdk

2.3 Generate a Java GC log file

To generate a Java GC log file, you must enable GC logging by setting the appropriate JVM parameters at application startup. The recommended parameter settings are as follows:

# For Java 8 and earlier
-XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:<path>

# For Java 9 and later
-Xlog:gc*:<path>:time

For more information about other GC logging parameters, see the official Oracle documentation.

Note:

  1. These parameters write the GC log to the specified <path>. You must specify a path. If you do not, the GC log is written to stdout by default, which may prevent ATP from parsing it correctly.

  2. ATP currently supports only GC logs that are generated by JDK 8 and later. ATP supports only Serial GC, Parallel GC, Concurrent Mark Sweep (CMS) GC, Garbage-First (G1) GC, and Z Garbage Collector (ZGC).

Step 2: Upload the data source

After you generate the data source, you can upload it to ATP. First, select the appropriate analysis tool from the navigation pane on the left based on your data source type:

  • Java Heap Analysis

  • Java Thread Stack Analysis

  • Java GC Log Analysis

Then, click the Upload File button to upload the data source. ATP currently supports the following upload methods:

  • Upload by URL. For more information about how to generate a URL for an OSS file, see the OSS documentation.

  • Upload from OSS. This method requires authorization to access OSS files.

  • Upload by pasting text. This method supports only thread stack analysis and GC log analysis. The text must be smaller than 10 MB.

  • Upload a local file. This method supports only thread stack analysis and GC log analysis. The file must be smaller than 10 MB and have a *.log or *.txt extension.

Note: When you upload a file from OSS, the ATP platform downloads it. This action incurs data transfer fees. For more information, see OSS Billing.

Step 3: Start the analysis

After the data source is uploaded, click Analyze. When the analysis is complete, the results page opens automatically. You can then proceed with your analysis. For more information about how to analyze issues, see other documentation.