Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for MCUs
  4. QTimer is very inaccurate
QtWS25 Last Chance

QTimer is very inaccurate

Scheduled Pinned Locked Moved Unsolved Qt for MCUs
qtimerqtcppqmlc++timeout
31 Posts 4 Posters 5.5k Views
  • 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
    Pavankumar S V
    wrote on last edited by Pavankumar S V
    #1

    Hello,

    Background:
    I'm starting a QTimer in the main thread of my QT embedded application with a timeout value of 20ms. Also I'm connecting the timeout signal of this timer to a slot(function that needs to be called when there is a 20ms timeout).

    Issue:
    I'm expecting that the timeout signal needs to be generated every 20ms and the slot function needs to be called every 20ms.
    But the timer is getting timeout at every 30/40/50ms.... instead of 20ms. Because of this, the interval at which my slot function should get called is getting delayed and my the performance of my application is getting affected.

    Things that I have tried(but not worked):

    • I have also tried other timeout values like 100ms, 500ms etc...In all these cases, timeout signal is getting generated with a very significant amount of delay. As per the QT's documentation, Qtimers may have inaccuracy of around 5%. But I'm getting inaccuracy of more than 30% most of the times and even 100% sometimes.

    • As per QT's documentation, QTimer will be of type CoarseTimer. I tried changing the timer type to PreciseTimer, but still the timer is significantly inaccurate.

    • We also have other threads other than the main thread. To make sure that other threads are not blocking the timer, I disabled all other user threads. But still the issue remains.

    Please find the code snippet below for reference:

    class MainClass : public QObject
    {
    	Q_OBJECT
    
    public:
            Application specific properties, methods.
    private:
            QTimer *timer;
            Other application specific properties, methods.
    }
    
    MainClass :: MainClass (QObject *parent):
    	QObject(parent)
    {
            //Some initailization functions, getting screen resolution etc..
    
    	timer = new QTimer(this);
    	connect(timer, &QTimer::timeout, this, &MainClass::timerEvnt);
    	timer->start(20);
    }
    
    void MainClass::timerEvnt()
    {
    	/*Function call to do Page Loading using QqmlIncubator to pre-load the qml pages in RAM for avoiding the delay in 
            displaying the page.*/
            //Function call to process the objects in Qml page that is currently being displayed in the screen.
            //Function call to update the strings in the currently displayed page to the selected language.
    }
    
    int main(int argc, char *argv[])
    {
             QApplication *app;
             app = new QApplication(argc, argv);
             MainClass maincls;
             maincls.view = new QQuickView;
    
             maincls.view->setSource(QUrl::fromLocalFile("Path of Loader.qml"));
    
             maincls.view->show();
    
              //starting all the user threads
    
             maincls.view->installEventFilter(&maincls);		//v2.29
           
           	 return app->exec();
    }
    

    Questions

    1. Please let me know if i'm missing something due to which Qtimer is very inaccurate in my case.
    2. Please let me know if there are any alternate options for the Qtimer to execute some functionalities periodically with a high accuracy.

    Thanks in Advance

    jsulmJ JonBJ 2 Replies Last reply
    0
    • P Pavankumar S V

      Hello,

      Background:
      I'm starting a QTimer in the main thread of my QT embedded application with a timeout value of 20ms. Also I'm connecting the timeout signal of this timer to a slot(function that needs to be called when there is a 20ms timeout).

      Issue:
      I'm expecting that the timeout signal needs to be generated every 20ms and the slot function needs to be called every 20ms.
      But the timer is getting timeout at every 30/40/50ms.... instead of 20ms. Because of this, the interval at which my slot function should get called is getting delayed and my the performance of my application is getting affected.

      Things that I have tried(but not worked):

      • I have also tried other timeout values like 100ms, 500ms etc...In all these cases, timeout signal is getting generated with a very significant amount of delay. As per the QT's documentation, Qtimers may have inaccuracy of around 5%. But I'm getting inaccuracy of more than 30% most of the times and even 100% sometimes.

      • As per QT's documentation, QTimer will be of type CoarseTimer. I tried changing the timer type to PreciseTimer, but still the timer is significantly inaccurate.

      • We also have other threads other than the main thread. To make sure that other threads are not blocking the timer, I disabled all other user threads. But still the issue remains.

      Please find the code snippet below for reference:

      class MainClass : public QObject
      {
      	Q_OBJECT
      
      public:
              Application specific properties, methods.
      private:
              QTimer *timer;
              Other application specific properties, methods.
      }
      
      MainClass :: MainClass (QObject *parent):
      	QObject(parent)
      {
              //Some initailization functions, getting screen resolution etc..
      
      	timer = new QTimer(this);
      	connect(timer, &QTimer::timeout, this, &MainClass::timerEvnt);
      	timer->start(20);
      }
      
      void MainClass::timerEvnt()
      {
      	/*Function call to do Page Loading using QqmlIncubator to pre-load the qml pages in RAM for avoiding the delay in 
              displaying the page.*/
              //Function call to process the objects in Qml page that is currently being displayed in the screen.
              //Function call to update the strings in the currently displayed page to the selected language.
      }
      
      int main(int argc, char *argv[])
      {
               QApplication *app;
               app = new QApplication(argc, argv);
               MainClass maincls;
               maincls.view = new QQuickView;
      
               maincls.view->setSource(QUrl::fromLocalFile("Path of Loader.qml"));
      
               maincls.view->show();
      
                //starting all the user threads
      
               maincls.view->installEventFilter(&maincls);		//v2.29
             
             	 return app->exec();
      }
      

      Questions

      1. Please let me know if i'm missing something due to which Qtimer is very inaccurate in my case.
      2. Please let me know if there are any alternate options for the Qtimer to execute some functionalities periodically with a high accuracy.

      Thanks in Advance

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Pavankumar-S-V How busy is your main thread where the timer is running? Maybe the load is very high, so the slot is called with long delay?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      P 1 Reply Last reply
      0
      • P Pavankumar S V

        Hello,

        Background:
        I'm starting a QTimer in the main thread of my QT embedded application with a timeout value of 20ms. Also I'm connecting the timeout signal of this timer to a slot(function that needs to be called when there is a 20ms timeout).

        Issue:
        I'm expecting that the timeout signal needs to be generated every 20ms and the slot function needs to be called every 20ms.
        But the timer is getting timeout at every 30/40/50ms.... instead of 20ms. Because of this, the interval at which my slot function should get called is getting delayed and my the performance of my application is getting affected.

        Things that I have tried(but not worked):

        • I have also tried other timeout values like 100ms, 500ms etc...In all these cases, timeout signal is getting generated with a very significant amount of delay. As per the QT's documentation, Qtimers may have inaccuracy of around 5%. But I'm getting inaccuracy of more than 30% most of the times and even 100% sometimes.

        • As per QT's documentation, QTimer will be of type CoarseTimer. I tried changing the timer type to PreciseTimer, but still the timer is significantly inaccurate.

        • We also have other threads other than the main thread. To make sure that other threads are not blocking the timer, I disabled all other user threads. But still the issue remains.

        Please find the code snippet below for reference:

        class MainClass : public QObject
        {
        	Q_OBJECT
        
        public:
                Application specific properties, methods.
        private:
                QTimer *timer;
                Other application specific properties, methods.
        }
        
        MainClass :: MainClass (QObject *parent):
        	QObject(parent)
        {
                //Some initailization functions, getting screen resolution etc..
        
        	timer = new QTimer(this);
        	connect(timer, &QTimer::timeout, this, &MainClass::timerEvnt);
        	timer->start(20);
        }
        
        void MainClass::timerEvnt()
        {
        	/*Function call to do Page Loading using QqmlIncubator to pre-load the qml pages in RAM for avoiding the delay in 
                displaying the page.*/
                //Function call to process the objects in Qml page that is currently being displayed in the screen.
                //Function call to update the strings in the currently displayed page to the selected language.
        }
        
        int main(int argc, char *argv[])
        {
                 QApplication *app;
                 app = new QApplication(argc, argv);
                 MainClass maincls;
                 maincls.view = new QQuickView;
        
                 maincls.view->setSource(QUrl::fromLocalFile("Path of Loader.qml"));
        
                 maincls.view->show();
        
                  //starting all the user threads
        
                 maincls.view->installEventFilter(&maincls);		//v2.29
               
               	 return app->exec();
        }
        

        Questions

        1. Please let me know if i'm missing something due to which Qtimer is very inaccurate in my case.
        2. Please let me know if there are any alternate options for the Qtimer to execute some functionalities periodically with a high accuracy.

        Thanks in Advance

        JonBJ Online
        JonBJ Online
        JonB
        wrote on last edited by
        #3

        @Pavankumar-S-V
        As @jsulm says: in particular, timerEvnt() comments indicate potentially quite a lot of processing, how long does that take? You won't get another timeout till it concludes. If you comment out (some of) its actions how accurate is the timer then?

        1 Reply Last reply
        1
        • jsulmJ jsulm

          @Pavankumar-S-V How busy is your main thread where the timer is running? Maybe the load is very high, so the slot is called with long delay?

          P Offline
          P Offline
          Pavankumar S V
          wrote on last edited by Pavankumar S V
          #4

          @jsulm , @JonB : Thanks for the response.
          I'm only doing some initializations inside the main thread and finally starting the event loop by calling "return app->exec".
          As per my understanding, main thread should not have consumed too much cpu time. But suprisingly, when checked in htop, it was consuming lot of cpu time(more than 100%). So i tried to limit the cpu usage of main thread using linux utility "cpulimit" and limited the cpu usage of the main thread to 70%,80%....But, there was no improvement in the accuracy of Qtimer.

          I also calculated the time taken to execute everything inside the timeout handler(timerEvnt()) of the QTimer using "QElapsedTimer" and saw that it was taking very less time(around 1/2ms) to complete the execution.

          JonBJ jsulmJ 2 Replies Last reply
          0
          • P Pavankumar S V

            @jsulm , @JonB : Thanks for the response.
            I'm only doing some initializations inside the main thread and finally starting the event loop by calling "return app->exec".
            As per my understanding, main thread should not have consumed too much cpu time. But suprisingly, when checked in htop, it was consuming lot of cpu time(more than 100%). So i tried to limit the cpu usage of main thread using linux utility "cpulimit" and limited the cpu usage of the main thread to 70%,80%....But, there was no improvement in the accuracy of Qtimer.

            I also calculated the time taken to execute everything inside the timeout handler(timerEvnt()) of the QTimer using "QElapsedTimer" and saw that it was taking very less time(around 1/2ms) to complete the execution.

            JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by JonB
            #5

            @Pavankumar-S-V said in QTimer is very inaccurate:

            As per my understanding, main thread should not have consumed too much cpu time.

            I don't understand. You have a timer and its slot running in the main thread. The main thread does not only do what you put in its constructor....

            You will not improve the accuracy of the timer by throttling the CPU if it is already using anywhere near 100%! That indicates it is very "busy" doing something, hence it won't have time to process your timer events quickly! You should find out why this is....

            P 1 Reply Last reply
            1
            • P Pavankumar S V

              @jsulm , @JonB : Thanks for the response.
              I'm only doing some initializations inside the main thread and finally starting the event loop by calling "return app->exec".
              As per my understanding, main thread should not have consumed too much cpu time. But suprisingly, when checked in htop, it was consuming lot of cpu time(more than 100%). So i tried to limit the cpu usage of main thread using linux utility "cpulimit" and limited the cpu usage of the main thread to 70%,80%....But, there was no improvement in the accuracy of Qtimer.

              I also calculated the time taken to execute everything inside the timeout handler(timerEvnt()) of the QTimer using "QElapsedTimer" and saw that it was taking very less time(around 1/2ms) to complete the execution.

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Pavankumar-S-V said in QTimer is very inaccurate:

              So i tried to limit the cpu usage of main thread using linux utility "cpulimit" and limited the cpu usage of the main thread to 70%,80%..

              That's not what you should do and I don't know why you think it could improve anything.
              What I and @JonB asked is: is your main thread too busy? Did you check that? As @JonB pointed out if you're doing too much stuff in the slot then the next timeout will not cause a new slot call untill the current one finishes. You should really check what you are doing in main thread (why is the CPU usage so high?). It's your application you should know what you are doing. You can also use a profiler to see which parts of your code cause most CPU load.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • JonBJ JonB

                @Pavankumar-S-V said in QTimer is very inaccurate:

                As per my understanding, main thread should not have consumed too much cpu time.

                I don't understand. You have a timer and its slot running in the main thread. The main thread does not only do what you put in its constructor....

                You will not improve the accuracy of the timer by throttling the CPU if it is already using anywhere near 100%! That indicates it is very "busy" doing something, hence it won't have time to process your timer events quickly! You should find out why this is....

                P Offline
                P Offline
                Pavankumar S V
                wrote on last edited by Pavankumar S V
                #7

                @JonB, @jsulm :
                Yes understood. But as I mentioned earlier, I'm not doing any time consuming tasks inside the main thread or timerEvnt() from application point of view. So, I could not understand why the cpu load was too high. Qt might be doing something internally that might be causing high cpu load. I wanted to know what could it be.

                The Reason why I tried limiting the cpu usage of main thread:

                Note: One of the main task of timerEvnt() is to exchange data with UI objects of the currently displayed screen.
                Because of the inaccuracy of the QTimer, I am seeing sluggishness when interacting with the UI(This is the actual issue that I'm facing). So, I'm trying to improve the accuracy of the Qtimer and see if it can improve the UI responsiveness.

                I read that "QSGRenderThread" thread is responsible for managing and controlling rendering operations for Qt Quick applications and also helps prevent the user interface from freezing or becoming unresponsive during resource-intensive graphical tasks.
                As my main thread was using too much cpu , I thought "QSGRenderThread" is starving and reducing the cpu usage of main thread may help to get more cpu time for "QSGRenderThread" thereby increasing the performance of the graphics. But this did not happen.

                @jsulm Also you mentioned that profiling might help me get a good picture of what is happening in the application. Can you please share any link with good description of how to profile Embedded QT applications?

                jsulmJ 1 Reply Last reply
                0
                • P Pavankumar S V

                  @JonB, @jsulm :
                  Yes understood. But as I mentioned earlier, I'm not doing any time consuming tasks inside the main thread or timerEvnt() from application point of view. So, I could not understand why the cpu load was too high. Qt might be doing something internally that might be causing high cpu load. I wanted to know what could it be.

                  The Reason why I tried limiting the cpu usage of main thread:

                  Note: One of the main task of timerEvnt() is to exchange data with UI objects of the currently displayed screen.
                  Because of the inaccuracy of the QTimer, I am seeing sluggishness when interacting with the UI(This is the actual issue that I'm facing). So, I'm trying to improve the accuracy of the Qtimer and see if it can improve the UI responsiveness.

                  I read that "QSGRenderThread" thread is responsible for managing and controlling rendering operations for Qt Quick applications and also helps prevent the user interface from freezing or becoming unresponsive during resource-intensive graphical tasks.
                  As my main thread was using too much cpu , I thought "QSGRenderThread" is starving and reducing the cpu usage of main thread may help to get more cpu time for "QSGRenderThread" thereby increasing the performance of the graphics. But this did not happen.

                  @jsulm Also you mentioned that profiling might help me get a good picture of what is happening in the application. Can you please share any link with good description of how to profile Embedded QT applications?

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Pavankumar-S-V You should really find out why you have such a high CPU load.
                  Either use a profiler or disable some code (comment out) until CPU load gets lower then you know which part of your code causes the CPU load.

                  "Because of the inaccuracy of the QTimer, I am seeing sluggishness when interacting with the UI" - I doubt it is "inaccuracy" of QTimer - as already explained if you have such high CPU load then it can delay slot calls. So, before blaming Qt check why you have so high CPU load...

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  P 1 Reply Last reply
                  4
                  • jsulmJ jsulm

                    @Pavankumar-S-V You should really find out why you have such a high CPU load.
                    Either use a profiler or disable some code (comment out) until CPU load gets lower then you know which part of your code causes the CPU load.

                    "Because of the inaccuracy of the QTimer, I am seeing sluggishness when interacting with the UI" - I doubt it is "inaccuracy" of QTimer - as already explained if you have such high CPU load then it can delay slot calls. So, before blaming Qt check why you have so high CPU load...

                    P Offline
                    P Offline
                    Pavankumar S V
                    wrote on last edited by Pavankumar S V
                    #9

                    @jsulm Ok, I will check which part of my application could be causing high cpu load.
                    If possible, can you please share any link with good description of how to profile Embedded QT applications?
                    Thanks a lot for the suggestions

                    @jsulm , @JonB can creating a separate thread for timerEvnt() with a msleep(20) will help me to get good accuracy?

                    JonBJ jsulmJ 3 Replies Last reply
                    0
                    • P Pavankumar S V

                      @jsulm Ok, I will check which part of my application could be causing high cpu load.
                      If possible, can you please share any link with good description of how to profile Embedded QT applications?
                      Thanks a lot for the suggestions

                      @jsulm , @JonB can creating a separate thread for timerEvnt() with a msleep(20) will help me to get good accuracy?

                      JonBJ Online
                      JonBJ Online
                      JonB
                      wrote on last edited by
                      #10

                      @Pavankumar-S-V said in QTimer is very inaccurate:

                      @jsulm , @JonB can creating a separate thread for timerEvnt() with a msleep(20) will help me to get good accuracy?

                      No.

                      1 Reply Last reply
                      2
                      • P Pavankumar S V

                        @jsulm Ok, I will check which part of my application could be causing high cpu load.
                        If possible, can you please share any link with good description of how to profile Embedded QT applications?
                        Thanks a lot for the suggestions

                        @jsulm , @JonB can creating a separate thread for timerEvnt() with a msleep(20) will help me to get good accuracy?

                        jsulmJ Offline
                        jsulmJ Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        @Pavankumar-S-V said in QTimer is very inaccurate:

                        can creating a separate thread for timerEvnt() with a msleep(20) will help me to get good accuracy?

                        I would say it depends whether the slot will be called in main thread or in the same thread where the timer is running. If in the same thread as timer then this could improve the situation (at least if the CPU has more than one core). But even then you should investigate the CPU load.

                        Profiling with GCC: https://www.thegeekstuff.com/2012/08/gprof-tutorial/

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        JonBJ P 4 Replies Last reply
                        2
                        • jsulmJ jsulm

                          @Pavankumar-S-V said in QTimer is very inaccurate:

                          can creating a separate thread for timerEvnt() with a msleep(20) will help me to get good accuracy?

                          I would say it depends whether the slot will be called in main thread or in the same thread where the timer is running. If in the same thread as timer then this could improve the situation (at least if the CPU has more than one core). But even then you should investigate the CPU load.

                          Profiling with GCC: https://www.thegeekstuff.com/2012/08/gprof-tutorial/

                          JonBJ Online
                          JonBJ Online
                          JonB
                          wrote on last edited by JonB
                          #12

                          @jsulm
                          If you want a timer to tick at 20ms and do some processing I cannot see how msleep(20) can do any good anywhere. At best it would occupy the whole desired 20ms interval, leaving no time to do any further processing...? Though you know better than I.

                          jsulmJ 1 Reply Last reply
                          0
                          • P Pavankumar S V

                            @jsulm Ok, I will check which part of my application could be causing high cpu load.
                            If possible, can you please share any link with good description of how to profile Embedded QT applications?
                            Thanks a lot for the suggestions

                            @jsulm , @JonB can creating a separate thread for timerEvnt() with a msleep(20) will help me to get good accuracy?

                            JonBJ Online
                            JonBJ Online
                            JonB
                            wrote on last edited by
                            #13

                            @Pavankumar-S-V
                            You might like to look at the topic Small example showing QTimer slowing to a halt. The important take away is the OP's last post there, https://forum.qt.io/topic/94657/small-example-showing-qtimer-slowing-to-a-halt/16, where the gist is

                            Currently I have moved the logging functionality on a separate thread and this seems to work fine.

                            Something in your application might benefit from being moved to a thread if the main thread is too busy to keep up.

                            But to me this still does not resolve your CPU usage issue. If anything takes near 100% CPU time you have a potential problem keeping up....

                            P 1 Reply Last reply
                            1
                            • JonBJ JonB

                              @jsulm
                              If you want a timer to tick at 20ms and do some processing I cannot see how msleep(20) can do any good anywhere. At best it would occupy the whole desired 20ms interval, leaving no time to do any further processing...? Though you know better than I.

                              jsulmJ Offline
                              jsulmJ Offline
                              jsulm
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

                              @JonB Oh, I should read more carefully :-) msleep() is of course not a good idea

                              https://forum.qt.io/topic/113070/qt-code-of-conduct

                              1 Reply Last reply
                              1
                              • jsulmJ jsulm

                                @Pavankumar-S-V said in QTimer is very inaccurate:

                                can creating a separate thread for timerEvnt() with a msleep(20) will help me to get good accuracy?

                                I would say it depends whether the slot will be called in main thread or in the same thread where the timer is running. If in the same thread as timer then this could improve the situation (at least if the CPU has more than one core). But even then you should investigate the CPU load.

                                Profiling with GCC: https://www.thegeekstuff.com/2012/08/gprof-tutorial/

                                P Offline
                                P Offline
                                Pavankumar S V
                                wrote on last edited by
                                #15

                                @jsulm ok, I will try to profile the application using gprof and see if I can figure out something.
                                Thank you

                                1 Reply Last reply
                                1
                                • JonBJ JonB

                                  @Pavankumar-S-V
                                  You might like to look at the topic Small example showing QTimer slowing to a halt. The important take away is the OP's last post there, https://forum.qt.io/topic/94657/small-example-showing-qtimer-slowing-to-a-halt/16, where the gist is

                                  Currently I have moved the logging functionality on a separate thread and this seems to work fine.

                                  Something in your application might benefit from being moved to a thread if the main thread is too busy to keep up.

                                  But to me this still does not resolve your CPU usage issue. If anything takes near 100% CPU time you have a potential problem keeping up....

                                  P Offline
                                  P Offline
                                  Pavankumar S V
                                  wrote on last edited by
                                  #16

                                  @JonB : Let me check this and see if it is useful for my case
                                  Thank you very much

                                  1 Reply Last reply
                                  1
                                  • jsulmJ jsulm

                                    @Pavankumar-S-V said in QTimer is very inaccurate:

                                    can creating a separate thread for timerEvnt() with a msleep(20) will help me to get good accuracy?

                                    I would say it depends whether the slot will be called in main thread or in the same thread where the timer is running. If in the same thread as timer then this could improve the situation (at least if the CPU has more than one core). But even then you should investigate the CPU load.

                                    Profiling with GCC: https://www.thegeekstuff.com/2012/08/gprof-tutorial/

                                    P Offline
                                    P Offline
                                    Pavankumar S V
                                    wrote on last edited by Pavankumar S V
                                    #17

                                    @jsulm : I tried to profile the application using "gprof" as per your suggestion.

                                    I followed the same procedure that is mentioned in the link shared by you. But the file that holds the profiled data(gmon.out) is not getting generated after running and exiting from the application.

                                    Just to confirm, I followed the following steps:
                                    1) Enabled -pg, -O0 in the compiler, linker and built the qt project.
                                    2) I made the following modification to the main() so that the application returns from main() gracefully(This is one of the condition for gprof):

                                    int main(int argc, char *argv[])
                                    {
                                             QApplication *app;
                                             app = new QApplication(argc, argv);
                                             MainClass maincls;
                                             maincls.view = new QQuickView;
                                    
                                             maincls.view->setSource(QUrl::fromLocalFile("Path of Loader.qml"));
                                    
                                             maincls.view->show();
                                    
                                              //starting all the user threads
                                    
                                             maincls.view->installEventFilter(&maincls);
                                    
                                             exitTimer = new QTimer();
                                             exitTimer->setSingleShot(true);
                                             QObject::connect(exitTimer, &QTimer::timeout, app, &QApplication::quit, Qt::QueuedConnection);
                                             exitTimer->start(85000);  //main event loop should run for 85 sec and return to the main function after that.
                                           
                                             app->exec();
                                    
                                             qDebug()<<"Exiting qt;";   //This message is printed successfully
                                           	 return 0;
                                    }
                                    

                                    The above procedure should have generated "gmon.out" file but it has not. I have used gprof before for C based application and successfully profiled it. But I'm facing this issue when profiling qt application using grpof.

                                    1. Please let me know if I'm missing something during profiling.
                                    2. Please let me know if gprof is a right profiling tool to profile the qt application. As per my experience with gprof before, it is not very suitable for multi threaded applications and also provides info related to only user space.
                                    3. Please guide me to the right way for profiling embedded qt applications as there is very limited information available online related to qt profiling. As I'm working on improving the performance of the qt based device, it would be very useful for me to profile the app.

                                    Thank you

                                    jsulmJ JoeCFDJ 2 Replies Last reply
                                    0
                                    • P Pavankumar S V

                                      @jsulm : I tried to profile the application using "gprof" as per your suggestion.

                                      I followed the same procedure that is mentioned in the link shared by you. But the file that holds the profiled data(gmon.out) is not getting generated after running and exiting from the application.

                                      Just to confirm, I followed the following steps:
                                      1) Enabled -pg, -O0 in the compiler, linker and built the qt project.
                                      2) I made the following modification to the main() so that the application returns from main() gracefully(This is one of the condition for gprof):

                                      int main(int argc, char *argv[])
                                      {
                                               QApplication *app;
                                               app = new QApplication(argc, argv);
                                               MainClass maincls;
                                               maincls.view = new QQuickView;
                                      
                                               maincls.view->setSource(QUrl::fromLocalFile("Path of Loader.qml"));
                                      
                                               maincls.view->show();
                                      
                                                //starting all the user threads
                                      
                                               maincls.view->installEventFilter(&maincls);
                                      
                                               exitTimer = new QTimer();
                                               exitTimer->setSingleShot(true);
                                               QObject::connect(exitTimer, &QTimer::timeout, app, &QApplication::quit, Qt::QueuedConnection);
                                               exitTimer->start(85000);  //main event loop should run for 85 sec and return to the main function after that.
                                             
                                               app->exec();
                                      
                                               qDebug()<<"Exiting qt;";   //This message is printed successfully
                                             	 return 0;
                                      }
                                      

                                      The above procedure should have generated "gmon.out" file but it has not. I have used gprof before for C based application and successfully profiled it. But I'm facing this issue when profiling qt application using grpof.

                                      1. Please let me know if I'm missing something during profiling.
                                      2. Please let me know if gprof is a right profiling tool to profile the qt application. As per my experience with gprof before, it is not very suitable for multi threaded applications and also provides info related to only user space.
                                      3. Please guide me to the right way for profiling embedded qt applications as there is very limited information available online related to qt profiling. As I'm working on improving the performance of the qt based device, it would be very useful for me to profile the app.

                                      Thank you

                                      jsulmJ Offline
                                      jsulmJ Offline
                                      jsulm
                                      Lifetime Qt Champion
                                      wrote on last edited by
                                      #18

                                      @Pavankumar-S-V said in QTimer is very inaccurate:

                                      Enabled -pg, -O0 in the compiler, linker and built the qt project.

                                      Can you show how?

                                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                                      P 1 Reply Last reply
                                      0
                                      • jsulmJ jsulm

                                        @Pavankumar-S-V said in QTimer is very inaccurate:

                                        Enabled -pg, -O0 in the compiler, linker and built the qt project.

                                        Can you show how?

                                        P Offline
                                        P Offline
                                        Pavankumar S V
                                        wrote on last edited by
                                        #19

                                        @jsulm : In the .pro file of qt project, I added these flags like below:

                                        QMAKE_CFLAGS += -Werror -O0 -pg
                                        QMAKE_CXXFLAGS += -Werror -O0 -pg

                                        QMAKE_LFLAGS += -pg

                                        jsulmJ 1 Reply Last reply
                                        0
                                        • P Pavankumar S V

                                          @jsulm : In the .pro file of qt project, I added these flags like below:

                                          QMAKE_CFLAGS += -Werror -O0 -pg
                                          QMAKE_CXXFLAGS += -Werror -O0 -pg

                                          QMAKE_LFLAGS += -pg

                                          jsulmJ Offline
                                          jsulmJ Offline
                                          jsulm
                                          Lifetime Qt Champion
                                          wrote on last edited by
                                          #20

                                          @Pavankumar-S-V Did you do a complete rebuild?

                                          • Delete build folder
                                          • Run qmake
                                          • Build

                                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                                          P 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