I want to create a program that monitors the CPU load (like the task manager of Windows NT).

I have no idea where to begin so any help will be appriciated.

Thanks
Posted on 2002-12-07 05:12:03 by titanium
I *think* you can get that info from the registry. Not sure where....
Posted on 2002-12-07 05:50:52 by Xtreme
Hi titanium,

On WinME I invoke GlobalMemoryStatus into a MEMORYSTATUS structure and read the 'load' from the MemStat.dwMemoryLoad structure element.

I use MyGetFreeSystemResources32@4 from the rsrc32.dll to get the System, User, and GDI amounts.

I gave up on trying to display the CPUusage percent, since M$ documentation stated it could be read from the registry...then later retracted that saying it wasn't accurate..HAHaha..read: way off. I see that several prgs deal with it in some way to get a stable accurate reading, but I put it aside on the backburner and haven't messed with it since.

I don't know if any of this has anything at all to do with NT or not though.
Posted on 2002-12-07 07:09:06 by gscundiff
gscundiff,

I've had the same experience with GlobalMemoryStatus. Not a reliable API.
Posted on 2002-12-07 16:31:40 by Xtreme
Indeed there is very simple/bad support for such a function in WIndows OS.

It wrongly assumes that IF you are not waisteing time in a GetMessage Loop (even if you are corectly using PeekMessage to deal with system requests) you are using 100% of CPU time.

This is obviouse wrong because if my application uses 100% of CPU time then how am i able to play MP3 music, read email, and act as a file server and router in the same time? eh?

You can try and use RDTSC instruction inside a driver (better) or even inside a ring3 WINAPI application to detect how much time all OTHER tasks took from you... but that will not be very accurate as there is no way of knowing where the time was waisted (ie inside OS or other applications).

You should inject your little RDTSC code int each and all applications and sum up the time they use, the rest has to be used up by the system OS... i guess ...

From here on you are on your own ;)
Posted on 2002-12-07 17:27:29 by BogdanOntanu
I've ported it FROM vb... ;) it use the Pdh* func.
Actually you'll have to change the line


pdhStrCounter db "\Processeur(0)\% Temps Processeur",0

to it's english equivalent.. (got a french windows version...)
it must be something like "Processor(0)\% Processor time" or SLT

Hope it helps...
Posted on 2002-12-09 01:31:21 by PhoBos
Just see the name of the zip file :))
ThX goes to Iczelion's tuts... :grin:
Posted on 2002-12-09 01:32:52 by PhoBos
just an information
PdhTool requires pdh.dll. The library is not supported by, and consequently PdhTool will not work on, systems running Windows 95, 98, or ME.

dont have pdh.dll, get it from here

another program that uses pdh with source PdhTool

both dont work on my NT4SP6. donno why.

one program that works, but no source TinyResMeter
Posted on 2002-12-09 05:32:31 by TBD