Results 1 to 17 of 17

Thread: CPU and Memory Usage

  1. #1
    Join Date
    Apr 2008
    Posts
    73
    Thanks
    11
    Thanked 7 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Post CPU and Memory Usage

    Hi again,
    I have found a thread regarding memory usage here 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!
    Best Regards,
    Phil Winder
    www.philwinder.com

  2. #2
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: CPU and Memory Usage

    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.

  3. #3
    Join Date
    Apr 2008
    Posts
    73
    Thanks
    11
    Thanked 7 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: CPU and Memory Usage

    Ok. Any pointers on how to do that then? I'm working on XP.
    Thanks.
    Best Regards,
    Phil Winder
    www.philwinder.com

  4. #4
    Join Date
    Feb 2008
    Posts
    51
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Smile Re: CPU and Memory Usage

    Hi,

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

    http://msdn.microsoft.com/en-us/libr...17(VS.85).aspx

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

  5. #5
    Join Date
    Apr 2008
    Posts
    73
    Thanks
    11
    Thanked 7 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: CPU and Memory Usage

    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.
    Best Regards,
    Phil Winder
    www.philwinder.com

  6. #6
    Join Date
    Apr 2008
    Posts
    73
    Thanks
    11
    Thanked 7 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: CPU and Memory Usage

    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.
    Best Regards,
    Phil Winder
    www.philwinder.com

  7. #7
    Join Date
    Feb 2008
    Posts
    51
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: CPU and Memory Usage

    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...scpuusage.aspx

    It may be helpful for you.

    Regards,
    Sandip

  8. #8
    Join Date
    Apr 2008
    Posts
    73
    Thanks
    11
    Thanked 7 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: CPU and Memory Usage

    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
    Best Regards,
    Phil Winder
    www.philwinder.com

  9. #9
    Join Date
    Apr 2008
    Posts
    73
    Thanks
    11
    Thanked 7 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: CPU and Memory Usage

    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?
    Best Regards,
    Phil Winder
    www.philwinder.com

  10. #10
    Join Date
    Feb 2008
    Posts
    51
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: CPU and Memory Usage

    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

  11. #11
    Join Date
    Aug 2006
    Posts
    250
    Thanks
    19
    Thanked 49 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: CPU and Memory Usage

    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.

  12. #12
    Join Date
    Apr 2008
    Posts
    73
    Thanks
    11
    Thanked 7 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: CPU and Memory Usage

    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!
    Best Regards,
    Phil Winder
    www.philwinder.com

  13. #13
    Join Date
    Apr 2008
    Posts
    73
    Thanks
    11
    Thanked 7 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: CPU and Memory Usage

    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
    Best Regards,
    Phil Winder
    www.philwinder.com

  14. #14
    Join Date
    Aug 2006
    Posts
    250
    Thanks
    19
    Thanked 49 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: CPU and Memory Usage

    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.

  15. #15
    Join Date
    Apr 2008
    Posts
    73
    Thanks
    11
    Thanked 7 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: CPU and Memory Usage

    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.
    Best Regards,
    Phil Winder
    www.philwinder.com

  16. #16
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,312
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: CPU and Memory Usage

    Quote Originally Posted by philwinder View Post
    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 it falls back on data from a session that was recorded on my linux box.

    Uwe

  17. #17
    Join Date
    Apr 2008
    Posts
    73
    Thanks
    11
    Thanked 7 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: CPU and Memory Usage

    What do you mean by modern? XP?
    Would you know how to get info from XP?
    Best Regards,
    Phil Winder
    www.philwinder.com

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.