Profiles overview
In Amazon CloudWatch Profiles, a profile is a collection of samples and associated metadata that shows where your application consumes resources during execution. Each sample records the call stack observed at a point in time, along with the resource value measured at that instant (for example, CPU time or bytes allocated). Aggregated over a time window, these samples form a flame graph that reveals the relative cost of every function in your code.
Sampling call stacks
A profiler doesn't record every function call. Instead, it records the call stacks of your threads at a fixed interval. Profilers use one of the following sampling techniques:
-
CPU sampling samples threads only while they run on the CPU.
-
Wall-clock sampling (also known as wall) samples every thread at a fixed interval, whether the thread is running or waiting.
A profiler collects samples over a period of time, the aggregation window, before it
sends them. For more information, see Aggregating samples. For information about how to
configure sampling, see the async-profiler repository
In CloudWatch, a profile type ID has five colon-separated parts, such as the following
examples. The AWS Distro for OpenTelemetry (ADOT) Java agent's wall mode appears as
wall:wall:nanoseconds:wall:nanoseconds, its CPU mode as
process_cpu:cpu:nanoseconds:cpu:nanoseconds, and async-profiler
event=itimer as process_itimer:itimer:count:itimer:ns. For more
information about profile type IDs, see Profile type IDs and labels.
In wall-clock mode, the ADOT Java agent marks each sample with a
thread.state attribute: RUNNABLE for on-CPU time and
SLEEPING for off-CPU time.
Aggregating samples
Profilers aggregate samples over a period of time, for example 5 minutes, into one profile before they send it to CloudWatch. This period is the aggregation window. You configure the aggregation window in your profiler. When you aggregate more samples into each profile, you send fewer ingestion requests and less data. When you keep samples apart (for example, for each trace, as the ADOT Java agent can), you send more data. There is no charge for CloudWatch Profiles during the preview. The amount of data that you send also affects your ingestion request rate and how long queries take.
Profile types
The profile types available for your application depend on its language runtime and the profiler that you use. Amazon CloudWatch Profiles supports the following profile types:
- CPU
-
Records the stack traces of your code over time, collected with CPU or wall-clock sampling. For more information, see Sampling call stacks. Use CPU profiles to find the functions behind high processor use or latency.
- Heap (memory)
-
Records stack traces of code that has allocated memory still in use. Use heap profiles to find memory leaks or unexpectedly large live data sets.
- Allocations (memory)
-
Records sampled allocation call sites, whether or not the memory was later freed. Use allocation profiles to identify code paths that create high garbage-collection pressure.
How profiles complement other signals
Each observability signal answers a different question about your system. The following table lists each signal and the question that it answers.
Signal |
Question it answers |
|---|---|
Logs |
What discrete events occurred in my system? |
Metrics |
What is the overall state of my system (for example, is CPU usage at 90%)? |
Traces |
How did a request travel through my distributed system? |
Profiles |
Which specific lines of code are consuming resources? |
Profiles are most useful when you combine them with other signals. For example, when a metric shows a CPU spike, query the profile of that service for the same time range to find the functions that used the CPU. When a trace shows a slow request, look at the profile of the service that served it for the same time range to see which code was running.
Correlating profiles with other signals
Some profilers link each sample to the trace and span of the request that the thread was serving. The ADOT Java agent does this for sampled traces when its profiler and tracing are both turned on. async-profiler and the OpenTelemetry eBPF profiler don't record trace context.
In CloudWatch Omni, open a trace and choose Analyze, then Analyze profiles. If the service's profiles are linked to that trace, Omni shows the profile samples recorded during it. Otherwise, the Omni agent analyzes the service's profiles for the trace's time window. For more information, see Go from a trace to a profile. To find the costliest spans across a time range with the query API, see Find costly spans with a heatmap and trace exemplars. This helps you answer questions such as "What code was running during this slow database call?"
Profile type IDs and labels
Labels are how you link profiles to the metrics, logs, and traces from the same service. When you query profile data, you identify the data with a profile type ID and a set of labels.
A profile type ID has five parts separated by colons:
.
For example, name:sample_type:sample_unit:period_type:period_unitprocess_cpu:cpu:nanoseconds:cpu:nanoseconds identifies CPU time
measured in nanoseconds.
Labels are key-value pairs that describe where the profile data
came from. Profile labels use the same @ prefix convention as OpenTelemetry Protocol (OTLP) metrics.
For more information, see PromQL querying. The exception is attributes of
individual samples: profiles use @sample. (for example,
@sample.thread.name), where metrics use @datapoint..
CloudWatch also provides service_name as a short alias for
@resource.service.name. It's the only short alias. For all other labels, use
the full key, for example, @resource.host.name rather than
host_name. Labels that start and end with two underscores are reserved. For
example, the __profile_type__ label holds the profile type ID.