<!--
{
  "documentType" : "article",
  "framework" : "Metal",
  "identifier" : "/documentation/Metal/gpu-counters-and-counter-sample-buffers",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "GPU counters and counter sample buffers"
}
-->

# GPU counters and counter sample buffers

Retrieve runtime data from a GPU device by sampling one or more of its counters.

## Discussion

A GPU *counter* ([`MTLCounter`](/documentation/Metal/MTLCounter)) is typically a hardware feature that tracks a specific performance metric, such as timestamps before and after an important rendering stage. A *counter set* ([`MTLCounterSet`](/documentation/Metal/MTLCounterSet)) is a collection of related counters. A *counter sample buffer* ([`MTLCounterSampleBuffer`](/documentation/Metal/MTLCounterSampleBuffer)) represents the memory where a GPU device stores the data for a specific counter set.

You can retrieve and inspect data from a GPU’s counter set with the following steps:

1. Inspect which GPU counter sets a GPU device supports (see [Confirming which counters and counter sets a GPU supports](/documentation/Metal/confirming-which-counters-and-counter-sets-a-gpu-supports)).
2. Make a counter sample buffer to store the data (see [Creating a counter sample buffer to store a GPU’s counter data during a pass](/documentation/Metal/creating-a-counter-sample-buffer-to-store-a-gpus-counter-data-during-a-pass)).
3. Instruct the GPU to save the counter set data to the buffer during a pass or an immediate mode command (see [Sampling GPU data into counter sample buffers](/documentation/Metal/sampling-gpu-data-into-counter-sample-buffers)).
4. Transform the counter set data into a standard type (see [Converting a GPU’s counter data into a readable format](/documentation/Metal/converting-a-gpus-counter-data-into-a-readable-format)).

If you’re sampling data from a timestamp counter set ([`timestamp`](/documentation/Metal/MTLCommonCounterSet/timestamp)), you may need to convert the timestamps from the GPU’s clock to the CPU’s clock. See [Converting GPU timestamps into CPU time](/documentation/Metal/converting-gpu-timestamps-into-cpu-time) for more information.

## Topics

### Counters and counter sets

[Confirming which counters and counter sets a GPU supports](/documentation/Metal/confirming-which-counters-and-counter-sets-a-gpu-supports)

Check whether a GPU produces the runtime performance data you want to sample.

[`MTLCounterSet`](/documentation/Metal/MTLCounterSet)

A collection of individual counters a GPU device supports for a counter set.

[`MTLCommonCounterSet`](/documentation/Metal/MTLCommonCounterSet)

The name of a specific counter set that a GPU device can support.

[`MTLCounter`](/documentation/Metal/MTLCounter)

An individual counter a GPU device lists within one of its counter sets.

[`MTLCommonCounter`](/documentation/Metal/MTLCommonCounter)

The name of a specific counter that can appear in a GPU device’s counter sets.

### Counter sample buffers

[Creating a counter sample buffer to store a GPU’s counter data during a pass](/documentation/Metal/creating-a-counter-sample-buffer-to-store-a-gpus-counter-data-during-a-pass)

Make a buffer that provides a place for a GPU to save its runtime performance metrics as it runs a pass.

[`MTLCounterSampleBufferDescriptor`](/documentation/Metal/MTLCounterSampleBufferDescriptor)

A group of properties that configures the counter sample buffers you create with it.

[`MTLCounterSampleBuffer`](/documentation/Metal/MTLCounterSampleBuffer)

A specialized memory buffer that stores a GPU’s counter set data.

[Sampling GPU data into counter sample buffers](/documentation/Metal/sampling-gpu-data-into-counter-sample-buffers)

Retrieve a GPU’s counter data at a time the GPU supports.

[`MTLCounterDontSample`](/documentation/Metal/MTLCounterDontSample)

A sentinel value that instructs an encoder to skip sampling a counter as the GPU runs the encoder’s pass.

### Counter sample data output

[Converting a GPU’s counter data into a readable format](/documentation/Metal/converting-a-gpus-counter-data-into-a-readable-format)

Inspect and use the data within a GPU’s counter sample buffer by resolving it into a standard format.

[`MTLCounterResultTimestamp`](/documentation/Metal/MTLCounterResultTimestamp)

The data structure for storing the data you resolve from a timestamp counter set.

[`MTLCounterResultStatistic`](/documentation/Metal/MTLCounterResultStatistic)

The data structure for storing the data you resolve from a statistic counter set.

[`MTLCounterResultStageUtilization`](/documentation/Metal/MTLCounterResultStageUtilization)

The data structure for storing the data you resolve from a stage-utilization counter set.

[`MTLCounterErrorValue`](/documentation/Metal/MTLCounterErrorValue)

A sentinel value for an entry in a counter sample buffer that indicates the entry’s data is invalid.

### Timestamp data

[Converting GPU timestamps into CPU time](/documentation/Metal/converting-gpu-timestamps-into-cpu-time)

Correlate GPU events with CPU timelines by calculating the CPU time equivalents for GPU timestamps.

[`MTLTimestamp`](/documentation/Metal/MTLTimestamp)

The number of nanoseconds for a point in absolute time or Mach absolute time.

### Counter sample buffer errors

[`MTLCounterSampleBufferError`](/documentation/Metal/MTLCounterSampleBufferError-swift.struct)

The error codes that indicate why a GPU driver can’t create a counter sample buffer.

### Counter sample buffer errors

[`MTLCounterSampleBufferError.Code`](/documentation/Metal/MTLCounterSampleBufferError-swift.struct/Code)

The underlying error code type that indicates why a GPU driver can’t create a counter sample buffer.

[`MTLCounterErrorDomain`](/documentation/Metal/MTLCounterErrorDomain)

The domain for Metal counter sample buffer errors.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)