Results 1 to 5 of 5

Thread: suggestion needed for qglwidget performance timer

  1. #1
    Join Date
    Jan 2011
    Posts
    55
    Thanks
    12
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default suggestion needed for qglwidget performance timer

    I'm building a Qt4.7 application that contains a qglwidget, and I'd like to have a custom performance timer in order to have smooth rotations, translations etc.

    In the qglwidget paintGL routine I have:

    myTimer.start(); // initialized as QTime myTimer
    DrawEverything();
    int elapsed=myTimer.restart();

    elapsed should contain the number of milliseconds needed to DrawEverything(). However, if the scene is empty I get a value of 16, if the opengl scene is filled with about 10000 display lists (which causes the gl viewport to be quite slow), the elapsed value is only 18, while it should be much higher, considering the amount of geometry to be drawn.
    I thought that maybe QTime would probably skip time lost in opengl operations, so I decided to create a custom timer (getTimeOfDay and similar), but the results are the same.
    Anybody successfully created a performance timer to be used with a qglwidget?
    Thanks

  2. #2
    Join Date
    Feb 2006
    Location
    Denmark
    Posts
    11
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: suggestion needed for qglwidget performance timer

    We use the following (platform dependent, Linux) for profiling OpenGL code, which returns a time-stamp in nanoseconds.

    Qt Code:
    1. #include <time.h>
    2.  
    3. inline uint64_t performanceCounter() {
    4. timespec timebase;
    5. clock_gettime(CLOCK_MONOTONIC,&timebase);
    6. return static_cast<uint64_t>(timebase.tv_sec)*1E9+timebase.tv_nsec;
    7. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2011
    Posts
    55
    Thanks
    12
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: suggestion needed for qglwidget performance timer

    Thanks moe, and do you read start and end time at the beginning and end of the draw function as I also do?

  4. #4
    Join Date
    Feb 2006
    Location
    Denmark
    Posts
    11
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: suggestion needed for qglwidget performance timer

    Yes, and also at various other places. We use this to profile the code doing the drawing and the preprocessing done before drawing.

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

    papillon (29th September 2011)

  6. #5
    Join Date
    Sep 2009
    Posts
    31
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: suggestion needed for qglwidget performance timer

    The main problem could be that your drawing is done on GPU. You should call glFinish() before start and before end of measuring to ensure that CPU will wait for GPU. Otherwise you are not measuring drawing but only calls to GPU.

    Qt Code:
    1. glFinish();
    2. myTimer.start(); // initialized as QTime myTimer
    3. DrawEverything();
    4. glFinish();
    5. int elapsed=myTimer.restart();
    To copy to clipboard, switch view to plain text mode 

    As a multiplatform solution you can use Embedded Profiler (free for Windows and Linux) which has a higher resolution. It has an interface to timer in a processor cycle count units and can give you a number of cycles per seconds:

    Qt Code:
    1. EProfilerTimer timer;
    2. glFinish();
    3. timer.Start();
    4. ... // your OpenGL code here
    5. glFinish();
    6. const uint64_t number_of_elapsed_cycles = timer.Stop();
    7. const uint64_t nano_seconds_elapsed =
    8. mumber_of_elapsed_cycles / (double) timer.GetCyclesPerSecond() * 1000000000;
    To copy to clipboard, switch view to plain text mode 

    Note:
    Recalculation of cycle count to time is possibly a dangerous operation with modern processors where CPU frequency can be changed dynamically. Therefore to be sure that converted times are correct, it is necessary to fix processor frequency before profiling.

Similar Threads

  1. timer problem(timer does not work)
    By masuk in forum Newbie
    Replies: 6
    Last Post: 14th February 2011, 05:00
  2. Replies: 8
    Last Post: 9th November 2010, 21:11
  3. Replies: 4
    Last Post: 5th May 2010, 13:24
  4. Replies: 4
    Last Post: 7th May 2008, 00:01
  5. QGLWidget 2d painting performance
    By amnesiac in forum Qt Programming
    Replies: 15
    Last Post: 28th January 2008, 14:09

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.