2

I am trying to gather performance information in C#. For RAM, CPU and other PC components i am using PerformanceCounters but for GPU there is not really one that gives me information like

% current GPU utilization

and

% current VRam utilization

For NVIDIA there is (in some cases) a performance counter category "NVIDIA GPU" that has all the important counters, but in some cases (e.g. MX250) or AMD GPUs there is not a Category of such kind.

I have tried using the "GPU-Engine" performance counter category, but i dont know how to interpret the data gathered with NextSample() (the NextValue() of the "Utilization Percentage" counter is just always 0, even if my GPU is at 15% or somthing).

The Information given here helped understanding why i need NextSample() but doesnt gave information about the correct way to calculate with rawValue.

i have tried using this:

var sample = gpuCounter.NextSample();
Task.Delay(2000).Wait()
var sample2 = gpuCounter.NextSample();
var ticks = ((sample2.TimeStamp - sample.TimeStamp) / sample.CounterFrequency) * 100000;
double calc = Math.Abs(raw2 - raw) / ticks;

Is there a way to gather live performance information for AMD and Intel in C# ?

Or does anybody know how to calculate the correct utilization value with the rawValue of the NextSample() from the "Utilization Percentage" counter from "GPU-Engine" category?

Any help welcome. Thanks in advance.

Update:

This calculation returns the same value as NextValue() for the "Utilization Percentage" but the value of NextValue() is way to low (if it is not 0).

My idea is that the instance of the "Utilization Percentage" counter is something like only for one process, this would also be the reason for alot of 0s.

Can anybody confirm this?

Update2:

if i add up all NextValues of all Counter Instances from (for example some kind of 3D instances) i get an pretty close to correct value, but you need to call NextValue() function twice in an interval more than 1s and take the second value or the results are useless(from my experience). The Problem: this leads to delayed results and so it is hard to say if it works

Franz73
  • 21
  • 3
  • 2
    Does this answer your question? [C# Performance Counter Help, Nvidia GPU](https://stackoverflow.com/questions/36389944/c-sharp-performance-counter-help-nvidia-gpu) – 0liveradam8 Feb 10 '21 at 12:27
  • 1
    I don't believe that the GPU manufacturers expose this information through the Performance Counters API, sadly. They all want you to use their own proprietary APIs that surface this information in ways specific to their interpretation of what the values mean. A better bet might be to use the [GPU-Z integration DLL](https://www.techpowerup.com/gpuz/) which provides a shared memory section that does a fair job of somewhat agnostically mapping the various GPU API-specific values. – Ian Kemp Feb 10 '21 at 12:32
  • @IanKemp thanks a lot, i am trying this out. Yes i also found a wrapper for Nvapi which does a great job, but only for NVIDIA. – Franz73 Feb 10 '21 at 12:47
  • @0liveradam8 not really, because there are no usefull category for AMD or Intel, but thanks anyway :D – Franz73 Feb 10 '21 at 12:48
  • 1
    See also [programmatically-fetch-gpu-utilization](https://stackoverflow.com/questions/2160935/programmatically-fetch-gpu-utilization) – JonasH Feb 10 '21 at 13:44
  • I use the following answer to read the CPU load: https://stackoverflow.com/a/71481615/171846 – Fidel Mar 15 '22 at 11:40

0 Answers0