Refactor startup timing a little by getting the current time the moment the application enters its main function, then passing that to Application's constructor. Also fix the titlebar bug by setting the title bar at the end of initializeGL() instead of at the end of the first frame (which would actually further the inaccuracy of the startup time).

This commit is contained in:
Geenz 2013-05-22 10:53:35 -04:00
parent a8c4e928b8
commit fb553fce80
3 changed files with 43 additions and 41 deletions

View file

@ -114,7 +114,7 @@ void GLCanvas::wheelEvent(QWheelEvent* event) {
Application::getInstance()->wheelEvent(event); Application::getInstance()->wheelEvent(event);
} }
Application::Application(int& argc, char** argv) : Application::Application(int& argc, char** argv, timeval &startup_time) :
QApplication(argc, argv), QApplication(argc, argv),
_window(new QMainWindow(desktop())), _window(new QMainWindow(desktop())),
_glWidget(new GLCanvas()), _glWidget(new GLCanvas()),
@ -152,7 +152,7 @@ Application::Application(int& argc, char** argv) :
_bytesPerSecond(0), _bytesPerSecond(0),
_bytesCount(0) _bytesCount(0)
{ {
gettimeofday(&_applicationStartupTime, NULL); _applicationStartupTime = startup_time;
_window->setWindowTitle("Interface"); _window->setWindowTitle("Interface");
printLog("Interface Startup:\n"); printLog("Interface Startup:\n");
@ -268,6 +268,15 @@ void Application::initializeGL() {
QTimer* idleTimer = new QTimer(this); QTimer* idleTimer = new QTimer(this);
connect(idleTimer, SIGNAL(timeout()), SLOT(idle())); connect(idleTimer, SIGNAL(timeout()), SLOT(idle()));
idleTimer->start(0); idleTimer->start(0);
if (_justStarted) {
float startupTime = (usecTimestampNow() - usecTimestamp(&_applicationStartupTime))/1000000.0;
_justStarted = false;
char title[50];
sprintf(title, "Interface: %4.2f seconds\n", startupTime);
printLog("%s", title);
_window->setWindowTitle(title);
}
} }
void Application::paintGL() { void Application::paintGL() {
@ -403,16 +412,6 @@ void Application::paintGL() {
_frameCount++; _frameCount++;
// If application has just started, report time from startup to now (first frame display)
if (_justStarted) {
float startupTime = (usecTimestampNow() - usecTimestamp(&_applicationStartupTime))/1000000.0;
_justStarted = false;
char title[50];
sprintf(title, "Interface: %4.2f seconds\n", startupTime);
printLog("%s", title);
_window->setWindowTitle(title);
}
} }
void Application::resizeGL(int width, int height) { void Application::resizeGL(int width, int height) {

View file

@ -46,7 +46,7 @@ class Application : public QApplication {
public: public:
static Application* getInstance() { return static_cast<Application*>(QCoreApplication::instance()); } static Application* getInstance() { return static_cast<Application*>(QCoreApplication::instance()); }
Application(int& argc, char** argv); Application(int& argc, char** argv, timeval &startup_time);
void initializeGL(); void initializeGL();
void paintGL(); void paintGL();

View file

@ -20,7 +20,10 @@
int main(int argc, const char * argv[]) { int main(int argc, const char * argv[]) {
Application app(argc, const_cast<char**>(argv)); timeval startup_time;
gettimeofday(&startup_time, NULL);
Application app(argc, const_cast<char**>(argv), startup_time);
printLog( "Created QT Application.\n" ); printLog( "Created QT Application.\n" );
int exitCode = app.exec(); int exitCode = app.exec();
printLog("Normal exit.\n"); printLog("Normal exit.\n");