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