Results 1 to 9 of 9

Thread: CPU usage due to curves with many points

  1. #1
    Join Date
    Dec 2017
    Location
    Cesena, Italy
    Posts
    13
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default CPU usage due to curves with many points

    Hello,
    I'm working on an application which uses qwt library to implement an oscilloscope like interface.
    The guy that developed the plots management part before I inherited it used an implementation based on QwtPlotCurve::setRawSamples method.
    The interface features the possibility to switch between two plot tabs, one (1) in which only the last trace is plotted and one (2) in which the last 10 traces are plotted overlapped.

    When I switch from tab (1) to tab (2) the CPU usage increases by several times and it seems to increase with the number of points plotted, for example if I increase the width of the time window.
    This is true even when the data acquisition logic is paused, so the CPU seems to be used just to keep the curves plotted on the screen: if I go back to tab (1) CPU usage goes down, then up again if I switch to tab (2), while no new data is added.

    So my questions:
    1) Is this possible or am I necessarily missing some thread which is regularly calling QwtPlot::replot or something similar?
    2) In case the CPU is really used just to keep the curves on screen (acquisition paused), is QwtPlotDirectPainter::drawSeries like in the oscilloscope example worth giving a try to reduce the CPU usage?
    3) Is there something else I could do?

    I'm not posting source code because the project is pretty big and I haven't got acquainted completely with it yet so it would take a while to extract the part related to plot managements, but if it is necessary to come to a conclusion I'll try to do that.

    Best regards,

    Filippo

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

    Default Re: CPU usage due to curves with many points

    Quote Originally Posted by fcona View Post
    am I necessarily missing some thread which is regularly calling QwtPlot::replot or something similar?
    Qwt does not do any updates on its own - it should be your application being responsible for triggering those updates explicitly.
    I recommend to use your debugger, setting a breakpoint in QwtPlot::replot to find out the culprit.

    Also have a look at the QwtPlotCanvas::BackingStore flag. While it can be an optimization during high frequent updates it should be re-enabled when the content has become stable ( f.e. in pause state ).

    Uwe

  3. The following user says thank you to Uwe for this useful post:

    fcona (9th May 2018)

  4. #3
    Join Date
    Dec 2017
    Location
    Cesena, Italy
    Posts
    13
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: CPU usage due to curves with many points

    Thanks Uwe for the prompt reply!
    Actually even if the data is not updated it seems replot is called by another thread, now I have to follow the thread of signals slots back to its origin.
    Now, since the CPU usage is apparently due to continue replots, could the use of QwtPlotDirectPainter::drawSeries make any difference?

    Bests,

    Filippo

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

    Default Re: CPU usage due to curves with many points

    Quote Originally Posted by fcona View Post
    Now, since the CPU usage is apparently due to continue replots, could the use of QwtPlotDirectPainter::drawSeries make any difference?
    Sure - you draw the new points only on top without repainting the previous parts.
    You could also have a look at a development branch( >= 6.2 ). For certain situations the new QwtPlotCurve::FilterPointsAggressive flag can make the difference.

    Uwe

  6. The following user says thank you to Uwe for this useful post:

    fcona (9th May 2018)

  7. #5
    Join Date
    Dec 2017
    Location
    Cesena, Italy
    Posts
    13
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: CPU usage due to curves with many points

    Thank you very much! I'll surely have a look at that.

    Bests,

    Filippo

  8. #6
    Join Date
    Dec 2017
    Location
    Cesena, Italy
    Posts
    13
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: CPU usage due to curves with many points

    I managed to implement the plot update using the QwtDirectPainter::drawSeries(), but now I have another problem.
    When the trace reaches the end of the screen it restarts from the left side, but the new points instead of replacing old ones are plotted over them.
    This does not happen if I call replot() after drawing the series, but using replot again increases the CPU usage to a condition worse than the initial one, while not calling replot actually improves the CPU usage even if the screen gets cluttered with points after the trace reaches the right end a bunch of times.
    I see that in the oscilloscope example the window is moved to the right when the trace reaches the right end, while in my case I keep the origin of time axis at 0 seconds (I do want one trace to be visible until the following one "eats" it away). Is there a way to configure the painter to work this way?

    Bests,

    Filippo

  9. #7
    Join Date
    Dec 2017
    Location
    Cesena, Italy
    Posts
    13
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: CPU usage due to curves with many points

    Ok, I just read this warning in QwtDirectPainter documentation:
    "Incremental painting will only help when no replot is triggered by another operation ( like changing scales ) and nothing needs to be erased."
    So I guess I should give up this development branch...

    Any other trick for improving performance is very welcome. I need to handle both the case in which there's only one trace that "eats" its own tail after reaching the right end of the screen and the case in which the last N traces are kept on the monitor (at the moment I have N QwtPlotCurve which I update circularly with new traces with setRawSamples method). The problem in the end is that in case 2 the N traces create quite a lot of points for replot to handle and while on my development desktop the application runs almost smoothly, it will crash on a typical notebook as soon as I increase the sampling rate a bit. Moreover, my actual implementation is completely non scalable: the CPU usage depends on the number of traces which I simply cannot increase too much, no matter how powerful my pc is.

    Bests,

    Filippo

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

    Default Re: CPU usage due to curves with many points

    Quote Originally Posted by fcona View Post
    I need to handle both the case in which there's only one trace that "eats" its own tail after reaching the right end of the screen...
    Well this one should be doable with using QwtDirectPainter. All you need to do is to call replot manually once, when the curve restarts - like it is done in the oscilloscope example.

    and the case in which the last N traces are kept on the monitor (at the moment I have N QwtPlotCurve which I update circularly with new traces with setRawSamples method).
    In this case all previous points have a different position, what means you always have to replot. Then it depends on how many points you have and of course on the specific attributes being used for drawing the curve.

    For reducing the number of points I again recommend to have a look at the QwtPlotCurve::FilterPointsAggressive flag. It is useful for line plots being monotonic in x or y direction. The effect is, that it limits the number of points to be rendered in the worst case to 4 * the canvas width ( or height ).

    Concerning the attributes: antialiasing or a pen width > 1 slow down rendering. You could also try a OpenGL canvas ( better use trunk then ) - or Qt4/X11 ( graphicssystem=native ), what is the best choice for hardware acceleration. Guess you don't use symbols - as this doesn't make too much sense for your type of plot.

    And of course always decouple the refresh rate of the plot from the sample rate. 10 fps should be by far good enough for oscilloscopes as only few pixels on screen are changing, but often less frequent updates are fine as well.

    Uwe

  11. #9
    Join Date
    Dec 2017
    Location
    Cesena, Italy
    Posts
    13
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: CPU usage due to curves with many points

    Quote Originally Posted by Uwe View Post
    Well this one should be doable with using QwtDirectPainter. All you need to do is to call replot manually once, when the curve restarts - like it is done in the oscilloscope example.
    The oscilloscope example is a bit different because it completely clears the old trace, while in my case it'd need to disappear gradually as the new trace is plotted over it (For some odd reason which I haven't figured out yet in my case calling the replot when the curve restarts as you suggest doesn't even clear the plot, but that's most probably due to something stupid I did...)
    Maybe these images can clear what I mean:
    oscilloscope:
    oscilloscope.png
    my application:
    my application.jpg
    This is my application with the 10 traces overlapped (the more saturated the color the more recent the trace):
    10 traces.jpg

    Not sure what you mean by
    In this case all previous points have a different position
    For reducing the number of points I again recommend to have a look at the QwtPlotCurve::FilterPointsAggressive flag.
    I checked it and it is very interesting because I already do something similar to reduce the amount of points when there are just too many to plot compared to the available widht in pixels, so I might switch to using QwtPlotCurve::FilterPointsAggressive that seems much more optimized!
    Concerning the attributes: antialiasing or a pen width > 1 slow down rendering
    When I inherited the software it had a pen width of 2 and actually it was much more demanding. Fortunately I read on a forum that it could be a good idea to use thin curves and corrected them.
    You could also try a OpenGL canvas
    Is there any example of how I can use OpenGL canvas?
    10 fps should be by far good enough for oscilloscopes
    That's exactly my refresh rate

    Thanks again for the great support!

    Filippo

Similar Threads

  1. Replies: 3
    Last Post: 16th December 2015, 20:39
  2. Replies: 2
    Last Post: 2nd May 2012, 10:49
  3. qwt several curves at a plot
    By freude3 in forum Qwt
    Replies: 4
    Last Post: 4th January 2011, 08:45
  4. Multiple curves on top of each other
    By jmsbc in forum Qwt
    Replies: 2
    Last Post: 15th July 2009, 20:46
  5. Replies: 2
    Last Post: 12th September 2008, 09:43

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.