Results 1 to 12 of 12

Thread: CPU load strongly increasing when making simple animation

  1. #1
    Join Date
    Jun 2015
    Posts
    6
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Exclamation CPU load strongly increasing when making simple animation

    I found that my application consumes more and more CPU power it time when making a simple animation.

    I wrote a simple program so everyone could check what am i talking about:

    Qt Code:
    1. import QtQuick 2.3
    2. import QtQuick.Controls 1.2
    3. import QtQuick.Window 2.2
    4.  
    5.  
    6. ApplicationWindow {visible: true; width: 640; height: 480;
    7.  
    8. Window{ height: 100; width: 100; visible: true; objectName: "w1"; id:w1;
    9. Image{anchors.fill: parent; source: sw?"qrc:/images/1":"qrc:/images/2"; }
    10. }
    11.  
    12. Window{ height: 100; width: 100; visible: true; objectName: "w2"; id:w2;
    13. Image{anchors.fill: parent; source: sw?"qrc:/images/1":"qrc:/images/2"; }
    14. }
    15.  
    16. Window{ height: 100; width: 100; visible: true; objectName: "w3"; id:w3;
    17. Image{anchors.fill: parent; source: sw?"qrc:/images/1":"qrc:/images/2"; }
    18. }
    19.  
    20. property bool sw: false;
    21. Timer { interval: 30;running: true;repeat: true;
    22. onTriggered: {sw=!sw;}
    23. }
    24.  
    25. }
    To copy to clipboard, switch view to plain text mode 
    001.jpg

    It happens only if animations is in few separate windows.
    If i completely reload animated windows with Loader{}, everything resets and CPU load starts to increase from beginning.( but I can't use such quick fix in my program!)
    If i reload only Image{} with Loader{}, it does not help.

    It happens also if i creating custom QQuickPaintedItem in two or more QQuickWindows and calling them update() method. EVEN WITH NO ACTUAL DRAWING!!!

    This issue was tested with Ubuntu 12.04+qt5.4.2+intel_video and ubuntu14.04+qt5.3.2+radeon_video.
    I need a quick fix for this!!!

    I had already tried to periodically call releaseResources() method and resetOpenGLState() method of QQuickWindow.

    Can anyone test this issue or give me an advise?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: CPU load strongly increasing when making simple animation

    Have you tried to not reload images all the time?

    Cheers,
    _

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

    Default Re: CPU load strongly increasing when making simple animation

    Where are the animations?
    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.


  4. #4
    Join Date
    Jun 2015
    Posts
    6
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: CPU load strongly increasing when making simple animation

    I am just swapping two images because it is just a test program. In my actual program i were acquiring images from camera. And i spend a day only to understand that this CPU issue is not related with camera, but with image drawing (or maybe even just a window content redrawing). It was very unexpected for me.

    Try it yourself. the code is very easy to compile, you just need two images. I was using these
    arrow1.png
    arrow2.png

    A program should not have these strange behaviour and slowly consume CPU. I could understand if it were RAM consumption, but this CPU consumption is very strange.

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: CPU load strongly increasing when making simple animation

    Quote Originally Posted by DDDIM View Post
    A program should not have these strange behaviour and slowly consume CPU. I could understand if it were RAM consumption, but this CPU consumption is very strange.
    You are constantly triggering CPU bound operations, why are you expecting the program to not use CPU?

    Data in a Qt resource is compressed, loading requires decompression (CPU bound operation 1).
    The image format might not be simple bitmap, loading requires decodign (CPU bound operation 2).
    Decoded image data might not have the same channel setup as the display, loading requires conversion (CPU bound operation 3, though some of that might be delegated to the GPU).

    Destroying and creating image buffers usually also requires CPU involvment.

    Try loading both images into one Image element each, and then switching visibiliy

    Qt Code:
    1. Window{ height: 100; width: 100; visible: true; objectName: "w1"; id:w1;
    2. Image{anchors.fill: parent; visible: sw; source: "qrc:/images/1"; }
    3. Image{anchors.fill: parent; visible: !sw; source: "qrc:/images/2"; }
    4. }
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

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

    Default Re: CPU load strongly increasing when making simple animation

    Or use a SpriteAnimation.
    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.


  7. #7
    Join Date
    Jun 2015
    Posts
    6
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: CPU load strongly increasing when making simple animation

    anda_skoa, I fully undenstand what you are talking about, but try to understand me too:

    1. this is a test program written for simplicity of explaining my issue, in my actual program, where i faced this issue i was getting images from webcamera, and firstly I thought that it is related with Image acquisition from camera, but i was wrong. Image acqusition was OK. It was a drawing in QQuickWindow. Namely not actual drawing(I commented all the drawing out, but issue has not disappeared) but calling update() method of my custom QQuickPaintedItem. I continued digging and ended with that simple program in first post.
    2. In first post i uploaded picture, showing that CPU load starts from less than 20% when the program starts, then I doing nothing, program runs simple image swapping and CPU load increasing linearly over time and in approx. 100 seconds it ends up at 60%. But program still does SAME thing!!! CPU load was increased in 3 times!
    3. Also very interesting is that when I apply putenv("LIBGL_ALWAYS_SOFTWARE=1"); in main.cpp this issue goes away and i have CONSTANT low CPU usage. But in my real application I need hardware rendering, so it is not an option for me.
    4. I think this is not a hardware or opengl-library-related issue because I tested it on two different machines with different video-adaptors and Ubuntu versions, as I wrote in first post.
    Last edited by DDDIM; 27th June 2015 at 15:36.

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

    Default Re: CPU load strongly increasing when making simple animation

    Apparently your GL implementation is broken. And painted items are slow, so it's likely you are hitting some slow code path.

    Which doesn't change the fact that your example is not a good test of your problem. The fact that something is "slow" doesn't mean the reason for it being "slow" is the same as in a different situation.
    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.


  9. #9
    Join Date
    Jun 2015
    Posts
    6
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: CPU load strongly increasing when making simple animation

    Ok. Here is another example.

    main.qml:
    Qt Code:
    1. import QtQuick 2.3
    2. import QtQuick.Controls 1.2
    3. import QtQuick.Window 2.2
    4.  
    5. ApplicationWindow {visible: true; width: 640; height: 480;
    6. Window{ height: 100; width: 100; visible: true; objectName: "w1"; id:w1; }
    7. Window{ height: 100; width: 100; visible: true; objectName: "w2"; id:w2; }
    8. Window{ height: 100; width: 100; visible: true; objectName: "w3"; id:w3; }
    9. }
    To copy to clipboard, switch view to plain text mode 

    main.cpp:
    Qt Code:
    1. #include <QApplication>
    2. #include <QQmlApplicationEngine>
    3. #include "worker.h"
    4.  
    5. QQmlApplicationEngine* engine;
    6.  
    7. int main(int argc, char *argv[])
    8. {
    9. //putenv("LIBGL_ALWAYS_SOFTWARE=1");
    10. QApplication app(argc, argv);
    11.  
    12. engine = new QQmlApplicationEngine(QUrl("qrc:/main.qml"));
    13.  
    14. worker = new Worker();
    15. worker->setConnections();
    16.  
    17. return app.exec();
    18. }
    To copy to clipboard, switch view to plain text mode 


    worker.h:
    Qt Code:
    1. #ifndef WORKER_H
    2. #define WORKER_H
    3.  
    4. #include <QObject>
    5. #include "QTimer"
    6.  
    7. class Worker : public QObject
    8. {
    9. Q_OBJECT
    10. public:
    11. explicit Worker(QObject *parent = 0);
    12. QTimer timer;
    13.  
    14. public slots:
    15. void setConnections();
    16. void reset();
    17. };
    18.  
    19. extern Worker* worker;
    20. extern QObject *root;
    21.  
    22. #endif // WORKER_H
    To copy to clipboard, switch view to plain text mode 

    worker.cpp:
    Qt Code:
    1. #include "worker.h"
    2. #include "QtQuick/QQuickView"
    3. #include "QtQml/QQmlApplicationEngine"
    4. #include "QQuickWindow"
    5.  
    6. Worker* worker;
    7. extern QQmlApplicationEngine* engine;
    8. QQuickWindow *w1,*w2,*w3;
    9. QObject *root;
    10.  
    11. Worker::Worker(QObject *parent) :
    12. QObject(parent)
    13. {
    14. root = engine->rootObjects().first();
    15. w1 = root->findChild<QQuickWindow*>(QString("w1"));
    16. w2 = root->findChild<QQuickWindow*>(QString("w2"));
    17. w3 = root->findChild<QQuickWindow*>(QString("w3"));
    18. timer.setInterval(30);
    19. timer.start();
    20. }
    21.  
    22. void Worker::setConnections(){ connect(&this->timer,SIGNAL(timeout()),this,SLOT(reset())); }
    23.  
    24. void Worker::reset(){
    25. w1->update();
    26. w2->update();
    27. w3->update();
    28. }
    To copy to clipboard, switch view to plain text mode 

    it shows all the same results.

    In stackoverflow forum Ansh helped me to find out that this it opensource-driver-related issue, but I can't use proprietary driver because it does not support my target PC's videoadapter radeon x300 and Intel builtin graphics.

    I compiled most fresh mesa release (10.5.8) but it did not helped.

    I don't know what to do now.
    Last edited by DDDIM; 28th June 2015 at 11:44.

  10. #10
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: CPU load strongly increasing when making simple animation

    Interesing find!

    I modifed the example a bit so it can be run with just qmlscene:
    Qt Code:
    1. import QtQuick 2.3
    2. import QtQuick.Controls 1.2
    3. import QtQuick.Window 2.2
    4.  
    5. ApplicationWindow {visible: true; width: 640; height: 480;
    6. Window{ height: 100; width: 100; visible: true; objectName: "w1"; id:w1; }
    7. Window{ height: 100; width: 100; visible: true; objectName: "w2"; id:w2; }
    8. Window{ height: 100; width: 100; visible: true; objectName: "w3"; id:w3; }
    9.  
    10. Timer {
    11. interval: 30
    12. repeat: true
    13. running: true
    14.  
    15. onTriggered: {
    16. w1.update();
    17. w2.update();
    18. w3.update();
    19. }
    20. }
    21. }
    To copy to clipboard, switch view to plain text mode 
    Indeed a constant increase in CPU load on my Intel GPU.
    It seems to behave stably if I close two of the three sub windows.

    To check if this has anything to do with multithreaded redering, I disabled Qt's GL sanity check (enabling multithreaded rendering despite Mesa being blacklisted):
    QT_OPENGL_NO_SANITY_CHECK=1 qmlscene updatetest.qml

    On one run it did not crash immediately and seemed to stay at a low CPU usage, but maybe it didn't run long enough yet.
    That is with Mesa 10.5.5, you could check if it survives with 10.5.8

    Cheers,
    _

  11. The following user says thank you to anda_skoa for this useful post:

    DDDIM (28th June 2015)

  12. #11
    Join Date
    Jun 2015
    Posts
    6
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: CPU load strongly increasing when making simple animation

    Just checked on mesa Mesa 8.0.4(from standard 12.04 repo)
    Qt Code:
    1. putenv("QT_OPENGL_NO_SANITY_CHECK=1");
    To copy to clipboard, switch view to plain text mode 
    CPU load was stable low until program crashed with
    Qt Code:
    1. imageTest: ../../src/xcb_conn.c:180: write_vec: Проверочное утверждение «!c->out.queue_len» не выполнено.
    To copy to clipboard, switch view to plain text mode 

    001.jpg

    I had already deleted 10.5.8. Reinstalling and rechecking now.

    Checked! All the same. CPU load low, but it crashes. If i run some other opengl program(glxgears) in parralel, it crashes much later and I can measure CPU usage.


    Added after 53 minutes:


    Any suggestions? is this a Qt or MESA issue? Don't have any idea what else should I try. Digging in source code can take forever.

    I had tried to analyse the CPU consumption with valgrind, but when I run test program with profiler(even with paused event recording), CPU loading already high (approx 60%) and doesn't changing. I have a feeling that some kind of CPU usage threshold is being reached.
    Last edited by DDDIM; 28th June 2015 at 14:53.

  13. #12
    Join Date
    Jun 2015
    Posts
    6
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: CPU load strongly increasing when making simple animation

    anda_skoa, please vote a bug on Qt bugtracker: https://bugreports.qt.io/browse/QTBUG-46900

Similar Threads

  1. Replies: 4
    Last Post: 10th October 2009, 17:59
  2. trouble making simple DOM model example editable
    By Mamra in forum Qt Programming
    Replies: 6
    Last Post: 1st October 2009, 14:40
  3. Simple Animation Help (Nevermind)
    By Pembar in forum Qt Programming
    Replies: 1
    Last Post: 19th May 2009, 12:33
  4. QT Animation Simple Pushbutton Help
    By Pembar in forum Qt Programming
    Replies: 4
    Last Post: 6th May 2009, 13:38
  5. Making some simple help for my application
    By Godlike in forum Newbie
    Replies: 9
    Last Post: 21st April 2006, 18: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.