Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private async Task<int> GetGPUUsage()
- {
- var pcc = new PerformanceCounterCategory("GPU Engine");
- var counterNames = pcc.GetInstanceNames();
- List<PerformanceCounter> counters = new List<PerformanceCounter>();
- var counterAccu = 0f;
- foreach (string counterName in counterNames)
- {
- if (counterName.EndsWith("engtype_3D"))
- {
- foreach (PerformanceCounter counter in pcc.GetCounters(counterName))
- {
- if (counter.CounterName == "Utilization Percentage")
- {
- counters.Add(counter);
- }
- }
- }
- }
- counters.ForEach(c =>
- {
- counterAccu += c.NextValue();
- });
- await Task.Delay(1000);
- counters.ForEach(c =>
- {
- counterAccu += c.NextValue();
- });
- return (int)counterAccu;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement