+ Reply to Thread
Results 1 to 2 of 2

Thread: Find the least used processor core

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    27

    Find the least used processor core

    I am writing an application and to optimize performance , i pick the least used processor core to assign the application to , so far i tried PerformanceCounter:
    Code:
            label1.Text = "";
            var cusage = new PerformanceCounter[Environment.ProcessorCount];
    
            for (var i = 0; i < cusage.Length; i++)
            {
                cusage[i] = new PerformanceCounter("Processor", "% Processor Time", i.ToString());
    
                label1.Text += "   |   " + cusage[i].CounterName + " ~ " + cusage[i].NextValue();
            }
    The output I'm getting are all Zeros....
    I don`t know where the problem could be.

  2. #2
    Junior Member
    Join Date
    Jan 2012
    Posts
    15
    Here is an idea :
    Code:
    var coreUsages = new PerformanceCounter[Environment.ProcessorCount];
    
    for (var i = 0; i < coreUsages.Length; i++)
    {
         coreUsages[i] = new PerformanceCounter("Processor", "% Processor Time", i.ToString());
         coreUsages[i].NextValue();
    }
    
    Thread.Sleep(1000);
    
    for (var i = 0; i < coreUsages.Length; i++)
    {
         //using the status bar as output for now, doesn't really matter
         Trace.WriteLine("   |   " + coreUsages[i].CounterName + " ~ " + coreUsages[i].NextValue());
    }

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts