Per-Process CPU Usage (Win9x)

Per-Process CPU Usage (Win9x)

Post by Javert9 » Wed, 22 May 2002 07:15:09



Hello, I was wondering if anyone knows how to get per-
process cpu usage on Window 95/98/Me. I have been trying
desperately to search the web for the answer, but I have
not gotten anywhere. Several articles pointed to writing a
device driver to communicate with the kernel, but give no
indication as to how the communication should work.
Besides, I am not familiar with driver development, and I
would prefer to limit my calls to the Win32 API
(regardless of whether they are documented or
undocumented). I know that it is possible because
SysInternal's 'Process Explorer' and the 'Windows Process
Explorer' (in Microsoft's Kernel Toys) both accomplish
this task. Thanks in advance for any help you can offer.
 
 
 

Per-Process CPU Usage (Win9x)

Post by Phil Wilso » Wed, 22 May 2002 07:43:38


The CreateToolhelp32Snapshot will get you a list of processids. Given these,
you can do an OpenProcess on each of them to get a handle to the process,
then call GetProcessTimes using the handle. You'll have to work out the
usage by periodically taking a delta between the sets of numbers and
dividing by the elapsed time between the two snapshots to get a usage rate.
Seems complicated, but I think that's the generally documented and supported
safe way.


Quote:> Hello, I was wondering if anyone knows how to get per-
> process cpu usage on Window 95/98/Me. I have been trying
> desperately to search the web for the answer, but I have
> not gotten anywhere. Several articles pointed to writing a
> device driver to communicate with the kernel, but give no
> indication as to how the communication should work.
> Besides, I am not familiar with driver development, and I
> would prefer to limit my calls to the Win32 API
> (regardless of whether they are documented or
> undocumented). I know that it is possible because
> SysInternal's 'Process Explorer' and the 'Windows Process
> Explorer' (in Microsoft's Kernel Toys) both accomplish
> this task. Thanks in advance for any help you can offer.


 
 
 

Per-Process CPU Usage (Win9x)

Post by NowCa » Wed, 22 May 2002 13:43:53


--

+----------------------+


  http://nowcan.yeah.net
+----------------------+

Quote:> The CreateToolhelp32Snapshot will get you a list of processids. Given
these,
> you can do an OpenProcess on each of them to get a handle to the process,
> then call GetProcessTimes using the handle. You'll have to work out the
> usage by periodically taking a delta between the sets of numbers and
> dividing by the elapsed time between the two snapshots to get a usage
rate.
> Seems complicated, but I think that's the generally documented and
supported
> safe way.

GetProcessTimes? Can it work in Win9X ?
 
 
 

Per-Process CPU Usage (Win9x)

Post by Phil Wilso » Thu, 23 May 2002 04:30:27


Oops, nope, you're right, my goof..


> --

> +----------------------+


>   http://nowcan.yeah.net
> +----------------------+


> > The CreateToolhelp32Snapshot will get you a list of processids. Given
> these,
> > you can do an OpenProcess on each of them to get a handle to the
process,
> > then call GetProcessTimes using the handle. You'll have to work out the
> > usage by periodically taking a delta between the sets of numbers and
> > dividing by the elapsed time between the two snapshots to get a usage
> rate.
> > Seems complicated, but I think that's the generally documented and
> supported
> > safe way.

> GetProcessTimes? Can it work in Win9X ?

 
 
 

Per-Process CPU Usage (Win9x)

Post by Phil Ashb » Fri, 24 May 2002 19:02:39



> Hello, I was wondering if anyone knows how to get per-
> process cpu usage on Window 95/98/Me. I have been trying
> desperately to search the web for the answer, but I have
> not gotten anywhere. Several articles pointed to writing a
> device driver to communicate with the kernel, but give no
> indication as to how the communication should work.
> Besides, I am not familiar with driver development, and I
> would prefer to limit my calls to the Win32 API
> (regardless of whether they are documented or
> undocumented). I know that it is possible because
> SysInternal's 'Process Explorer' and the 'Windows Process
> Explorer' (in Microsoft's Kernel Toys) both accomplish
> this task. Thanks in advance for any help you can offer.

The kernel toys WinTOP program uses a device driver (wintop.vxd) to
monitor thread usage, and attempts to associate this with Win32
threads/processes (although it sometimes goes wrong when a handle
is re-used between updates!). I believe the Win32 association is
done by reading various undocumented areas of kernel data structures
associated with Win32 processes/threads... see the source code for
Filemon/Regmon (www.sysinternal.com) device drivers for details of
a technique that may work (quite possibly reverse engineered from
WinTOP!).

--
Phil "Phlash" Ashby (speaking only for himself)
Work: http://www.internet-designers.net/
Home: http://www.ashbysoft.com/