QWidgets Application - High CPU Usage
-
I've noticed over the past few days that my
QWidgets
application seems to have pretty high CPU usage and I really can't understand why or what is causing this high CPU usage.Looking at Task Manager in Windows 10, when the application is idle, nearly 50% of the CPU time is being used by my application. When I say my application is idle, literally nothing is going on - no threads running, no displays updating, nothing. If I pause the debugger, it hits the following line in
main.cpp
:QApplication a(argc, argv); // Initialize my application state here... MainWindow w; w.showMaximized(); return a.exec();
When I "initialize my application state", I load in a settings file using
QSettings
, prepare a few variables and call a few functions but then the application shows theMainWindow
before going idle while waiting for the user to click a "connect" button which hooks up a number of threads, etc and connects to various hardware devices viaQSerialPorts
. At the time of checking the high CPU time, none of this has happened.What debugging features available in Qt Creator can help me figure out what is going on? This seems really unusual behaviour.
Thanks
-
Hi,
Callgrind could be used and you might want to also take a look at KDAB's HotSpot project.
Hope it helps
-
Hi,
Callgrind could be used and you might want to also take a look at KDAB's HotSpot project.
Hope it helps
-
@webzoid For Valgrind integration with Qt Creator, take a look at this.
However, most of the Valgrind tool set is intended to be run under Linux, and you have mentioned Windows 10... Is it possible for you to run your application under Linux? at least to check if it behaves the same and in such case to go ahead with profiling session. -
@webzoid For Valgrind integration with Qt Creator, take a look at this.
However, most of the Valgrind tool set is intended to be run under Linux, and you have mentioned Windows 10... Is it possible for you to run your application under Linux? at least to check if it behaves the same and in such case to go ahead with profiling session.@Pablo-J.-Rogina Unfortunately I don't have access to a Linux machine. There is scope to set up an Ubuntu VM however I've only got a small SSD in my laptop and it would mean clearing the way somehow.
I think I'll just have to do it the old fashioned blood-and-thunder way using
qDebug()
statements. -
@Pablo-J.-Rogina Unfortunately I don't have access to a Linux machine. There is scope to set up an Ubuntu VM however I've only got a small SSD in my laptop and it would mean clearing the way somehow.
I think I'll just have to do it the old fashioned blood-and-thunder way using
qDebug()
statements.