Home All Groups Group Topic Archive Search About

How to detect total CPU percentage utilization

Author
14 Nov 2006 6:23 PM
dgk
For the whole machine, not a specific process. I looked at an earlier
thread by Cor and Ken Tucker, but I don't find anything in the
management that looks like... Oh. Here is a really good site. Really,
I don't know the guy but just found it via Google. I guess I don't
need to post this anymore but just in case someone else is looking for
the info, here it is. It's in C# but nobody is perfect.

http://skilldrive.com/book/DOTNETinSamples.htm#_Toc112335378

Set a reference to System.Management and adapting the earlier thread's
code:
   Dim moReturn As Management.ManagementObjectCollection
    Dim moSearch As Management.ManagementObjectSearcher
    Dim mo As Management.ManagementObject
    moSearch = New Management.ManagementObjectSearcher("Select * from
Win32_Processor")
    moReturn = moSearch.Get
    For Each mo In moReturn
      Dim strout As String = String.Format("{0} - {1}", mo("Name"),
mo("LoadPercentage"))
      Debug.WriteLine(strout)
    Next

LoadPercentage is the key for what I was looking for. Two comments
about the code. First, why would there be more than one mo returned? I
guess multi-processor systems. I'll have to try it on my dual-core at
home.

Second, the "Select * from Win32_Processor" parameter. Kind of cute,
looks like a foreshadowing of DLINQ. Using SQL syntax for non-database
objects I think. Nice.

I started out by trying MY, as in My.Computer.Info but no CPU stuff is
there. Too bad, I'm getting spoiled by My.

Author
14 Nov 2006 7:10 PM
Miro
Could you not detect the System Idl Process ?  100 - Idle = used

Just a thought.

Miro


Show quoteHide quote
"dgk" <d**@somewhere.com> wrote in message
news:ib1kl2db0g8jrsrobmcc55nv5l90fhgluj@4ax.com...
> For the whole machine, not a specific process. I looked at an earlier
> thread by Cor and Ken Tucker, but I don't find anything in the
> management that looks like... Oh. Here is a really good site. Really,
> I don't know the guy but just found it via Google. I guess I don't
> need to post this anymore but just in case someone else is looking for
> the info, here it is. It's in C# but nobody is perfect.
>
> http://skilldrive.com/book/DOTNETinSamples.htm#_Toc112335378
>
> Set a reference to System.Management and adapting the earlier thread's
> code:
>   Dim moReturn As Management.ManagementObjectCollection
>    Dim moSearch As Management.ManagementObjectSearcher
>    Dim mo As Management.ManagementObject
>    moSearch = New Management.ManagementObjectSearcher("Select * from
> Win32_Processor")
>    moReturn = moSearch.Get
>    For Each mo In moReturn
>      Dim strout As String = String.Format("{0} - {1}", mo("Name"),
> mo("LoadPercentage"))
>      Debug.WriteLine(strout)
>    Next
>
> LoadPercentage is the key for what I was looking for. Two comments
> about the code. First, why would there be more than one mo returned? I
> guess multi-processor systems. I'll have to try it on my dual-core at
> home.
>
> Second, the "Select * from Win32_Processor" parameter. Kind of cute,
> looks like a foreshadowing of DLINQ. Using SQL syntax for non-database
> objects I think. Nice.
>
> I started out by trying MY, as in My.Computer.Info but no CPU stuff is
> there. Too bad, I'm getting spoiled by My.
Author
15 Nov 2006 1:28 PM
dgk
On Tue, 14 Nov 2006 14:10:48 -0500, "Miro" <miron***@golden.net>
wrote:

>Could you not detect the System Idl Process ?  100 - Idle = used
>
>Just a thought.
>
>Miro
>

Good thinking. Is that a real process?
Author
15 Nov 2006 4:03 PM
Miro
Take a look at this link.

This might help you
Ive only delt with processes, not the system Idle processes, but it seems he
is doing the same thing ur trying to do.

http://www.codeproject.com/csharp/processescpuusage.asp


M.


Show quoteHide quote
"dgk" <d**@somewhere.com> wrote in message
news:tc5ml2hg1iimtdjbe1se85sgr89rpm2bq6@4ax.com...
> On Tue, 14 Nov 2006 14:10:48 -0500, "Miro" <miron***@golden.net>
> wrote:
>
>>Could you not detect the System Idl Process ?  100 - Idle = used
>>
>>Just a thought.
>>
>>Miro
>>
>
> Good thinking. Is that a real process?
Author
15 Nov 2006 7:41 PM
dgk
Show quote Hide quote
On Wed, 15 Nov 2006 11:03:06 -0500, "Miro" <miron***@golden.net>
wrote:

>Take a look at this link.
>
>This might help you
>Ive only delt with processes, not the system Idle processes, but it seems he
>is doing the same thing ur trying to do.
>
>http://www.codeproject.com/csharp/processescpuusage.asp
Thanks.