Discussion:
CPU Idle Time
(too old to reply)
Software Engineer
2005-07-15 05:12:37 UTC
Permalink
Please tell me how can I get CPU idletime in windows 2000 and windows
NT.

I actually want to calculate the CPU usage of a process in percentage
and
for that I require the cpu time for that process and system idle
time(cpu ide
time). It can be retrived in Windows XP and 2k3 by using function
GetSystemTimes() but I can't find corresponding function for Windows
200 and
2003

Thanks in Anticipation
TC
2005-07-15 05:18:50 UTC
Permalink
To calculate process cpu usage, I would have thought that you just
needed the total cpu time used by your process in a known elapsed time.
If so, how does the cpu idle time help? What is your formula for cpu
usage?

TC
Software Engineer
2005-07-15 05:25:08 UTC
Permalink
The formula i plan to use is
cpu = int( (system - idle) *100 / system );
where system is the time taken by the process i want to monitor and
idle is the time taken by the system idle process.
Software Engineer
2005-07-15 05:27:48 UTC
Permalink
Orignal question was
---------------------------------------------------------------
Please tell me how can I get CPU idletime in windows 2000 and windows
NT.

I actually want to calculate the CPU usage of a process in percentage
and for that I require the cpu time for that process and system idle
time(cpu idle time). It can be retrived in Windows XP and 2k3 by using
function GetSystemTimes() but I can't find corresponding function for
Windows 200 and 2003.

Thanks in Anticipation.
---------------------------------------------------------------
TC
2005-07-15 05:28:36 UTC
Permalink
Wow, that was quick!

Your formula is surely wrong.

your process = 1ms
some other process = 99ms
idle = 0ms

gives your processes cpu usage as 100% - but it was actually 1%

TC
Software Engineer
2005-07-15 05:36:50 UTC
Permalink
So can you please suggest me something how can i calculate cpu usage in
windows Nt and windows 2000, similar to what we get in task manager,
for a particular process.
TC
2005-07-15 05:40:36 UTC
Permalink
"To calculate process cpu usage, I would have thought that you just
needed the total cpu time used by your process in a known elapsed
time."

I'm personally not sure of what is the best way to do that. Someone
else can doubtless help. But at least you have a better forumla now!

Cheers,
TC
Software Engineer
2005-07-15 05:46:42 UTC
Permalink
No. i don't have any formula now.
The only formula i had had been prooved wrong by you.
Now i am helpless. Please help.
TC
2005-07-15 05:52:41 UTC
Permalink
If your process has used 'x' amount of cpu time, in 'y' amount of
elapsed time, the process usage in that time period would have been:
(100 * x) / y percent.

So you need to get 'x' and 'y'.

I'm not sure what is the best way to do that.

Maybe someoine else can help.

Cheers,
TC
Software Engineer
2005-07-15 06:05:20 UTC
Permalink
well there is a correction.

can i use the formula as

process_time(taken in 1 sec)/(1-idle_time)
TC
2005-07-15 06:24:43 UTC
Permalink
You're kidding me, right?

Sorry, I am on a public PC, I have to go now.

Good luck,
TC
Software Engineer
2005-07-15 06:49:40 UTC
Permalink
The formula i wrote earlier, i took that from a posting which didn't
have complete description.
And the above formula, based on your observations, i modified to
actually get what i need.

But the question still remains the same. How can I get the Idle CPU
Time on windows 2000 and NT???
Post by TC
You're kidding me, right?
Sorry, I am on a public PC, I have to go now.
Good luck,
TC
stork
2005-07-15 16:01:11 UTC
Permalink
Use WMI?

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/monitoring_performance_data.asp
Tim Kannel
2005-07-15 19:45:43 UTC
Permalink
Post by TC
If your process has used 'x' amount of cpu time, in 'y' amount of
(100 * x) / y percent.
So you need to get 'x' and 'y'.
I'm not sure what is the best way to do that.
x -> GetProcessTimes() (kernel time + user time)

y -> One way to determine elapsed time is by using
QueryPerformanceCounter and QueryPerformanceFrequency
(I won't comment one whether this is the best way).


Related info about accurracy of Task Manager:
http://support.microsoft.com/default.aspx?scid=kb;en-us;873289

Considering the issue mentioned in that article, I'm not sure how accurate
GetProcessTimes() is. Task Manager (XP version thereof) doesn't use
GetProcessTimes, but maybe a similar issue exists. If that's a concern
then using WMI, as "stork" suggested, may be better.
--
Tim Kannel

TCAP - Captures console I/O to a file (DOS,Win9x)
http://www.simtel.net/pub/pd/11141.shtml
TC
2005-07-16 06:37:15 UTC
Permalink
Let's just hope he gets the >formula< right!

TC

Loading...