aboutsummaryrefslogtreecommitdiffstats
path: root/doc/qtcreator/src/analyze/creator-ctf-visualizer.qdoc
blob: 87f63f95e4427c719e890e82b5c0b3cb492ce351 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
/****************************************************************************
**
** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Creator documentation.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
**
****************************************************************************/

// **********************************************************************
// NOTE: the sections are not ordered by their logical order to avoid
// reshuffling the file each time the index order changes (i.e., often).
// Run the fixnavi.pl script to adjust the links to the index order.
// **********************************************************************

/*!
    \previouspage creator-cppcheck.html
    \page creator-ctf-visualizer.html
    \nextpage creator-autotest.html

    \title Visualizing Chrome Trace Events

    You can use \e {full stack tracing} to trace from the top level QML or
    JavaScript down to the C++ and all the way to the kernel space. This
    enables you to measure the performance of an application and to check
    whether it is CPU or I/O bound or influenced by other applications
    running on the same system. Tracing provides insight into what a system is
    doing and why an application is performing in a particular way. It indicates
    how the hardware is utilized and what the kernel and application are doing.

    Tracing information can also provide you additional insight into the data
    collected by \l{Profiling QML Applications}{QML Profiler}. For example, you
    could check why a trivial binding evaluation is taking so long. This might
    be caused by C++ being executed or the disk I/O being slow.

    Several tracing tools (such as \c {chrome://about}) can generate information
    about Chrome trace events in Chrome Trace Format (CTF). You can open CTF
    files in \QC for viewing. This is especially useful when viewing trace files
    larger than 100 MB, which are difficult to view with the built-in
    trace-viewer (\c{chrome://tracing}) due to its high memory usage.

    The visualizer supports all event types used in data that the
    \l {https://lttng.org/}{LTTng} tracing framework generates, converted
    to CTF. However, some of the more advanced event types used, for example,
    in Android system traces, are not supported. The visualizer silently
    ignores unsupported event types.

    The visualizer supports the following event types:

    \list
        \li Begin, end, duration, and instant events
        \li Counter events (graphs)
        \li Metadata events (process and thread name)
    \endlist

    \section1 Opening JSON Files

    To open JSON files for viewing, select \uicontrol Analyze >
    \uicontrol {Chrome Trace Format Viewer} > \uicontrol {Load JSON File}.

    \section1 Visualizing Events

    The \uicontrol Timeline view displays a graphical representation of trace
    events and a condensed view of all recorded events.

    \image qtcreator-ctf-visualizer-timeline.png "Chrome Trace Format Visualizer"

    Each category in the timeline describes a thread in the application. Move
    the cursor on an event (1) on a row to view its duration and event category.
    To display the information only when an event is selected, disable the
    \uicontrol {View Event Information on Mouseover} button (2).

    The outline (3) summarizes the period for which data was collected. Drag
    the zoom range (4) or click the outline to move on the outline. To move
    between events, select the \uicontrol {Jump to Previous Event} and
    \uicontrol {Jump to Next Event} buttons (5).

    Select the \uicontrol {Show Zoom Slider} button (6) to open a slider that
    you can use to set the zoom level. You can also drag the zoom handles (7).
    To reset the default zoom level, right-click the timeline to open the
    context menu, and select \uicontrol {Reset Zoom}.

    Select the \inlineimage filtericon.png
    (\uicontrol {Restrict to Threads}) button (10) to select the threads to
    show.

    \section2 Selecting Event Ranges

    You can select an event range (8) to view the time it represents or to zoom
    into a specific region of the trace. Select the \uicontrol {Select Range}
    button (9) to activate the selection tool. Then click in the timeline to
    specify the beginning of the event range. Drag the selection handle to
    define the end of the range.

    You can use event ranges also to measure delays between two subsequent
    events. Place a range between the end of the first event and the beginning
    of the second event. The \uicontrol Duration field displays the delay
    between the events in milliseconds.

    To zoom into an event range, double-click it.

    To remove an event range, close the \uicontrol Selection dialog.

    \section1 Viewing Statistics

    \image qtcreator-ctf-visualizer-statistics.png

    The \uicontrol Statistics view displays the number of samples each function
    in the timeline was contained in, in total and when on the top of the
    stack (called \c self). This allows you to examine which functions you need
    to optimize. A high number of occurrences might indicate that a function is
    triggered unnecessarily or takes very long to execute.

    \section1 Collecting LTTng Data

    LTTng is a tracing toolkit for Linux that you can apply on embedded Linux
    systems to find out how to optimize the startup time of an application.

    Since Qt 5.13, Qt provides a set of kernel trace points and a tracing
    subsystem for custom user space trace points.

    \section2 Configuring the Kernel

    To use LTTng, you have to set the following configuration options for the
    kernel before building it:

    \list
        \li \c CONFIG_HIGH_RES_TIMERS
        \li \c CONFIG_KALLSYMS
        \li \c CONFIG_MODULES
        \li \c CONFIG_TRACEPOINTS
    \endlist

    We recommend that you set the following additional options:

    \list
        \li \c CONFIG_EVENT_TRACING
        \li \c CONFIG_HAVE_SYSCALL_TRACEPOINTS
        \li \c CONFIG_KALLSYMS_ALL
    \endlist

    In Yocto, you can activate the above options in \uicontrol Menu >
    \uicontrol Config > \uicontrol {Kernel Hacking} > \uicontrol Tracers.

    \section2 Installing LTTng

    After you build the kernel and deploy it on your device, you'll need to
    install the following LTTng packages on your device:

     \list
        \li \c lttng-tools to control the tracing session
        \li \c lttng-modules for kernel trace points
        \li \c lttng-ust for user space trace points
    \endlist

    In Yocto, you just need to enable
    \c {EXTRA_IMAGE_FEATURES += "tools profile"}.

    \section2 Building Qt with Tracepoints

    Trace points are continuously being added to Qt versions. To use them, you
    need to build Qt yourself with the \c {configure -trace lttng} option.

    \section2 Recording Events

    To create a session, you call the \c {lttng create} command. Then you
    call \c {lttng enable-channel kernel -k} to enable the kernel channel.
    Within the kernel channel, you specify the appropriate trace points as
    \c {kernel_events} and call \c {lttng enable-event} to enable them.
    Finally, you call \c {lttng start} to start tracing.

    You call \c {lttng stop} to stop tracing. You can use \c sleep to set the
    length of the session. After stopping, you can call \c {lttng destroy} to
    destroy the session.

    You can write and run scripts that contain the above commands to start and
    stop full-stack tracing. You can use \c systemd to execute the scripts.

    \section2 Enabling Trace Points

    Data is recorded according to the trace points that you enable in the LTTng
    session. Usually, it is useful to enable scheduler switch, syscall, and Qt
    trace points.

    \section3 Scheduler Switch Trace Points

    Scheduler switch trace points are reached when an application is switched
    out due to predemption, for example, when another process gets the chance
    to run on the CPU core. Enable scheduler schwitch trace points to record
    the thread that is currently running and the process it belongs to, as
    well as the time when the process started and stopped.

    \section3 Syscall Trace Points

    Syscall trace points help you to understand why a scheduler switch happened.
    The following are examples of syscalls to trace:

    \list
        \li \c openat and \c close map file descriptors to file names
        \li \c mmap maps page faults to files
        \li \c read and \c write are triggered by I/O operations
        \li \c nanosleep, \c futex, and \c poll explain scheduler switches
        \li \c ioctl controls the GPU and display
    \endlist

    \section1 Converting LTTng Data to CTF

    The \l{https://github.com/KDAB/ctf2ctf}{ctf2ctf} tool uses \c babeltrace to
    parse binary Common Trace Format (CTF) and converts it to Chrome Trace
    Format (CTF). It performs the following custom tasks to make the recording
    more human-readable:

    \list
        \li Map file descriptors to file names
        \li Map page faults to file names
        \li Annotate interrupts and block devices with names
        \li Convert UTF-16 QString data to UTF-8 strings
        \li Count memory page allocations
    \endlist

    To generate JSON files that contain the trace data in Chrome Trace Format,
    enter the following command on the command line:

    \code
    ctf2ctf -o trace.json path/to/lttng trace/
    \endcode
*/