Search code examples
c++qtprofilingsignals-slots

Can I get Qt to profile signal-slot execution duration?


I have a Qt console application on windows. I want to profile it, but QtCreator profiling does not work on windows.

I have just a few signals/slots which I use. The aplication is single threaded, every connection is Qt::QueuedConnection.

Could Qt log how much time it took to execute every slot that was called from the event loop? It would help me finding CPU bottleneck without manually adding timers everywhere in the program.

Is it maybe possible to override the slot calling mechanism and measure time when the called slot was executing?


Solution

  • Queued slot calls are delivered as a QMetaCallEvent to the receiving QObject. Thus you could time the QCoreApplication::notify when it delivers these events: the QObject::event is invoked from within that method.

    There are two aspects of this:

    1. Timing and data collection - see this answer for a complete example.

    2. Decoding the contents of QMetaCallEvent to know which method was called - see this question.