7

The Windows Task Manager shows CPU usage in percentage. What's the formula behind this? Is it this:

% CPU usage for process A = (Sum of all time slices given to A till now)/ Total time since the machine booted

Or is it something else?

4 Answers 4

10

I am not 100% sure what is uses, but I think you are a bit off on the CPU calculation.

I believe they are doing something like.

Process A CPU Usage = (Cycles for A over last X seconds)/(Total cycles for last X seconds)

I believe it is tied to the "update interval" set in task manager.

While doing a bit of research for you though I found this MSDN article that shows a microsoft recommended way of calculating the CPU time of a set of instructions, this might point you a bit towards their calculation as well.

8

No, it's not "since boot time" - it's far more time-sensitive than that.

It's "proportion of time during which a CPU was actively running a thread in that process since the last refresh". (Where the refresh rate is typically about a second.) In task manager I believe it's then divided by the number of CPUs, so the total ends up being 100% (i.e. on a dual core machine, a single-threaded CPU hog will show as 50%). Other similar programs sometimes don't do this, giving a total of 100% * cores.

3
  • Dang! You got the same thing as me...but as normal you beat me to it. How are you always here? Commented May 1, 2009 at 6:19
  • Makes sense. Thank you both Jon and Mitchel
    – G S
    Commented May 1, 2009 at 6:22
  • "How are you always here?" huge LOL
    – Ric Tokyo
    Commented May 1, 2009 at 6:32
1

You may also want to check this article as the way CPU cycles are handled with regards to scheduling was changed as part of Vista. I presume that this also applies to Win7.

-2

See the source code of Task Manager

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