PDA

View Full Version : CPU and Memory Usage



philwinder
14th May 2008, 12:20
Hi again,
I have found a thread regarding memory usage here (http://www.qtcentre.org/forum/f-general-programming-9/t-how-to-determine-memory-usage-5610.html) but it seems a bit of a complicated way to do it.... So:

Does anyone know how to get the CPU and Memory usage of the entire system?

I found an example that comes with Qwt called CPUplot, but it turned out that it is using fake data! Shocking!

ChristianEhrlicher
14th May 2008, 15:31
Because this is very different on every OS Qt can't do it for you. You have to implement it by your own for every OS you want.

philwinder
14th May 2008, 15:36
:( Ok. Any pointers on how to do that then? I'm working on XP.
Thanks.

Sandip
14th May 2008, 16:13
Hi,

Following links may help you to solve your problem on Windows Operating systems -

http://msdn.microsoft.com/en-us/library/aa394317(VS.85).aspx

http://msdn.microsoft.com/en-us/library/ms974615.aspx

philwinder
14th May 2008, 19:18
Hi Sandip,
Thanks for the links, they look pretty interesting! Although, this looks to be a bit complicated (cant remember how to convert dll's into .a libraries so will have to look that up).
Will have a bash tommorow when I'm a bit more awake.
In the mean time, any example code will be helpful.

philwinder
14th May 2008, 20:56
Well after about 2 hours research its still incredibly hard to find out you CPU usage. There was a mention about a GetSystemTimes function in the winapi, but I dont think it works for XP. Only vista. Also, you have to take before and after results because it specifies the amount of time the processor has been idle, active etc. A completely nonsensical way of doing things.

There was also links to WMI functions, but it was way too complicated for me.

So I will just have to do without, or make a call to open the task manager! I cant believe that there isnt an easier way to do this.

If anyone has done this before, or has any insight then please feel free to reply.

Sandip
15th May 2008, 09:10
Hi,

Sorry.
It's not possible for me to write a sample program. If I will get time to look at it then will post it here. Anyway you can find it on internet.
Look at the following link:
http://www.codeproject.com/KB/system/MultiCPUUsage.aspx
http://www.codeproject.com/KB/system/processescpuusage.aspx

It may be helpful for you.

Regards,
Sandip

philwinder
15th May 2008, 09:38
Hi again Sandip.
I did find both those links, and I specifically tried the second one, but it wouldnt work for XP. I didnt try the first link, so I might give it another go...

Cheers,
Phil

philwinder
15th May 2008, 11:12
Arrrhhhggg...
Pulling my hair out.
I tried it the way from the first link you found, and everything is fine until you need to include:
#include "comdef.h"
#include "Wbemidl.h"

These two files come with the platform SDK, so after downloading for ages, put the right paths in and bummer, the most errors I have ever got. 16861 to be exact. Thats a lot of errors.

All from these include files. So I dont know much about this, but I get the impression if its not included with mingw32 then we have no chance.....

Have you had any luck?

Sandip
15th May 2008, 12:20
Hi philwinder,

I think you are using open souce edition of qt. Please try to build these projects using qt with Visual Studio Integration. It reduces a lot of your work.
You don't need to specify the libraries and all other stuff.
I also got errors while using SDK functions in qt classes in my other project.

So my suggestion is to try with Visual Studio first.

Meanwhile If I will get a chance then I will try to run these projects.

Best Regards,
Sandip

pherthyl
15th May 2008, 19:41
I would also suggest using Visual Studio. The 2008 express version to be exact. Compiling the open source version of Qt with Visual Studio used to be a huge pain in the ass with patching Qt and the platform sdk and getting paths right. It's much much easier now. Get the source of Qt 4.4, install VS 2008 express, and then do a configure, nmake in the qt directory. Once it compiles you're good to go. Nothing else necessary.

philwinder
16th May 2008, 09:49
Ok, I'll give it a go. But I'm warning you windows, this better all be worth it!
I just didnt want to get stuck down with using all proprietary windows stuff. I have never used Qt with VS before. Suppose its about time I tried!

philwinder
16th May 2008, 17:51
Ok Ive had enough.
I spent 3 hours downloading, configuring and nmakeing QT then I have spent the next 5 hours trying to get the WINAPI code working. I havent. So I give up. I dont like using VS Express 2008 anyway. Its too big, cumbersome, and it feels like the Qt integration has been bodged.

Back to QDevelop and no interesting CPU information. Hopefully Qt will add it in the future.

Cheers,
Phil

pherthyl
16th May 2008, 19:49
It shouldn't be that difficult. Download Qt source, configure, nmake, wait. Then use nmake to compile your projects (either with VS or from the command line). If the headers you need aren't in VS, then you might need the full platform SDK.

I generally prefer mingw+qdevelop as well, but when you need windows stuff beyond the basics it causes more problems than it solves.

philwinder
17th May 2008, 10:31
I wasnt difficult, just complicated. There are too many hoops to jump through to get thing to do what you want. But the code itself was utterly rediculous. It should be as easy as calling a function. But its not.

The program complied fine, and it was working to an extent, but the person who wrote that code took a stats reading, sleep for 2 seconds, took another stats reading then took the two results away from each other. I tried to change it so it didnt have to sleep, but it didnt work. So I gave up.

This was all for a bit of eye candy anyway. Not essential.

Uwe
17th May 2008, 17:13
I found an example that comes with Qwt called CPUplot, but it turned out that it is using fake data! Shocking!
On modern operating systems the demo reads its values from "/proc/stat". Only for the exotic environments :rolleyes: it falls back on data from a session that was recorded on my linux box.

Uwe

philwinder
17th May 2008, 23:25
What do you mean by modern? XP?
Would you know how to get info from XP?