Skip to main content

Implementing Tracepoints in Qt Applications using Qt Creator 21

Comments

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!

Comments

Subscribe to our blog

Try Qt 6.12 Now!

Download the latest release here: www.qt.io/download

Qt 6.12 LTS is now available, with new features and improvements for application developers and device creators.

We're Hiring

Check out all our open positions here and follow us on Instagram to see what it's like to be #QtPeople.