Discussion:
Getting 'System Idle Process' to the ms
(too old to reply)
Marco Shaw
2007-08-24 17:53:48 UTC
Permalink
Want to do some calculations. 'System Idle Process' isn't something
that will show with a get-process, likely because it really isn't a
process...

I could do tasklist, but that gives me only seconds, from what I can tell.

Other then adding all the milliseconds for all the processes, and
subtracting that from the uptime or similar, is there another way to get
the time of how long the CPU has been idle since boot in millisecs?

Marco
--
----------------
PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
RichS
2007-08-24 19:10:02 UTC
Permalink
Not that I'm aware of. I've just done a get-process on a Vista machine and
it does show an Idle process but the totlaprocessortime doesn't return
anything
--
Richard Siddaway
Please note that all scripts are supplied "as is" and with no warranty
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk
Post by Marco Shaw
Want to do some calculations. 'System Idle Process' isn't something
that will show with a get-process, likely because it really isn't a
process...
I could do tasklist, but that gives me only seconds, from what I can tell.
Other then adding all the milliseconds for all the processes, and
subtracting that from the uptime or similar, is there another way to get
the time of how long the CPU has been idle since boot in millisecs?
Marco
--
----------------
PowerGadgets MVP
http://www.powergadgets.com/mvp
http://marcoshaw.blogspot.com
Keith Hill [MVP]
2007-08-24 22:37:56 UTC
Permalink
Want to do some calculations. 'System Idle Process' isn't something that
will show with a get-process, likely because it really isn't a process...
It does show up. Just look for "Idle" instead. However there doesn't seem
to be much useful info on it -
UserProcessorTime and PrivilegedProcessorTime aren't set.
I could do tasklist, but that gives me only seconds, from what I can tell.
Other then adding all the milliseconds for all the processes, and
subtracting that from the uptime or similar, is there another way to get
the time of how long the CPU has been idle since boot in millisecs?
The following works and jives with what I see in PerfMon (Process / Elapsed
Time) as you expect, unfortunately it doesn't jive with Task Manager, hmm.

$pc = new-object System.Diagnostics.PerformanceCounter 'Process', 'Elapsed
Time', 'Idle'
$sample = $pc.NextSample()
[TimeSpan]::FromSeconds($sample.Timestamp / $sample.SystemFrequency)

--
Keith
urkec
2007-08-25 11:58:01 UTC
Permalink
Post by Keith Hill [MVP]
The following works and jives with what I see in PerfMon (Process / Elapsed
Time) as you expect, unfortunately it doesn't jive with Task Manager, hmm.
$pc = new-object System.Diagnostics.PerformanceCounter 'Process', 'Elapsed
Time', 'Idle'
$sample = $pc.NextSample()
[TimeSpan]::FromSeconds($sample.Timestamp / $sample.SystemFrequency)
--
Keith
I used this to get Win32_Process.KernelModeTime for System idle process

Get-WmiObject Win32_Process -Filter "Name='System idle process'" |
Format-List Name, KernelModeTime

and it seemes to return about the same value as in Task manager (in 100
nanoseconds).
--
urkec
Keith Hill
2007-08-25 16:49:30 UTC
Permalink
Post by urkec
Post by Keith Hill [MVP]
The following works and jives with what I see in PerfMon (Process / Elapsed
Time) as you expect, unfortunately it doesn't jive with Task Manager, hmm.
$pc = new-object System.Diagnostics.PerformanceCounter 'Process', 'Elapsed
Time', 'Idle'
$sample = $pc.NextSample()
[TimeSpan]::FromSeconds($sample.Timestamp / $sample.SystemFrequency)
I used this to get Win32_Process.KernelModeTime for System idle process
Get-WmiObject Win32_Process -Filter "Name='System idle process'" |
Format-List Name, KernelModeTime
and it seemes to return about the same value as in Task manager (in 100
nanoseconds).
I think you have a winner there. Nice!

--
Keith
Flowering Weeds
2007-08-25 18:20:26 UTC
Permalink
"Marco Shaw"
is there another way to get the
time of how long the CPU has been
idle since boot in millisecs?
As mentioned Win23_Process

"Data type: uint64
Access type: Read-only

Time in kernel mode, in 100 nanosecond units."

Win32_Process (Windows)
http://msdn2.microsoft.com/en-us/library/aa394372.aspx

And

"The value of a TimeSpan object is the
number of ticks that equal the represented
time interval. A tick is equal to 100
nanoseconds, and the value of a TimeSpan
object can range from MinValue to MaxValue."

TimeSpan Structure (System)
http://msdn2.microsoft.com/en-us/library/system.timespan(VS.80).aspx

PS> Get-WmiObject Win32_Process -Filter "Name='System idle process'"
| Select KernelModeTime | format-table -autosize

KernelModeTime
--------------
134007187500

PS> $timeSpan = new-object System.TimeSpan 134007187500
PS> $timeSpan

Days : 0
Hours : 3
Minutes : 43
Seconds : 20
Milliseconds : 718
Ticks : 134007187500
TotalDays : 0.155100911458333
TotalHours : 3.722421875
TotalMinutes : 223.3453125
TotalSeconds : 13400.71875
TotalMilliseconds : 13400718.75

PS>
Kiron
2007-08-25 18:38:58 UTC
Permalink
Casting:
[timeSpan][long](gwmi Win32_Process -f "Name='System idle
process'").KernelModeTime

--
Kiron

Continue reading on narkive:
Loading...