Qhimm.com Forums
Miscellaneous Forums => Scripting and Reverse Engineering => Topic started by: Alhexx on 2002-07-03 18:34:29
-
I'm trying to show the current memory/CPU usage in a C++ App like the Windows Task Manager in WinNT systems do. However, I can't find any useful API calls to read out those values.
Does anyone know where to get them?
- Alhexx
-
Memory usage, there's a single API call thats something like "GetGlobalMemoryStatus" IIRC (haven't got my docs to hand). CPU usage I suspect you need to delve into performance statistics, which aren't *quite* so simple (I've never actually done that myself).
-
CPU usage is tricky -- under Windows NT, you can get your own process's memory usage with GetProcessTimes() and GetThreadTimes(), but I don't know how to read the global CPU usage yet since I haven't been able to get a usable process or thread handle for the idle process. Get*Times() doesn't work under Windows 95/98, but you can get the global CPU usage from the registry. See oshelper.cpp in the VirtualDub source code for ways to measure CPU usage under both NT and 9x.
It is possible to measure per-thread CPU usage under 9x, but it's difficult -- the KernelToy WinTop does it by loading a special VxD that activates on context switches.
-
Okay, I'll try that out...
thanx
- Alhexx
-
Im new at this process thingies, but as i look at the help, how about to get handle to idle process by OpenProcess() with id 0, (that should be idle one) and then GetProcessTimes() with this handle ?
just a thought.
-
I've never gotten it to work -- OpenProcess() always returns NULL, even with Administrator privileges. Might need some NT security mojo.
-
Okay, I don't care 'bout the CPU usage atthe moment, but I read out the memory usage via GetProcessMemoryInfo(). However, it uses the "psapi.dll" which is only implemented on WinNT systems.
What do you think, would my app also work on Win9x systems if I deliver the psapi.dll together with my app?
- Alhexx
-
Perhaps. Generally it's a bad idea to include system DLLs from specific OS's with your program, though. Either find a work-around that works on Win9x (not sure if Win9x can even measure process memory usage...), or exclude that functionality in Win9x programmatically (dynamic linking). Might not be what you want, though ;-)
-
I think the easiest way to find it out is to try it out. Kaoru has got Win98 installed on his machine - I'll try it before releasing Ultima 0.31 ...
- Alhexx
-
I tried to copy a dinput8.dll to my program (which was messing with joystick) on the computer without directx installed. It didn't work.
-
Okay, I've tried it out - it doesn't work ... I've gotta find another solution...
- Alhexx