Results 1 to 16 of 16

Thread: High CPU Usage in Drawing

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2010
    Posts
    5
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: High CPU Usage in Drawing

    i change the interval to 50 msec then CPU usage decrease to 25 percent !
    i am now working on do something to avoid repaint all of pixmap every 50 msec .

    now my question is 25 percent just for drawing 800 line is not too high although i use opengl widget ?
    my program is not too efficient or its is common usage for this job .

    another interesting result is happens . when i change my widget from QGLWidget to QWidget and re run the program the result do not change and CPU usage is also about 25. i am sure that this usage is just for drawing because when i comment the line of drawing pixmap the usage then decrease to 3 percent.

    are you sure that Qt doing something extra about using GPU in use of QGLWidget ?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: High CPU Usage in Drawing

    You are drawing a pixmap, not 800 lines. And if you do that through OpenGL then it's the GPU that does that and not the CPU. The latter is busy recalculating your polyline And please don't measure CPU usage in percentages
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: High CPU Usage in Drawing

    In general applications should be designed to use as little resources as possible, starting with the CPU.
    Nonetheless, when there is work to be done, I don't was a slacker CPU that's only giving me 60%, or anything less than 100%, of its capability.

    What really needs to be measured here is performance - is the drawing taking place quickly enough, with "enough" defined to match application requirements. Or, whether or not the entire system is bogging down during drawing, which doesn't seem to be the case.

    As others have already noted, desktop tools are pretty much useless for measuring things like this. On Unix, anyway, there are command line tools and system calls that will report CPU usage over a given timespan; whether there are similar tools in a Windows environment, I don't know, but I imagine there must be.

  4. #4
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: High CPU Usage in Drawing

    Quote Originally Posted by lordhippo View Post
    i change the interval to 50 msec then CPU usage decrease to 25 percent !
    i am now working on do something to avoid repaint all of pixmap every 50 msec .

    now my question is 25 percent just for drawing 800 line is not too high although i use opengl widget ?
    Doesn't that depend on the processor, what other applications are running, and lots of other things?

    If your processor is a 386DX-33, then 25% for your drawing is quite acceptable. If it's a Core i7 975, then 25% is 100% CPU usage of a single core, so it's awful.

    Nonetheless, when there is work to be done, I don't was a slacker CPU that's only giving me 60%, or anything less than 100%, of its capability.
    The only processors that do give you 60% is mobile versions that care about battery life. You have to select whether you want maximum performance or maximum battery life, or let the system decide depending on load over a given time period. Desktop processor typically always run at 100%, the figure is an estimation of what the running processes are currently using in a given time frame. If there is no work to be done (for example, all processes are waiting for timers to expire, I/O, or things like that), the processor might as well be asleep, so it will do so.

  5. The following user says thank you to squidge for this useful post:

    lordhippo (21st May 2010)

  6. #5
    Join Date
    May 2010
    Posts
    5
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: High CPU Usage in Drawing

    hi again

    my computer is a Sony Vaio Z laptop with core2 Duo 2.66 cpu and 4GB Ram.
    after wysota post the previous reply i write a program to tell him that my question is about the true trues.

    here is a very very simple program for test , it just refresh a pixmap without any change in screen .
    my result is when i use QGLWidget : 8-10% cpu usage and when use QWidget about 45-50% just for this program.
    there is some mistake in my program or it is common !

    thanks for your attention
    Attached Files Attached Files

  7. #6
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: High CPU Usage in Drawing

    A Core2 Duo is a dual-core processor, so 50% is an entire core doing nothing but your application. If you put your application on a single core machine, it would use up 100% CPU, constantly.

    You do understand that the 'update' method causes the widget to repaint, and your using it in your repaint function, so the repaint never finishes, right?

  8. The following user says thank you to squidge for this useful post:

    lordhippo (21st May 2010)

  9. #7
    Join Date
    May 2010
    Posts
    5
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: High CPU Usage in Drawing

    yes
    you right . i comment the update function and call it from a timer time-out function and its just working properly , but when i decrease the timer interval lower than 20 msec the cpu usage go up to 25%.
    it is for overlapping the function call ?
    do you know how many time the paintEvent function calls in a second ?

    thank you very very much for your help

  10. #8
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: High CPU Usage in Drawing

    It will be called whenever it needs to be called - eg. if another window is obscurring it, and then moves away, or when you call the update method. It's not a specific number of times per second.

    I don't know why you need to repaint the window 50 times a second either? (1000/20 = 50).

  11. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: High CPU Usage in Drawing

    Quote Originally Posted by lordhippo View Post
    my computer is a Sony Vaio Z laptop with core2 Duo 2.66 cpu and 4GB Ram.
    after wysota post the previous reply i write a program to tell him that my question is about the true trues.

    here is a very very simple program for test , it just refresh a pixmap without any change in screen .
    my result is when i use QGLWidget : 8-10% cpu usage and when use QWidget about 45-50% just for this program.
    there is some mistake in my program or it is common !
    If you want to make a test that has any reliablility, you need to call the function under test few thousand times and measure the total time used by the process (it's not the same as real time elapsing between start and end of the measurement) and then divide it by the number of iterations to know how much time it takes to process the function. For instance to measure time used by the process you can use time(1) on Linux or clock(3) or QBENCHMARK macro from QTestLib regardless of the platform (just use a proper backend).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. PyQt4 app : high CPU usage from python and Xorg
    By tipote in forum Qt Programming
    Replies: 3
    Last Post: 30th January 2012, 17:50
  2. high resolution timer
    By ChasW in forum Qt Programming
    Replies: 18
    Last Post: 24th June 2011, 18:50
  3. High CPU Utilization
    By navi1084 in forum Qt Programming
    Replies: 4
    Last Post: 10th July 2009, 09:37
  4. Very high CPU usage with QTableView and MVC
    By montylee in forum Qt Programming
    Replies: 7
    Last Post: 24th March 2009, 06:14
  5. high processor waste...
    By kernel_panic in forum Qt Programming
    Replies: 4
    Last Post: 9th June 2008, 23:12

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
  •  
Qt is a trademark of The Qt Company.