Advertisement
Spiritreader

Untitled

Apr 23rd, 2020
553
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.08 KB | None | 0 0
  1. private async Task<int> GetGPUUsage()
  2.         {
  3.             var pcc = new PerformanceCounterCategory("GPU Engine");
  4.             var counterNames = pcc.GetInstanceNames();
  5.             List<PerformanceCounter> counters = new List<PerformanceCounter>();
  6.             var counterAccu = 0f;
  7.             foreach (string counterName in counterNames)
  8.             {
  9.                 if (counterName.EndsWith("engtype_3D"))
  10.                 {
  11.                     foreach (PerformanceCounter counter in pcc.GetCounters(counterName))
  12.                     {
  13.                         if (counter.CounterName == "Utilization Percentage")
  14.                         {
  15.                             counters.Add(counter);
  16.                         }
  17.                     }
  18.                 }
  19.             }
  20.             counters.ForEach(c =>
  21.             {
  22.                 counterAccu += c.NextValue();
  23.             });
  24.             await Task.Delay(1000);
  25.             counters.ForEach(c =>
  26.             {
  27.                 counterAccu += c.NextValue();
  28.             });
  29.             return (int)counterAccu;
  30.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement