View a markdown version of this page

Compare two profiles - Amazon CloudWatch

Compare two profiles

The Diff operation compares two flame graphs, a left side and a right side. Use it to find regressions or improvements, for example before and after a deployment, or between two hosts. Each side is a complete flame graph query. For more information about flame graph queries, see Retrieve a flame graph.

You can compare two profiles in the CloudWatch console or 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:

Compare two profiles in the CloudWatch console

In the CloudWatch console, you use Compare with to compare the current selection with an earlier time range (Time) or with a second label set (Labels). While you compare, you can't change the service or the profile type.

To compare two time ranges or label sets in the CloudWatch console
  1. Open the CloudWatch console at https://console.aws.amazon.com/cloudwatch/.

  2. In the navigation pane, choose Profiles.

  3. In the navigation bar at the top, select the Region where you send your profile data.

  4. For Service, select the service to compare, for example, example-java-service.

  5. For Profile type, select the profile type to compare. Both selections use this profile type.

  6. For Compare with, choose Time or Labels.

Next, set up the comparison selection and run the query. Use one of the following procedures.

To compare with an earlier time range
  1. For the time offset, choose how far back to compare, for example, 1h ago.

  2. Choose Run.

To compare two label sets
  1. In the first Label row, for Label name, select a label, for example, k8s.pod.name.

  2. For Label value, select the value for the baseline.

  3. In the second Label row, for Label name, select the same label.

  4. For Label value, select the value to compare.

  5. Choose Run.

The flame graph shows the differences between the two selections. Its legend marks each function as Added, Grew, Removed, Shrank, or Unchanged. In a time comparison, the chart legend labels the two series as the baseline (now) and the comparison, for example, 1h ago.

Comparison examples

To compare two profiles with the API, send a Diff request. The following examples show common requests and the response.

The left and right objects each take the same fields as a SelectMergeStacktraces request. CloudWatch validates each side separately, and each side's time range can't be longer than 24 hours. For all request fields, see Diff in the query API reference.

Important

Use the same profileTypeID on both sides. The Diff operation doesn't reject sides with different profile types, but the result isn't meaningful.

Example – compare two time ranges

This request compares the CPU profile of example-java-service in the first half hour of a window with the second half hour. For example, you can use the time of a deployment as the boundary.

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 '{ "left": { "profileTypeID": "process_cpu:cpu:nanoseconds:cpu:nanoseconds", "labelSelector": "{service_name=\"example-java-service\"}", "maxNodes": 4, "start": 1793793600000, "end": 1793795400000 }, "right": { "profileTypeID": "process_cpu:cpu:nanoseconds:cpu:nanoseconds", "labelSelector": "{service_name=\"example-java-service\"}", "maxNodes": 4, "start": 1793795400000, "end": 1793797200000 } }' \ https://monitoring.us-east-1.amazonaws.com/querier.v1.QuerierService/Diff
Example – compare two hosts

This request body compares two hosts that run example-java-service over the same time range.

{ "left": { "profileTypeID": "process_cpu:cpu:nanoseconds:cpu:nanoseconds", "labelSelector": "{service_name=\"example-java-service\",\"@resource.host.name\"=\"host-a.example.internal\"}", "start": 1793793600000, "end": 1793797200000 }, "right": { "profileTypeID": "process_cpu:cpu:nanoseconds:cpu:nanoseconds", "labelSelector": "{service_name=\"example-java-service\",\"@resource.host.name\"=\"host-b.example.internal\"}", "start": 1793793600000, "end": 1793797200000 } }
Example – read the comparison response

The response contains a flamegraph object that combines both sides. The following response is trimmed.

{ "flamegraph": { "names": ["total", "..."], "levels": [ {"values": ["0", "36049186800", "0", "0", "34779903100", "0", "0"]} ], "total": "70829089900", "maxSelf": "6557877300", "leftTicks": "36049186800", "rightTicks": "34779903100" } }

Each values list holds seven numbers for each node: the left offset, left total, and left self values, then the right offset, right total, and right self values, and finally the index of the node's name in names. leftTicks and rightTicks are the totals of each side, and total is their sum.