title: How to get accurate CPU usage for a process on a multi-processor / multi-core system
body: <p>Or maybe the question is more like "What am I doing blatantly wrong here?"</p>
  
  <p>I have a test app which does nothing but watch its own cpu usage.  It looks a little something like this:</p>
  
  <pre><code>protected PerformanceTrace()
  {
     Process currentProcess = Process.GetCurrentProcess();
     this.cpuCounter = new PerformanceCounter("Process", "% Processor Time", currentProcess.ProcessName);
     this.coreCount = Environment.ProcessorCount;
  }
  
  private int coreCount;
  private DateTime lastCpuRead = DateTime.MinValue;
  private float _cpuUsage;
  private float CpuUsage
  {
     get
     {
        if ((DateTime.Now - this.lastCpuRead) &gt; TimeSpan.FromSeconds(1.0))
        {
           this._cpuUsage = this.cpuCounter.NextValue();
        }
        return this._cpuUsage / this.coreCount;
     }
  }
  </code></pre>
  
  <p>The CpuUsage property is read very frequently.  Here's the thing:</p>
  
  <p>On my machine, <code>Environment.ProcessorCount</code> produces a value of 2.  However, the value coming from the counter is often up to 800.  What I am assuming is it has something to do with multiple cores and hyperthreading.  What can I do to get the actual value that I'm looking for? (The total % processor time for this particular process)</p>