View a markdown version of this page

Tutorials: Profile Java applications - Amazon CloudWatch

Tutorials: Profile Java applications

Follow a tutorial to get started sending profiles from your applications to Amazon CloudWatch Profiles.

Each tutorial takes you from a Java application without profiling to flame graphs in CloudWatch. Both tutorials use the async-profiler that's embedded in the AWS Distro for OpenTelemetry (ADOT) Java agent, with the same profiling settings. With these settings, the profiler collects wall-clock profiles, which sample threads both on and off the CPU, and memory allocation profiles. The ADOT Java agent leaves memory profiling off by default. On Kubernetes, the add-on and the Helm chart turn on memory profiling for you. The Amazon EC2 tutorial turns it on explicitly. For more information about the ADOT Java agent settings that you can change, see Profile your application.

In these tutorials, your application sends profiles to the CloudWatch agent. The agent signs each request with AWS Signature Version 4 (SigV4) using its IAM role, such as the Amazon EC2 instance role or the node role. That role needs the cloudwatch:PutProfileRecords permission. The CloudWatchAgentServerPolicy managed policy on that role grants the permission. For more information about the required permissions, see IAM permissions required.

If you plan to read the profiles in CloudWatch Omni, see Recommended resource attributes for correlation for the resource attributes to set.

Choose your setup path

The following table compares the two tutorials. Choose the tutorial that matches where your Java application runs.

Consideration Amazon EC2 with the CloudWatch agent Kubernetes with the CloudWatch Observability EKS add-on or the Helm chart
Who it's for Teams that run Java applications directly on Amazon EC2 instances, or that want to try profiling on a single instance Teams that run Java workloads on Amazon EKS with the amazon-cloudwatch-observability add-on, or on any other Kubernetes cluster (or on Amazon EKS without the add-on) with the amazon-cloudwatch-observability Helm chart
What you install The CloudWatch agent, the ADOT Java agent, and a Java runtime on the instance The add-on version v8.0.1-eksbuild.1 or later, or the Helm chart version 8.0.0 or later. Nothing else.
How you turn on profiling Start the JVM with the -javaagent option and set OTEL_AWS_PROFILER_ENABLED to true. Set the profiling value in the advanced configuration of the add-on, or in the Helm chart.
Restart impact You restart the Java application. You restart the workloads so that new pods start with profiling turned on. Only new pods are profiled.
Code changes None. You change only the command that starts the JVM. None. You don't change images, entry points, or startup commands.

To profile every process on a Linux host, in any supported language, without changing your applications, see the OpenTelemetry eBPF profiler in Profile your application.

Tutorial topics

Use the following tutorials to set up profiling for your environment. Each tutorial states its cost. You might incur charges for the Amazon EC2 instances or the cluster that you use. To stop sending profile data, follow Step 6: Clean up in the Amazon EC2 tutorial or Clean up in the Kubernetes tutorial.