|
|
How can I programmatically monitor CPU load
Like is done in 'windows task manager' \ preformance. I want to add a
section i my existing code that gets and records current CPU load. I
believe I once saw a way to do this but now that I want it I an unable
to find it.
Thanks
AL
|
|
0
|
|
|
|
Reply
|
aldavis (7)
|
8/3/2010 1:38:10 PM |
|
TaskManager and Co. uses information from the registry.
The system stores a *lot* of performance statistics in
a hive called HKEY_PERFORMANCE_DATA on NT systems.
among them CPU usage statistics.
There's a sample in the SDK you can dig into to get
the hang of using these statistics:
<SDK>\Samples\SDKTools\WinNT\PerfMon
It's probably a lot more than you need, being a full-fledged
programmers tool, but it's considered *the* example of using
the system performance data.
HTH
Love
On Tue, 3 Aug 2010 06:38:10 -0700 (PDT), yzfoot <aldavis@mich.com>
wrote:
>Like is done in 'windows task manager' \ preformance. I want to add a
>section i my existing code that gets and records current CPU load. I
>believe I once saw a way to do this but now that I want it I an unable
>to find it.
>
>Thanks
>AL
|
|
0
|
|
|
|
Reply
|
B
|
9/11/2010 8:48:04 AM
|
|
On Aug 3, 2:38=A0pm, yzfoot <alda...@mich.com> wrote:
> Like is done in 'windows task manager' \ preformance. =A0I want to add a
> section i my existing code that gets and records current CPU load.
Call NtQuerySystemInformation with the
SystemProcessorPerformanceInformation parameter:
http://msdn.microsoft.com/en-us/library/ms724509.aspx
If it worries you that the function is deprecated you can instead call
GetSystemTimes (but that only gives you the total for all processors):
http://msdn.microsoft.com/en-us/library/ms724400.aspx
To find the CPU load call the function periodically (e.g. once per
second) and subtract the previous values from the latest values to see
by how much each of the times (user, kernel, idle) has increased. The
average load for that period is:
cpuload =3D (userdelta+kerneldelta-idledelta)/(userdelta+kerneldelta)
Richard.
http://www.rtrussell.co.uk/
|
|
0
|
|
|
|
Reply
|
Richard
|
9/11/2010 10:22:48 PM
|
|
Though the original post, to which I replied, have gone away,
I felt like giving anyone curious enough one more pointer.
It's fun after all, to be able to put up a CPU usage graph.
Matt Pietrek wrote two crystal clear articles about how to
access the performance data, in MS Systems Journal 1996,
in the "Under the Hood" column of theMarch and April issues.
That's a much better place to start than the SDK sample
I pointed out. The articles were also re-published on MSDN,
so You might still find it on the web site, or the CD release,
if You can't find the magazines at Your reference library.
Best Regards
Love
On Sat, 11 Sep 2010 15:48:04 +0700, B.O. Love <nomail.please@no.net>
wrote:
>TaskManager and Co. uses information from the registry.
>
>The system stores a *lot* of performance statistics in
>a hive called HKEY_PERFORMANCE_DATA on NT systems.
>among them CPU usage statistics.
>
>There's a sample in the SDK you can dig into to get
>the hang of using these statistics:
>
><SDK>\Samples\SDKTools\WinNT\PerfMon
>
>It's probably a lot more than you need, being a full-fledged
>programmers tool, but it's considered *the* example of using
>the system performance data.
>
>HTH
>Love
>
>
>On Tue, 3 Aug 2010 06:38:10 -0700 (PDT), yzfoot <aldavis@mich.com>
>wrote:
>
>>Like is done in 'windows task manager' \ preformance. I want to add a
>>section i my existing code that gets and records current CPU load. I
>>believe I once saw a way to do this but now that I want it I an unable
>>to find it.
>>
>>Thanks
>>AL
|
|
0
|
|
|
|
Reply
|
B
|
9/13/2010 3:16:08 PM
|
|
|
3 Replies
689 Views
(page loaded in 0.079 seconds)
|
|
|
|
|
|
|
|
|