Sometimes, as a developer, you need to find out why your application is misbehaving. The usual advice is to add tracing or use a profiler.
If you are developing for Qt, you can use the built-in tracing framework. There are Q_TRACE_* macros embedded throughout Qt Core, Gui, Widgets, OpenGL, Qml, Quick, and Quick3D.
The Qt configure script has this option:
-trace [backend] ..... Enable instrumentation with tracepoints.
Currently supported backends are 'etw' (Windows),
'lttng' (Linux), 'ctf' (Common Trace Format, cross-platform)
or 'yes' for auto-detection. [no]
The ctf (Common Trace Format) backend was added in Qt 6.5.
Qt Creator 21’s Profile Mode
I have built Qt 6.12 with the -trace ctf configure parameter as a Release with Debug Information and registered it in Qt Creator.
Below is the Basic Drawing Example running with the Qt Tracepoints backend.
Qt Tracepoints in User Applications
Qt Creator also allows you to use this internal Qt tracing framework within your own Qt based applications.
In the Basic Drawing Example, I would like to know how long the paint operation takes.
Qt Creator 21 includes a Wizard and a Quick Fix for easy usage:
- Setting up the CMake boilerplate code
- Inserting the trace macro into the C++ code
Qt Tracepoints Internals
As mentioned above, the Qt Tracepoints API is internal; however, with the help of Artificial Intelligence, I have prepared an overview at: Instrumented Tracing in Qt — the CTF backend (-trace ctf)
Feedback
What would you expect from the Qt Tracepoints API or from the IDE? Let us know in the comments below!