Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Measuring CPU usage and internet bandwidth
Forum Updated to NodeBB v4.3 + New Features

Measuring CPU usage and internet bandwidth

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 5.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    praveen gaur
    wrote on last edited by
    #1

    HI,

    Is there any way in QT we can measure CPU usage and Internet bandwidth?

    1 Reply Last reply
    0
    • F Offline
      F Offline
      fluca1978
      wrote on last edited by
      #2

      No, it is too much platform related. You have to use operating system facilities to extract such information.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        MuldeR
        wrote on last edited by
        #3

        You didn't mention what platform you are on, but on Win32 detect the CPU usage is straight forward:

        Simply call GetSystemTimes() in a loop (with a Sleep() between the calls) and calculate the difference of the counters between the current call and the previous call. That will give you the time the CPU has spent in each of the three states (kernel/user/idle) within the last interval. Then you can calculate the fraction of the time that the CPU was "busy" (not idle) in the last interval. And that's the "CPU usage". The interval size is up to you.

        (Only take care that the "lpKernelTime" counter also includes the "idle" time!)

        My OpenSource software at: http://muldersoft.com/

        Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

        Go visit the coop: http://youtu.be/Jay...

        1 Reply Last reply
        0
        • F Offline
          F Offline
          fluca1978
          wrote on last edited by
          #4

          [quote author="MuldeR" date="1338225732"]
          Simply call GetSystemTimes() in a loop (with a Sleep() between the calls) and calculate the difference of the counters between the current call and the previous call. That will give you the time the CPU has spent in each of the three states (kernel/user/idle) within the last interval. Then you can calculate the fraction of the time that the CPU was "busy" (not idle) in the last interval. And that's the "CPU usage". The interval size is up to you.
          [/quote]

          Quite an hand-made solution, and it is going to work only on Windows.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            MuldeR
            wrote on last edited by
            #5

            Yeah, as said before, there probably isn't a platform independent solution for this. GetSystemTimes() is the way to do it on the Windows platform. You'd have to look for a different way to get the CPU time counters on Linux, e.g. by reading "/proc/stat". Anyway, the basic idea on how to calculate the "CPU usage" should be the same!

            My OpenSource software at: http://muldersoft.com/

            Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

            Go visit the coop: http://youtu.be/Jay...

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved