> For the complete documentation index, see [llms.txt](https://docs.groundcover.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.groundcover.com/reference/remote-access-and-apis/api-examples/query-profiling.md).

# Query Profiling Flamegraphs

Retrieve profiling flamegraphs and compare profiles across time ranges or filters.

### Endpoints

* **GET** `/api/profiling/v1/flamegraph`
* **GET** `/api/profiling/v1/flamegraph-diff`

### Authentication

Send `Authorization: Bearer <YOUR_API_KEY>` and `X-Backend-Id: <YOUR_BACKEND_ID>`. JSON requests also require `Content-Type: application/json`. The examples use `https://api.groundcover.com`; use your deployment's API URL for a self-hosted installation. Replace the example time range with one containing your data.

### Query Parameters

| Parameter      | Required | Description                                                                                                        |
| -------------- | -------- | ------------------------------------------------------------------------------------------------------------------ |
| `start`, `end` | Yes      | `start` and `end` are RFC3339 timestamps; `start` must be earlier than `end`.                                      |
| `query`        | Yes      | gcQL filters selecting one workload, one stored `profile_type`, and one `sample_type` as top-level AND conditions. |
| `limit`        | No       | Maximum detailed stacks, default 50000, maximum 50000.                                                             |
| `focus`        | No       | JSON array of exact root-to-leaf frame names, such as `["main","worker"]`.                                         |
| `frameFilter`  | No       | Case-sensitive substring that must occur in a retained stack.                                                      |
| `invert`       | No       | `true` returns sampled functions first, followed by callers.                                                       |

Use the exact stored profile and sample identifiers. Shorthand aliases are not expanded. Discover them with [field/value discovery](https://docs.groundcover.com/reference/remote-access-and-apis/api-examples/discover-fields-and-metrics.md) using `type: "profiling_samples"`.

### Retrieve a Flamegraph

```bash
curl --get 'https://api.groundcover.com/api/profiling/v1/flamegraph' \
  --header 'Authorization: Bearer <YOUR_API_KEY>' \
  --header 'X-Backend-Id: <YOUR_BACKEND_ID>' \
  --data-urlencode 'start=2026-10-28T10:00:00Z' \
  --data-urlencode 'end=2026-10-28T11:00:00Z' \
  --data-urlencode 'query=workload:checkout-service AND profile_type:"pprof:cpu_samples:count" AND sample_type:samples' \
  --data-urlencode 'limit=1000'
```

### Response

The JSON response contains:

* `root`: tree nodes with `name`, inclusive `value`, direct sampled weight `self`, and optional `children`.
* `profileType`, `sampleType`, `unit`, and `period`: the measurement and selected range.
* `total`: weight of the original authorized selection.
* `filteredValue`: signed weight removed by focus/frame filtering. `root.value` equals `total - filteredValue`.
* `truncated`: whether tree detail was collapsed.
* `stacks.total` and `stacks.returned`: matching aggregate stacks and stacks selected for detailed paths.

Synthetic remainder nodes have `omitted: true`; distinguish these from a real function named `other`. In a normal tree, `value = self + sum(children.value)`. In an inverted tree, callers partition the same sampled weight, so that identity does not apply.

Window measurements sum samples. Snapshot measurements such as in-use memory average snapshots per pod before summing pods. An empty selection returns a zero-weight root.

### Compare Two Windows

Use `/flamegraph-diff` with the same parameters, adding `baseStart` and `baseEnd` together. Optional `baseQuery` defaults to `query`. Both selections must pin the same workload, `profile_type`, and `sample_type`.

```bash
curl --get 'https://api.groundcover.com/api/profiling/v1/flamegraph-diff' \
  --header 'Authorization: Bearer <YOUR_API_KEY>' \
  --header 'X-Backend-Id: <YOUR_BACKEND_ID>' \
  --data-urlencode 'start=2026-10-28T10:00:00Z' \
  --data-urlencode 'end=2026-10-28T11:00:00Z' \
  --data-urlencode 'baseStart=2026-10-28T09:00:00Z' \
  --data-urlencode 'baseEnd=2026-10-28T10:00:00Z' \
  --data-urlencode 'query=workload:checkout-service AND profile_type:"pprof:cpu_samples:count" AND sample_type:samples'
```

Diff nodes add `baseValue` and `baseSelf`; the response adds `baseTotal`, `baseFilteredValue`, and `basePeriod`. Values are raw weights per side, so normalize by duration in your client when comparing windows of different lengths. A frame absent from one side has zero weight on that side. Diff ranges are half-open `[start,end)`; the single flamegraph endpoint includes its end timestamp.

If `baseStart`/`baseEnd` are omitted, the baseline uses the current time range; set `baseQuery` to compare filters within one window. Focus, frame filtering, and inversion apply to both sides.

### Errors

* **400:** invalid filters, missing pins, mismatched comparison measurements, or invalid parameters.
* **404:** profiling reads unavailable in the backend.
* **422:** read limits exceeded or unsupported negative values in a comparison. Narrow the range or filters.
* **504:** query deadline exceeded.

A truncated response still accounts for omitted weight with remainder nodes. A read-limit error is not a successful partial result.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.groundcover.com/reference/remote-access-and-apis/api-examples/query-profiling.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
