1

On my system with 32 physical cores I'm constantly spawning 100 threads that run for anywhere between 0 and 3 seconds. After all are finished, the next batch is spawned.

I'd like to get correct average cpu usage, i.e. to what percentage are these cores used on a say 1 minute average. If they are idle for 30% of the time, that value should be 0.7

When using htop, I get a load average of more than 40 which higher than the number of cores However, as can be seen in this video, the CPU cores are not always used to 100%. This is what I expect as all 100 threads have to finish before new ones are generated.

How can I get a more precise measurement of CPU usage?

  • Does your system support hyperthreading? If so, you might be running two threads on each core. – Qudit Jun 7 '15 at 19:58
  • Nope, it's definitely disabled / not even supported. – helm Jun 7 '15 at 20:07
  • What kind of average? I suspect you want mean, but it could also be median (or possibly even mode). – roaima Jun 7 '15 at 20:57
  • It's the mean I want. – helm Jun 7 '15 at 21:23
1

Load average is not the cpu usage per say. This is an often cited explanation of what Load Average means. So a load average of 40 seems pretty reasonable for 100 threads that don't quite use 100% of a core.

To measure the actual CPU usage, I would look into using perf which can read hardware performance counters. Perf is a pretty powerful tool and can measure many things, in your case I might try:

perf stat -e cycles ./your_executable

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.