1

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?

Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778
  • Note that even if there is some hack or alternative profiling solution, I am still looking for answer on how to profile slot execution in particular. – Tomáš Zato Apr 20 '17 at 11:47
  • Slot is a general function. Why can't you use a profiler to measure how much time it takes to execute a function? – vahancho Apr 20 '17 at 12:17
  • @vahancho Because I don't know any general purpose profiler that works reliably on windows. Trust me, I tried lot of them and they all sucked. – Tomáš Zato Apr 20 '17 at 13:06

1 Answers1

1

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.

Community
  • 1
  • 1
Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
  • So I implemented this and it kinda works. But the problem is that I use the compile time signal/slot syntax (&MyClass::mySlot) and target->metaObject()->method(metaCall->id()).methodSignature‌​() always returns empty string because the meta method is invalid. Can you add more detail, or should I ask another question specifically about this? – Tomáš Zato Apr 20 '17 at 13:51
  • The linked question is still valid, it just needs another answer that deals with modern call syntax. It's an easy fix to get the method signature from the new syntax as well. I just didn't get to it yet. – Kuba hasn't forgotten Monica Apr 20 '17 at 16:32
  • Is there anything I could have a look on to figure it out? It's not like I need it that desperatelly - at this point I'm better off using manual timers in methods - but I find this digging in Qt internal stuff quite interesting. – Tomáš Zato Apr 20 '17 at 16:42