<!--
{
  "documentType" : "article",
  "framework" : "Metal",
  "identifier" : "/documentation/Metal/confirming-which-counters-and-counter-sets-a-gpu-supports",
  "metadataVersion" : "0.1.0",
  "role" : "article",
  "title" : "Confirming which counters and counter sets a GPU supports"
}
-->

# Confirming which counters and counter sets a GPU supports

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

## Discussion

You can check to see which counters a GPU device supports before attempting to programmatically sample data from them. A GPU *counter* is typically a hardware feature that tracks a specific performance metric, such as timestamps before and after an important rendering stage. Checking which counters a GPU supports at runtime avoids assumptions that may trigger an error or a crash on a person’s device.

A *counter set* is a collection of related counters. The [`MTLCommonCounterSet`](/documentation/Metal/MTLCommonCounterSet) type defines the name of each set, and the [`MTLCommonCounter`](/documentation/Metal/MTLCommonCounter) type defines the name of each individual counter. Check which counter sets an [`MTLDevice`](/documentation/Metal/MTLDevice) instance supports before you request one by checking its [`counterSets`](/documentation/Metal/MTLDevice/counterSets) property.

```swift
func getCounterSet(_ commonCounterSetName: MTLCommonCounterSet,
                   from device: MTLDevice) -> MTLCounterSet? {
    let counterSetName = commonCounterSetName.rawValue

    guard let counterSets = device.counterSets else {
        print("GPU device \"\(device.name)\" doesn't support any counter sets.")
        return nil
    }

    for counterSet in counterSets {
        guard counterSet.name == counterSetName else { continue }

        print("GPU device \"\(device.name)\" supports the \"\(counterSetName)\" counter set.")
        return counterSet
    }

    print("GPU device \"\(device.name)\" doesn't support the \"\(counterSetName)\" counter set.")
    return nil
}
```

The method iterates through each counter set the device supports, and compares its name to the [`MTLCommonCounterSet`](/documentation/Metal/MTLCommonCounterSet) parameter.

Even though a GPU device supports a counter set, it may only support some of the counters in that set. You can check which individual counters a device supports by checking the elements of a counter set’s [`counters`](/documentation/Metal/MTLCounterSet/counters) property.

```swift
static func counterSet(_ counterSet: MTLCounterSet,
                       contains commonCounterName: MTLCommonCounter) -> Bool {

    let counterName = commonCounterName.rawValue
    for counter in counterSet.counters {
        guard counter.name == counterName else { continue }

        print("Counter set \"\(counterSet.name)\" contains the \"\(counterName)\" counter.")
        return true
    }

    print("Counter set \"\(counterSet.name)\" doesn't contain the \"\(counterName)\" counter.")
    return false
}
```

The method iterates through each counter in the device’s counter set, and compares its name to the [`MTLCommonCounter`](/documentation/Metal/MTLCommonCounter) property.

When you know a GPU supports a counter, your app can create and safely use an [`MTLCounterSampleBuffer`](/documentation/Metal/MTLCounterSampleBuffer) instance to store that counter’s 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) for more information and next steps.

---

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)