[Development] Adding Tracepoints to Qt

Rafael Roquetto rafael.roquetto at kdab.com
Fri Feb 10 19:52:22 CET 2017


Hello,

I have been working lately on trying to bring tracing support to Qt,
internally. The idea is to support LTTNG on Linux and ETW on Windows, at
first. Eventually, we would like to add DTrace support as well, if feasible.

LTTNG and ETW offer very distinct APIs, which are very difficult to abstract
together using only C++ and macros. After a few failed attempts, I decided to
go for a code generation. The most relevant reason for this is that both rely
a lot on macros, leaving a very small amount of things that can be done after
the preprocessor has run. Eventually, we decided to go for a code generator,
which is unsurprisingly called 'tracegen', and is written in Perl,usince Qt
already depends on it during build time (not to metion that Perl makes it very
easy to process textual data).

A very *RAW* WIP version can be found here:
    https://codereview.qt-project.org/#/c/185287/2

The commit message sums it up. The idea is that, for each Qt module, one can
define a tracepoint provider. Each tracepoint provider is defined on its own
file. See qtcore.provider on the review above for details (the contents of
that file are merely illustrative for now).

Here are the highlights, though, on how to create a tracepoint:

    1. you add a new entry to the provider file, i.e.

        qwidget_geometry(const QRect &, rect)

    2. On the trace location, you do:

    #include <private/qtraceevent_p.h>
    .
    .
    Q_TRACE(qwidget_geometry, geometry());

And that's it. There are other two macros, Q_DO_TRACE() and Q_TRACE_ENABLED().
Those are mostly relevant for LTTNG. See the commit message for further info.

At this time, this is just a prototype. I would appreciate any kind of
constructive feedback, and hope that we can eventually have the results of
this merged upstream. If anyone has any questions, please don't think twice
before asking :)

Also, bear in mind that I did not put a lot of thought yet on the build
process. I was just trying to make it work.

To get started, I have a couple of questions:

    1. is corelib/global the appropriate place for this?
    2. is utils/tracegen the appropriate location for the code generator?
    3. could someone with qmake knowledge give some feedback on the changes I
        made to the .pri files? I suppose there might be better ways to
        achieve what I want.
    4. specially, what would be the best way to make this work accross
    modules?
    5. For the configure switches, I would prefer -trace [lttng|etw], but
    similar options hint to -lttng and -etw instead (which is what I currently
    have). What would be the best approach?
    6. What subset of Qt types should we support out of the box? I am thinking
    of QString, QByteArray, QRect[F], QSize[F], i.e. geometry types, QUrl,
    etc... ?

Thanks for reading!

Rafael

-- 
Rafael Roquetto | rafael.roquetto at kdab.com | Software Engineer
Klarälvdalens Datakonsult AB, a KDAB Group company
Tel. Sweden (HQ) +46-563-540090, USA +1-866-777-KDAB(5322)
KDAB - The Qt, C++ and OpenGL Experts



More information about the Development mailing list