I'm looking for a function that return percentage usage of processor's time for each process/thread.
Something like that you can see in Wintop or XP's taskmgr.(I was looking into Wintop's code in SoftIce, Win32DAsm... for nothing).
My program like Wintop uses CreateToolhelp32Snapshot, Process32First, Process32Next, but I can't read processor's usage.
Posted on 2003-04-29 16:13:21 by Dryobates
GetProcessTimes perhaps? (NT only)
Posted on 2003-04-29 16:47:03 by f0dder
Unfortunately there is no such thing... not for real

The older Windows (aka win9x) used a dummy method for this:
-They check how much time an application uses from its own time slice int the GetMessage loop.

This resulted in very funny situations like 2 applications that use PeekMessage to use idle message time for anuimations and stuff (aka games) to end up both use 100% of CPU... imposible of course :D

Actually ANY application that uses PeekMessage and has NO Sleep inserted in message loop will end up using 100% CPU time...again absurd as i can still do many OTHER things with the same CPU

Win2k has another "ideea" counts the "time in kernel mode" and the time in "user mode"

making a percent of the compared to all applications time could be relatively accurate... curently is NOT
Posted on 2003-04-29 18:10:12 by BogdanOntanu
1) Thnx Dryobates for putting my question here :alright:
2) Have you seen an application Microsoft Wintop? It is exactly what I want to write (of course with many additional things).
And I don?t think Wintop uses algorithm described by BogdanOntanu, because I haven?t noticed a ?strange? behavior like e.g. two programs using 100% CPU time.
It is using it's own vxd file and calls a function in it for every active process/thread. I was trying to understand this vxd, but I'm not good enough for that :(.
Maybe you have an idea how to use it in my program?
Thnx in adv.
Posted on 2003-04-29 18:48:51 by Marooned
Indeed "mea culpa" i just checked it and Win2k makes a much better and corect calculation.

You should use GetProcess times indeed on NT... for Win9x i guess you should try and duplicate the NT api ... if possible ...
Posted on 2003-04-29 21:47:24 by BogdanOntanu
for Win9x i guess you should try and duplicate the NT api ... if possible ...

I forgot to write that I'm using WinMe. So it's important to me to find the solution working on this OS. Could you describe this method a little bit more?
Or maybe you can help me to use a ?wintop.vxd? file (if it possible) in my application?
Posted on 2003-04-29 23:51:54 by Marooned