title: How to read system usage (CPU, RAM etc)
body: <p>In unity3d I'm trying to read the system usage in order to see the CPU and RAM usage whilst a person is playing a VR game. I know how I can show it on the computer screen and how to keep it away from the players VR screen. </p>
  
  <p>I have been looking all around Google for as far as I know. Most of them lead to the same answer which I cannot seem to get working correctly. </p>
  
  <p>I have been checking out the post: <a href="https://answers.unity.com/questions/506736/measure-cpu-and-memory-load-in-code.html" rel="nofollow noreferrer">https://answers.unity.com/questions/506736/measure-cpu-and-memory-load-in-code.html</a> which leads me to the stackoverflow page: <a href="https://stackoverflow.com/questions/278071/how-to-get-the-cpu-usage-in-c">How to get the CPU Usage in C#?</a></p>
  
  <p>In these posts they always get the problem of having the CPU usage stuck at 100%, even though this is incorrect. I have been trying the System.Threading.Thread.Sleep(1000). But this locks the entire game to 1fps due to it waiting 1 sec every second. And even with having 1fps I cannot get any other read than 100%.</p>
  
  <p>In this code I'm using the Sleep thread which slows down the game to 1fps</p>
  
  <pre><code>using UnityEngine;
  using System.Diagnostics;
  using TMPro;
  
  public class DebugUIManager : MonoBehaviour
  {
      private PerformanceCounter cpuCounter;
      [SerializeField] private TMP_Text cpuCounterText;
  
      private void Start()
      {
          cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
      }
  
      private void Update()
      {
          cpuCounterText.text = getCurrentCpuUsage();
      }
  
      private string getCurrentCpuUsage()
      {
          dynamic firstValue = cpuCounter.NextValue() + "% CPU";
          System.Threading.Thread.Sleep(1000);
          dynamic secondValue = cpuCounter.NextValue() + "% CPU";
  
          return secondValue;
      }
  }
  </code></pre>
  
  <p>Whenever I change the</p>
  
  <pre><code>    private string getCurrentCpuUsage()
      {
          dynamic firstValue = cpuCounter.NextValue() + "% CPU";
          System.Threading.Thread.Sleep(1000);
          dynamic secondValue = cpuCounter.NextValue() + "% CPU";
  
          return secondValue;
      }
  </code></pre>
  
  <p>to</p>
  
  <pre><code>    private string getCurrentCpuUsage()
      {
          return cpuCounter.NextValue() + "%";
      }
  </code></pre>
  
  <p>the game won't get dropped in fps, but it also doesn't do anything still.</p>
  
  <p>I haven't been getting any error messages because it runs without issues. But I would really like to know how to get the CPU usage, so I can figure out the rest myself. </p>
  
  <p>Any answers helping would be appreciated.</p>