File: timer.qdoc

package info (click to toggle)
gammaray 3.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 21,612 kB
  • sloc: cpp: 94,643; ansic: 2,227; sh: 336; python: 164; yacc: 90; lex: 82; xml: 61; makefile: 26
file content (69 lines) | stat: -rw-r--r-- 2,928 bytes parent folder | download | duplicates (2)
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
/*
  timer.qdoc

  This file is part of GammaRay, the Qt application inspection and manipulation tool.

  SPDX-FileCopyrightText: 2017 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
  Author: Volker Krause <volker.krause@kdab.com>

  SPDX-License-Identifier: GPL-2.0-or-later

  Contact KDAB at <info@kdab.com> for commercial licensing options.
*/

/*!
    \example timer
    \title Timer
    \brief Analyze out of control timers.
    \ingroup examples-gammaray

    This examples shows GammaRay's capabilities in analyzing timer activity.

    \section1 Problem

    The example application shows two buttons, clicking any one of them is supposed to trigger
    a deferred repaint of the application using two variations of a single-shot timer. In both
    cases we however observe 100% CPU load afterwards.

    Analyzing the CPU load with a debugger or profiler points to frequently firing timers, but
    doesn't support us in finding where that timer actually came from.

    \section1 Investigation

    While the target application is running, open the \l{Timers} view in GammaRay
    to obtain a list of all active timers. Sorting by \uicontrol{Total Wakeups} or
    \uicontrol{Wakeups/Sec} allows to quickly identify timers running amok, such as the
    recurring 0-interval timers in our example.

    When working with a debug build, the context menu on the \l{Timers} view allows you directly
    to navigate to the source code of the created timer object, or timer event receiver.

    \section2 QTimer and QML Timer

    When using timer objects such as QTimer or a QML Timer, you can further inspect those by
    switching to the \l{Object Browser} via the context menu in the \l{Timers} view. In the object
    browser the following inspection views are particularly useful for timer objects:
    \list
        \li The \l{Connections} view allows you to inspect to which action the timeout() signal is connected
            to, which can help to identify the timer if source navigation is not available.
        \li The \l{Methods} view allows to manually stop timers, to verify a specific timer is the source
            of a problem, or to observe if it gets erroneously restarted.
    \endlist

    In the above example, we notice that the QTimer::singleShot property was accidentally left on false,
    causing the timer to fire constantly.

    \snippet timer/timer.cpp Missing setSingleShot

    The \l{Signal Plotter} view of GammaRay can provide additional help in finding too frequently triggering timer
    object, by means of observing their timeout signals.

    \section2 QTimerEvent

    Raw timer events are less commonly used than timer object and provide fewer options for runtime
    diagnostics unfortunately.

    In our example the source of the problem is a missing QObject::killTimer call in the QTimerEvent handler.

    \snippet timer/timer.cpp Missing killTimer
*/