To retrieve GPU usage for a specific process using the Performance Data Helper (PDH) API, you need to construct the counter path correctly. The counter path format you are trying to use, \GPU Engine(%s#%d)\Utilization Percentage, is close, but you should ensure that you are using the correct instance name and index for the GPU engine you are targeting.
Here are some steps to help you combine the counter path:
- Identify the GPU Engine: Make sure you know the exact name of the GPU engine you want to monitor. This can often be found in the Performance Monitor or similar tools.
- Use the Correct Instance Index: The instance index should correspond to the specific instance of the GPU engine you are interested in. If there are multiple instances, you can use
#0,#1, etc., to specify them. - Check the Counter Path Syntax: Ensure that your counter path follows the correct syntax. For example:
- If the GPU engine is named "NVIDIA GPU", and you are interested in the first instance, your counter path might look like this:
\GPU Engine(NVIDIA GPU#0)\Utilization Percentage.
- If the GPU engine is named "NVIDIA GPU", and you are interested in the first instance, your counter path might look like this:
- Use Wildcards if Necessary: If you are unsure about the instance names, you can use wildcards to expand the list of available instances. For example, you could use
\GPU Engine(*)\Utilization Percentageto see all available GPU engines and their utilization percentages.
Make sure to test the counter path in the PDH API to ensure it returns the expected results. If you continue to experience issues, verify that your GPU driver supports the necessary instrumentation features and that you have the appropriate permissions to access the performance counters.