Retrieve a flame graph
The SelectMergeStacktraces operation merges the stack trace samples that
match a profile type and a label selector over a time range. It returns the result as flame
graph data. For more information about profiles and flame graphs, see Profiles overview.
You can view a flame graph in the CloudWatch console or retrieve it with the query API. This topic describes the console first, and then the API.
Prerequisites
Before you begin, make sure that you have the following:
-
An identity with the
cloudwatch:GetProfileRecordspermission. For more information, see IAM permissions required. You need this permission to view profiles in the CloudWatch console and to call the query API. -
The profile type ID and the service name to query. For instructions, see Discover profile types, services, and labels.
View a flame graph in the CloudWatch console
In the CloudWatch console, you select a service, a profile type, and a time range, and then run the query to view the flame graph.
To view a flame graph in the CloudWatch console
-
Open the CloudWatch console at https://console.aws.amazon.com/cloudwatch/
. -
In the navigation pane, choose Profiles.
-
In the navigation bar at the top, select the Region where you send your profile data.
-
For Service, select the service name that your application reports in
service.name, for example,example-java-service. -
For Profile type, select the profile type that your profiler sends, for example,
process_cpu. -
At the top of the page, choose the time range that you want to analyze, for example, 1h.
-
Choose Run.
The results show a time series chart and the flame graph on the Flamegraph tab. You can use the following options to explore the results:
-
To list the functions with their self and total values, choose the Top Functions tab.
-
To view the call hierarchy, choose the Call tree tab.
-
To find a function, enter its name in Search frames.
-
To show two views side by side, choose Split.
To narrow the flame graph to matching profile data, in the Label row, select a Label name and a Label value, and then choose Run again. For more information, see Query profile data in the CloudWatch console.
Flame graph examples
To retrieve a flame graph with the API, send a SelectMergeStacktraces
request. The following examples show common requests and the response.
A SelectMergeStacktraces request requires profileTypeID. The
time range can't be longer than 24 hours. Timestamps are in milliseconds since the Unix
epoch. For all request fields, see SelectMergeStacktraces in the query API reference.
Example: retrieve a CPU flame graph for a service
This request retrieves CPU profile data for example-java-service over a
one-hour window.
curl --request POST \ --aws-sigv4 "aws:amz:us-east-1:monitoring" \ --user "$AWS_ACCESS_KEY_ID:$AWS_SECRET_ACCESS_KEY" \ --header "x-amz-security-token: $AWS_SESSION_TOKEN" \ --header "Content-Type: application/json" \ --data '{ "profileTypeID": "process_cpu:cpu:nanoseconds:cpu:nanoseconds", "labelSelector": "{service_name=\"example-java-service\"}", "start": 1793793600000, "end": 1793797200000 }' \ https://monitoring.us-east-1.amazonaws.com/querier.v1.QuerierService/SelectMergeStacktraces
Example: retrieve a smaller flame graph for one host
This request body narrows the query to one host and limits the size of the result with
maxNodes. The limit is approximate. CloudWatch rolls up the nodes that it trims into
nodes named other or other (.
If you omit parent)maxNodes, the response contains the full tree.
{ "profileTypeID": "process_cpu:cpu:nanoseconds:cpu:nanoseconds", "labelSelector": "{service_name=\"example-java-service\",\"@resource.host.name\"=\"host-a.example.internal\"}", "maxNodes": 8, "start": 1793793600000, "end": 1793797200000 }
Example: read the flame graph response
The response contains a flamegraph object. The following response is
trimmed to its first two levels, so the node with the largest self value
(maxSelf) isn't shown.
{ "flamegraph": { "names": ["total", "frame-a", "other", "frame-b"], "levels": [ {"values": ["0", "70445399426", "0", "0"]}, {"values": ["0", "68187123095", "0", "1", "0", "2258276331", "2258276331", "2"]} ], "total": "70445399426", "maxSelf": "68167123095" } }
The response has the following fields:
-
names– The function names in the flame graph. Index0istotal. -
levels– One entry for each depth of the stack. Eachvalueslist holds four numbers for each node: the x-offset, the total value, the self value, and the index of the node's name innames. -
totalandmaxSelf– The total value of the flame graph and the largest self value of any node.
Values use the unit of the profile type, for example, nanoseconds of CPU time. The API
returns numbers as strings. To get the result as a binary tree instead, set
"format": "PROFILE_FORMAT_TREE". The response then contains a
tree field with base64-encoded data.