0

I am trying to obtain the CPU load at run time. I am trying this fantastic answer but this code gives me the output like this:

Core: 0 Usage: 0.120000
Core: 1 Usage: 0.080000
Core: 2 Usage: 0.066667
Core: 3 Usage: 0.070000 

This is more than I need. How do I get the load in a scale from 0 to 100%, independently of how many cores/CPUS the user has?

OK, I can average these numbers but suppose the average is 0.08. Does it means the load is at 8%? I am not sure about that.

Community
  • 1
  • 1
Duck
  • 34,902
  • 47
  • 248
  • 470

1 Answers1

1

If you read the code you provided, you can see (@"Core: %u Usage: %f",i,inUse / total) which can be converted to percent easily with a simple inUse / total*100.

And by the way: enter image description here

Thomas Ayoub
  • 29,063
  • 15
  • 95
  • 142
  • OK I did that but the numbers don't appear to match the ones reported by Activity Monitor. Are you sure the number coming from this operation is CPU usage in percent? – Duck Feb 18 '15 at 10:07
  • By how much they are different @SpaceDog ? – Thomas Ayoub Feb 18 '15 at 10:09
  • It was probably some temporary stuff, now it is more or less giving the same values. THANKS. – Duck Feb 18 '15 at 10:17