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 frame rendering time
Forum Updated to NodeBB v4.3 + New Features

Measuring frame rendering time

Scheduled Pinned Locked Moved Unsolved General and Desktop
18 Posts 4 Posters 2.1k Views 2 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.
  • mrjbomM Offline
    mrjbomM Offline
    mrjbom
    wrote on last edited by
    #3
    This post is deleted!
    1 Reply Last reply
    0
    • Kent-DorfmanK Kent-Dorfman

      two things:

      • clock resolution is platform dependent so don't expect microsecond or nanosecond precision unless you know for a fact that your clock supports it

      • you are using a mult-tasking system that may preempt your code, so unless you disable interrupts while generating your frame, the timing of that frame generation shouldn't be considered highly accurate.

      The long and short of it is that you cannot measure frame render efficiency the way you are trying to. About as close as you can get would be to iteratively accumulate thousands of render times, then subtract the percentage of CPU time that is not spent on the actual render, and then divide it out to get an "average" render time.

      mrjbomM Offline
      mrjbomM Offline
      mrjbom
      wrote on last edited by
      #4

      @Kent-Dorfman Describe in more detail how you suggest I measure the frame rendering time?

      artwawA 1 Reply Last reply
      0
      • mrjbomM mrjbom

        @Kent-Dorfman Describe in more detail how you suggest I measure the frame rendering time?

        artwawA Offline
        artwawA Offline
        artwaw
        wrote on last edited by
        #5

        @mrjbom

        QTimer timer;
        timer.setTimerType(Qt::PreciseTimer);
        timer.start();
        //do your rendering here
        qDebug() << timer.elapsed();
        

        Accuracy of this, however, like @Kent-Dorfman mentioned, is platform-dependent.

        For more information please re-read.

        Kind Regards,
        Artur

        mrjbomM 1 Reply Last reply
        1
        • mrjbomM Offline
          mrjbomM Offline
          mrjbom
          wrote on last edited by
          #6
          This post is deleted!
          1 Reply Last reply
          0
          • artwawA artwaw

            @mrjbom

            QTimer timer;
            timer.setTimerType(Qt::PreciseTimer);
            timer.start();
            //do your rendering here
            qDebug() << timer.elapsed();
            

            Accuracy of this, however, like @Kent-Dorfman mentioned, is platform-dependent.

            mrjbomM Offline
            mrjbomM Offline
            mrjbom
            wrote on last edited by
            #7

            @artwaw, How does your timer differ from the one I use?
            I believe it will also give values with a large difference.
            In addition, I am interested in exactly in microseconds.

            1 Reply Last reply
            0
            • nageshN Offline
              nageshN Offline
              nagesh
              wrote on last edited by nagesh
              #8

              @mrjbom said in Measuring frame rendering time:

              As per QT Doc

              If you need to trigger a repaint from places other than paintGL() 
              (a typical example is when using timers to animate scenes),
               you should call the widget's update() function to schedule an update.
              

              I feel if you want to measure the frame rendering time

              void MainOpenGLWidget::paintGL()
              {
              QElapsedTimer framerateTime;
              framerateTime.start();

              sceneManager->callInitSceneAndOptionsWidget(this->width(), this->height());
              sceneManager->callDrawScene();
              
              lastFrameRenderTimeInNanoseconds = framerateTime.nsecsElapsed();
              

              }

              1 Reply Last reply
              0
              • Kent-DorfmanK Offline
                Kent-DorfmanK Offline
                Kent-Dorfman
                wrote on last edited by
                #9

                I just noticed something. You should not call update() from within paintGL(). It works the other way around: update(), whether called implicitly or explicitly, calls paintGl() to render the scene...paintGL() is a virtual callback, not a slot.

                public:
                    render_time;
                void paintGl() {
                    begin_time=now()
                    // do stuff
                    render_time = now() - begin_time
                }
                

                I light my way forward with the fires of all the bridges I've burned behind me.

                mrjbomM 2 Replies Last reply
                1
                • Kent-DorfmanK Kent-Dorfman

                  I just noticed something. You should not call update() from within paintGL(). It works the other way around: update(), whether called implicitly or explicitly, calls paintGl() to render the scene...paintGL() is a virtual callback, not a slot.

                  public:
                      render_time;
                  void paintGl() {
                      begin_time=now()
                      // do stuff
                      render_time = now() - begin_time
                  }
                  
                  mrjbomM Offline
                  mrjbomM Offline
                  mrjbom
                  wrote on last edited by mrjbom
                  #10

                  @Kent-Dorfman, do you suggest not calling update() at all?
                  If I don't call it from paintGL() or other places, then my frames don't update(sometimes abruptly update themselves).

                  1 Reply Last reply
                  0
                  • Kent-DorfmanK Kent-Dorfman

                    I just noticed something. You should not call update() from within paintGL(). It works the other way around: update(), whether called implicitly or explicitly, calls paintGl() to render the scene...paintGL() is a virtual callback, not a slot.

                    public:
                        render_time;
                    void paintGl() {
                        begin_time=now()
                        // do stuff
                        render_time = now() - begin_time
                    }
                    
                    mrjbomM Offline
                    mrjbomM Offline
                    mrjbom
                    wrote on last edited by
                    #11

                    @Kent-Dorfman, @nagesh, The documentation says: The signals aboutToCompose() and frameSwapped() will be emitted when the composition is starting and ending.

                    What happens if I start measuring the time when aboutToCompose() happens and end the change when frameSwapped() happens, so I get the frame rendering time?

                    1 Reply Last reply
                    0
                    • nageshN Offline
                      nageshN Offline
                      nagesh
                      wrote on last edited by
                      #12

                      @mrjbom calling update will schedule the paint event for the processing which means internally it triggers paintGL().
                      For constant update of frames you can do it with the QTimer slot call update()
                      or as soon as new frame is available call update()

                      As per QT doc
                      in frameSwapped()

                      This signal is emitted after the potentially blocking buffer swap has been done. 
                      Applications that wish to continuously repaint synchronized to the vertical refresh,
                       should issue an update() upon this signal. This allows for a much smoother experience 
                      compared to the traditional usage of timers.
                      

                      I feel frame rendering is happening in paintGL()

                      mrjbomM 1 Reply Last reply
                      1
                      • nageshN nagesh

                        @mrjbom calling update will schedule the paint event for the processing which means internally it triggers paintGL().
                        For constant update of frames you can do it with the QTimer slot call update()
                        or as soon as new frame is available call update()

                        As per QT doc
                        in frameSwapped()

                        This signal is emitted after the potentially blocking buffer swap has been done. 
                        Applications that wish to continuously repaint synchronized to the vertical refresh,
                         should issue an update() upon this signal. This allows for a much smoother experience 
                        compared to the traditional usage of timers.
                        

                        I feel frame rendering is happening in paintGL()

                        mrjbomM Offline
                        mrjbomM Offline
                        mrjbom
                        wrote on last edited by
                        #13

                        @nagesh said in Measuring frame rendering time:

                        I feel frame rendering is happening in paintGL()

                        In paintGL, the frame is being prepared. So it is useless to measure time there.

                        1 Reply Last reply
                        0
                        • nageshN Offline
                          nageshN Offline
                          nagesh
                          wrote on last edited by
                          #14

                          @mrjbom read the description for paintGL()
                          https://doc.qt.io/qt-5/qopenglwidget.html
                          it says.. paintGL() - Renders the OpenGL scene. Gets called whenever the widget needs to be updated.

                          What does your function
                          sceneManager->callDrawScene() doing?

                          mrjbomM 1 Reply Last reply
                          0
                          • nageshN nagesh

                            @mrjbom read the description for paintGL()
                            https://doc.qt.io/qt-5/qopenglwidget.html
                            it says.. paintGL() - Renders the OpenGL scene. Gets called whenever the widget needs to be updated.

                            What does your function
                            sceneManager->callDrawScene() doing?

                            mrjbomM Offline
                            mrjbomM Offline
                            mrjbom
                            wrote on last edited by
                            #15

                            @nagesh It draws the current scene. The usual functions that are usually found in paintGL().

                            In any case, if I measure the time only within paintGL (), then the time is constantly different from the previous one.
                            Probably because QElapsedTimer reads the time within the operating system, not my application, so due to the task switching by the operating system, it is different.
                            How can I measure the time regardless of the task switching by the operating system?

                            Kent-DorfmanK 1 Reply Last reply
                            0
                            • nageshN Offline
                              nageshN Offline
                              nagesh
                              wrote on last edited by
                              #16

                              @mrjbom There is class in qt QOpenGLTimerQuery
                              https://doc.qt.io/qt-5/qopengltimerquery.html

                              Whether it's applicable for your requirement not sure.

                              mrjbomM 1 Reply Last reply
                              0
                              • mrjbomM mrjbom

                                @nagesh It draws the current scene. The usual functions that are usually found in paintGL().

                                In any case, if I measure the time only within paintGL (), then the time is constantly different from the previous one.
                                Probably because QElapsedTimer reads the time within the operating system, not my application, so due to the task switching by the operating system, it is different.
                                How can I measure the time regardless of the task switching by the operating system?

                                Kent-DorfmanK Offline
                                Kent-DorfmanK Offline
                                Kent-Dorfman
                                wrote on last edited by Kent-Dorfman
                                #17

                                @mrjbom Dude! We've been over this. You cannot accurately measure the time spent in a call that takes nanoseconds or microseconds to complete. you are not using a realtime OS. Either research the science of RTOS or give up on getting consistent numbers.

                                I light my way forward with the fires of all the bridges I've burned behind me.

                                1 Reply Last reply
                                1
                                • nageshN nagesh

                                  @mrjbom There is class in qt QOpenGLTimerQuery
                                  https://doc.qt.io/qt-5/qopengltimerquery.html

                                  Whether it's applicable for your requirement not sure.

                                  mrjbomM Offline
                                  mrjbomM Offline
                                  mrjbom
                                  wrote on last edited by
                                  #18

                                  @nagesh Got it! This is what I need.
                                  To be more precise, QOpenGLTimeMonitor () helped me.
                                  Thank you for your help.

                                  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